diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-29 01:44:10 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-29 01:44:10 +0800 |
commit | 36b21e6e7b8033117c9a1313c1294682184462f8 (patch) | |
tree | 71add18ce6347de87698b04915bec3c7de900e14 /packages/0x.js/test/utils/subproviders | |
parent | 977a6b279467c944223f3484bd0f07078706472c (diff) | |
download | dexon-sol-tools-36b21e6e7b8033117c9a1313c1294682184462f8.tar dexon-sol-tools-36b21e6e7b8033117c9a1313c1294682184462f8.tar.gz dexon-sol-tools-36b21e6e7b8033117c9a1313c1294682184462f8.tar.bz2 dexon-sol-tools-36b21e6e7b8033117c9a1313c1294682184462f8.tar.lz dexon-sol-tools-36b21e6e7b8033117c9a1313c1294682184462f8.tar.xz dexon-sol-tools-36b21e6e7b8033117c9a1313c1294682184462f8.tar.zst dexon-sol-tools-36b21e6e7b8033117c9a1313c1294682184462f8.zip |
Add fake gas estimate suprovider for tests
Diffstat (limited to 'packages/0x.js/test/utils/subproviders')
-rw-r--r-- | packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts | 27 | ||||
-rw-r--r-- | packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts | 31 |
2 files changed, 58 insertions, 0 deletions
diff --git a/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts b/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts new file mode 100644 index 000000000..bc11e56d8 --- /dev/null +++ b/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts @@ -0,0 +1,27 @@ +import {JSONRPCPayload} from '../../../src/types'; + +/* + * This class implements the web3-provider-engine subprovider interface and returns + * that the provider has no addresses when queried. + * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js + */ +export class EmptyWalletSubProvider { + // This method needs to be here to satisfy the interface but linter wants it to be static. + // tslint:disable-next-line:prefer-function-over-method + public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error|null, result: any) => void) { + switch (payload.method) { + case 'eth_accounts': + end(null, []); + return; + + default: + next(); + return; + } + } + // Required to implement this method despite not needing it for this subprovider + // tslint:disable-next-line:prefer-function-over-method + public setEngine(engine: any) { + // noop + } +} diff --git a/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts b/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts new file mode 100644 index 000000000..5eccb3d24 --- /dev/null +++ b/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts @@ -0,0 +1,31 @@ +import {JSONRPCPayload} from '../../../src/types'; + +/* + * This class implements the web3-provider-engine subprovider interface and returns + * the constant gas estimate when queried. + * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js + */ +export class FakeGasEstimateProvider { + private constantGasAmount: number; + constructor(constantGasAmount: number) { + this.constantGasAmount = constantGasAmount; + } + // This method needs to be here to satisfy the interface but linter wants it to be static. + // tslint:disable-next-line:prefer-function-over-method + public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error|null, result: any) => void) { + switch (payload.method) { + case 'eth_estimateGas': + end(null, this.constantGasAmount); + return; + + default: + next(); + return; + } + } + // Required to implement this method despite not needing it for this subprovider + // tslint:disable-next-line:prefer-function-over-method + public setEngine(engine: any) { + // noop + } +} |