aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/0x.js/src/contract.ts2
-rw-r--r--packages/0x.js/test/utils/constants.ts1
-rw-r--r--packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts (renamed from packages/0x.js/src/subproviders/empty_wallet_subprovider.ts)2
-rw-r--r--packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts31
-rw-r--r--packages/0x.js/test/utils/web3_factory.ts4
5 files changed, 37 insertions, 3 deletions
diff --git a/packages/0x.js/src/contract.ts b/packages/0x.js/src/contract.ts
index 25a0609aa..0cd3a315f 100644
--- a/packages/0x.js/src/contract.ts
+++ b/packages/0x.js/src/contract.ts
@@ -58,7 +58,7 @@ export class Contract implements Web3.ContractInstance {
const promise = new Promise(async (resolve, reject) => {
const lastArg = args[args.length - 1];
let txData: Partial<Web3.TxData> = {};
- if (this.isTxData(lastArg)) {
+ if (!_.isUndefined(lastArg) && this.isTxData(lastArg)) {
txData = args.pop();
}
// Gas amount sourced with the following priorities:
diff --git a/packages/0x.js/test/utils/constants.ts b/packages/0x.js/test/utils/constants.ts
index 212abf4d6..75fdf49c9 100644
--- a/packages/0x.js/test/utils/constants.ts
+++ b/packages/0x.js/test/utils/constants.ts
@@ -8,4 +8,5 @@ export const constants = {
KOVAN_RPC_URL: 'https://kovan.infura.io',
ROPSTEN_RPC_URL: 'https://ropsten.infura.io',
ZRX_DECIMALS: 18,
+ GAS_ESTIMATE: 500000,
};
diff --git a/packages/0x.js/src/subproviders/empty_wallet_subprovider.ts b/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts
index 2993bc801..bc11e56d8 100644
--- a/packages/0x.js/src/subproviders/empty_wallet_subprovider.ts
+++ b/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts
@@ -1,4 +1,4 @@
-import {JSONRPCPayload} from '../types';
+import {JSONRPCPayload} from '../../../src/types';
/*
* This class implements the web3-provider-engine subprovider interface and returns
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
+ }
+}
diff --git a/packages/0x.js/test/utils/web3_factory.ts b/packages/0x.js/test/utils/web3_factory.ts
index b4bf1acd3..854c6091d 100644
--- a/packages/0x.js/test/utils/web3_factory.ts
+++ b/packages/0x.js/test/utils/web3_factory.ts
@@ -7,7 +7,8 @@ import * as Web3 from 'web3';
import ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
-import {EmptyWalletSubProvider} from '../../src/subproviders/empty_wallet_subprovider';
+import {EmptyWalletSubProvider} from './subproviders/empty_wallet_subprovider';
+import {FakeGasEstimateProvider} from './subproviders/fake_gas_estimate_subprovider';
import {constants} from './constants';
@@ -24,6 +25,7 @@ export const web3Factory = {
if (!hasAddresses) {
provider.addProvider(new EmptyWalletSubProvider());
}
+ provider.addProvider(new FakeGasEstimateProvider(constants.GAS_ESTIMATE));
provider.addProvider(new RpcSubprovider({
rpcUrl,
}));