Move our contract templates to accept Provider instead of Web3Wrapper

This commit is contained in:
Leonid Logvinov
2018-04-03 16:19:38 +03:00
parent 674e56cea6
commit 249bf0163d
85 changed files with 791 additions and 719 deletions

View File

@@ -9,7 +9,7 @@ import { ContractName } from '../util/types';
import { chaiSetup } from './utils/chai_setup';
import { deployer } from './utils/deployer';
import { web3, web3Wrapper } from './utils/web3_wrapper';
import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -26,7 +26,7 @@ describe('EtherToken', () => {
const etherToken = await deployer.deployAsync(ContractName.EtherToken);
etherTokenAddress = etherToken.address;
zeroEx = new ZeroEx(web3.currentProvider, {
zeroEx = new ZeroEx(provider, {
gasPrice,
networkId: constants.TESTRPC_NETWORK_ID,
});
@@ -51,7 +51,7 @@ describe('EtherToken', () => {
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
@@ -76,7 +76,7 @@ describe('EtherToken', () => {
});
it('should convert ether tokens to ether with sufficient balance', async () => {
const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);

View File

@@ -22,7 +22,7 @@ import { OrderFactory } from '../../util/order_factory';
import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
import { web3, web3Wrapper } from '../utils/web3_wrapper';
import { provider, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -59,22 +59,22 @@ describe('Exchange', () => {
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
]);
rep = new DummyTokenContract(web3Wrapper, repInstance.abi, repInstance.address);
dgd = new DummyTokenContract(web3Wrapper, dgdInstance.abi, dgdInstance.address);
zrx = new DummyTokenContract(web3Wrapper, zrxInstance.abi, zrxInstance.address);
rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider);
dgd = new DummyTokenContract(dgdInstance.abi, dgdInstance.address, provider);
zrx = new DummyTokenContract(zrxInstance.abi, zrxInstance.address, provider);
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
provider,
);
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
zrx.address,
tokenTransferProxy.address,
]);
exchange = new ExchangeContract(web3Wrapper, exchangeInstance.abi, exchangeInstance.address);
exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
zeroEx = new ZeroEx(web3.currentProvider, {
zeroEx = new ZeroEx(provider, {
exchangeContractAddress: exchange.address,
networkId: constants.TESTRPC_NETWORK_ID,
});

View File

@@ -17,7 +17,7 @@ import { OrderFactory } from '../../util/order_factory';
import { ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
import { web3, web3Wrapper } from '../utils/web3_wrapper';
import { provider, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -46,9 +46,9 @@ describe('Exchange', () => {
zrx.address,
tokenTransferProxy.address,
]);
const exchange = new ExchangeContract(web3Wrapper, exchangeInstance.abi, exchangeInstance.address);
const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] });
const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);
const defaultOrderParams = {
exchangeContractAddress: exchange.address,

View File

@@ -22,7 +22,7 @@ import { OrderFactory } from '../../util/order_factory';
import { BalancesByOwner, ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
import { web3, web3Wrapper } from '../utils/web3_wrapper';
import { provider, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -59,28 +59,25 @@ describe('Exchange', () => {
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS),
]);
rep = new DummyTokenContract(web3Wrapper, repInstance.abi, repInstance.address);
dgd = new DummyTokenContract(web3Wrapper, dgdInstance.abi, dgdInstance.address);
zrx = new DummyTokenContract(web3Wrapper, zrxInstance.abi, zrxInstance.address);
rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider);
dgd = new DummyTokenContract(dgdInstance.abi, dgdInstance.address, provider);
zrx = new DummyTokenContract(zrxInstance.abi, zrxInstance.address, provider);
const tokenRegistryInstance = await deployer.deployAsync(ContractName.TokenRegistry);
tokenRegistry = new TokenRegistryContract(
web3Wrapper,
tokenRegistryInstance.abi,
tokenRegistryInstance.address,
);
tokenRegistry = new TokenRegistryContract(tokenRegistryInstance.abi, tokenRegistryInstance.address, provider);
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
provider,
);
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
zrx.address,
tokenTransferProxy.address,
provider,
]);
exchange = new ExchangeContract(web3Wrapper, exchangeInstance.abi, exchangeInstance.address);
exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
exWrapper = new ExchangeWrapper(exchange, zeroEx);
const defaultOrderParams = {

View File

@@ -15,13 +15,13 @@ import { ContractName, SubmissionContractEventArgs } from '../util/types';
import { chaiSetup } from './utils/chai_setup';
import { deployer } from './utils/deployer';
import { web3, web3Wrapper } from './utils/web3_wrapper';
import { provider, web3Wrapper } from './utils/web3_wrapper';
const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLockArtifact.networks[constants.TESTRPC_NETWORK_ID].abi;
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
const abiDecoder = new AbiDecoder([MULTI_SIG_ABI]);
describe('MultiSigWalletWithTimeLock', () => {
@@ -53,9 +53,9 @@ describe('MultiSigWalletWithTimeLock', () => {
0,
]);
multiSig = new MultiSigWalletWithTimeLockContract(
web3Wrapper,
multiSigInstance.abi,
multiSigInstance.address,
provider,
);
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
@@ -150,9 +150,9 @@ describe('MultiSigWalletWithTimeLock', () => {
SECONDS_TIME_LOCKED,
]);
multiSig = new MultiSigWalletWithTimeLockContract(
web3Wrapper,
multiSigInstance.abi,
multiSigInstance.address,
provider,
);
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);

View File

@@ -16,7 +16,7 @@ import { ContractName, SubmissionContractEventArgs, TransactionDataParams } from
import { chaiSetup } from './utils/chai_setup';
import { deployer } from './utils/deployer';
import { web3, web3Wrapper } from './utils/web3_wrapper';
import { provider, web3Wrapper } from './utils/web3_wrapper';
const PROXY_ABI = artifacts.TokenTransferProxyArtifact.networks[constants.TESTRPC_NETWORK_ID].abi;
const MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI =
artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact.networks[constants.TESTRPC_NETWORK_ID]
@@ -28,7 +28,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
const abiDecoder = new AbiDecoder([MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI]);
describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
let owners: string[];
const requiredApprovals = 2;
const SECONDS_TIME_LOCKED = 1000000;
@@ -49,9 +49,9 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const initialOwner = accounts[0];
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
provider,
);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(authorizedAddress, {
from: initialOwner,
@@ -61,9 +61,9 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
[owners, requiredApprovals, SECONDS_TIME_LOCKED, tokenTransferProxy.address],
);
multiSig = new MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract(
web3Wrapper,
multiSigInstance.abi,
multiSigInstance.address,
provider,
);
await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, {
from: initialOwner,

View File

@@ -14,7 +14,7 @@ import { ContractName } from '../util/types';
import { chaiSetup } from './utils/chai_setup';
import { deployer } from './utils/deployer';
import { web3, web3Wrapper } from './utils/web3_wrapper';
import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -30,7 +30,7 @@ describe('TokenRegistry', () => {
owner = accounts[0];
notOwner = accounts[1];
const tokenRegInstance = await deployer.deployAsync(ContractName.TokenRegistry);
tokenReg = new TokenRegistryContract(web3Wrapper, tokenRegInstance.abi, tokenRegInstance.address);
tokenReg = new TokenRegistryContract(tokenRegInstance.abi, tokenRegInstance.address, provider);
tokenRegWrapper = new TokenRegWrapper(tokenReg);
});
beforeEach(async () => {

View File

@@ -8,7 +8,7 @@ import { constants } from '../../util/constants';
import { ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
import { web3, web3Wrapper } from '../utils/web3_wrapper';
import { provider, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -25,9 +25,9 @@ describe('TokenTransferProxy', () => {
notOwner = accounts[1];
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
provider,
);
});
beforeEach(async () => {

View File

@@ -11,7 +11,7 @@ import { constants } from '../../util/constants';
import { ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
import { web3, web3Wrapper } from '../utils/web3_wrapper';
import { provider, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -33,12 +33,12 @@ describe('TokenTransferProxy', () => {
owner = notAuthorized = accounts[0];
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
provider,
);
const repInstance = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
rep = new DummyTokenContract(web3Wrapper, repInstance.abi, repInstance.address);
rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider);
dmyBalances = new Balances([rep], [accounts[0], accounts[1]]);
await Promise.all([

View File

@@ -17,7 +17,7 @@ import { OrderFactory } from '../../util/order_factory';
import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
import { web3, web3Wrapper } from '../utils/web3_wrapper';
import { provider, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -69,18 +69,18 @@ describe('Arbitrage', () => {
edTakerFee,
edFeeRebate,
]);
etherDelta = new EtherDeltaContract(web3Wrapper, etherDeltaInstance.abi, etherDeltaInstance.address);
etherDelta = new EtherDeltaContract(etherDeltaInstance.abi, etherDeltaInstance.address, provider);
const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
zrx.address,
tokenTransferProxy.address,
]);
await tokenTransferProxy.addAuthorizedAddress(exchangeInstance.address, { from: accounts[0] });
zeroEx = new ZeroEx(web3.currentProvider, {
zeroEx = new ZeroEx(provider, {
exchangeContractAddress: exchangeInstance.address,
networkId: constants.TESTRPC_NETWORK_ID,
});
const exchange = new ExchangeContract(web3Wrapper, exchangeInstance.abi, exchangeInstance.address);
const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
exWrapper = new ExchangeWrapper(exchange, zeroEx);
makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
@@ -102,7 +102,7 @@ describe('Arbitrage', () => {
etherDelta.address,
tokenTransferProxy.address,
]);
arbitrage = new ArbitrageContract(web3Wrapper, arbitrageInstance.abi, arbitrageInstance.address);
arbitrage = new ArbitrageContract(arbitrageInstance.abi, arbitrageInstance.address, provider);
// Enable arbitrage and withdrawals of tokens
await arbitrage.setAllowances.sendTransactionAsync(weth.address, { from: coinbase });
await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase });

View File

@@ -11,7 +11,7 @@ import { ContractName } from '../util/types';
import { chaiSetup } from './utils/chai_setup';
import { deployer } from './utils/deployer';
import { web3, web3Wrapper } from './utils/web3_wrapper';
import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -23,7 +23,7 @@ describe('UnlimitedAllowanceToken', () => {
const config = {
networkId: constants.TESTRPC_NETWORK_ID,
};
const zeroEx = new ZeroEx(web3.currentProvider, config);
const zeroEx = new ZeroEx(provider, config);
const MAX_MINT_VALUE = new BigNumber(100000000000000000000);
let tokenAddress: string;
@@ -34,7 +34,7 @@ describe('UnlimitedAllowanceToken', () => {
owner = accounts[0];
spender = accounts[1];
const tokenInstance = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS);
token = new DummyTokenContract(web3Wrapper, tokenInstance.abi, tokenInstance.address);
token = new DummyTokenContract(tokenInstance.abi, tokenInstance.address, provider);
await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner });
tokenAddress = token.address;
});

View File

@@ -3,4 +3,5 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
const web3ProviderConfig = { shouldUseInProcessGanache: true };
export const web3 = web3Factory.create(web3ProviderConfig);
export const web3Wrapper = new Web3Wrapper(web3.currentProvider);
export const provider = web3.currentProvider;
export const web3Wrapper = new Web3Wrapper(provider);

View File

@@ -11,7 +11,7 @@ import { ContractName } from '../util/types';
import { chaiSetup } from './utils/chai_setup';
import { deployer } from './utils/deployer';
import { web3, web3Wrapper } from './utils/web3_wrapper';
import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -31,11 +31,11 @@ describe('ZRXToken', () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
spender = accounts[1];
zeroEx = new ZeroEx(web3.currentProvider, {
zeroEx = new ZeroEx(provider, {
networkId: constants.TESTRPC_NETWORK_ID,
});
const zrxInstance = await deployer.deployAsync(ContractName.ZRXToken);
zrx = new ZRXTokenContract(web3Wrapper, zrxInstance.abi, zrxInstance.address);
zrx = new ZRXTokenContract(zrxInstance.abi, zrxInstance.address, provider);
zrxAddress = zrx.address;
MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
});