Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: include additional tests #959

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
98 changes: 94 additions & 4 deletions packages/hardhat-zksync-vyper/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand All @@ -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 () {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
});
Expand Down
18 changes: 0 additions & 18 deletions scripts/test/fixtures/CHANGELOG.md

This file was deleted.

21 changes: 0 additions & 21 deletions scripts/test/tests.js

This file was deleted.

Loading