Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Migrates SDK CLI tests to test-environment #1288

Merged
merged 53 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
e1f2654
Migrate lib contract tests to test-environment
nventuro Nov 20, 2019
af58643
Migrate cli tests to test-env
ylv-io Nov 21, 2019
a2e61c5
Fix accounts.test.js
ylv-io Nov 21, 2019
a3343f6
Fix accounts.test.js
ylv-io Nov 21, 2019
0e3a80a
Update gsn-dapp.adoc for Contracts 2.4 (#1287)
abcoathup Nov 21, 2019
a92cc79
Migrate src tests
nventuro Nov 20, 2019
86e5373
Remove remnants of old setup and unused coverage
nventuro Nov 21, 2019
ea599c7
No longer skip the first account
nventuro Nov 21, 2019
cae6c6d
Fix ZWeb3 with HTTP provider test
nventuro Nov 21, 2019
b6106e0
Fix ZWeb3 accounts test
nventuro Nov 21, 2019
471c413
Fix ZWeb3 balance test
nventuro Nov 21, 2019
a45e1e7
Fix ZWeb3 network id tests
nventuro Nov 21, 2019
2fae6f4
Fix sendTransaction test
nventuro Nov 21, 2019
085a1f9
Remove --exit flag, fix Loggy tests
nventuro Nov 21, 2019
98d9cc1
Remove package-lock.json
ylv-io Nov 25, 2019
ac06ddc
Fix tests, Bumpt cache version
ylv-io Nov 25, 2019
d92fd8d
Fix tests
ylv-io Nov 25, 2019
510aed6
Documentation: Update linking.adoc (#1292)
abcoathup Nov 25, 2019
429fcf5
Add timeout for Mocha test
ylv-io Nov 25, 2019
ac21405
Set Mocha timeout to 5000
ylv-io Nov 25, 2019
bbdad15
Fix ContractManager test by removing Foo.json after the test
ylv-io Nov 25, 2019
6db985b
Fix ContractManager test by removing Foo.json after the test
ylv-io Nov 25, 2019
12ae5db
Upgrade test-enviroment to release version
nventuro Nov 25, 2019
89c15a8
Apply mocha timeout to single test
nventuro Nov 25, 2019
15c0bf7
Require up-to-date yarn version
nventuro Nov 25, 2019
6b67324
Make Circle abort if the yarn lockfile is modified on install
nventuro Nov 25, 2019
4d645a2
Update CI docker image to one with an updated yarn
nventuro Nov 25, 2019
4f34852
Also update CI Docker image for integration tests
nventuro Nov 25, 2019
b2f30f3
Merge branch 'master' into test-env-migration
nventuro Nov 25, 2019
5cf5621
Merge pull request #1290 from nventuro/test-env-migration
nventuro Nov 25, 2019
fa81d67
Migrate cli tests to test-env
ylv-io Nov 21, 2019
c5a4390
Fix accounts.test.js
ylv-io Nov 21, 2019
034da6f
Fix accounts.test.js
ylv-io Nov 21, 2019
457901a
Remove package-lock.json
ylv-io Nov 25, 2019
acfb299
Fix tests, Bumpt cache version
ylv-io Nov 25, 2019
9fe3ace
Fix tests
ylv-io Nov 25, 2019
bbd84c9
Add timeout for Mocha test
ylv-io Nov 25, 2019
5aff715
Set Mocha timeout to 5000
ylv-io Nov 25, 2019
27ea902
Fix ContractManager test by removing Foo.json after the test
ylv-io Nov 25, 2019
ccec10a
Fix ContractManager test by removing Foo.json after the test
ylv-io Nov 25, 2019
b1d78fb
Merge branch 'feature/test-env-cli' of https://github.com/zeppelinos/…
ylv-io Nov 26, 2019
0aa6b62
Use Mocha timeout per test
ylv-io Nov 26, 2019
20e2aa6
Merge remote-tracking branch 'origin/master' into feature/test-env-cli
ylv-io Nov 26, 2019
5158309
Add Solidity contracts compilation as a part of a prepare process
ylv-io Nov 26, 2019
b395daf
Rename compile-ts and compile-contracts
ylv-io Nov 27, 2019
7f2a278
Bump test-environment version
ylv-io Nov 27, 2019
b439b21
Remove utils.toChecksumAddress calls from tests
ylv-io Nov 27, 2019
cf4f869
Fix Transaction tests
ylv-io Nov 27, 2019
3bc51ce
Merge branch 'master' into feature/test-env-cli
ylv-io Nov 27, 2019
1b546b0
Move accounts inside describe block
ylv-io Nov 27, 2019
6568993
Merge branch 'feature/test-env-cli' of https://github.com/zeppelinos/…
ylv-io Nov 27, 2019
c2a821a
Move accounts destructuring inside describe block
nventuro Nov 27, 2019
a00d84c
Fix linter errors
nventuro Nov 27, 2019
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
7 changes: 3 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ commands:
condition: << parameters.run-yarn >>
steps:
- restore_cache:
key: yarn-cache-v7-
key: yarn-cache-v8-
- run:
command: yarn
working_directory: "~/openzeppelin/<< parameters.workspace >>"
Expand All @@ -48,15 +48,14 @@ commands:
working_directory: "~/openzeppelin/<< parameters.workspace >>"

jobs:

setup:
<<: *defaults
steps:
- checkout
- restore_cache:
keys:
- dependency-cache-v5-{{ checksum "yarn.lock" }}
- yarn-cache-v7-
- yarn-cache-v8-
- run:
name: Install dependencies and build
command: yarn
Expand All @@ -73,7 +72,7 @@ jobs:
- packages/cli/node_modules
- packages/lib/node_modules
- save_cache:
key: yarn-cache-v7-{{ checksum "yarn.lock" }}
key: yarn-cache-v8-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn/v6
- persist_to_workspace:
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"scripts": {
"copy-files": "./scripts/copy-files.sh",
"compile-ts": "rm -rf lib && tsc",
"prepare": "npm run compile-ts && npm run copy-files && chmod 755 ./lib/bin/oz-cli.js",
"test": "./scripts/test.sh",
"compile-contracts": "rm -rf build/contracts && truffle compile",
"prepare": "npm run compile-contracts && npm run compile-ts && npm run copy-files && chmod 755 ./lib/bin/oz-cli.js",
"test": "TS_NODE_PROJECT='tsconfig.test.json' npx mocha --require ts-node/register --recursive test",
"gen-docs": "./scripts/gen-docs.sh",
"watch": "tsc -w",
"lint": "eslint '*/**/*.{js,ts}' --quiet --fix",
Expand Down Expand Up @@ -57,6 +58,7 @@
"dependencies": {
"@openzeppelin/resolver-engine-core": "^0.3.3",
"@openzeppelin/resolver-engine-imports-fs": "^0.3.3",
"@openzeppelin/test-environment": "^0.1.0",
"@openzeppelin/upgrades": "^2.6.0",
"@types/fs-extra": "^7.0.0",
"@types/npm": "^2.0.29",
Expand Down Expand Up @@ -137,7 +139,7 @@
"@types/node": "^10.12.12",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"chai": "^4.1.2",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-bignumber": "^2.0.2",
"chai-string": "^1.5.0",
Expand All @@ -149,6 +151,7 @@
"lint-staged": "4.3.0",
"lodash.mapkeys": "^4.6.0",
"lodash.random": "^3.2.0",
"mocha": "^6.2.2",
"mock-stdlib": "file:./test/mocks/mock-stdlib",
"mock-stdlib-2": "file:./test/mocks/mock-stdlib-2",
"mock-stdlib-invalid": "file:./test/mocks/mock-stdlib-invalid",
Expand Down
40 changes: 0 additions & 40 deletions packages/cli/scripts/test.sh

This file was deleted.

1 change: 1 addition & 0 deletions packages/cli/test/bin/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect } from 'chai';
import findRootDirectory from '../../src/bin/helpers';

describe('bin helpers', function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/commands/create2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require('../setup');

import { stubCommands, itShouldParse } from './share';

contract('create2 command', function() {
describe('create2 command', function() {
stubCommands();

itShouldParse(
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/commands/link.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('link command', function() {
itShouldParse(
'should call link script with a list of dependencies and no install',
'link',
'zos link mock-stdlib@1.1.0 mock-stdlib-2@1.2.0 --no-install',
'openzeppelin link mock-stdlib@1.1.0 mock-stdlib-2@1.2.0 --no-install --no-interactive',
function(link) {
const dependencies = ['mock-stdlib@1.1.0', 'mock-stdlib-2@1.2.0'];
link.should.have.been.calledWithExactly({
Expand All @@ -22,7 +22,7 @@ describe('link command', function() {
itShouldParse(
'should call push script when passing --push option',
'push',
'zos link mock-stdlib@1.1.0 mock-stdlib-2@1.2.0 --push test',
'openzeppelin link mock-stdlib@1.1.0 mock-stdlib-2@1.2.0 --push test',
function(push) {
push.should.have.been.calledWithExactly({
deployProxyAdmin: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/config/TruffleConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FileSystem } from '@openzeppelin/upgrades';
import TruffleConfig from '../../src/models/config/TruffleConfig';
import CaptureLogs from '../helpers/captureLogs';

contract('TruffleConfig', () => {
describe('TruffleConfig', () => {
const testDir = `${process.cwd()}/test/tmp`;

beforeEach('create test dir', function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/interface/ValidationLogger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import CaptureLogs from '../helpers/captureLogs';
import { Contracts, getStorageLayout, compareStorageLayouts, getBuildArtifacts } from '@openzeppelin/upgrades';
import ValidationLogger from '../../src/interface/ValidationLogger';

contract('ValidationLogger', function() {
describe('ValidationLogger', function() {
beforeEach('capturing log output', function() {
this.logs = new CaptureLogs();
});
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/test/models/ContractManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

require('../setup');

import { expect } from 'chai';

import sinon from 'sinon';
import { FileSystem, Contracts } from '@openzeppelin/upgrades';
import ContractManager from '../../src/models/local/ContractManager';
import ProjectFile from '../../src/models/files/ProjectFile';
import ConfigManager from '../../src/models/config/ConfigManager';

contract('ContractManager', function([_, from]) {
ylv-io marked this conversation as resolved.
Show resolved Hide resolved
describe('ContractManager', function() {
describe('methods', function() {
describe('getContractNames', function() {
context('without directory created', function() {
Expand Down Expand Up @@ -61,14 +63,16 @@ contract('ContractManager', function([_, from]) {
bytecode: '0x124',
contractName: 'Foo',
};
FileSystem.writeJson(`${this.testDir}/build/contracts/Foo.json`, builtContract);
this.fooContractPath = `${this.testDir}/build/contracts/Foo.json`;
FileSystem.writeJson(this.fooContractPath, builtContract);
this.projectFile = new ProjectFile(`${this.testDir}/zos.json`);
this.contractManager = new ContractManager(this.projectFile);
sinon.stub(ConfigManager, 'getBuildDir').returns(`${this.testDir}/build/contracts`);
sinon.stub(Contracts, 'getLocalContractsDir').returns(`${this.testDir}/contracts`);
});

afterEach(function() {
FileSystem.remove(this.fooContractPath);
nventuro marked this conversation as resolved.
Show resolved Hide resolved
sinon.restore();
});

Expand Down
9 changes: 7 additions & 2 deletions packages/cli/test/models/Dependency.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

require('../setup');

import { expect } from 'chai';
import { accounts } from '@openzeppelin/test-environment';

import sinon from 'sinon';
import npm from 'npm-programmatic';
import Dependency from '../../src/models/dependency/Dependency';

contract('Dependency', function([_, from]) {
describe('Dependency', function() {
const [from] = accounts;

describe('static methods', function() {
describe('#satisfiesVersion', function() {
it('verifies if requirement satisfies version', function() {
Expand All @@ -24,7 +29,7 @@ contract('Dependency', function([_, from]) {
it('fetches version from npm for org package', async function() {
const actual = await Dependency.fetchVersionFromNpm('@openzeppelin/cli');
actual.should.match(/^@openzeppelin\/cli@\^\d+\.\d+\.0$/);
});
}).timeout(5000);
});

describe('#fromNameAndVersion', function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/models/ManifestVersion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { checkVersion, isMigratableManifestVersion } from '../../src/models/file

const projectFileName = 'project.json';

contract('ManifestVersion', function() {
describe('ManifestVersion', function() {
describe('functions', function() {
describe('checkVersion', function() {
context('when latest version', function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/models/NetworkFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import NetworkFile from '../../src/models/files/NetworkFile';
import ProjectFile from '../../src/models/files/ProjectFile';
import { MANIFEST_VERSION } from '../../src/models/files/ManifestVersion';

contract('NetworkFile', function() {
describe('NetworkFile', function() {
beforeEach('loads parent package file', function() {
this.appProjectFile = new ProjectFile('test/mocks/packages/package-empty.zos.json');
});
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/test/models/ProjectFile.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';
require('../setup');

import { expect } from 'chai';

import ProjectFile from '../../src/models/files/ProjectFile';
import { MANIFEST_VERSION } from '../../src/models/files/ManifestVersion';

contract('ProjectFile', function() {
describe('ProjectFile', function() {
describe('class methods', function() {
describe('#getLinkedDependencies', function() {
it('gets an array of dependencies', function() {
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/test/models/TestHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
require('../setup');

import { Contracts } from '@openzeppelin/upgrades';
import { accounts } from '@openzeppelin/test-environment';

import TestHelper from '../../src/models/TestHelper';
import ProjectFile from '../../src/models/files/ProjectFile';
import NetworkFile from '../../src/models/files/NetworkFile';

const ImplV1 = Contracts.getFromLocal('ImplV1');
const WithLibraryImpl = Contracts.getFromLocal('WithLibraryImplV1');

contract('TestHelper', function([_, owner]) {
describe('TestHelper', function() {
const [owner] = accounts;
const txParams = { from: owner };
const projectName = 'Herbs';
const initialVersion = '1.1.0';
Expand Down
1 change: 1 addition & 0 deletions packages/cli/test/prompts/prompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require('../setup');
import sinon from 'sinon';
import { expect } from 'chai';

import * as prompt from '../../src/prompts/prompt';

Expand Down
8 changes: 3 additions & 5 deletions packages/cli/test/scripts/accounts.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict';

require('../setup');
import utils from 'web3-utils';
import sinon from 'sinon';
import { ZWeb3 } from '@openzeppelin/upgrades';
import { defaultSender, accounts as accountList } from '@openzeppelin/test-environment';

import accounts from '../../src/scripts/accounts';
import CaptureLogs from '../helpers/captureLogs';

contract('accounts script', function(accountList) {
accountList = accountList.map(utils.toChecksumAddress);
const [defaultAccount] = accountList;
describe('accounts script', function() {
const network = 'test';

beforeEach('caputre logs', function() {
Expand All @@ -27,7 +25,7 @@ contract('accounts script', function(accountList) {

this.logs.infos.should.have.lengthOf(3);
this.logs.infos[0].should.eq(`Accounts for ${network}:`);
this.logs.infos[1].should.eq(`Default: ${defaultAccount}`);
this.logs.infos[1].should.eq(`Default: ${defaultSender}`);
accountList.forEach(account => this.logs.infos[2].should.match(new RegExp(account)));
});
});
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/test/scripts/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
require('../setup');

import sinon from 'sinon';
import { expect } from 'chai';

import add from '../../src/scripts/add';
import addAll from '../../src/scripts/add-all';
import ProjectFile from '../../src/models/files/ProjectFile';

contract('add script', function() {
describe('add script', function() {
const contractName = 'ImplV1';
const contractAlias = 'Impl';
const contractsData = [{ name: contractName, alias: contractAlias }];
Expand Down
12 changes: 8 additions & 4 deletions packages/cli/test/scripts/balance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
require('../setup');

import utils from 'web3-utils';
import { ZWeb3, Contracts } from '@openzeppelin/upgrades';
import { Contracts } from '@openzeppelin/upgrades';
import { accounts, web3 } from '@openzeppelin/test-environment';

import CaptureLogs from '../helpers/captureLogs';
import { fromWei } from '../../src/utils/units';

import balance from '../../src/scripts/balance';

const ERC20 = Contracts.getFromLocal('ERC20Fake');
const ERC20Detailed = Contracts.getFromLocal('ERC20FakeDetailed');

contract('balance script', function(accounts) {
const [_, accountAddress] = accounts.map(utils.toChecksumAddress);
describe('balance script', function() {
const [accountAddress] = accounts;

beforeEach('set logger captures', function() {
this.logs = new CaptureLogs();
Expand All @@ -30,9 +33,10 @@ contract('balance script', function(accounts) {

context('when not specifying an ERC20 token address', function() {
it('logs balance in ETH', async function() {
const eth = fromWei(await web3.eth.getBalance(accountAddress), 'ether');
await balance({ accountAddress });
this.logs.infos.should.have.lengthOf(1);
this.logs.infos[0].should.eq('Balance: 100 ETH');
this.logs.infos[0].should.eq(`Balance: ${eth} ETH`);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/scripts/bump.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import bump from '../../src/scripts/bump';
import link from '../../src/scripts/link';
import ProjectFile from '../../src/models/files/ProjectFile';

contract('bump script', function() {
describe('bump script', function() {
const newVersion = '0.2.0';

describe('on app', function() {
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/test/scripts/call.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
'use strict';
require('../setup');

import utils from 'web3-utils';
import { accounts } from '@openzeppelin/test-environment';

import add from '../../src/scripts/add';
import push from '../../src/scripts/push';
import call from '../../src/scripts/call';
import sendTx from '../../src/scripts/send-tx';
import createProxy from '../../src/scripts/create';
import { Contracts } from '@openzeppelin/upgrades';
import CaptureLogs from '../helpers/captureLogs';
import ProjectFile from '../../src/models/files/ProjectFile';
import NetworkFile from '../../src/models/files/NetworkFile';

contract('call script', function(accounts) {
accounts = accounts.map(utils.toChecksumAddress);
const [_skipped, account] = accounts;
describe('call script', function() {
const [account] = accounts;
const txParams = { from: account };

const network = 'test';

beforeEach('setup', async function() {
Expand Down
Loading