From c536114b1638e30e5053dfc33d8e16465c0d373c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 12:25:17 +0200 Subject: make web3Wrapper a private instance variable --- test/0x.js_test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/0x.js_test.ts') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index bb312a00f..c45c70991 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -194,9 +194,9 @@ describe('ZeroEx library', () => { const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); stubs = [ - Sinon.stub(zeroEx.web3Wrapper, 'getNodeVersionAsync') + Sinon.stub((zeroEx as any).web3Wrapper, 'getNodeVersionAsync') .returns(Promise.resolve(newParityNodeVersion)), - Sinon.stub(zeroEx.web3Wrapper, 'signTransactionAsync') + Sinon.stub((zeroEx as any).web3Wrapper, 'signTransactionAsync') .returns(Promise.resolve(signature)), Sinon.stub(ZeroEx, 'isValidSignature').returns(true), ]; @@ -218,9 +218,9 @@ describe('ZeroEx library', () => { const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); stubs = [ - Sinon.stub(zeroEx.web3Wrapper, 'getNodeVersionAsync') + Sinon.stub((zeroEx as any).web3Wrapper, 'getNodeVersionAsync') .returns(Promise.resolve(newParityNodeVersion)), - Sinon.stub(zeroEx.web3Wrapper, 'signTransactionAsync') + Sinon.stub((zeroEx as any).web3Wrapper, 'signTransactionAsync') .returns(Promise.resolve(signature)), Sinon.stub(ZeroEx, 'isValidSignature').returns(true), ]; -- cgit v1.2.3 From d15002a1109ea00f4d92c7ae6259b5b657f5e4b3 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 12:30:38 +0200 Subject: Add tests for setProvider --- test/0x.js_test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/0x.js_test.ts') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index c45c70991..1e76ae71a 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -4,6 +4,7 @@ import 'mocha'; import * as BigNumber from 'bignumber.js'; import ChaiBigNumber = require('chai-bignumber'); import * as Sinon from 'sinon'; +import ProviderEngine = require('web3-provider-engine'); import {ZeroEx} from '../src/0x.js'; import {constants} from './utils/constants'; import {web3Factory} from './utils/web3_factory'; @@ -13,6 +14,28 @@ chai.use(ChaiBigNumber()); const expect = chai.expect; describe('ZeroEx library', () => { + describe('#setProvider', () => { + it('overrides the provider in the nested web3 instance and invalidates contractInstances', async () => { + const web3 = web3Factory.create(); + const zeroEx = new ZeroEx(web3); + // Instantiate the exchangeContract instance with the current provider + await (zeroEx.exchange as any).instantiateExchangeContractIfDoesntExistAsync(); + + const newProvider = web3Factory.getRpcProvider(); + // Add property to newProvider so that we can differentiate it from old provider + (newProvider as any).zeroExTestId = 1; + zeroEx.setProvider(newProvider); + + // Check that exchangeContract instance removed after provider update + expect((zeroEx.exchange as any).exchangeContractIfExists).to.be.an('undefined'); + + // Check that all nested web3 instances return the updated provider + const nestedWeb3WrapperProvider = (zeroEx as any).web3Wrapper.getCurrentProvider(); + expect((nestedWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); + const contractWrapperWeb3WrapperProvider = zeroEx.exchange.web3Wrapper.getCurrentProvider(); + expect((nestedWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); + }); + }); describe('#getOrderHash', () => { const expectedOrderHash = '0x103a5e97dab5dbeb8f385636f86a7d1e458a7ccbe1bd194727f0b2f85ab116c7'; it('defaults takerAddress to NULL address', () => { -- cgit v1.2.3 From a3ce892f85e7a8c1bb0e707f1e64f204a2ce29c6 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 12:43:50 +0200 Subject: Make tokenRegistry contract instantiation lazy and clear it on provider update --- test/0x.js_test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/0x.js_test.ts') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 1e76ae71a..4125b83fe 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -26,8 +26,9 @@ describe('ZeroEx library', () => { (newProvider as any).zeroExTestId = 1; zeroEx.setProvider(newProvider); - // Check that exchangeContract instance removed after provider update + // Check that contractInstances with old provider are removed after provider update expect((zeroEx.exchange as any).exchangeContractIfExists).to.be.an('undefined'); + expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.be.an('undefined'); // Check that all nested web3 instances return the updated provider const nestedWeb3WrapperProvider = (zeroEx as any).web3Wrapper.getCurrentProvider(); -- cgit v1.2.3 From 6aded80b2f1fd630323cdc97a4d66f1e82ce1632 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 12:51:34 +0200 Subject: remove unused import --- test/0x.js_test.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'test/0x.js_test.ts') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 4125b83fe..496b2780a 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -4,7 +4,6 @@ import 'mocha'; import * as BigNumber from 'bignumber.js'; import ChaiBigNumber = require('chai-bignumber'); import * as Sinon from 'sinon'; -import ProviderEngine = require('web3-provider-engine'); import {ZeroEx} from '../src/0x.js'; import {constants} from './utils/constants'; import {web3Factory} from './utils/web3_factory'; -- cgit v1.2.3 From 007c57ec4049ce4c929cbf97ca000a375570aeb4 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 12:52:28 +0200 Subject: Also instantiate tokenRegistry contract instance --- test/0x.js_test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/0x.js_test.ts') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 496b2780a..21e4b5a3b 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -17,8 +17,9 @@ describe('ZeroEx library', () => { it('overrides the provider in the nested web3 instance and invalidates contractInstances', async () => { const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); - // Instantiate the exchangeContract instance with the current provider + // Instantiate the contract instances with the current provider await (zeroEx.exchange as any).instantiateExchangeContractIfDoesntExistAsync(); + await (zeroEx.tokenRegistry as any).instantiateTokenRegistryContractIfDoesntExistAsync(); const newProvider = web3Factory.getRpcProvider(); // Add property to newProvider so that we can differentiate it from old provider -- cgit v1.2.3 From eefc8ca7ecb0543da3dad54ad1146eacb5a446f6 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 12:53:42 +0200 Subject: add assertions that contractInstances are not undefined before provider update --- test/0x.js_test.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/0x.js_test.ts') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 21e4b5a3b..041c5b433 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -20,6 +20,8 @@ describe('ZeroEx library', () => { // Instantiate the contract instances with the current provider await (zeroEx.exchange as any).instantiateExchangeContractIfDoesntExistAsync(); await (zeroEx.tokenRegistry as any).instantiateTokenRegistryContractIfDoesntExistAsync(); + expect((zeroEx.exchange as any).exchangeContractIfExists).to.not.be.an('undefined'); + expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.not.be.an('undefined'); const newProvider = web3Factory.getRpcProvider(); // Add property to newProvider so that we can differentiate it from old provider -- cgit v1.2.3 From 8561258ded12bc7d284933e61f6d052941258f40 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 12:56:10 +0200 Subject: Also test that web3Wrapper nested under tokenRegistryWrapper has updated provider --- test/0x.js_test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test/0x.js_test.ts') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 041c5b433..0c2afe879 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -35,8 +35,10 @@ describe('ZeroEx library', () => { // Check that all nested web3 instances return the updated provider const nestedWeb3WrapperProvider = (zeroEx as any).web3Wrapper.getCurrentProvider(); expect((nestedWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); - const contractWrapperWeb3WrapperProvider = zeroEx.exchange.web3Wrapper.getCurrentProvider(); - expect((nestedWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); + const exchangeWeb3WrapperProvider = zeroEx.exchange.web3Wrapper.getCurrentProvider(); + expect((exchangeWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); + const tokenRegistryWeb3WrapperProvider = zeroEx.tokenRegistry.web3Wrapper.getCurrentProvider(); + expect((tokenRegistryWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); }); }); describe('#getOrderHash', () => { -- cgit v1.2.3 From ad14c307cec8e0e7621b47e9e1ecb2652985190f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 14:23:44 +0200 Subject: Refactor exchangeWrapper and tokenRegistryWrapper to use contract getter that instantiates contract instance if not already instantiated --- test/0x.js_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/0x.js_test.ts') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 0c2afe879..b404b27ba 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -18,8 +18,8 @@ describe('ZeroEx library', () => { const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); // Instantiate the contract instances with the current provider - await (zeroEx.exchange as any).instantiateExchangeContractIfDoesntExistAsync(); - await (zeroEx.tokenRegistry as any).instantiateTokenRegistryContractIfDoesntExistAsync(); + await (zeroEx.exchange as any).getExchangeContractAsync(); + await (zeroEx.tokenRegistry as any).getTokenRegistryContractAsync(); expect((zeroEx.exchange as any).exchangeContractIfExists).to.not.be.an('undefined'); expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.not.be.an('undefined'); -- cgit v1.2.3 From 3522f94ff6cde1aad83299def7308025da9432d5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 14:26:07 +0200 Subject: use .be.undefined instead of .be.an('undefined') --- test/0x.js_test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/0x.js_test.ts') diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index b404b27ba..5d23d7094 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -20,8 +20,8 @@ describe('ZeroEx library', () => { // Instantiate the contract instances with the current provider await (zeroEx.exchange as any).getExchangeContractAsync(); await (zeroEx.tokenRegistry as any).getTokenRegistryContractAsync(); - expect((zeroEx.exchange as any).exchangeContractIfExists).to.not.be.an('undefined'); - expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.not.be.an('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(); // Add property to newProvider so that we can differentiate it from old provider @@ -29,8 +29,8 @@ describe('ZeroEx library', () => { zeroEx.setProvider(newProvider); // Check that contractInstances with old provider are removed after provider update - expect((zeroEx.exchange as any).exchangeContractIfExists).to.be.an('undefined'); - expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.be.an('undefined'); + expect((zeroEx.exchange as any).exchangeContractIfExists).to.be.undefined; + expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.be.undefined; // Check that all nested web3 instances return the updated provider const nestedWeb3WrapperProvider = (zeroEx as any).web3Wrapper.getCurrentProvider(); -- cgit v1.2.3