From 209266dbed9d7d038c90c2da8d9b99acab77c80c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 9 May 2018 20:36:28 +0200 Subject: Split 0x.js into contract-wrappers, order-watcher but keep 0x.js as a unifying library with the same interface --- packages/contracts/test/tutorials/arbitrage.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/contracts/test/tutorials') diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index ad83bbca3..2fbf850d0 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -1,5 +1,6 @@ import { ECSignature, SignedOrder, ZeroEx } from '0x.js'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; +import { ExchangeContractErrs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; @@ -14,7 +15,7 @@ import { constants } from '../../util/constants'; import { crypto } from '../../util/crypto'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; import { OrderFactory } from '../../util/order_factory'; -import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; +import { BalancesByOwner, ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; import { deployer } from '../utils/deployer'; import { provider, web3Wrapper } from '../utils/web3_wrapper'; -- cgit From 3d58b38e4e8565e7ee10e4d6c9f57cd745957ab4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 7 May 2018 22:11:09 +0200 Subject: Remove deployer from metacoin and contract tests --- packages/contracts/test/tutorials/arbitrage.ts | 74 +++++++++++++++++++------- 1 file changed, 54 insertions(+), 20 deletions(-) (limited to 'packages/contracts/test/tutorials') diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index ad83bbca3..f28120883 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 { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -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.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ); + zrx = await DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ); + const accountLevels = await AccountLevelsContract.deploy0xArtifactAsync( + artifacts.AccountLevels, + provider, + defaults, + ); 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.deploy0xArtifactAsync( + artifacts.EtherDelta, + provider, + defaults, 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.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, + provider, + defaults, + ); + const exchange = await ExchangeContract.deploy0xArtifactAsync( + artifacts.Exchange, + provider, + defaults, 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,12 +129,14 @@ describe('Arbitrage', () => { takerFee: new BigNumber(0), }; orderFactory = new OrderFactory(zeroEx, defaultOrderParams); - const arbitrageInstance = await deployer.deployAsync(ContractName.Arbitrage, [ + arbitrage = await ArbitrageContract.deploy0xArtifactAsync( + artifacts.Arbitrage, + provider, + defaults, 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 }); -- cgit From 75d24dea0e10d098d3833488a420498410c22991 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 8 May 2018 16:02:04 +0200 Subject: Fix linter issues --- packages/contracts/test/tutorials/arbitrage.ts | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'packages/contracts/test/tutorials') diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index f28120883..43dbd2989 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -40,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; @@ -58,7 +58,7 @@ describe('Arbitrage', () => { before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); [coinbase, maker, edMaker, edFrontRunner] = accounts; - weth = await DummyTokenContract.deploy0xArtifactAsync( + weth = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -67,7 +67,7 @@ describe('Arbitrage', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ); - zrx = await DummyTokenContract.deploy0xArtifactAsync( + zrx = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -76,7 +76,7 @@ describe('Arbitrage', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ); - const accountLevels = await AccountLevelsContract.deploy0xArtifactAsync( + const accountLevels = await AccountLevelsContract.deployFrom0xArtifactAsync( artifacts.AccountLevels, provider, defaults, @@ -85,7 +85,7 @@ describe('Arbitrage', () => { const edMakerFee = new BigNumber(0); const edTakerFee = new BigNumber(0); const edFeeRebate = new BigNumber(0); - etherDelta = await EtherDeltaContract.deploy0xArtifactAsync( + etherDelta = await EtherDeltaContract.deployFrom0xArtifactAsync( artifacts.EtherDelta, provider, defaults, @@ -96,12 +96,12 @@ describe('Arbitrage', () => { edTakerFee, edFeeRebate, ); - const tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, ); - const exchange = await ExchangeContract.deploy0xArtifactAsync( + const exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, defaults, @@ -129,7 +129,7 @@ describe('Arbitrage', () => { takerFee: new BigNumber(0), }; orderFactory = new OrderFactory(zeroEx, defaultOrderParams); - arbitrage = await ArbitrageContract.deploy0xArtifactAsync( + arbitrage = await ArbitrageContract.deployFrom0xArtifactAsync( artifacts.Arbitrage, provider, defaults, @@ -142,26 +142,26 @@ describe('Arbitrage', () => { 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 }); }); @@ -228,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, @@ -252,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); }); }); -- cgit From f854f3ee2bd74bbb61ed465099168b4d391f92c8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 15:20:00 +0200 Subject: Remove unused deployer docs configs --- packages/contracts/test/tutorials/arbitrage.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'packages/contracts/test/tutorials') diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index 43dbd2989..89062d4dc 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -21,7 +21,7 @@ import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -61,7 +61,7 @@ describe('Arbitrage', () => { weth = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -70,7 +70,7 @@ describe('Arbitrage', () => { zrx = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -79,7 +79,7 @@ describe('Arbitrage', () => { const accountLevels = await AccountLevelsContract.deployFrom0xArtifactAsync( artifacts.AccountLevels, provider, - defaults, + txDefaults, ); const edAdminAddress = accounts[0]; const edMakerFee = new BigNumber(0); @@ -88,7 +88,7 @@ describe('Arbitrage', () => { etherDelta = await EtherDeltaContract.deployFrom0xArtifactAsync( artifacts.EtherDelta, provider, - defaults, + txDefaults, edAdminAddress, feeRecipient, accountLevels.address, @@ -99,12 +99,12 @@ describe('Arbitrage', () => { const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); const exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, - defaults, + txDefaults, zrx.address, tokenTransferProxy.address, ); @@ -132,7 +132,7 @@ describe('Arbitrage', () => { arbitrage = await ArbitrageContract.deployFrom0xArtifactAsync( artifacts.Arbitrage, provider, - defaults, + txDefaults, exchange.address, etherDelta.address, tokenTransferProxy.address, -- cgit From e972ed8456b4e98af649b0e7878693322ed94a90 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 18:12:34 +0200 Subject: Fix linter errors --- packages/contracts/test/tutorials/arbitrage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts/test/tutorials') diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index 89062d4dc..aa86ecd43 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -21,7 +21,7 @@ import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; -- cgit