From 6dd74eb24b27040762b592111ac63a425392df2c Mon Sep 17 00:00:00 2001 From: nikola-bozin-txfusion Date: Thu, 28 Mar 2024 12:54:57 +0100 Subject: [PATCH 1/2] chore: include additional tests --- .../contracts/Greeter.vy | 13 +++ .../hardhat.config.ts | 33 +++++++ packages/hardhat-zksync-vyper/test/tests.ts | 98 ++++++++++++++++++- 3 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 packages/hardhat-zksync-vyper/test/fixture-projects/unsupported-fallback-optimize/contracts/Greeter.vy create mode 100644 packages/hardhat-zksync-vyper/test/fixture-projects/unsupported-fallback-optimize/hardhat.config.ts diff --git a/packages/hardhat-zksync-vyper/test/fixture-projects/unsupported-fallback-optimize/contracts/Greeter.vy b/packages/hardhat-zksync-vyper/test/fixture-projects/unsupported-fallback-optimize/contracts/Greeter.vy new file mode 100644 index 000000000..cfee0ca24 --- /dev/null +++ b/packages/hardhat-zksync-vyper/test/fixture-projects/unsupported-fallback-optimize/contracts/Greeter.vy @@ -0,0 +1,13 @@ +# @version ^0.3.9 +# vim: ft=python + +greeting: String[100] + +@external +def __init__(): + self.greeting = "Hello World" + +@external +@view +def greet() -> String[100]: + return self.greeting diff --git a/packages/hardhat-zksync-vyper/test/fixture-projects/unsupported-fallback-optimize/hardhat.config.ts b/packages/hardhat-zksync-vyper/test/fixture-projects/unsupported-fallback-optimize/hardhat.config.ts new file mode 100644 index 000000000..699eda211 --- /dev/null +++ b/packages/hardhat-zksync-vyper/test/fixture-projects/unsupported-fallback-optimize/hardhat.config.ts @@ -0,0 +1,33 @@ +import '@nomiclabs/hardhat-vyper'; +import '../../../src/index'; +import { HardhatUserConfig } from 'hardhat/config'; +import '../../../src/type-extensions'; + +const config: HardhatUserConfig = { + zkvyper: { + version: '1.3.14', + compilerSource: 'binary', + settings: { + optimizer: { + fallback_to_optimizing_for_size: true, + }, + }, + }, + networks: { + hardhat: { + zksync: true, + }, + otherNetwork: { + zksync: false, + url: 'http://0.0.0.0:3050', + }, + }, + vyper: { + version: '0.3.9', + }, + solidity: { + version: '0.8.17', + }, +}; + +export default config; diff --git a/packages/hardhat-zksync-vyper/test/tests.ts b/packages/hardhat-zksync-vyper/test/tests.ts index 0e456a3fb..47e2bef54 100644 --- a/packages/hardhat-zksync-vyper/test/tests.ts +++ b/packages/hardhat-zksync-vyper/test/tests.ts @@ -3,14 +3,67 @@ import { TASK_COMPILE } from 'hardhat/builtin-tasks/task-names'; import chalk from 'chalk'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; +import fse from 'fs-extra'; +import path from 'path'; +import semver from 'semver'; import { compile, getWindowsOutput } from '../src/compile/index'; import * as compiler from '../src/compile/binary'; import { ZkSyncArtifact, ZkVyperConfig, CompilerOutput } from '../src/types'; +import { getLatestRelease, getZkvyperUrl, pluralize, saltFromUrl, saveDataToFile, sha1 } from '../src/utils'; +import { USER_AGENT, ZKVYPER_BIN_OWNER, ZKVYPER_BIN_REPOSITORY, ZKVYPER_BIN_REPOSITORY_NAME } from '../src/constants'; import { useEnvironment } from './helpers'; chai.use(sinonChai); describe('zkvyper plugin', async function () { + it('should get release zkVyper url', async function () { + const url = getZkvyperUrl(ZKVYPER_BIN_REPOSITORY, '1.3.14'); + assert( + url === + 'https://github.com/matter-labs/zkvyper-bin/releases/download/v1.3.14/zkvyper-linux-amd64-musl-v1.3.14', + 'Url is not correct.', + ); + }); + + it('should get zkVyper url', async function () { + const url = getZkvyperUrl(ZKVYPER_BIN_REPOSITORY, '1.3.14', false); + assert( + url === 'https://github.com/matter-labs/zkvyper-bin/raw/main/linux-amd64/zkvyper-linux-amd64-musl-v1.3.14', + 'Url is not correct.', + ); + }); + + it('should create sha1', function () { + const word = 'test'; + const result = sha1(word); + assert(result === saltFromUrl(word), 'invalid sha'); + }); + + it('should get latest release', async function () { + const latestRelease = await getLatestRelease(ZKVYPER_BIN_OWNER, ZKVYPER_BIN_REPOSITORY_NAME, USER_AGENT); + const isGreaterThanOne = semver.gt(latestRelease, '1.0.0'); + assert.isTrue(isGreaterThanOne, `Expected latest version to be greater than 1.0.0, got ${latestRelease}`); + }); + + it('should save data to file, check content, and delete the file afterwards', async function () { + const targetPath = path.join(process.cwd(), './xad.json'); + + console.info(process.cwd()); + await saveDataToFile({ test: 'test' }, targetPath); + + const fileContent = await fse.readJson(targetPath); + assert.deepStrictEqual(fileContent, { test: 'test' }, 'File content does not match expected JSON'); + + await fse.remove(targetPath); + }); + + describe('Tests pluralize', function () { + it('returns explicit plural when plural parameter is provided and n is not 1', function () { + const result = pluralize(2, 'mouse', 'mice'); + expect(result === 'mice', 'Result should be mice.'); + }); + }); + describe('Simple', async function () { useEnvironment('simple'); @@ -107,6 +160,19 @@ describe('zkvyper plugin', async function () { }); }); + describe('Should not compile because of unsupported fallback option', async function () { + useEnvironment('unsupported-fallback-optimize', 'hardhat', true); + + it('Should not compile', async function () { + try { + const hh = require('hardhat'); + await hh.run(TASK_COMPILE); + } catch (e: any) { + expect(e.message).to.include('allback_to_optimizing_for_size option in optimizer is not supported'); + } + }); + }); + describe('Compiling nothing', async function () { useEnvironment('nothing-to-compile'); @@ -120,6 +186,30 @@ describe('zkvyper plugin', async function () { } assert(isError === false); }); + + it('should throw an error of incorrect compiler source', async function () { + try { + await compile({ version: 'latest', settings: {} }, [], '', '', undefined); + } catch (e: any) { + assert(e.message.includes('Incorrect compiler source:')); + } + }); + + it('should throw an error of unspecified vyper executable', async function () { + try { + await compile({ version: 'latest', compilerSource: 'binary', settings: {} }, [], '', '', null as any); + } catch (e: any) { + assert(e.message.includes('vyper executable is not specified')); + } + }); + + it('should fail the compilation because undefined is not found', async function () { + try { + await compile({ version: 'latest', compilerSource: 'binary', settings: {} }, [], '', '', undefined); + } catch (e: any) { + assert(e.message.includes('Command failed: undefined')); + } + }); }); describe('Factory with compiler version >= 1.4.0', async function () { @@ -229,9 +319,9 @@ describe('getWindowsOutput', () => { }, }; - const path = 'C:\\path\\to\\file.sol'; + const path_ = 'C:\\path\\to\\file.sol'; - const result = getWindowsOutput(output, path); + const result = getWindowsOutput(output, path_); expect(result).to.be.an('object'); expect(result).to.have.property('version'); @@ -261,9 +351,9 @@ describe('getWindowsOutput', () => { }, }; - const path = 'path/to/file.sol'; + const path_ = 'path/to/file.sol'; - const result = getWindowsOutput(output, path); + const result = getWindowsOutput(output, path_); expect(result).to.deep.equal(output); }); From 2e52792e933f01b1fb2b1dba19802e566a67648c Mon Sep 17 00:00:00 2001 From: Marko Arambasic Date: Mon, 23 Dec 2024 00:36:18 -0800 Subject: [PATCH 2/2] chore: delete scripts --- scripts/test/fixtures/CHANGELOG.md | 18 ------------------ scripts/test/tests.js | 21 --------------------- 2 files changed, 39 deletions(-) delete mode 100644 scripts/test/fixtures/CHANGELOG.md delete mode 100644 scripts/test/tests.js diff --git a/scripts/test/fixtures/CHANGELOG.md b/scripts/test/fixtures/CHANGELOG.md deleted file mode 100644 index cea058bfa..000000000 --- a/scripts/test/fixtures/CHANGELOG.md +++ /dev/null @@ -1,18 +0,0 @@ -# @matterlabs/hardhat-zksync-solc - -## 0.1.3 - -### Minor Changes - -- 6fdd34b: Change 2 -- 7fdd34b: Change 3 - -### Patch Changes - -- Change 4 [#235](https://github.com/matter-labs/hardhat-zksync/pull/235) [e63173](https://github.com/matter-labs/hardhat-zksync/pull/235/commits/e631737f79ed76b4772c4869af131740e96acea4) - -## 0.1.2 - -### Patch Changes - -- 5fdd34b: Change 1 \ No newline at end of file diff --git a/scripts/test/tests.js b/scripts/test/tests.js deleted file mode 100644 index dc166149d..000000000 --- a/scripts/test/tests.js +++ /dev/null @@ -1,21 +0,0 @@ -import { parseReleaseNotes } from '../create-release-from-tags/index.js'; -import fs from 'fs'; -import path from 'path'; -import { expect } from 'chai'; -import { fileURLToPath } from 'url'; - -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const readFixture = (filename) => { - return fs.readFileSync(path.join(__dirname, 'fixtures', filename), { encoding: 'utf8' }); -}; - -describe('parseReleaseNotes', () => { - it('should parse release notes from changelog for specific version', () => { - const changelogText = readFixture('CHANGELOG.md'); - - const releaseNotes = parseReleaseNotes(changelogText, '0.1.3'); - - expect(releaseNotes).to.be.equal('\n### Minor Changes\n\n- 6fdd34b: Change 2\n- 7fdd34b: Change 3\n\n### Patch Changes\n\n- Change 4 [#235](https://github.com/matter-labs/hardhat-zksync/pull/235) [e63173](https://github.com/matter-labs/hardhat-zksync/pull/235/commits/e631737f79ed76b4772c4869af131740e96acea4)\n'); - }); -});