Skip to content

Commit

Permalink
Ensuring web3 is properly wrapped into testUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgonecrypto committed Apr 16, 2020
1 parent 100c0c7 commit b54d60f
Show file tree
Hide file tree
Showing 34 changed files with 512 additions and 490 deletions.
2 changes: 1 addition & 1 deletion test/contracts/AddressResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { assert } = require('./common');

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/DelegateApprovals.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const EternalStorage = artifacts.require('EternalStorage');
const DelegateApprovals = artifacts.require('DelegateApprovals');
const { onlyGivenAddressCanInvoke, ensureOnlyExpectedMutativeFunctions } = require('./helpers');
const { toBytes32 } = require('../..');
const { ZERO_ADDRESS } = require('../utils');
const { ZERO_ADDRESS } = require('../utils')();

contract('DelegateApprovals', async accounts => {
const [deployerAccount, owner, account1, account2, account3] = accounts;
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/Depot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
toUnit,
multiplyDecimal,
divideDecimal,
} = require('../utils');
} = require('../utils')();

const {
onlyGivenAddressCanInvoke,
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/EtherCollateral.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/ExchangeRates.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { artifacts, contract, web3 } = require('@nomiclabs/buidler');

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/ExchangeState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { artifacts, contract } = require('@nomiclabs/buidler');
const { assert } = require('./common');

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

const { isBN } = require('web3-utils');
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/Exchanger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { contract, web3 } = require('@nomiclabs/buidler');

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/ExternStateToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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');
const { ZERO_ADDRESS, toUnit } = require('../utils')();

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/FeePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
ZERO_ADDRESS,
fromUnit,
multiplyDecimal,
} = require('../utils');
} = require('../utils')();

const {
ensureOnlyExpectedMutativeFunctions,
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/FeePoolState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { artifacts, contract } = require('@nomiclabs/buidler');

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

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

const FeePoolState = artifacts.require('FeePoolState');
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/Issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

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

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

const {
setExchangeWaitingPeriod,
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/LimitedSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { artifacts, contract } = require('@nomiclabs/buidler');

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

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

const OneWeekSetup = artifacts.require('OneWeekSetup');
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { assert } = require('./common');
const SafeDecimalMath = artifacts.require('SafeDecimalMath');
const PublicMath = artifacts.require('PublicMath');

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

const { toBN } = web3.utils;

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/MixinResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');
const MixinResolver = artifacts.require('MixinResolver');
const AddressResolver = artifacts.require('AddressResolver');

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/MultiCollateralSynth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const TokenState = artifacts.require('TokenState');
const Proxy = artifacts.require('Proxy');

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

const { setupAllContracts } = require('./setup');
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/Owned.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { artifacts, contract } = require('@nomiclabs/buidler');
const { assert } = require('./common');

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

contract('Owned', accounts => {
const [deployerAccount, account1, account2, account3, account4] = accounts;
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/Pausable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
timeIsClose,
ensureOnlyExpectedMutativeFunctions,
} = require('./helpers');
const { currentTime, fastForward } = require('../utils');
const { currentTime, fastForward } = require('../utils')();

const Pausable = artifacts.require('Pausable');
const TestablePausable = artifacts.require('TestablePausable');
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/ProxyERC20.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const TokenExchanger = artifacts.require('TokenExchanger');

const { toBytes32 } = require('../..');
const { mockToken } = require('./setup');
const { toUnit } = require('../utils');
const { toUnit } = require('../utils')();
const { ensureOnlyExpectedMutativeFunctions, proxyThruTo } = require('./helpers');

contract('ProxyERC20', async accounts => {
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/PurgeableSynth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const PurgeableSynth = artifacts.require('PurgeableSynth');
const TokenState = artifacts.require('TokenState');
const Proxy = artifacts.require('Proxy');

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

const {
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/RewardEscrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

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

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

contract('RewardEscrow', async accounts => {
const SECOND = 1000;
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/RewardsDistribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');
const RewardsDistribution = artifacts.require('RewardsDistribution');
const MockRewardsRecipient = artifacts.require('MockRewardsRecipient');

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/RewardsIntegrationTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/SafeDecimalMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { assert } = require('./common');
const SafeDecimalMath = artifacts.require('SafeDecimalMath');
const PublicSafeDecimalMath = artifacts.require('PublicSafeDecimalMath');

const { toUnit, fromUnit, toPreciseUnit, fromPreciseUnit } = require('../utils');
const { toUnit, fromUnit, toPreciseUnit, fromPreciseUnit } = require('../utils')();

const { toBN } = web3.utils;

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/SelfDestructible.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/SupplySchedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
multiplyDecimal,
powerToDecimal,
ZERO_ADDRESS,
} = require('../utils');
} = require('../utils')();

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/Synth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Synth = artifacts.require('Synth');

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

const { currentTime, toUnit, ZERO_ADDRESS, bytesToString } = require('../utils');
const { currentTime, toUnit, ZERO_ADDRESS, bytesToString } = require('../utils')();
const {
issueSynthsToUser,
ensureOnlyExpectedMutativeFunctions,
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/Synthetix.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const {
toUnit,
fromUnit,
ZERO_ADDRESS,
} = require('../utils');
} = require('../utils')();

const {
onlyGivenAddressCanInvoke,
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/SynthetixState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { assert, addSnapshotBeforeRestoreAfterEach } = require('./common');

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/TokenState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { artifacts, contract } = require('@nomiclabs/buidler');
const { assert } = require('./common');

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

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

Expand Down
2 changes: 1 addition & 1 deletion test/contracts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
fromUnit,
takeSnapshot,
restoreSnapshot,
} = require('../utils');
} = require('../utils')();

// Helper for logging transactions
console.logTransaction = transaction => {
Expand Down
2 changes: 1 addition & 1 deletion test/contracts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const abiDecoder = require('abi-decoder');

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

const { currentTime, toUnit } = require('../utils');
const { currentTime, toUnit } = require('../utils')();
const { toBytes32 } = require('../..');

module.exports = {
Expand Down
20 changes: 13 additions & 7 deletions test/publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { loadCompiledFiles } = require('../../publish/src/solidity');

const deployCmd = require('../../publish/src/commands/deploy');
const { buildPath } = deployCmd.DEFAULTS;
const { loadLocalUsers, isCompileRequired } = require('../utils');
const testUtils = require('../utils');

const commands = {
build: require('../../publish/src/commands/build').build,
Expand All @@ -27,14 +27,9 @@ const {
DEPLOYMENT_FILENAME,
} = require('../../publish/src/constants');

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

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

// load accounts used by local EVM
const users = loadLocalUsers();

describe('publish scripts', function() {
this.timeout(30e3);
const deploymentPath = path.join(__dirname, '..', '..', 'publish', 'deployed', 'local');
Expand All @@ -56,6 +51,7 @@ describe('publish scripts', function() {
let sETH;
let web3;
let compiledSources;
let fastForward;

const resetConfigAndSynthFiles = () => {
// restore the synths and config files for this env (cause removal updated it)
Expand Down Expand Up @@ -86,6 +82,17 @@ describe('publish scripts', function() {

beforeEach(async function() {
console.log = (...input) => fs.appendFileSync(logfilePath, input.join(' ') + '\n');

web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545'));

let loadLocalUsers;
let isCompileRequired;

({ loadLocalUsers, isCompileRequired, fastForward } = testUtils({ web3 }));

// load accounts used by local EVM
const users = loadLocalUsers();

accounts = {
deployer: users[0],
first: users[1],
Expand All @@ -106,7 +113,6 @@ describe('publish scripts', function() {

gasLimit = 5000000;
[SNX, sUSD, sBTC, sETH] = ['SNX', 'sUSD', 'sBTC', 'sETH'].map(toBytes32);
web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545'));
web3.eth.accounts.wallet.add(accounts.deployer.private);
gasPrice = web3.utils.toWei('5', 'gwei');
});
Expand Down
9 changes: 5 additions & 4 deletions test/testnet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ const commands = {
deploy: require('../../publish/src/commands/deploy').deploy,
};

const { loadLocalUsers, isCompileRequired } = require('../utils');
const { currentTime, fastForward } = require('../utils');
const testUtils = require('../utils');

const { loadConnections, confirmAction } = require('../../publish/src/util');

Expand Down Expand Up @@ -74,10 +73,13 @@ program
let privateKey = envPrivateKey;

const web3 = new Web3(new Web3.providers.HttpProvider(providerUrl));

const { loadLocalUsers, isCompileRequired, fastForward } = testUtils({ web3 });

const synths = snx.getSynths({ network });

const gas = 4e6; // 4M
const gasPrice = web3.utils.toWei(gasPriceInGwei, 'gwei');
const gasPrice = toWei(gasPriceInGwei, 'gwei');
const [sUSD, sETH] = ['sUSD', 'sETH'].map(toBytes32);

const updateableSynths = synths.filter(({ name }) => ['sUSD'].indexOf(name) < 0);
Expand Down Expand Up @@ -119,7 +121,6 @@ program
snx.getSource({ network, contract: 'ExchangeRates' }).abi,
snx.getTarget({ network, contract: 'ExchangeRates' }).address
);
timestamp = await currentTime();

// update rates
await ExchangeRates.methods
Expand Down
Loading

0 comments on commit b54d60f

Please sign in to comment.