aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-30 20:48:10 +0800
committerFabio Berger <me@fabioberger.com>2017-05-30 20:48:10 +0800
commit1f09470838342e4b9d493b9ddc2eecf65409483e (patch)
tree4ef197dc2e45fa79f6b5c7686fd88037d519c290 /test
parentf4bc7ecf5f72ee32931cf4fa44fffb50505d696d (diff)
parent6b321ca1c70b9dcf188b2a112015386cba0ad5f2 (diff)
downloaddexon-sol-tools-1f09470838342e4b9d493b9ddc2eecf65409483e.tar
dexon-sol-tools-1f09470838342e4b9d493b9ddc2eecf65409483e.tar.gz
dexon-sol-tools-1f09470838342e4b9d493b9ddc2eecf65409483e.tar.bz2
dexon-sol-tools-1f09470838342e4b9d493b9ddc2eecf65409483e.tar.lz
dexon-sol-tools-1f09470838342e4b9d493b9ddc2eecf65409483e.tar.xz
dexon-sol-tools-1f09470838342e4b9d493b9ddc2eecf65409483e.tar.zst
dexon-sol-tools-1f09470838342e4b9d493b9ddc2eecf65409483e.zip
Merge branch 'master' into erc20Wrapper
# Conflicts: # src/0x.js.ts
Diffstat (limited to 'test')
-rw-r--r--test/0x.js_test.ts36
-rw-r--r--test/exchange_wrapper.ts1
-rw-r--r--test/token_registry_wrapper_test.ts4
-rw-r--r--test/utils/web3_factory.ts10
4 files changed, 41 insertions, 10 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts
index bb312a00f..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', () => {
@@ -194,9 +222,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 +246,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),
];
diff --git a/test/exchange_wrapper.ts b/test/exchange_wrapper.ts
index 4bfc49374..55b84ce36 100644
--- a/test/exchange_wrapper.ts
+++ b/test/exchange_wrapper.ts
@@ -1,7 +1,6 @@
import 'mocha';
import * as chai from 'chai';
import chaiAsPromised = require('chai-as-promised');
-import * as Web3 from 'web3';
import {web3Factory} from './utils/web3_factory';
import {ZeroEx} from '../src/0x.js';
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
diff --git a/test/token_registry_wrapper_test.ts b/test/token_registry_wrapper_test.ts
index cd435c48c..c91555d8b 100644
--- a/test/token_registry_wrapper_test.ts
+++ b/test/token_registry_wrapper_test.ts
@@ -31,12 +31,12 @@ describe('TokenRegistryWrapper', () => {
describe('#getTokensAsync', () => {
it('should return all the tokens added to the tokenRegistry during the migration', async () => {
const tokens = await zeroEx.tokenRegistry.getTokensAsync();
- expect(tokens.length).to.be.equal(TOKEN_REGISTRY_SIZE_AFTER_MIGRATION);
+ expect(tokens).to.have.lengthOf(TOKEN_REGISTRY_SIZE_AFTER_MIGRATION);
const schemaValidator = new SchemaValidator();
_.each(tokens, token => {
const validationResult = schemaValidator.validate(token, tokenSchema);
- expect(validationResult.errors.length).to.be.equal(0);
+ expect(validationResult.errors).to.have.lengthOf(0);
});
});
});
diff --git a/test/utils/web3_factory.ts b/test/utils/web3_factory.ts
index 493fbc2df..ffdc0e4cf 100644
--- a/test/utils/web3_factory.ts
+++ b/test/utils/web3_factory.ts
@@ -10,14 +10,18 @@ import {constants} from './constants';
export const web3Factory = {
create(): Web3 {
+ const provider = this.getRpcProvider();
+ const web3 = new Web3();
+ web3.setProvider(provider);
+ return web3;
+ },
+ getRpcProvider(): Web3.Provider {
const provider = new ProviderEngine();
const rpcUrl = `http://${constants.RPC_HOST}:${constants.RPC_PORT}`;
provider.addProvider(new RpcSubprovider({
rpcUrl,
}));
provider.start();
- const web3 = new Web3();
- web3.setProvider(provider);
- return web3;
+ return provider;
},
};