diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-12 03:53:22 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-12 07:15:08 +0800 |
commit | 8052625e76675fbe8c894e7a58fe8707ee14c5ad (patch) | |
tree | 9fc20b56c46fdd76525cdf5ef2e1a7c839ed03bc /test | |
parent | 2787bdc46b1670fb0444578b62ae85e6aa626264 (diff) | |
download | dexon-sol-tools-8052625e76675fbe8c894e7a58fe8707ee14c5ad.tar dexon-sol-tools-8052625e76675fbe8c894e7a58fe8707ee14c5ad.tar.gz dexon-sol-tools-8052625e76675fbe8c894e7a58fe8707ee14c5ad.tar.bz2 dexon-sol-tools-8052625e76675fbe8c894e7a58fe8707ee14c5ad.tar.lz dexon-sol-tools-8052625e76675fbe8c894e7a58fe8707ee14c5ad.tar.xz dexon-sol-tools-8052625e76675fbe8c894e7a58fe8707ee14c5ad.tar.zst dexon-sol-tools-8052625e76675fbe8c894e7a58fe8707ee14c5ad.zip |
Migrate to using a single Exchange contract
Diffstat (limited to 'test')
-rw-r--r-- | test/0x.js_test.ts | 31 | ||||
-rw-r--r-- | test/artifacts_test.ts | 3 | ||||
-rw-r--r-- | test/exchange_wrapper_test.ts | 67 | ||||
-rw-r--r-- | test/proxy_wrapper_test.ts | 4 |
4 files changed, 24 insertions, 81 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 0c82c803d..c6ede843f 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -17,11 +17,10 @@ describe('ZeroEx library', () => { const zeroEx = new ZeroEx(web3.currentProvider); describe('#setProvider', () => { it('overrides provider in nested web3s and invalidates contractInstances', async () => { - const [exchangeContractAddress] = await zeroEx.getAvailableExchangeContractAddressesAsync(); // Instantiate the contract instances with the current provider - await (zeroEx.exchange as any)._getExchangeContractAsync(exchangeContractAddress); + await (zeroEx.exchange as any)._getExchangeContractAsync(); await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); - expect((zeroEx.exchange as any)._exchangeContractByAddress[exchangeContractAddress]).to.not.be.undefined(); + expect((zeroEx.exchange as any)._exchangeContractIfExists).to.not.be.undefined(); expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.not.be.undefined(); const newProvider = web3Factory.getRpcProvider(); @@ -30,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)._exchangeContractByAddress[exchangeContractAddress]).to.be.undefined(); + expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined(); expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.be.undefined(); // Check that all nested web3 wrapper instances return the updated provider @@ -52,10 +51,6 @@ describe('ZeroEx library', () => { s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', }; const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; - let exchangeContractAddress: string; - before(async () => { - [exchangeContractAddress] = await zeroEx.getAvailableExchangeContractAddressesAsync(); - }); 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( @@ -81,7 +76,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, exchangeContractAddress); + ._isValidSignatureUsingContractCallAsync(dataHex, signature, address); return expect(isValidSignatureOnContract).to.be.true(); }); }); @@ -210,22 +205,4 @@ describe('ZeroEx library', () => { expect(ecSignature).to.deep.equal(expectedECSignature); }); }); - describe('#getAvailableExchangeContractAddressesAsync', () => { - it('returns the exchange contract addresses', async () => { - const exchangeAddresses = await zeroEx.getAvailableExchangeContractAddressesAsync(); - _.map(exchangeAddresses, exchangeAddress => { - assert.isETHAddressHex('exchangeAddress', exchangeAddress); - }); - }); - }); - describe('#getProxyAuthorizedExchangeContractAddressesAsync', () => { - it('returns the Proxy authorized exchange contract addresses', async () => { - const exchangeAddresses = await zeroEx.getProxyAuthorizedExchangeContractAddressesAsync(); - for (const exchangeAddress of exchangeAddresses) { - assert.isETHAddressHex('exchangeAddress', exchangeAddress); - const isAuthorized = await zeroEx.proxy.isAuthorizedAsync(exchangeAddress); - expect(isAuthorized).to.be.true(); - } - }); - }); }); diff --git a/test/artifacts_test.ts b/test/artifacts_test.ts index 8393250aa..04b9ecb2d 100644 --- a/test/artifacts_test.ts +++ b/test/artifacts_test.ts @@ -27,8 +27,7 @@ describe('Artifacts', () => { await (zeroEx.token as any)._getProxyAddressAsync(); }).timeout(TIMEOUT); it('exchange contract is deployed', async () => { - const exchangeContractAddresses = await zeroEx.getAvailableExchangeContractAddressesAsync(); - expect(exchangeContractAddresses).to.have.lengthOf.above(0); + await zeroEx.exchange.getContractAddressAsync(); }).timeout(TIMEOUT); }); }); diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index ed2e45abf..d8af9d1cd 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -44,7 +44,7 @@ describe('ExchangeWrapper', () => { before(async () => { web3 = web3Factory.create(); zeroEx = new ZeroEx(web3.currentProvider); - [exchangeContractAddress] = await zeroEx.getAvailableExchangeContractAddressesAsync(); + exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); userAddresses = await promisify(web3.eth.getAccounts)(); tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokenUtils = new TokenUtils(tokens); @@ -418,12 +418,8 @@ describe('ExchangeWrapper', () => { }); it('should successfully fill multiple orders', async () => { await zeroEx.exchange.batchFillOrdersAsync(orderFillBatch, shouldCheckTransfer, takerAddress); - const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync( - signedOrderHashHex, exchangeContractAddress, - ); - const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync( - anotherOrderHashHex, exchangeContractAddress, - ); + const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); + const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); expect(filledAmount).to.be.bignumber.equal(fillTakerAmount); expect(anotherFilledAmount).to.be.bignumber.equal(fillTakerAmount); }); @@ -455,12 +451,8 @@ describe('ExchangeWrapper', () => { await zeroEx.exchange.fillOrdersUpToAsync( signedOrders, fillUpToAmount, shouldCheckTransfer, takerAddress, ); - const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync( - signedOrderHashHex, exchangeContractAddress, - ); - const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync( - anotherOrderHashHex, exchangeContractAddress, - ); + const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex); + const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex); expect(filledAmount).to.be.bignumber.equal(fillableAmount); const remainingFillAmount = fillableAmount.minus(1); expect(anotherFilledAmount).to.be.bignumber.equal(remainingFillAmount); @@ -520,9 +512,7 @@ describe('ExchangeWrapper', () => { describe('successful cancels', () => { it('should cancel an order', async () => { await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); - const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync( - orderHashHex, exchangeContractAddress, - ); + const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); }); it('should return cancelled amount', async () => { @@ -568,11 +558,9 @@ describe('ExchangeWrapper', () => { describe('successful batch cancels', () => { it('should cancel a batch of orders', async () => { await zeroEx.exchange.batchCancelOrdersAsync(cancelBatch); - const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync( - orderHashHex, exchangeContractAddress, - ); + const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); const anotherCancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync( - anotherOrderHashHex, exchangeContractAddress, + anotherOrderHashHex, ); expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); expect(anotherCancelledAmount).to.be.bignumber.equal(cancelAmount); @@ -605,68 +593,49 @@ describe('ExchangeWrapper', () => { describe('#getUnavailableTakerAmountAsync', () => { it('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; - return expect(zeroEx.exchange.getUnavailableTakerAmountAsync( - invalidOrderHashHex, exchangeContractAddress, - )).to.be.rejected(); + return expect(zeroEx.exchange.getUnavailableTakerAmountAsync(invalidOrderHashHex)).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, exchangeContractAddress, - ); + const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(NON_EXISTENT_ORDER_HASH); 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, exchangeContractAddress, - ); + const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(orderHash); 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, exchangeContractAddress, - )).to.be.rejected(); + return expect(zeroEx.exchange.getFilledTakerAmountAsync(invalidOrderHashHex)).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, exchangeContractAddress, + const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(NON_EXISTENT_ORDER_HASH, ); 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, exchangeContractAddress, - ); + const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(orderHash); 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, exchangeContractAddress, - )).to.be.rejected(); + return expect(zeroEx.exchange.getCanceledTakerAmountAsync(invalidOrderHashHex)).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, exchangeContractAddress, - ); + const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(NON_EXISTENT_ORDER_HASH); 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, exchangeContractAddress, - ); + const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHash); 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, exchangeContractAddress, - ); + const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHash); expect(cancelledValueT).to.be.bignumber.equal(cancelAmount); }); }); diff --git a/test/proxy_wrapper_test.ts b/test/proxy_wrapper_test.ts index c7f1a080a..42baed2b1 100644 --- a/test/proxy_wrapper_test.ts +++ b/test/proxy_wrapper_test.ts @@ -9,11 +9,9 @@ const expect = chai.expect; describe('ProxyWrapper', () => { let zeroEx: ZeroEx; - let exchangeContractAddress: string; before(async () => { const web3 = web3Factory.create(); zeroEx = new ZeroEx(web3.currentProvider); - [exchangeContractAddress] = await zeroEx.getAvailableExchangeContractAddressesAsync(); }); describe('#isAuthorizedAsync', () => { it('should return false if the address is not authorized', async () => { @@ -23,7 +21,7 @@ describe('ProxyWrapper', () => { }); describe('#getAuthorizedAddressesAsync', () => { it('should return the list of authorized addresses', async () => { - const authorizedAddresses = await zeroEx.proxy.getAuthorizedAddressesAsync(exchangeContractAddress); + const authorizedAddresses = await zeroEx.proxy.getAuthorizedAddressesAsync(); for (const authorizedAddress of authorizedAddresses) { const isAuthorized = await zeroEx.proxy.isAuthorizedAsync(authorizedAddress); expect(isAuthorized).to.be.true(); |