aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-07 06:18:17 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-07 06:18:56 +0800
commite19c222f30accde6cdfe6b0a6c4c4a0dc450e33e (patch)
treee8d3f05e3d28abbe732718652fd5a5aaf93b4c8d
parent8b88ad835cf16786f8bd76157784fb09b63d1088 (diff)
downloaddexon-sol-tools-e19c222f30accde6cdfe6b0a6c4c4a0dc450e33e.tar
dexon-sol-tools-e19c222f30accde6cdfe6b0a6c4c4a0dc450e33e.tar.gz
dexon-sol-tools-e19c222f30accde6cdfe6b0a6c4c4a0dc450e33e.tar.bz2
dexon-sol-tools-e19c222f30accde6cdfe6b0a6c4c4a0dc450e33e.tar.lz
dexon-sol-tools-e19c222f30accde6cdfe6b0a6c4c4a0dc450e33e.tar.xz
dexon-sol-tools-e19c222f30accde6cdfe6b0a6c4c4a0dc450e33e.tar.zst
dexon-sol-tools-e19c222f30accde6cdfe6b0a6c4c4a0dc450e33e.zip
Add tests for networkId caching and invalidation
-rw-r--r--test/utils/constants.ts1
-rw-r--r--test/web3_trapper_test.ts29
2 files changed, 30 insertions, 0 deletions
diff --git a/test/utils/constants.ts b/test/utils/constants.ts
index 9b150b5c1..2e9a84e64 100644
--- a/test/utils/constants.ts
+++ b/test/utils/constants.ts
@@ -2,5 +2,6 @@ export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
RPC_HOST: 'localhost',
RPC_PORT: 8545,
+ RPC_NETWORK_ID: 50,
KOVAN_RPC_URL: 'https://kovan.0xproject.com',
};
diff --git a/test/web3_trapper_test.ts b/test/web3_trapper_test.ts
new file mode 100644
index 000000000..d417c9af5
--- /dev/null
+++ b/test/web3_trapper_test.ts
@@ -0,0 +1,29 @@
+import * as chai from 'chai';
+import {web3Factory} from './utils/web3_factory';
+import {ZeroEx} from '../src/';
+import {Web3Wrapper} from '../src/web3_wrapper';
+import {constants} from './utils/constants';
+
+chai.config.includeStack = true;
+const expect = chai.expect;
+
+describe.only('Web3Wrapper', () => {
+ const web3Provider = web3Factory.create().currentProvider;
+ describe('#getNetworkIdIfExistsAsync', () => {
+ it('caches network id requests', async () => {
+ const web3Wrapper = (new ZeroEx(web3Provider) as any)._web3Wrapper as Web3Wrapper;
+ expect((web3Wrapper as any).networkIdIfExists).to.be.undefined();
+ const networkId = await web3Wrapper.getNetworkIdIfExistsAsync();
+ expect((web3Wrapper as any).networkIdIfExists).to.be.equal(constants.RPC_NETWORK_ID);
+ });
+ it('invalidates network id cache on setProvider call', async () => {
+ const web3Wrapper = (new ZeroEx(web3Provider) as any)._web3Wrapper as Web3Wrapper;
+ expect((web3Wrapper as any).networkIdIfExists).to.be.undefined();
+ const networkId = await web3Wrapper.getNetworkIdIfExistsAsync();
+ expect((web3Wrapper as any).networkIdIfExists).to.be.equal(constants.RPC_NETWORK_ID);
+ const newProvider = web3Factory.create().currentProvider;
+ web3Wrapper.setProvider(newProvider);
+ expect((web3Wrapper as any).networkIdIfExists).to.be.undefined();
+ });
+ });
+});