diff options
Diffstat (limited to 'packages/contracts/test')
-rw-r--r-- | packages/contracts/test/ether_token.ts | 8 | ||||
-rw-r--r-- | packages/contracts/test/exchange/core.ts | 62 | ||||
-rw-r--r-- | packages/contracts/test/exchange/helpers.ts | 61 | ||||
-rw-r--r-- | packages/contracts/test/exchange/wrapper.ts | 62 | ||||
-rw-r--r-- | packages/contracts/test/multi_sig_with_time_lock.ts | 28 | ||||
-rw-r--r-- | packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts | 41 | ||||
-rw-r--r-- | packages/contracts/test/token_registry.ts | 7 | ||||
-rw-r--r-- | packages/contracts/test/token_transfer_proxy/auth.ts | 12 | ||||
-rw-r--r-- | packages/contracts/test/token_transfer_proxy/transfer_from.ts | 24 | ||||
-rw-r--r-- | packages/contracts/test/tutorials/arbitrage.ts | 98 | ||||
-rw-r--r-- | packages/contracts/test/unlimited_allowance_token.ts | 15 | ||||
-rw-r--r-- | packages/contracts/test/utils/deployer.ts | 18 | ||||
-rw-r--r-- | packages/contracts/test/utils/web3_wrapper.ts | 6 | ||||
-rw-r--r-- | packages/contracts/test/zrx_token.ts | 7 |
14 files changed, 287 insertions, 162 deletions
diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 4023abad0..f80f2159e 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -4,12 +4,14 @@ import { BigNumber, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; +import { WETH9Contract } from '../src/contract_wrappers/generated/weth9'; +import { artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; + +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -24,7 +26,7 @@ describe('EtherToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); account = accounts[0]; - const etherToken = await deployer.deployAsync(ContractName.EtherToken); + const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, txDefaults); etherTokenAddress = etherToken.address; zeroEx = new ZeroEx(provider, { gasPrice, diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 689b11062..e40b564c6 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -13,7 +13,9 @@ import { LogErrorContractEventArgs, LogFillContractEventArgs, } from '../../src/contract_wrappers/generated/exchange'; +import { MaliciousTokenContract } from '../../src/contract_wrappers/generated/malicious_token'; import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { crypto } from '../../util/crypto'; @@ -21,8 +23,8 @@ import { ExchangeWrapper } from '../../util/exchange_wrapper'; 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 { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -54,25 +56,47 @@ describe('Exchange', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); maker = accounts[0]; [tokenOwner, taker, feeRecipient] = accounts; - const [repInstance, dgdInstance, zrxInstance] = await Promise.all([ - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), + [rep, dgd, zrx] = await Promise.all([ + DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), ]); - 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( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + txDefaults, ); - const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [ + exchange = await ExchangeContract.deployFrom0xArtifactAsync( + artifacts.Exchange, + provider, + txDefaults, zrx.address, tokenTransferProxy.address, - ]); - exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider); + ); await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] }); zeroEx = new ZeroEx(provider, { exchangeContractAddress: exchange.address, @@ -689,7 +713,11 @@ describe('Exchange', () => { it('should throw if getBalance or getAllowance attempts to change state and \ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { - const maliciousToken = await deployer.deployAsync(ContractName.MaliciousToken); + const maliciousToken = await MaliciousTokenContract.deployFrom0xArtifactAsync( + artifacts.MaliciousToken, + provider, + txDefaults, + ); await maliciousToken.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: taker, }); diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts index 8fc30c0b5..441c1bc28 100644 --- a/packages/contracts/test/exchange/helpers.ts +++ b/packages/contracts/test/exchange/helpers.ts @@ -11,13 +11,18 @@ import { LogErrorContractEventArgs, LogFillContractEventArgs, } from '../../src/contract_wrappers/generated/exchange'; + +import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token'; +import { TokenRegistryContract } from '../../src/contract_wrappers/generated/token_registry'; +import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { constants } from '../../util/constants'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; import { OrderFactory } from '../../util/order_factory'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -35,19 +40,53 @@ describe('Exchange', () => { before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); [maker, feeRecipient] = accounts; - const tokenRegistry = await deployer.deployAsync(ContractName.TokenRegistry); - const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy); + const tokenRegistry = await TokenRegistryContract.deployFrom0xArtifactAsync( + artifacts.TokenRegistry, + provider, + txDefaults, + ); + const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( + artifacts.TokenTransferProxy, + provider, + txDefaults, + ); const [rep, dgd, zrx] = await Promise.all([ - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), + DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), ]); - const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [ + const exchange = await ExchangeContract.deployFrom0xArtifactAsync( + artifacts.Exchange, + provider, + txDefaults, zrx.address, tokenTransferProxy.address, - ]); - const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider); - await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] }); + ); + await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] }); const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID }); exchangeWrapper = new ExchangeWrapper(exchange, zeroEx); const defaultOrderParams = { diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index c658dca79..57ccd05bd 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -15,14 +15,15 @@ import { } from '../../src/contract_wrappers/generated/exchange'; import { TokenRegistryContract } from '../../src/contract_wrappers/generated/token_registry'; import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -54,27 +55,52 @@ describe('Exchange', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); tokenOwner = accounts[0]; [maker, taker, feeRecipient] = accounts; - const [repInstance, dgdInstance, zrxInstance] = await Promise.all([ - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), + [rep, dgd, zrx] = await Promise.all([ + DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), ]); - 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(tokenRegistryInstance.abi, tokenRegistryInstance.address, provider); - const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy); - tokenTransferProxy = new TokenTransferProxyContract( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenRegistry = await TokenRegistryContract.deployFrom0xArtifactAsync( + artifacts.TokenRegistry, + provider, + txDefaults, + ); + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + txDefaults, ); - const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [ + exchange = await ExchangeContract.deployFrom0xArtifactAsync( + artifacts.Exchange, + provider, + txDefaults, zrx.address, tokenTransferProxy.address, - ]); - exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider); + ); await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] }); const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID }); exWrapper = new ExchangeWrapper(exchange, zeroEx); diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 5cc744713..01bc0ec90 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -14,10 +14,10 @@ import { MultiSigWrapper } from '../util/multi_sig_wrapper'; import { ContractName, SubmissionContractEventArgs } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; -const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLockArtifact.compilerOutput.abi; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; + +const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLock.compilerOutput.abi; chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); @@ -47,15 +47,13 @@ describe('MultiSigWalletWithTimeLock', () => { describe('changeTimeLock', () => { describe('initially non-time-locked', async () => { before('deploy a wallet', async () => { - const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ + multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( + artifacts.MultiSigWalletWithTimeLock, + provider, + txDefaults, owners, SIGNATURES_REQUIRED, - 0, - ]); - multiSig = new MultiSigWalletWithTimeLockContract( - multiSigInstance.abi, - multiSigInstance.address, - provider, + new BigNumber(0), ); multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract); @@ -144,15 +142,13 @@ describe('MultiSigWalletWithTimeLock', () => { }); describe('initially time-locked', async () => { before('deploy a wallet', async () => { - const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ + multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( + artifacts.MultiSigWalletWithTimeLock, + provider, + txDefaults, owners, SIGNATURES_REQUIRED, SECONDS_TIME_LOCKED, - ]); - multiSig = new MultiSigWalletWithTimeLockContract( - multiSigInstance.abi, - multiSigInstance.address, - provider, ); multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract); diff --git a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts index 06fa30d96..1c2ddea87 100644 --- a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts +++ b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts @@ -1,6 +1,6 @@ import { LogWithDecodedArgs, ZeroEx } from '0x.js'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; -import { AbiDecoder } from '@0xproject/utils'; +import { AbiDecoder, BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import * as Web3 from 'web3'; @@ -15,11 +15,11 @@ import { MultiSigWrapper } from '../util/multi_sig_wrapper'; import { ContractName, SubmissionContractEventArgs, TransactionDataParams } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; -const PROXY_ABI = artifacts.TokenTransferProxyArtifact.compilerOutput.abi; + +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; +const PROXY_ABI = artifacts.TokenTransferProxy.compilerOutput.abi; const MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI = - artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact.compilerOutput.abi; + artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.compilerOutput.abi; chaiSetup.configure(); const expect = chai.expect; @@ -29,8 +29,8 @@ const abiDecoder = new AbiDecoder([MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_A describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID }); let owners: string[]; - const requiredApprovals = 2; - const SECONDS_TIME_LOCKED = 1000000; + const requiredApprovals = new BigNumber(2); + const SECONDS_TIME_LOCKED = new BigNumber(1000000); // initialize fake addresses let authorizedAddress: string; @@ -46,23 +46,22 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { owners = [accounts[0], accounts[1]]; [authorizedAddress, unauthorizedAddress] = accounts; const initialOwner = accounts[0]; - const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy); - tokenTransferProxy = new TokenTransferProxyContract( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + txDefaults, ); await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(authorizedAddress, { from: initialOwner, }); - const multiSigInstance = await deployer.deployAsync( - ContractName.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, - [owners, requiredApprovals, SECONDS_TIME_LOCKED, tokenTransferProxy.address], - ); - multiSig = new MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract( - multiSigInstance.abi, - multiSigInstance.address, + multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync( + artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, provider, + txDefaults, + owners, + requiredApprovals, + SECONDS_TIME_LOCKED, + tokenTransferProxy.address, ); await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner, @@ -110,7 +109,11 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { }); it('should throw if tx destination is not the tokenTransferProxy', async () => { - const invalidTokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy); + const invalidTokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( + artifacts.TokenTransferProxy, + provider, + txDefaults, + ); const invalidDestination = invalidTokenTransferProxy.address; const dataParams: TransactionDataParams = { name: 'removeAuthorizedAddress', diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 4c404176b..8b7c3048d 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -8,13 +8,13 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import { TokenRegistryContract } from '../src/contract_wrappers/generated/token_registry'; +import { artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; import { TokenRegWrapper } from '../util/token_registry_wrapper'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -29,8 +29,7 @@ describe('TokenRegistry', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; notOwner = accounts[1]; - const tokenRegInstance = await deployer.deployAsync(ContractName.TokenRegistry); - tokenReg = new TokenRegistryContract(tokenRegInstance.abi, tokenRegInstance.address, provider); + tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync(artifacts.TokenRegistry, provider, txDefaults); tokenRegWrapper = new TokenRegWrapper(tokenReg); }); beforeEach(async () => { diff --git a/packages/contracts/test/token_transfer_proxy/auth.ts b/packages/contracts/test/token_transfer_proxy/auth.ts index 885ff3bc1..97e8d0c2e 100644 --- a/packages/contracts/test/token_transfer_proxy/auth.ts +++ b/packages/contracts/test/token_transfer_proxy/auth.ts @@ -4,11 +4,12 @@ import * as chai from 'chai'; import * as Web3 from 'web3'; import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { constants } from '../../util/constants'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -23,11 +24,10 @@ describe('TokenTransferProxy', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = address = accounts[0]; notOwner = accounts[1]; - const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy); - tokenTransferProxy = new TokenTransferProxyContract( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + txDefaults, ); }); beforeEach(async () => { diff --git a/packages/contracts/test/token_transfer_proxy/transfer_from.ts b/packages/contracts/test/token_transfer_proxy/transfer_from.ts index dff1a0cfb..c31d8a1cb 100644 --- a/packages/contracts/test/token_transfer_proxy/transfer_from.ts +++ b/packages/contracts/test/token_transfer_proxy/transfer_from.ts @@ -6,12 +6,13 @@ import * as Web3 from 'web3'; import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token'; import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -31,15 +32,20 @@ describe('TokenTransferProxy', () => { before(async () => { accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = notAuthorized = accounts[0]; - const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy); - tokenTransferProxy = new TokenTransferProxyContract( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + txDefaults, + ); + rep = await DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, ); - const repInstance = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS); - rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider); - dmyBalances = new Balances([rep], [accounts[0], accounts[1]]); await Promise.all([ rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index ad83bbca3..aa86ecd43 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -6,9 +6,13 @@ import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); import * as Web3 from 'web3'; +import { AccountLevelsContract } from '../../src/contract_wrappers/generated/account_levels'; import { ArbitrageContract } from '../../src/contract_wrappers/generated/arbitrage'; +import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token'; import { EtherDeltaContract } from '../../src/contract_wrappers/generated/ether_delta'; import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange'; +import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { crypto } from '../../util/crypto'; @@ -16,8 +20,8 @@ import { ExchangeWrapper } from '../../util/exchange_wrapper'; 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 { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -36,8 +40,8 @@ describe('Arbitrage', () => { const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18); const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18); - let weth: Web3.ContractInstance; - let zrx: Web3.ContractInstance; + let weth: DummyTokenContract; + let zrx: DummyTokenContract; let arbitrage: ArbitrageContract; let etherDelta: EtherDeltaContract; @@ -54,33 +58,61 @@ describe('Arbitrage', () => { before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); [coinbase, maker, edMaker, edFrontRunner] = accounts; - weth = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS); - zrx = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS); - const accountLevels = await deployer.deployAsync(ContractName.AccountLevels); + weth = await DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ); + zrx = await DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ); + const accountLevels = await AccountLevelsContract.deployFrom0xArtifactAsync( + artifacts.AccountLevels, + provider, + txDefaults, + ); const edAdminAddress = accounts[0]; - const edMakerFee = 0; - const edTakerFee = 0; - const edFeeRebate = 0; - const etherDeltaInstance = await deployer.deployAsync(ContractName.EtherDelta, [ + const edMakerFee = new BigNumber(0); + const edTakerFee = new BigNumber(0); + const edFeeRebate = new BigNumber(0); + etherDelta = await EtherDeltaContract.deployFrom0xArtifactAsync( + artifacts.EtherDelta, + provider, + txDefaults, edAdminAddress, feeRecipient, accountLevels.address, edMakerFee, edTakerFee, edFeeRebate, - ]); - etherDelta = new EtherDeltaContract(etherDeltaInstance.abi, etherDeltaInstance.address, provider); - const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy); - const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [ + ); + const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( + artifacts.TokenTransferProxy, + provider, + txDefaults, + ); + const exchange = await ExchangeContract.deployFrom0xArtifactAsync( + artifacts.Exchange, + provider, + txDefaults, zrx.address, tokenTransferProxy.address, - ]); - await tokenTransferProxy.addAuthorizedAddress(exchangeInstance.address, { from: accounts[0] }); + ); + await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] }); zeroEx = new ZeroEx(provider, { - exchangeContractAddress: exchangeInstance.address, + exchangeContractAddress: exchange.address, networkId: constants.TESTRPC_NETWORK_ID, }); - const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider); exWrapper = new ExchangeWrapper(exchange, zeroEx); makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); @@ -97,37 +129,39 @@ describe('Arbitrage', () => { takerFee: new BigNumber(0), }; orderFactory = new OrderFactory(zeroEx, defaultOrderParams); - const arbitrageInstance = await deployer.deployAsync(ContractName.Arbitrage, [ + arbitrage = await ArbitrageContract.deployFrom0xArtifactAsync( + artifacts.Arbitrage, + provider, + txDefaults, exchange.address, etherDelta.address, tokenTransferProxy.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 }); // Give some tokens to arbitrage contract - await weth.setBalance(arbitrage.address, takerTokenAmount, { from: coinbase }); + await weth.setBalance.sendTransactionAsync(arbitrage.address, takerTokenAmount, { from: coinbase }); // Fund the maker on exchange side - await zrx.setBalance(maker, makerTokenAmount, { from: coinbase }); + await zrx.setBalance.sendTransactionAsync(maker, makerTokenAmount, { from: coinbase }); // Set the allowance for the maker on Exchange side - await zrx.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker }); + await zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker }); amountGive = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18); // Fund the maker on EtherDelta side - await weth.setBalance(edMaker, amountGive, { from: coinbase }); + await weth.setBalance.sendTransactionAsync(edMaker, amountGive, { from: coinbase }); // Set the allowance for the maker on EtherDelta side - await weth.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edMaker }); + await weth.approve.sendTransactionAsync(etherDelta.address, INITIAL_ALLOWANCE, { from: edMaker }); // Deposit maker funds into EtherDelta await etherDelta.depositToken.sendTransactionAsync(weth.address, amountGive, { from: edMaker }); amountGet = makerTokenAmount; // Fund the front runner on EtherDelta side - await zrx.setBalance(edFrontRunner, amountGet, { from: coinbase }); + await zrx.setBalance.sendTransactionAsync(edFrontRunner, amountGet, { from: coinbase }); // Set the allowance for the front-runner on EtherDelta side - await zrx.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edFrontRunner }); + await zrx.approve.sendTransactionAsync(etherDelta.address, INITIAL_ALLOWANCE, { from: edFrontRunner }); // Deposit front runner funds into EtherDelta await etherDelta.depositToken.sendTransactionAsync(zrx.address, amountGet, { from: edFrontRunner }); }); @@ -194,11 +228,11 @@ describe('Arbitrage', () => { from: coinbase, }); const res = await zeroEx.awaitTransactionMinedAsync(txHash); - const postBalance = await weth.balanceOf(arbitrage.address); + const postBalance = await weth.balanceOf.callAsync(arbitrage.address); expect(postBalance).to.be.bignumber.equal(amountGive); }); it('should fail and revert if front-runned', async () => { - const preBalance = await weth.balanceOf(arbitrage.address); + const preBalance = await weth.balanceOf.callAsync(arbitrage.address); // Front-running transaction await etherDelta.trade.sendTransactionAsync( tokenGet, @@ -218,7 +252,7 @@ describe('Arbitrage', () => { await expect( arbitrage.makeAtomicTrade.sendTransactionAsync(addresses, values, v, r, s, { from: coinbase }), ).to.be.rejectedWith(constants.REVERT); - const postBalance = await weth.balanceOf(arbitrage.address); + const postBalance = await weth.balanceOf.callAsync(arbitrage.address); expect(preBalance).to.be.bignumber.equal(postBalance); }); }); diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 618bda72d..da2e5fb5b 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -6,12 +6,12 @@ import * as chai from 'chai'; import * as Web3 from 'web3'; import { DummyTokenContract } from '../src/contract_wrappers/generated/dummy_token'; +import { artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -33,8 +33,15 @@ describe('UnlimitedAllowanceToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; spender = accounts[1]; - const tokenInstance = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS); - token = new DummyTokenContract(tokenInstance.abi, tokenInstance.address, provider); + token = await DummyTokenContract.deployFrom0xArtifactAsync( + artifacts.DummyToken, + provider, + txDefaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ); await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner }); tokenAddress = token.address; }); diff --git a/packages/contracts/test/utils/deployer.ts b/packages/contracts/test/utils/deployer.ts deleted file mode 100644 index 2f0951475..000000000 --- a/packages/contracts/test/utils/deployer.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Deployer } from '@0xproject/deployer'; -import { devConstants } from '@0xproject/dev-utils'; -import * as path from 'path'; - -import { constants } from '../../util/constants'; - -import { web3 } from './web3_wrapper'; - -const deployerOpts = { - provider: web3.currentProvider, - artifactsDir: path.resolve('lib', 'src', 'artifacts'), - networkId: constants.TESTRPC_NETWORK_ID, - defaults: { - gas: devConstants.GAS_ESTIMATE, - }, -}; - -export const deployer = new Deployer(deployerOpts); diff --git a/packages/contracts/test/utils/web3_wrapper.ts b/packages/contracts/test/utils/web3_wrapper.ts index dd6f198c4..ed1c488a2 100644 --- a/packages/contracts/test/utils/web3_wrapper.ts +++ b/packages/contracts/test/utils/web3_wrapper.ts @@ -1,7 +1,11 @@ -import { web3Factory } from '@0xproject/dev-utils'; +import { devConstants, web3Factory } from '@0xproject/dev-utils'; import { Provider } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +export const txDefaults = { + from: devConstants.TESTRPC_FIRST_ADDRESS, + gas: devConstants.GAS_ESTIMATE, +}; const providerConfigs = { shouldUseInProcessGanache: true }; export const web3 = web3Factory.create(providerConfigs); export const provider = web3.currentProvider; diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index b01615b39..0056ed4b5 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -6,12 +6,12 @@ import * as chai from 'chai'; import * as Web3 from 'web3'; import { ZRXTokenContract } from '../src/contract_wrappers/generated/zrx_token'; +import { artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -34,8 +34,7 @@ describe('ZRXToken', () => { zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID, }); - const zrxInstance = await deployer.deployAsync(ContractName.ZRXToken); - zrx = new ZRXTokenContract(zrxInstance.abi, zrxInstance.address, provider); + zrx = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); zrxAddress = zrx.address; MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; }); |