Skip to content

Commit

Permalink
Cleaning up util usage and test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgonecrypto committed Apr 16, 2020
1 parent f1cbdb8 commit 100c0c7
Show file tree
Hide file tree
Showing 36 changed files with 157 additions and 204 deletions.
6 changes: 3 additions & 3 deletions test/contracts/AddressResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

const { artifacts, contract } = require('@nomiclabs/buidler');

const { assert } = require('../utils/common');
const { assert } = require('./common');

const { toBytes32 } = require('../..');
const { onlyGivenAddressCanInvoke } = require('../utils/setupUtils');
const { ZERO_ADDRESS } = require('../utils/testUtils');
const { onlyGivenAddressCanInvoke } = require('./helpers');
const { ZERO_ADDRESS } = require('../utils');

const AddressResolver = artifacts.require('AddressResolver');

Expand Down
9 changes: 3 additions & 6 deletions test/contracts/DelegateApprovals.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

const { artifacts, contract } = require('@nomiclabs/buidler');

const { assert, addSnapshotBeforeRestoreAfterEach } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const EternalStorage = artifacts.require('EternalStorage');
const DelegateApprovals = artifacts.require('DelegateApprovals');
const {
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
} = require('../utils/setupUtils');
const { onlyGivenAddressCanInvoke, ensureOnlyExpectedMutativeFunctions } = require('./helpers');
const { toBytes32 } = require('../..');
const { ZERO_ADDRESS } = require('../utils/testUtils');
const { ZERO_ADDRESS } = require('../utils');

contract('DelegateApprovals', async accounts => {
const [deployerAccount, owner, account1, account2, account3] = accounts;
Expand Down
6 changes: 3 additions & 3 deletions test/contracts/Depot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { contract, web3 } = require('@nomiclabs/buidler');

const { assert, addSnapshotBeforeRestoreAfterEach } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const {
currentTime,
Expand All @@ -11,13 +11,13 @@ const {
toUnit,
multiplyDecimal,
divideDecimal,
} = require('../utils/testUtils');
} = require('../utils');

const {
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
setStatus,
} = require('../utils/setupUtils');
} = require('./helpers');

const { mockToken, setupAllContracts } = require('./setup');

Expand Down
12 changes: 3 additions & 9 deletions test/contracts/EtherCollateral.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@

const { contract, web3 } = require('@nomiclabs/buidler');

const { assert, addSnapshotBeforeRestoreAfterEach } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const BN = require('bn.js');

const {
fastForward,
getEthBalance,
toUnit,
multiplyDecimal,
currentTime,
} = require('../utils/testUtils');
const { fastForward, getEthBalance, toUnit, multiplyDecimal, currentTime } = require('../utils');

const { mockToken, setupAllContracts } = require('./setup');

const {
setStatus,
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
} = require('../utils/setupUtils');
} = require('./helpers');

const { toBytes32 } = require('../..');

Expand Down
32 changes: 15 additions & 17 deletions test/contracts/ExchangeRates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@

const { artifacts, contract, web3 } = require('@nomiclabs/buidler');

const { assert } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const {
currentTime,
fastForward,
toUnit,
bytesToString,
ZERO_ADDRESS,
} = require('../utils/testUtils');
const { currentTime, fastForward, toUnit, bytesToString, ZERO_ADDRESS } = require('../utils');

const {
ensureOnlyExpectedMutativeFunctions,
onlyGivenAddressCanInvoke,
} = require('../utils/setupUtils');
const { ensureOnlyExpectedMutativeFunctions, onlyGivenAddressCanInvoke } = require('./helpers');

const { setupContract } = require('./setup');

Expand Down Expand Up @@ -64,17 +55,24 @@ contract('Exchange Rates', async accounts => {
'sAUD',
].map(toBytes32);
let instance;
let timeSent;
let aggregatorJPY;
let aggregatorXTZ;
let initialTime;
let timeSent;

beforeEach(async () => {
before(async () => {
initialTime = await currentTime();
instance = await setupContract({ accounts, contract: 'ExchangeRates' });
timeSent = await currentTime();
aggregatorJPY = await MockAggregator.new({ from: owner });
aggregatorXTZ = await MockAggregator.new({ from: owner });
});

addSnapshotBeforeRestoreAfterEach();

beforeEach(async () => {
timeSent = await currentTime();
});

it('only expected functions should be mutative', () => {
ensureOnlyExpectedMutativeFunctions({
abi: instance.abi,
Expand Down Expand Up @@ -105,13 +103,13 @@ contract('Exchange Rates', async accounts => {
assert.etherEqual(await instance.rateForCurrency(toBytes32('OTHER')), '0');

const lastUpdatedTimeSUSD = await instance.lastRateUpdateTimes.call(sUSD);
assert.isAtLeast(lastUpdatedTimeSUSD.toNumber(), timeSent);
assert.isAtLeast(lastUpdatedTimeSUSD.toNumber(), initialTime);

const lastUpdatedTimeOTHER = await instance.lastRateUpdateTimes.call(toBytes32('OTHER'));
assert.equal(lastUpdatedTimeOTHER.toNumber(), 0);

const lastUpdatedTimeSNX = await instance.lastRateUpdateTimes.call(SNX);
assert.isAtLeast(lastUpdatedTimeSNX.toNumber(), timeSent);
assert.isAtLeast(lastUpdatedTimeSNX.toNumber(), initialTime);

const sUSDRate = await instance.rateForCurrency(sUSD);
assert.bnEqual(sUSDRate, toUnit('1'));
Expand Down
9 changes: 3 additions & 6 deletions test/contracts/ExchangeState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

const { artifacts, contract } = require('@nomiclabs/buidler');

const { assert } = require('../utils/common');
const { assert } = require('./common');

const { toBytes32 } = require('../..');
const { toUnit } = require('../utils/testUtils');
const {
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
} = require('../utils/setupUtils');
const { toUnit } = require('../utils');
const { onlyGivenAddressCanInvoke, ensureOnlyExpectedMutativeFunctions } = require('./helpers');

const { isBN } = require('web3-utils');

Expand Down
12 changes: 3 additions & 9 deletions test/contracts/Exchanger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

const { contract, web3 } = require('@nomiclabs/buidler');

const { assert, addSnapshotBeforeRestoreAfterEach } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const {
currentTime,
fastForward,
multiplyDecimal,
divideDecimal,
toUnit,
} = require('../utils/testUtils');
const { currentTime, fastForward, multiplyDecimal, divideDecimal, toUnit } = require('../utils');

const { setupAllContracts } = require('./setup');

Expand All @@ -22,7 +16,7 @@ const {
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
setStatus,
} = require('../utils/setupUtils');
} = require('./helpers');

const { toBytes32 } = require('../..');

Expand Down
9 changes: 3 additions & 6 deletions test/contracts/ExternStateToken.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
const { artifacts, contract } = require('@nomiclabs/buidler');

const { assert } = require('../utils/common');
const { assert } = require('./common');

const ExternStateToken = artifacts.require('ExternStateToken');
const PublicEST = artifacts.require('PublicEST');
const ProxyERC20 = artifacts.require('ProxyERC20');
const TokenState = artifacts.require('TokenState');
const { ZERO_ADDRESS, toUnit } = require('../utils/testUtils');
const { ZERO_ADDRESS, toUnit } = require('../utils');

const {
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
} = require('../utils/setupUtils');
const { onlyGivenAddressCanInvoke, ensureOnlyExpectedMutativeFunctions } = require('./helpers');

contract('ExternStateToken', async accounts => {
const [deployerAccount, owner, account1, account2, account3] = accounts;
Expand Down
6 changes: 3 additions & 3 deletions test/contracts/FeePool.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { artifacts, contract, web3 } = require('@nomiclabs/buidler');

const { assert, addSnapshotBeforeRestoreAfterEach } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const FeePool = artifacts.require('FeePool');

Expand All @@ -12,7 +12,7 @@ const {
ZERO_ADDRESS,
fromUnit,
multiplyDecimal,
} = require('../utils/testUtils');
} = require('../utils');

const {
ensureOnlyExpectedMutativeFunctions,
Expand All @@ -21,7 +21,7 @@ const {
getDecodedLogs,
decodedEventEqual,
proxyThruTo,
} = require('../utils/setupUtils');
} = require('./helpers');

const { setupAllContracts } = require('./setup');

Expand Down
9 changes: 3 additions & 6 deletions test/contracts/FeePoolState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

const { artifacts, contract } = require('@nomiclabs/buidler');

const { assert } = require('../utils/common');
const { assert } = require('./common');

const { toPreciseUnit, toUnit } = require('../utils/testUtils');
const {
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
} = require('../utils/setupUtils');
const { toPreciseUnit, toUnit } = require('../utils');
const { onlyGivenAddressCanInvoke, ensureOnlyExpectedMutativeFunctions } = require('./helpers');

const FeePoolState = artifacts.require('FeePoolState');

Expand Down
12 changes: 3 additions & 9 deletions test/contracts/Issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@

const { contract, web3 } = require('@nomiclabs/buidler');

const { assert, addSnapshotBeforeRestoreAfterEach } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const { setupAllContracts } = require('./setup');

const {
currentTime,
multiplyDecimal,
divideDecimal,
toUnit,
fastForward,
} = require('../utils/testUtils');
const { currentTime, multiplyDecimal, divideDecimal, toUnit, fastForward } = require('../utils');

const {
setExchangeWaitingPeriod,
Expand All @@ -22,7 +16,7 @@ const {
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
setStatus,
} = require('../utils/setupUtils');
} = require('./helpers');

const { toBytes32 } = require('../..');

Expand Down
11 changes: 8 additions & 3 deletions test/contracts/LimitedSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

const { artifacts, contract } = require('@nomiclabs/buidler');

const { assert } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const { currentTime, fastForward } = require('../utils/testUtils');
const { timeIsClose } = require('../utils/setupUtils');
const { currentTime, fastForward } = require('../utils');
const { timeIsClose } = require('./helpers');

const OneWeekSetup = artifacts.require('OneWeekSetup');

Expand All @@ -14,6 +14,11 @@ contract('LimitedSetup', accounts => {

let instance;
let timestamp;

// we must snapshot here so that invoking fastForward() later on in this test does not
// pollute the global scope by moving on the block timestamp from its starting point
addSnapshotBeforeRestoreAfterEach();

beforeEach(async () => {
timestamp = await currentTime();
// the owner is the associated contract, so we can simulate
Expand Down
4 changes: 2 additions & 2 deletions test/contracts/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

const { artifacts, contract, web3 } = require('@nomiclabs/buidler');

const { assert } = require('../utils/common');
const { assert } = require('./common');

const SafeDecimalMath = artifacts.require('SafeDecimalMath');
const PublicMath = artifacts.require('PublicMath');

const { toUnit } = require('../utils/testUtils');
const { toUnit } = require('../utils');

const { toBN } = web3.utils;

Expand Down
18 changes: 4 additions & 14 deletions test/contracts/MixinResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@

const { artifacts, contract } = require('@nomiclabs/buidler');

const { assert, addSnapshotBeforeRestoreAfterEach } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const MixinResolver = artifacts.require('MixinResolver');
const AddressResolver = artifacts.require('AddressResolver');

const {
// currentTime,
// fastForward,
// multiplyDecimal,
// divideDecimal,
// toUnit,
ZERO_ADDRESS,
} = require('../utils/testUtils');

const {
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
} = require('../utils/setupUtils');
const { ZERO_ADDRESS } = require('../utils');

const { onlyGivenAddressCanInvoke, ensureOnlyExpectedMutativeFunctions } = require('./helpers');

const { toBytes32 } = require('../..');

Expand Down
9 changes: 3 additions & 6 deletions test/contracts/MultiCollateralSynth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

const { artifacts, contract, web3 } = require('@nomiclabs/buidler');

const { assert, addSnapshotBeforeRestoreAfterEach } = require('../utils/common');
const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

const MultiCollateralSynth = artifacts.require('MultiCollateralSynth');
const TokenState = artifacts.require('TokenState');
const Proxy = artifacts.require('Proxy');

const {
onlyGivenAddressCanInvoke,
ensureOnlyExpectedMutativeFunctions,
} = require('../utils/setupUtils');
const { toUnit, ZERO_ADDRESS } = require('../utils/testUtils');
const { onlyGivenAddressCanInvoke, ensureOnlyExpectedMutativeFunctions } = require('./helpers');
const { toUnit, ZERO_ADDRESS } = require('../utils');
const { toBytes32 } = require('../..');

const { setupAllContracts } = require('./setup');
Expand Down
4 changes: 2 additions & 2 deletions test/contracts/Owned.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

const { artifacts, contract } = require('@nomiclabs/buidler');

const { assert } = require('../utils/common');
const { assert } = require('./common');

const Owned = artifacts.require('Owned');
const { ZERO_ADDRESS } = require('../utils/testUtils');
const { ZERO_ADDRESS } = require('../utils');

contract('Owned', accounts => {
const [deployerAccount, account1, account2, account3, account4] = accounts;
Expand Down
Loading

0 comments on commit 100c0c7

Please sign in to comment.