diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-27 10:33:49 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-27 10:44:21 +0800 |
commit | de0e436aad5d6b1c8a9425f075dbc3074b2fe31f (patch) | |
tree | 2090b3c57415106e6c4c8f5f051dbc23225d8533 /test | |
parent | 2c5f2210730d9c477e612fb3cb70db8d87e8545c (diff) | |
download | dexon-sol-tools-de0e436aad5d6b1c8a9425f075dbc3074b2fe31f.tar dexon-sol-tools-de0e436aad5d6b1c8a9425f075dbc3074b2fe31f.tar.gz dexon-sol-tools-de0e436aad5d6b1c8a9425f075dbc3074b2fe31f.tar.bz2 dexon-sol-tools-de0e436aad5d6b1c8a9425f075dbc3074b2fe31f.tar.lz dexon-sol-tools-de0e436aad5d6b1c8a9425f075dbc3074b2fe31f.tar.xz dexon-sol-tools-de0e436aad5d6b1c8a9425f075dbc3074b2fe31f.tar.zst dexon-sol-tools-de0e436aad5d6b1c8a9425f075dbc3074b2fe31f.zip |
Allow multiple exchange versions t be functional at the same time
Diffstat (limited to 'test')
-rw-r--r-- | test/0x.js_test.ts | 18 | ||||
-rw-r--r-- | test/artifacts_test.ts | 8 | ||||
-rw-r--r-- | test/exchange_wrapper_test.ts | 98 | ||||
-rw-r--r-- | test/utils/fill_scenarios.ts | 7 | ||||
-rw-r--r-- | test/utils/order_factory.ts | 2 |
5 files changed, 95 insertions, 38 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 9ec0a0c8e..3ddb5db1d 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -16,10 +16,11 @@ describe('ZeroEx library', () => { it('overrides provider in nested web3s and invalidates contractInstances', async () => { const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3.currentProvider); + const [exchangeContractAddress] = await zeroEx.exchange.getAvailableContractAddressedAsync(); // Instantiate the contract instances with the current provider - await (zeroEx.exchange as any)._getExchangeContractAsync(); + await (zeroEx.exchange as any)._getExchangeContractAsync(exchangeContractAddress); await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); - expect((zeroEx.exchange as any)._exchangeContractIfExists).to.not.be.undefined(); + expect((zeroEx.exchange as any)._exchangeContractByAddress[exchangeContractAddress]).to.not.be.undefined(); expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.not.be.undefined(); const newProvider = web3Factory.getRpcProvider(); @@ -28,7 +29,7 @@ describe('ZeroEx library', () => { await zeroEx.setProviderAsync(newProvider); // Check that contractInstances with old provider are removed after provider update - expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined(); + expect((zeroEx.exchange as any)._exchangeContractByAddress[exchangeContractAddress]).to.be.undefined(); expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.be.undefined(); // Check that all nested web3 instances return the updated provider @@ -52,6 +53,10 @@ describe('ZeroEx library', () => { const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3.currentProvider); + let exchangeContractAddress: string; + before(async () => { + [exchangeContractAddress] = await zeroEx.exchange.getAvailableContractAddressedAsync(); + }); it('should return false if the data doesn\'t pertain to the signature & address', async () => { expect(ZeroEx.isValidSignature('0x0', signature, address)).to.be.false(); return expect( @@ -77,7 +82,7 @@ describe('ZeroEx library', () => { const isValidSignatureLocal = ZeroEx.isValidSignature(dataHex, signature, address); expect(isValidSignatureLocal).to.be.true(); const isValidSignatureOnContract = await (zeroEx.exchange as any) - ._isValidSignatureUsingContractCallAsync(dataHex, signature, address); + ._isValidSignatureUsingContractCallAsync(dataHex, signature, address, exchangeContractAddress); return expect(isValidSignatureOnContract).to.be.true(); }); }); @@ -126,14 +131,15 @@ describe('ZeroEx library', () => { }); }); describe('#getOrderHashHexAsync', () => { - const exchangeContractAddress = constants.NULL_ADDRESS; - const expectedOrderHash = '0x103a5e97dab5dbeb8f385636f86a7d1e458a7ccbe1bd194727f0b2f85ab116c7'; + const expectedOrderHash = '0x39da987067a3c9e5f1617694f1301326ba8c8b0498ebef5df4863bed394e3c83'; + const exchangeContractAddress = '0xb69e673309512a9d726f87304c6984054f87a93b'; const order: Order = { maker: constants.NULL_ADDRESS, taker: constants.NULL_ADDRESS, feeRecipient: constants.NULL_ADDRESS, makerTokenAddress: constants.NULL_ADDRESS, takerTokenAddress: constants.NULL_ADDRESS, + exchangeContractAddress, salt: new BigNumber(0), makerFee: new BigNumber(0), takerFee: new BigNumber(0), diff --git a/test/artifacts_test.ts b/test/artifacts_test.ts index d71b45567..8bc110b21 100644 --- a/test/artifacts_test.ts +++ b/test/artifacts_test.ts @@ -1,9 +1,14 @@ import * as fs from 'fs'; +import * as chai from 'chai'; +import {chaiSetup} from './utils/chai_setup'; import HDWalletProvider = require('truffle-hdwallet-provider'); import {ZeroEx} from '../src'; import {web3Factory} from './utils/web3_factory'; import {constants} from './utils/constants'; +chaiSetup.configure(); +const expect = chai.expect; + // Those tests are slower cause they're talking to a remote node const TIMEOUT = 10000; @@ -22,7 +27,8 @@ describe('Artifacts', () => { await (zeroEx.token as any)._getProxyAddressAsync(); }).timeout(TIMEOUT); it('exchange contract is deployed', async () => { - await (zeroEx.exchange as any)._getExchangeContractAsync(); + const exchangeContractAddresses = await zeroEx.exchange.getAvailableContractAddressedAsync(); + expect(exchangeContractAddresses).to.have.lengthOf.above(0); }).timeout(TIMEOUT); }); }); diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 211c2819c..168d20e97 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -1,4 +1,5 @@ import 'mocha'; +import * as _ from 'lodash'; import * as chai from 'chai'; import * as Web3 from 'web3'; import * as BigNumber from 'bignumber.js'; @@ -37,14 +38,16 @@ describe('ExchangeWrapper', () => { let userAddresses: string[]; let zrxTokenAddress: string; let fillScenarios: FillScenarios; + let exchangeContractAddress: string; before(async () => { web3 = web3Factory.create(); zeroEx = new ZeroEx(web3.currentProvider); + [exchangeContractAddress] = await zeroEx.exchange.getAvailableContractAddressedAsync(); userAddresses = await promisify(web3.eth.getAccounts)(); tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokenUtils = new TokenUtils(tokens); zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address; - fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress); + fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress, exchangeContractAddress); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -413,8 +416,12 @@ describe('ExchangeWrapper', () => { }); it('should successfully fill multiple orders', async () => { await zeroEx.exchange.batchFillOrderAsync(orderFillBatch, shouldCheckTransfer, takerAddress); - const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); - const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); + const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync( + signedOrderHashHex, exchangeContractAddress, + ); + const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync( + anotherOrderHashHex, exchangeContractAddress, + ); expect(filledAmount).to.be.bignumber.equal(fillTakerAmount); expect(anotherFilledAmount).to.be.bignumber.equal(fillTakerAmount); }); @@ -446,8 +453,12 @@ describe('ExchangeWrapper', () => { await zeroEx.exchange.fillOrdersUpToAsync( signedOrders, fillUpToAmount, shouldCheckTransfer, takerAddress, ); - const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); - const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); + const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync( + signedOrderHashHex, exchangeContractAddress, + ); + const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync( + anotherOrderHashHex, exchangeContractAddress, + ); expect(filledAmount).to.be.bignumber.equal(fillableAmount); const remainingFillAmount = fillableAmount.minus(1); expect(anotherFilledAmount).to.be.bignumber.equal(remainingFillAmount); @@ -507,7 +518,9 @@ describe('ExchangeWrapper', () => { describe('successful cancels', () => { it('should cancel an order', async () => { await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); - const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); + const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync( + orderHashHex, exchangeContractAddress, + ); expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); }); it('should return cancelled amount', async () => { @@ -553,9 +566,12 @@ describe('ExchangeWrapper', () => { describe('successful batch cancels', () => { it('should cancel a batch of orders', async () => { await zeroEx.exchange.batchCancelOrderAsync(cancelBatch); - const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); + const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync( + orderHashHex, exchangeContractAddress, + ); const anotherCancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync( - anotherOrderHashHex); + anotherOrderHashHex, exchangeContractAddress, + ); expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); expect(anotherCancelledAmount).to.be.bignumber.equal(cancelAmount); }); @@ -587,48 +603,68 @@ describe('ExchangeWrapper', () => { describe('#getUnavailableTakerAmountAsync', () => { it ('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; - return expect(zeroEx.exchange.getUnavailableTakerAmountAsync(invalidOrderHashHex)).to.be.rejected(); + return expect(zeroEx.exchange.getUnavailableTakerAmountAsync( + invalidOrderHashHex, exchangeContractAddress, + )).to.be.rejected(); }); it ('should return zero if passed a valid but non-existent orderHash', async () => { - const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(NON_EXISTENT_ORDER_HASH); + const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync( + NON_EXISTENT_ORDER_HASH, exchangeContractAddress, + ); expect(unavailableValueT).to.be.bignumber.equal(0); }); it ('should return the unavailableValueT for a valid and partially filled orderHash', async () => { - const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(orderHash); + const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync( + orderHash, exchangeContractAddress, + ); expect(unavailableValueT).to.be.bignumber.equal(partialFillAmount); }); }); describe('#getFilledTakerAmountAsync', () => { it ('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; - return expect(zeroEx.exchange.getFilledTakerAmountAsync(invalidOrderHashHex)).to.be.rejected(); + return expect(zeroEx.exchange.getFilledTakerAmountAsync( + invalidOrderHashHex, exchangeContractAddress, + )).to.be.rejected(); }); it ('should return zero if passed a valid but non-existent orderHash', async () => { - const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(NON_EXISTENT_ORDER_HASH); + const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync( + NON_EXISTENT_ORDER_HASH, exchangeContractAddress, + ); expect(filledValueT).to.be.bignumber.equal(0); }); it ('should return the filledValueT for a valid and partially filled orderHash', async () => { - const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(orderHash); + const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync( + orderHash, exchangeContractAddress, + ); expect(filledValueT).to.be.bignumber.equal(partialFillAmount); }); }); describe('#getCanceledTakerAmountAsync', () => { it ('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; - return expect(zeroEx.exchange.getCanceledTakerAmountAsync(invalidOrderHashHex)).to.be.rejected(); + return expect(zeroEx.exchange.getCanceledTakerAmountAsync( + invalidOrderHashHex, exchangeContractAddress, + )).to.be.rejected(); }); it ('should return zero if passed a valid but non-existent orderHash', async () => { - const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(NON_EXISTENT_ORDER_HASH); + const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync( + NON_EXISTENT_ORDER_HASH, exchangeContractAddress, + ); expect(cancelledValueT).to.be.bignumber.equal(0); }); it ('should return the cancelledValueT for a valid and partially filled orderHash', async () => { - const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHash); + const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync( + orderHash, exchangeContractAddress, + ); expect(cancelledValueT).to.be.bignumber.equal(0); }); it ('should return the cancelledValueT for a valid and cancelled orderHash', async () => { const cancelAmount = fillableAmount.minus(partialFillAmount); await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); - const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHash); + const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync( + orderHash, exchangeContractAddress, + ); expect(cancelledValueT).to.be.bignumber.equal(cancelAmount); }); }); @@ -669,8 +705,9 @@ describe('ExchangeWrapper', () => { fromBlock: 0, toBlock: 'latest', }; - const zeroExEvent = await zeroEx.exchange.subscribeAsync(ExchangeEvents.LogFill, subscriptionOpts, - indexFilterValues); + const zeroExEvent = await zeroEx.exchange.subscribeAsync( + ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress, + ); zeroExEvent.watch((err: Error, event: ContractEvent) => { expect(err).to.be.null(); expect(event).to.not.be.undefined(); @@ -688,8 +725,9 @@ describe('ExchangeWrapper', () => { fromBlock: 0, toBlock: 'latest', }; - const zeroExEvent = await zeroEx.exchange.subscribeAsync(ExchangeEvents.LogCancel, subscriptionOpts, - indexFilterValues); + const zeroExEvent = await zeroEx.exchange.subscribeAsync( + ExchangeEvents.LogCancel, subscriptionOpts, indexFilterValues, exchangeContractAddress, + ); zeroExEvent.watch((err: Error, event: ContractEvent) => { expect(err).to.be.null(); expect(event).to.not.be.undefined(); @@ -706,7 +744,7 @@ describe('ExchangeWrapper', () => { toBlock: 'latest', }; const eventSubscriptionToBeCancelled = await zeroEx.exchange.subscribeAsync( - ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, + ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress, ); eventSubscriptionToBeCancelled.watch((err: Error, event: ContractEvent) => { done(new Error('Expected this subscription to have been cancelled')); @@ -716,7 +754,7 @@ describe('ExchangeWrapper', () => { await zeroEx.setProviderAsync(newProvider); const eventSubscriptionToStay = await zeroEx.exchange.subscribeAsync( - ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, + ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress, ); eventSubscriptionToStay.watch((err: Error, event: ContractEvent) => { expect(err).to.be.null(); @@ -737,7 +775,7 @@ describe('ExchangeWrapper', () => { toBlock: 'latest', }; const eventSubscriptionToBeStopped = await zeroEx.exchange.subscribeAsync( - ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, + ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress, ); eventSubscriptionToBeStopped.watch((err: Error, event: ContractEvent) => { done(new Error('Expected this subscription to have been stopped')); @@ -773,10 +811,12 @@ describe('ExchangeWrapper', () => { expect(orderHash).to.equal(orderHashFromContract); }); }); - describe('#getContractAddressAsync', () => { - it('returns the exchange contract address', async () => { - const exchangeAddress = await zeroEx.exchange.getContractAddressAsync(); - assert.isETHAddressHex('exchangeAddress', exchangeAddress); + describe('#getAvailableContractAddressedAsync', () => { + it('returns the exchange contract addresses', async () => { + const exchangeAddresses = await zeroEx.exchange.getAvailableContractAddressedAsync(); + _.map(exchangeAddresses, exchangeAddress => { + assert.isETHAddressHex('exchangeAddress', exchangeAddress); + }); }); }); }); diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index b8ad7eb12..65a912955 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -9,12 +9,15 @@ export class FillScenarios { private tokens: Token[]; private coinbase: string; private zrxTokenAddress: string; - constructor(zeroEx: ZeroEx, userAddresses: string[], tokens: Token[], zrxTokenAddress: string) { + private exchangeContractAddress: string; + constructor(zeroEx: ZeroEx, userAddresses: string[], + tokens: Token[], zrxTokenAddress: string, exchangeContractAddress: string) { this.zeroEx = zeroEx; this.userAddresses = userAddresses; this.tokens = tokens; this.coinbase = userAddresses[0]; this.zrxTokenAddress = zrxTokenAddress; + this.exchangeContractAddress = exchangeContractAddress; } public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string, makerAddress: string, takerAddress: string, @@ -103,7 +106,7 @@ export class FillScenarios { const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, makerAddress, takerAddress, makerFee, takerFee, makerFillableAmount, makerTokenAddress, takerFillableAmount, takerTokenAddress, - feeRecepient, expirationUnixTimestampSec); + this.exchangeContractAddress, feeRecepient, expirationUnixTimestampSec); return signedOrder; } } diff --git a/test/utils/order_factory.ts b/test/utils/order_factory.ts index ef19f2c4c..0ac430dfe 100644 --- a/test/utils/order_factory.ts +++ b/test/utils/order_factory.ts @@ -13,6 +13,7 @@ export const orderFactory = { makerTokenAddress: string, takerTokenAmount: BigNumber.BigNumber, takerTokenAddress: string, + exchangeContractAddress: string, feeRecipient: string, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise<SignedOrder> { const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite @@ -29,6 +30,7 @@ export const orderFactory = { makerTokenAddress, takerTokenAddress, salt: ZeroEx.generatePseudoRandomSalt(), + exchangeContractAddress, feeRecipient, expirationUnixTimestampSec, }; |