diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-07-08 05:21:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-08 05:21:25 +0800 |
commit | 3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53 (patch) | |
tree | 341a0b69c4b72ddf437780fc952fa344979b29ef /test | |
parent | 6593ddf35cdcd7f474ea0cd108c19f673bdc441c (diff) | |
parent | 73a48ddb0d36064a1c5f50c3b917992fe5de89b4 (diff) | |
download | dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.gz dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.bz2 dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.lz dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.xz dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.zst dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.zip |
Merge pull request #95 from 0xProject/cache_net_version
Cache `net_version` requests
Diffstat (limited to 'test')
-rw-r--r-- | test/utils/constants.ts | 1 | ||||
-rw-r--r-- | test/web3_wrapper_test.ts | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/test/utils/constants.ts b/test/utils/constants.ts index 9b150b5c1..b677d7361 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, + TESTRPC_NETWORK_ID: 50, KOVAN_RPC_URL: 'https://kovan.0xproject.com', }; diff --git a/test/web3_wrapper_test.ts b/test/web3_wrapper_test.ts new file mode 100644 index 000000000..d1c2e8e89 --- /dev/null +++ b/test/web3_wrapper_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('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 networkIdIfExists = await web3Wrapper.getNetworkIdIfExistsAsync(); + expect((web3Wrapper as any).networkIdIfExists).to.be.equal(constants.TESTRPC_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 networkIdIfExists = await web3Wrapper.getNetworkIdIfExistsAsync(); + expect((web3Wrapper as any).networkIdIfExists).to.be.equal(constants.TESTRPC_NETWORK_ID); + const newProvider = web3Factory.create().currentProvider; + web3Wrapper.setProvider(newProvider); + expect((web3Wrapper as any).networkIdIfExists).to.be.undefined(); + }); + }); +}); |