aboutsummaryrefslogtreecommitdiffstats
path: root/test/0x.js_test.ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-05-30 20:31:37 +0800
committerGitHub <noreply@github.com>2017-05-30 20:31:37 +0800
commitb0436a4f679fb5ecb2e13cc9af18cb114d71ed63 (patch)
tree8c7b600fb2ead36e828d6acfbd0d47e3e7fb78d9 /test/0x.js_test.ts
parent911ab437b8f9371f70e835f680d799b7c62fb140 (diff)
parent3522f94ff6cde1aad83299def7308025da9432d5 (diff)
downloaddexon-sol-tools-b0436a4f679fb5ecb2e13cc9af18cb114d71ed63.tar
dexon-sol-tools-b0436a4f679fb5ecb2e13cc9af18cb114d71ed63.tar.gz
dexon-sol-tools-b0436a4f679fb5ecb2e13cc9af18cb114d71ed63.tar.bz2
dexon-sol-tools-b0436a4f679fb5ecb2e13cc9af18cb114d71ed63.tar.lz
dexon-sol-tools-b0436a4f679fb5ecb2e13cc9af18cb114d71ed63.tar.xz
dexon-sol-tools-b0436a4f679fb5ecb2e13cc9af18cb114d71ed63.tar.zst
dexon-sol-tools-b0436a4f679fb5ecb2e13cc9af18cb114d71ed63.zip
Merge pull request #25 from 0xProject/dontReinstantiateContractInstances
Add zeroEx.setProvider and clear contractInstances created with old provider
Diffstat (limited to 'test/0x.js_test.ts')
-rw-r--r--test/0x.js_test.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts
index c45c70991..5d23d7094 100644
--- a/test/0x.js_test.ts
+++ b/test/0x.js_test.ts
@@ -13,6 +13,34 @@ 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 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.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
+ (newProvider as any).zeroExTestId = 1;
+ zeroEx.setProvider(newProvider);
+
+ // Check that contractInstances with old provider are removed after provider update
+ 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();
+ 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', () => {
const expectedOrderHash = '0x103a5e97dab5dbeb8f385636f86a7d1e458a7ccbe1bd194727f0b2f85ab116c7';
it('defaults takerAddress to NULL address', () => {