From c0b01e271b214605032f3e285b115fbbc037b9a7 Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 28 May 2020 15:51:38 +0100 Subject: [PATCH 1/2] fix(dev-utils): update contexts to use snapshots to revert time --- packages/dev-utils/src/mochaContexts.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/dev-utils/src/mochaContexts.js b/packages/dev-utils/src/mochaContexts.js index 264c25a..818a99f 100644 --- a/packages/dev-utils/src/mochaContexts.js +++ b/packages/dev-utils/src/mochaContexts.js @@ -14,9 +14,11 @@ function contextForSpecificTime( functions, ) { const now = bigNumberify(moment().format('X')); + let snapshot; describe(contextText, function () { beforeEach(async function () { + snapshot = await traveler.takeSnapshot(provider); await traveler.advanceBlockAndSetTime( provider, now.add(timeDuration.toString()).toNumber(), @@ -26,7 +28,7 @@ function contextForSpecificTime( functions(); afterEach(async function () { - await traveler.advanceBlockAndSetTime(provider, now.toNumber()); + await traveler.revertToSnapshot(provider, snapshot); }); }); } From 29956c098970c078f65e0a6a787c4b72a7b0faae Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 28 May 2020 15:53:50 +0100 Subject: [PATCH 2/2] test(contracts): update tests to use buidler's waffle provider --- packages/contracts/.waffle.json | 3 --- packages/contracts/package.json | 2 +- packages/contracts/test/NoteStream/cancelStream.js | 9 +++------ packages/contracts/test/NoteStream/constructor.js | 5 +++-- packages/contracts/test/NoteStream/createStream.js | 9 +++------ packages/contracts/test/NoteStream/getStream.js | 9 +++------ packages/contracts/test/NoteStream/withdrawFromStream.js | 3 ++- packages/contracts/test/StreamUtilities/getRatio.js | 9 +++------ .../test/StreamUtilities/processCancellation.js | 9 +++------ .../contracts/test/StreamUtilities/processWithdrawal.js | 9 +++------ .../test/StreamUtilities/validateJoinSplitProof.js | 9 +++------ .../contracts/test/StreamUtilities/validateRatioProof.js | 9 +++------ 12 files changed, 30 insertions(+), 55 deletions(-) delete mode 100644 packages/contracts/.waffle.json diff --git a/packages/contracts/.waffle.json b/packages/contracts/.waffle.json deleted file mode 100644 index 2b5c271..0000000 --- a/packages/contracts/.waffle.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "compilerVersion": "0.5.15" -} diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 5878e81..2bea997 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -21,7 +21,7 @@ "deploy": "buidler run scripts/deploy.js", "export": "buidler export", "has:changed": "bash ../monorepo-scripts/ci/hasChanged.sh contracts", - "test": "waffle .waffle.json && mocha test/runTests.js --timeout 5000", + "test": "buidler test test/runTests.js", "lint:js": "eslint --config .eslintrc.js ./scripts ./test" }, "files": [ diff --git a/packages/contracts/test/NoteStream/cancelStream.js b/packages/contracts/test/NoteStream/cancelStream.js index 0217c1e..c49d70e 100644 --- a/packages/contracts/test/NoteStream/cancelStream.js +++ b/packages/contracts/test/NoteStream/cancelStream.js @@ -1,9 +1,6 @@ +const { waffle } = require('@nomiclabs/buidler'); const { use, expect } = require('chai'); -const { - solidity, - MockProvider, - createFixtureLoader, -} = require('ethereum-waffle'); +const { solidity, createFixtureLoader } = require('ethereum-waffle'); const { bigNumberify, Interface } = require('ethers/utils'); const { devConstants, mochaContexts } = require('@notestream/dev-utils'); @@ -28,7 +25,7 @@ const { use(solidity); -const provider = new MockProvider(); +const { provider } = waffle; const [sender, recipient, attacker] = provider.getWallets(); const loadFixture = createFixtureLoader(provider, [sender, recipient]); diff --git a/packages/contracts/test/NoteStream/constructor.js b/packages/contracts/test/NoteStream/constructor.js index 1dd8c49..224a3a4 100644 --- a/packages/contracts/test/NoteStream/constructor.js +++ b/packages/contracts/test/NoteStream/constructor.js @@ -1,5 +1,6 @@ +const { waffle } = require('@nomiclabs/buidler'); const { use, expect } = require('chai'); -const { solidity, MockProvider, deployContract } = require('ethereum-waffle'); +const { solidity, deployContract } = require('ethereum-waffle'); const { devConstants } = require('@notestream/dev-utils'); const NoteStream = require('../../build/NoteStream.json'); @@ -10,7 +11,7 @@ use(solidity); // eslint-disable-next-line no-undef describe('NoteStream - constructor', function () { - const provider = new MockProvider(); + const { provider } = waffle; const [deployer] = provider.getWallets(); it('reverts when the ACE contract is the zero address', async function () { diff --git a/packages/contracts/test/NoteStream/createStream.js b/packages/contracts/test/NoteStream/createStream.js index d9de3f7..358071e 100644 --- a/packages/contracts/test/NoteStream/createStream.js +++ b/packages/contracts/test/NoteStream/createStream.js @@ -1,10 +1,7 @@ // const { devConstants } = require("@notestream/dev-utils"); +const { waffle } = require('@nomiclabs/buidler'); const { use, expect } = require('chai'); -const { - solidity, - MockProvider, - createFixtureLoader, -} = require('ethereum-waffle'); +const { solidity, createFixtureLoader } = require('ethereum-waffle'); const { bigNumberify, Interface } = require('ethers/utils'); const { devConstants } = require('@notestream/dev-utils'); @@ -25,7 +22,7 @@ use(solidity); // eslint-disable-next-line no-undef describe('NoteStream - createStream', function () { - const provider = new MockProvider(); + const { provider } = waffle; const [sender, recipient] = provider.getWallets(); const loadFixture = createFixtureLoader(provider, [sender, recipient]); diff --git a/packages/contracts/test/NoteStream/getStream.js b/packages/contracts/test/NoteStream/getStream.js index 73f8a8a..1decafb 100644 --- a/packages/contracts/test/NoteStream/getStream.js +++ b/packages/contracts/test/NoteStream/getStream.js @@ -1,10 +1,7 @@ // const { devConstants } = require("@notestream/dev-utils"); +const { waffle } = require('@nomiclabs/buidler'); const { use, expect } = require('chai'); -const { - solidity, - MockProvider, - createFixtureLoader, -} = require('ethereum-waffle'); +const { solidity, createFixtureLoader } = require('ethereum-waffle'); const { bigNumberify } = require('ethers/utils'); const { noteStreamFixture } = require('../fixtures'); @@ -13,7 +10,7 @@ use(solidity); // eslint-disable-next-line no-undef describe('NoteStream - getStream', function () { - const provider = new MockProvider(); + const { provider } = waffle; const [sender, recipient] = provider.getWallets(); const loadFixture = createFixtureLoader(provider, [sender, recipient]); diff --git a/packages/contracts/test/NoteStream/withdrawFromStream.js b/packages/contracts/test/NoteStream/withdrawFromStream.js index 9023033..797d7dd 100644 --- a/packages/contracts/test/NoteStream/withdrawFromStream.js +++ b/packages/contracts/test/NoteStream/withdrawFromStream.js @@ -1,3 +1,4 @@ +const { waffle } = require('@nomiclabs/buidler'); const { use, expect } = require('chai'); const { solidity, @@ -29,7 +30,7 @@ const { use(solidity); function runTests() { - const provider = new MockProvider(); + const { provider } = waffle; const [sender, recipient] = provider.getWallets(); const loadFixture = createFixtureLoader(provider, [sender, recipient]); diff --git a/packages/contracts/test/StreamUtilities/getRatio.js b/packages/contracts/test/StreamUtilities/getRatio.js index 4d526c7..b96fe77 100644 --- a/packages/contracts/test/StreamUtilities/getRatio.js +++ b/packages/contracts/test/StreamUtilities/getRatio.js @@ -1,15 +1,12 @@ +const { waffle } = require('@nomiclabs/buidler'); const { use } = require('chai'); -const { - solidity, - MockProvider, - createFixtureLoader, -} = require('ethereum-waffle'); +const { solidity, createFixtureLoader } = require('ethereum-waffle'); const { StreamUtilitiesFixture } = require('../fixtures'); use(solidity); describe('StreamUtilities - getRatio', function () { - const provider = new MockProvider(); + const { provider } = waffle; const [sender, recipient] = provider.getWallets(); const loadFixture = createFixtureLoader(provider, [sender, recipient]); diff --git a/packages/contracts/test/StreamUtilities/processCancellation.js b/packages/contracts/test/StreamUtilities/processCancellation.js index 346a9bc..7a10bf2 100644 --- a/packages/contracts/test/StreamUtilities/processCancellation.js +++ b/packages/contracts/test/StreamUtilities/processCancellation.js @@ -1,15 +1,12 @@ +const { waffle } = require('@nomiclabs/buidler'); const { use } = require('chai'); -const { - solidity, - MockProvider, - createFixtureLoader, -} = require('ethereum-waffle'); +const { solidity, createFixtureLoader } = require('ethereum-waffle'); const { StreamUtilitiesFixture } = require('../fixtures'); use(solidity); describe('StreamUtilities - processCancellation', function () { - const provider = new MockProvider(); + const { provider } = waffle; const [sender, recipient] = provider.getWallets(); const loadFixture = createFixtureLoader(provider, [sender, recipient]); diff --git a/packages/contracts/test/StreamUtilities/processWithdrawal.js b/packages/contracts/test/StreamUtilities/processWithdrawal.js index e68a463..7d4cdbc 100644 --- a/packages/contracts/test/StreamUtilities/processWithdrawal.js +++ b/packages/contracts/test/StreamUtilities/processWithdrawal.js @@ -1,15 +1,12 @@ +const { waffle } = require('@nomiclabs/buidler'); const { use } = require('chai'); -const { - solidity, - MockProvider, - createFixtureLoader, -} = require('ethereum-waffle'); +const { solidity, createFixtureLoader } = require('ethereum-waffle'); const { StreamUtilitiesFixture } = require('../fixtures'); use(solidity); describe('StreamUtilities - processWithdrawal', function () { - const provider = new MockProvider(); + const { provider } = waffle; const [sender, recipient] = provider.getWallets(); const loadFixture = createFixtureLoader(provider, [sender, recipient]); diff --git a/packages/contracts/test/StreamUtilities/validateJoinSplitProof.js b/packages/contracts/test/StreamUtilities/validateJoinSplitProof.js index 84521bf..18c671e 100644 --- a/packages/contracts/test/StreamUtilities/validateJoinSplitProof.js +++ b/packages/contracts/test/StreamUtilities/validateJoinSplitProof.js @@ -1,15 +1,12 @@ +const { waffle } = require('@nomiclabs/buidler'); const { use } = require('chai'); -const { - solidity, - MockProvider, - createFixtureLoader, -} = require('ethereum-waffle'); +const { solidity, createFixtureLoader } = require('ethereum-waffle'); const { StreamUtilitiesFixture } = require('../fixtures'); use(solidity); describe('StreamUtilities - validateJoinSplitProof', function () { - const provider = new MockProvider(); + const { provider } = waffle; const [sender, recipient] = provider.getWallets(); const loadFixture = createFixtureLoader(provider, [sender, recipient]); diff --git a/packages/contracts/test/StreamUtilities/validateRatioProof.js b/packages/contracts/test/StreamUtilities/validateRatioProof.js index 057b46f..51b68e1 100644 --- a/packages/contracts/test/StreamUtilities/validateRatioProof.js +++ b/packages/contracts/test/StreamUtilities/validateRatioProof.js @@ -1,15 +1,12 @@ +const { waffle } = require('@nomiclabs/buidler'); const { use } = require('chai'); -const { - solidity, - MockProvider, - createFixtureLoader, -} = require('ethereum-waffle'); +const { solidity, createFixtureLoader } = require('ethereum-waffle'); const { StreamUtilitiesFixture } = require('../fixtures'); use(solidity); describe('StreamUtilities - validateRatioProof', function () { - const provider = new MockProvider(); + const { provider } = waffle; const [sender, recipient] = provider.getWallets(); const loadFixture = createFixtureLoader(provider, [sender, recipient]);