From 59cb2132f27c0c28a1e6077aaac320e485786e65 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 5 Jun 2018 11:46:05 -0700 Subject: Linter now passes --- packages/contracts/src/utils/coverage.ts | 1 - packages/contracts/src/utils/exchange_wrapper.ts | 2 +- packages/contracts/src/utils/log_decoder.ts | 2 +- packages/contracts/src/utils/match_order_tester.ts | 24 +--------------------- packages/contracts/src/utils/multi_sig_wrapper.ts | 1 - packages/contracts/src/utils/order_factory.ts | 1 - packages/contracts/src/utils/order_utils.ts | 3 +-- .../contracts/src/utils/transaction_factory.ts | 1 - packages/contracts/src/utils/types.ts | 4 ++-- packages/contracts/src/utils/web3_wrapper.ts | 1 - 10 files changed, 6 insertions(+), 34 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/coverage.ts b/packages/contracts/src/utils/coverage.ts index a37939464..41c83f703 100644 --- a/packages/contracts/src/utils/coverage.ts +++ b/packages/contracts/src/utils/coverage.ts @@ -1,6 +1,5 @@ import { devConstants } from '@0xproject/dev-utils'; import { CoverageSubprovider, SolCompilerArtifactAdapter } from '@0xproject/sol-cov'; -import * as fs from 'fs'; import * as _ from 'lodash'; let coverageSubprovider: CoverageSubprovider; diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts index dd278e77c..ea8eb47c7 100644 --- a/packages/contracts/src/utils/exchange_wrapper.ts +++ b/packages/contracts/src/utils/exchange_wrapper.ts @@ -1,7 +1,7 @@ import { AssetProxyId, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import { LogEntry, Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; +import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; import { ExchangeContract } from '../contract_wrappers/generated/exchange'; diff --git a/packages/contracts/src/utils/log_decoder.ts b/packages/contracts/src/utils/log_decoder.ts index 07d10e69d..79d41d2da 100644 --- a/packages/contracts/src/utils/log_decoder.ts +++ b/packages/contracts/src/utils/log_decoder.ts @@ -39,7 +39,7 @@ export class LogDecoder { } public decodeLogOrThrow(log: LogEntry): LogWithDecodedArgs | RawLog { const logWithDecodedArgsOrLog = this._abiDecoder.tryToDecodeLogOrNoop(log); - if (_.isUndefined((logWithDecodedArgsOrLog as LogWithDecodedArgs).args)) { + if (_.isUndefined((logWithDecodedArgsOrLog).args)) { throw new Error(`Unable to decode log: ${JSON.stringify(log)}`); } LogDecoder.wrapLogBigNumbers(logWithDecodedArgsOrLog); diff --git a/packages/contracts/src/utils/match_order_tester.ts b/packages/contracts/src/utils/match_order_tester.ts index 6170188bc..f4f7f965b 100644 --- a/packages/contracts/src/utils/match_order_tester.ts +++ b/packages/contracts/src/utils/match_order_tester.ts @@ -1,38 +1,21 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; -import { assetProxyUtils, crypto, orderHashUtils } from '@0xproject/order-utils'; +import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils'; import { AssetProxyId, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; -import { LogWithDecodedArgs } from 'ethereum-types'; -import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; -import { DummyERC20TokenContract } from '../contract_wrappers/generated/dummy_e_r_c20_token'; -import { DummyERC721TokenContract } from '../contract_wrappers/generated/dummy_e_r_c721_token'; -import { ERC20ProxyContract } from '../contract_wrappers/generated/e_r_c20_proxy'; -import { ERC721ProxyContract } from '../contract_wrappers/generated/e_r_c721_proxy'; -import { - CancelContractEventArgs, - ExchangeContract, - FillContractEventArgs, -} from '../contract_wrappers/generated/exchange'; import { chaiSetup } from '../utils/chai_setup'; -import { constants } from '../utils/constants'; import { ERC20Wrapper } from '../utils/erc20_wrapper'; import { ERC721Wrapper } from '../utils/erc721_wrapper'; import { ExchangeWrapper } from '../utils/exchange_wrapper'; -import { OrderFactory } from '../utils/order_factory'; import { - ContractName, ERC20BalancesByOwner, ERC721TokenIdsByOwner, TransferAmountsByMatchOrders as TransferAmounts, } from '../utils/types'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); export class MatchOrderTester { private _exchangeWrapper: ExchangeWrapper; @@ -112,11 +95,6 @@ export class MatchOrderTester { initialTakerAssetFilledAmountLeft?: BigNumber, initialTakerAssetFilledAmountRight?: BigNumber, ): Promise<[ERC20BalancesByOwner, ERC721TokenIdsByOwner]> { - // Test setup & verify preconditions - const makerAddressLeft = signedOrderLeft.makerAddress; - const makerAddressRight = signedOrderRight.makerAddress; - const feeRecipientAddressLeft = signedOrderLeft.feeRecipientAddress; - const feeRecipientAddressRight = signedOrderRight.feeRecipientAddress; // Verify Left order preconditions const orderTakerAssetFilledAmountLeft = await this._exchangeWrapper.getTakerAssetFilledAmountAsync( orderHashUtils.getOrderHashHex(signedOrderLeft), diff --git a/packages/contracts/src/utils/multi_sig_wrapper.ts b/packages/contracts/src/utils/multi_sig_wrapper.ts index 9971e8f6e..750466ce1 100644 --- a/packages/contracts/src/utils/multi_sig_wrapper.ts +++ b/packages/contracts/src/utils/multi_sig_wrapper.ts @@ -6,7 +6,6 @@ import * as _ from 'lodash'; import { AssetProxyOwnerContract } from '../contract_wrappers/generated/asset_proxy_owner'; import { MultiSigWalletContract } from '../contract_wrappers/generated/multi_sig_wallet'; -import { constants } from './constants'; import { LogDecoder } from './log_decoder'; export class MultiSigWrapper { diff --git a/packages/contracts/src/utils/order_factory.ts b/packages/contracts/src/utils/order_factory.ts index af411c01f..6e4c9a883 100644 --- a/packages/contracts/src/utils/order_factory.ts +++ b/packages/contracts/src/utils/order_factory.ts @@ -1,7 +1,6 @@ import { generatePseudoRandomSalt, orderHashUtils } from '@0xproject/order-utils'; import { Order, SignatureType, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; -import * as _ from 'lodash'; import { constants } from './constants'; import { signingUtils } from './signing_utils'; diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts index 0d0329aa1..2a8791e4c 100644 --- a/packages/contracts/src/utils/order_utils.ts +++ b/packages/contracts/src/utils/order_utils.ts @@ -1,6 +1,5 @@ -import { Order, OrderWithoutExchangeAddress, SignedOrder } from '@0xproject/types'; +import { OrderWithoutExchangeAddress, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; -import ethUtil = require('ethereumjs-util'); import { CancelOrder, MatchOrder } from './types'; diff --git a/packages/contracts/src/utils/transaction_factory.ts b/packages/contracts/src/utils/transaction_factory.ts index 434611908..a060263b1 100644 --- a/packages/contracts/src/utils/transaction_factory.ts +++ b/packages/contracts/src/utils/transaction_factory.ts @@ -1,6 +1,5 @@ import { crypto, generatePseudoRandomSalt } from '@0xproject/order-utils'; import { SignatureType } from '@0xproject/types'; -import { BigNumber } from '@0xproject/utils'; import * as ethUtil from 'ethereumjs-util'; import { signingUtils } from './signing_utils'; diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index 360e1fdbc..491890fa1 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -1,6 +1,6 @@ -import { Order, OrderWithoutExchangeAddress } from '@0xproject/types'; +import { OrderWithoutExchangeAddress } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; -import { AbiDefinition, ContractAbi } from 'ethereum-types'; +import { AbiDefinition } from 'ethereum-types'; export interface ERC20BalancesByOwner { [ownerAddress: string]: { diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts index 1049ab967..95fb55753 100644 --- a/packages/contracts/src/utils/web3_wrapper.ts +++ b/packages/contracts/src/utils/web3_wrapper.ts @@ -1,7 +1,6 @@ import { devConstants, env, EnvVars, web3Factory } from '@0xproject/dev-utils'; import { prependSubprovider } from '@0xproject/subproviders'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import { Provider } from 'ethereum-types'; import { coverage } from './coverage'; -- cgit From 72fb8460e90237fb7879fc47e95d84b6aa54911b Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 21 May 2018 14:26:25 -0700 Subject: Update code after rebase --- packages/contracts/src/utils/assertions.ts | 20 ++++++++++++++++++++ packages/contracts/src/utils/constants.ts | 1 + packages/contracts/src/utils/web3_wrapper.ts | 8 ++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 packages/contracts/src/utils/assertions.ts (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts new file mode 100644 index 000000000..72c2734d8 --- /dev/null +++ b/packages/contracts/src/utils/assertions.ts @@ -0,0 +1,20 @@ +import * as chai from 'chai'; +import * as _ from 'lodash'; + +import { constants } from './constants'; + +const expect = chai.expect; + +// throws if the given promise does not reject with one of two expected error +// messages. +export const expectRevertOrAlwaysFailingTransaction = (p: Promise) => { + return expect(p) + .to.be.rejected() + .then(e => { + expect(e).to.satisfy( + (err: Error) => + _.includes(err.message, constants.REVERT) || + _.includes(err.message, constants.ALWAYS_FAILING_TRANSACTION), + ); + }); +}; diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts index 9b0b92545..144e22bc2 100644 --- a/packages/contracts/src/utils/constants.ts +++ b/packages/contracts/src/utils/constants.ts @@ -19,6 +19,7 @@ const TESTRPC_PRIVATE_KEYS_STRINGS = [ export const constants = { INVALID_OPCODE: 'invalid opcode', REVERT: 'revert', + ALWAYS_FAILING_TRANSACTION: 'always failing transaction', TESTRPC_NETWORK_ID: 50, AWAIT_TRANSACTION_MINED_MS: 100, MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts index 1049ab967..a89d7e8d0 100644 --- a/packages/contracts/src/utils/web3_wrapper.ts +++ b/packages/contracts/src/utils/web3_wrapper.ts @@ -7,13 +7,17 @@ import { coverage } from './coverage'; export const txDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, - gas: devConstants.GAS_LIMIT, + // gas: devConstants.GAS_LIMIT, +}; +const providerConfigs = { + shouldUseInProcessGanache: false, + rpcUrl: 'http://localhost:8501', }; -const providerConfigs = { shouldUseInProcessGanache: true }; export const provider = web3Factory.getRpcProvider(providerConfigs); const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage); if (isCoverageEnabled) { const coverageSubprovider = coverage.getCoverageSubproviderSingleton(); prependSubprovider(provider, coverageSubprovider); } + export const web3Wrapper = new Web3Wrapper(provider); -- cgit From 1cc9d9c0713a56b59717498fcae6dc2720ca4fb0 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 22 May 2018 12:47:37 -0700 Subject: Replace constant.REVERT test assertions with expectRevertOrAlwaysFailingTransaction --- packages/contracts/src/utils/assertions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index 72c2734d8..e3f31bf89 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -7,7 +7,7 @@ const expect = chai.expect; // throws if the given promise does not reject with one of two expected error // messages. -export const expectRevertOrAlwaysFailingTransaction = (p: Promise) => { +export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { return expect(p) .to.be.rejected() .then(e => { @@ -17,4 +17,4 @@ export const expectRevertOrAlwaysFailingTransaction = (p: Promise) => { _.includes(err.message, constants.ALWAYS_FAILING_TRANSACTION), ); }); -}; +} -- cgit From 2004c0d7398a5e77d08e3b4d8030c0f22cb09cc8 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Fri, 1 Jun 2018 13:19:36 -0700 Subject: Add ability to quickly switch between Geth and Ganache by changing a const --- packages/contracts/src/utils/web3_wrapper.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts index a89d7e8d0..bd582e841 100644 --- a/packages/contracts/src/utils/web3_wrapper.ts +++ b/packages/contracts/src/utils/web3_wrapper.ts @@ -5,14 +5,27 @@ import { Provider } from 'ethereum-types'; import { coverage } from './coverage'; -export const txDefaults = { +const useGeth = false; + +const ganacheTxDefaults = { + from: devConstants.TESTRPC_FIRST_ADDRESS, + gas: devConstants.GAS_LIMIT, +}; +const gethTxDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, - // gas: devConstants.GAS_LIMIT, }; -const providerConfigs = { +export const txDefaults = useGeth ? gethTxDefaults : ganacheTxDefaults; + +const gethConfigs = { shouldUseInProcessGanache: false, rpcUrl: 'http://localhost:8501', + shouldUseFakeGasEstimate: false, +}; +const ganacheConfigs = { + shouldUseInProcessGanache: true, }; +const providerConfigs = useGeth ? gethConfigs : ganacheConfigs; + export const provider = web3Factory.getRpcProvider(providerConfigs); const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage); if (isCoverageEnabled) { -- cgit From 98ffe9931d4fd8886955c45c42eb63b33184ddd2 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Fri, 1 Jun 2018 14:03:12 -0700 Subject: Get LibBytes tests working on both Ganache and Geth --- packages/contracts/src/utils/constants.ts | 5 +++++ packages/contracts/src/utils/web3_wrapper.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts index 144e22bc2..a0369c256 100644 --- a/packages/contracts/src/utils/constants.ts +++ b/packages/contracts/src/utils/constants.ts @@ -20,6 +20,11 @@ export const constants = { INVALID_OPCODE: 'invalid opcode', REVERT: 'revert', ALWAYS_FAILING_TRANSACTION: 'always failing transaction', + LIB_BYTES_GT_ZERO_LENGTH_REQUIRED: 'Length must be greater than 0.', + LIB_BYTES_GTE_4_LENGTH_REQUIRED: 'Length must be greater than or equal to 4.', + LIB_BYTES_GTE_20_LENGTH_REQUIRED: 'Length must be greater than or equal to 20.', + LIB_BYTES_GTE_32_LENGTH_REQUIRED: 'Length must be greater than or equal to 32.', + LIB_BYTES_INDEX_OUT_OF_BOUNDS: 'Specified array index is out of bounds.', TESTRPC_NETWORK_ID: 50, AWAIT_TRANSACTION_MINED_MS: 100, MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts index bd582e841..49744dea1 100644 --- a/packages/contracts/src/utils/web3_wrapper.ts +++ b/packages/contracts/src/utils/web3_wrapper.ts @@ -5,7 +5,7 @@ import { Provider } from 'ethereum-types'; import { coverage } from './coverage'; -const useGeth = false; +const useGeth = true; const ganacheTxDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, -- cgit From 2dfc4680941293ca9f4a55f3ca58b9ee68872754 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Fri, 1 Jun 2018 15:59:34 -0700 Subject: Update more tests to pass on Geth --- packages/contracts/src/utils/assertions.ts | 12 ++++++++++++ packages/contracts/src/utils/constants.ts | 2 ++ 2 files changed, 14 insertions(+) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index e3f31bf89..1e8d58b9f 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -18,3 +18,15 @@ export function expectRevertOrAlwaysFailingTransaction(p: Promise): Promis ); }); } + +export function expectInsufficientFunds(p: Promise): PromiseLike { + return expect(p) + .to.be.rejected() + .then(e => { + expect(e).to.satisfy( + (err: Error) => + _.includes(err.message, 'insufficient funds') || + _.includes(err.message, "sender doesn't have enough funds"), + ); + }); +} diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts index a0369c256..60f41b51b 100644 --- a/packages/contracts/src/utils/constants.ts +++ b/packages/contracts/src/utils/constants.ts @@ -25,6 +25,8 @@ export const constants = { LIB_BYTES_GTE_20_LENGTH_REQUIRED: 'Length must be greater than or equal to 20.', LIB_BYTES_GTE_32_LENGTH_REQUIRED: 'Length must be greater than or equal to 32.', LIB_BYTES_INDEX_OUT_OF_BOUNDS: 'Specified array index is out of bounds.', + ERC20_INSUFFICIENT_BALANCE: 'Insufficient balance to complete transfer.', + ERC20_INSUFFICIENT_ALLOWANCE: 'Insufficient allowance to complete transfer.', TESTRPC_NETWORK_ID: 50, AWAIT_TRANSACTION_MINED_MS: 100, MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, -- cgit From 5900899c0195a851c8d20ca0d4ad85dbbf4c100f Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 4 Jun 2018 17:47:18 -0700 Subject: Add support for TEST_PROVIDER env var --- packages/contracts/src/utils/web3_wrapper.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts index 49744dea1..6df8ac073 100644 --- a/packages/contracts/src/utils/web3_wrapper.ts +++ b/packages/contracts/src/utils/web3_wrapper.ts @@ -5,7 +5,7 @@ import { Provider } from 'ethereum-types'; import { coverage } from './coverage'; -const useGeth = true; +const testProvider = process.env.TEST_PROVIDER || 'ganache'; const ganacheTxDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, @@ -14,7 +14,7 @@ const ganacheTxDefaults = { const gethTxDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, }; -export const txDefaults = useGeth ? gethTxDefaults : ganacheTxDefaults; +export const txDefaults = testProvider === 'ganache' ? ganacheTxDefaults : gethTxDefaults; const gethConfigs = { shouldUseInProcessGanache: false, @@ -24,7 +24,8 @@ const gethConfigs = { const ganacheConfigs = { shouldUseInProcessGanache: true, }; -const providerConfigs = useGeth ? gethConfigs : ganacheConfigs; + +const providerConfigs = testProvider === 'ganache' ? ganacheConfigs : gethConfigs; export const provider = web3Factory.getRpcProvider(providerConfigs); const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage); -- cgit From 577a8dd005715ba0fd22a5118d99ccc87af0782c Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 4 Jun 2018 17:51:50 -0700 Subject: Fix some more test cases, especially those that call increaseTime --- packages/contracts/src/utils/increase_time.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 packages/contracts/src/utils/increase_time.ts (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/increase_time.ts b/packages/contracts/src/utils/increase_time.ts new file mode 100644 index 000000000..726a759f3 --- /dev/null +++ b/packages/contracts/src/utils/increase_time.ts @@ -0,0 +1,26 @@ +import * as _ from 'lodash'; + +import { constants } from './constants'; +import { web3Wrapper } from './web3_wrapper'; + +let firstAccount: string | undefined; + +// increases time by the given number of seconds and then mines a block so that +// the current block timestamp has the offset applied. +export async function increaseTimeAndMineBlockAsync(seconds: number): Promise { + if (_.isUndefined(firstAccount)) { + const accounts = await web3Wrapper.getAvailableAddressesAsync(); + firstAccount = accounts[0]; + } + + const offset = await web3Wrapper.increaseTimeAsync(seconds); + // Note: we need to send a transaction after increasing time so + // that a block is actually mined. The contract looks at the + // last mined block for the timestamp. + await web3Wrapper.awaitTransactionSuccessAsync( + await web3Wrapper.sendTransactionAsync({ from: firstAccount, to: firstAccount, value: 0 }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + + return offset; +} -- cgit From bca62c813d2e821c56968916615861366402435b Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 4 Jun 2018 18:10:42 -0700 Subject: Throw in web3-wrapper when rawCallResult is '0x' --- packages/contracts/src/utils/assertions.ts | 12 ++++++++++++ packages/contracts/src/utils/constants.ts | 1 + 2 files changed, 13 insertions(+) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index 1e8d58b9f..4fc410363 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -30,3 +30,15 @@ export function expectInsufficientFunds(p: Promise): PromiseLike { ); }); } + +export function expectRevertOrContractCallFailed(p: Promise): PromiseLike { + return expect(p) + .to.be.rejected() + .then(e => { + expect(e).to.satisfy( + (err: Error) => + _.includes(err.message, constants.REVERT) || + _.includes(err.message, constants.CONTRACT_CALL_FAILED), + ); + }); +} diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts index 60f41b51b..a21ca29ed 100644 --- a/packages/contracts/src/utils/constants.ts +++ b/packages/contracts/src/utils/constants.ts @@ -20,6 +20,7 @@ export const constants = { INVALID_OPCODE: 'invalid opcode', REVERT: 'revert', ALWAYS_FAILING_TRANSACTION: 'always failing transaction', + CONTRACT_CALL_FAILED: 'Contract call failed', LIB_BYTES_GT_ZERO_LENGTH_REQUIRED: 'Length must be greater than 0.', LIB_BYTES_GTE_4_LENGTH_REQUIRED: 'Length must be greater than or equal to 4.', LIB_BYTES_GTE_20_LENGTH_REQUIRED: 'Length must be greater than or equal to 20.', -- cgit From 36b01fbdcfcda93d185e018e31a919c36f2848ac Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 14:59:20 -0700 Subject: Add additional gas to calls to fillOrderNoThrow --- packages/contracts/src/utils/exchange_wrapper.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts index dd278e77c..24c3ba4be 100644 --- a/packages/contracts/src/utils/exchange_wrapper.ts +++ b/packages/contracts/src/utils/exchange_wrapper.ts @@ -60,14 +60,14 @@ export class ExchangeWrapper { public async fillOrderNoThrowAsync( signedOrder: SignedOrder, from: string, - opts: { takerAssetFillAmount?: BigNumber } = {}, + opts: { takerAssetFillAmount?: BigNumber; gas?: number } = {}, ): Promise { const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount); const txHash = await this._exchange.fillOrderNoThrow.sendTransactionAsync( params.order, params.takerAssetFillAmount, params.signature, - { from }, + { from, gas: opts.gas }, ); const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash); return tx; @@ -105,14 +105,14 @@ export class ExchangeWrapper { public async batchFillOrdersNoThrowAsync( orders: SignedOrder[], from: string, - opts: { takerAssetFillAmounts?: BigNumber[] } = {}, + opts: { takerAssetFillAmounts?: BigNumber[]; gas?: number } = {}, ): Promise { const params = formatters.createBatchFill(orders, opts.takerAssetFillAmounts); const txHash = await this._exchange.batchFillOrdersNoThrow.sendTransactionAsync( params.orders, params.takerAssetFillAmounts, params.signatures, - { from }, + { from, gas: opts.gas }, ); const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash); return tx; @@ -135,14 +135,14 @@ export class ExchangeWrapper { public async marketSellOrdersNoThrowAsync( orders: SignedOrder[], from: string, - opts: { takerAssetFillAmount: BigNumber }, + opts: { takerAssetFillAmount: BigNumber; gas?: number }, ): Promise { const params = formatters.createMarketSellOrders(orders, opts.takerAssetFillAmount); const txHash = await this._exchange.marketSellOrdersNoThrow.sendTransactionAsync( params.orders, params.takerAssetFillAmount, params.signatures, - { from }, + { from, gas: opts.gas }, ); const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash); return tx; -- cgit From 63caddea62453863de84a4b53e14fe3e61d3008f Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 15:12:09 -0700 Subject: Small fixes and cleanup --- packages/contracts/src/utils/assertions.ts | 6 ++---- packages/contracts/src/utils/constants.ts | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index 4fc410363..1ea071d01 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -13,8 +13,7 @@ export function expectRevertOrAlwaysFailingTransaction(p: Promise): Promis .then(e => { expect(e).to.satisfy( (err: Error) => - _.includes(err.message, constants.REVERT) || - _.includes(err.message, constants.ALWAYS_FAILING_TRANSACTION), + _.includes(err.message, constants.REVERT) || _.includes(err.message, 'always failing transaction'), ); }); } @@ -37,8 +36,7 @@ export function expectRevertOrContractCallFailed(p: Promise): PromiseLike< .then(e => { expect(e).to.satisfy( (err: Error) => - _.includes(err.message, constants.REVERT) || - _.includes(err.message, constants.CONTRACT_CALL_FAILED), + _.includes(err.message, constants.REVERT) || _.includes(err.message, 'Contract call failed'), ); }); } diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts index a21ca29ed..fa2a4af3c 100644 --- a/packages/contracts/src/utils/constants.ts +++ b/packages/contracts/src/utils/constants.ts @@ -19,8 +19,6 @@ const TESTRPC_PRIVATE_KEYS_STRINGS = [ export const constants = { INVALID_OPCODE: 'invalid opcode', REVERT: 'revert', - ALWAYS_FAILING_TRANSACTION: 'always failing transaction', - CONTRACT_CALL_FAILED: 'Contract call failed', LIB_BYTES_GT_ZERO_LENGTH_REQUIRED: 'Length must be greater than 0.', LIB_BYTES_GTE_4_LENGTH_REQUIRED: 'Length must be greater than or equal to 4.', LIB_BYTES_GTE_20_LENGTH_REQUIRED: 'Length must be greater than or equal to 20.', -- cgit From d6d7f4e875b161aa7284467a61f67989f76ec89e Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 16:20:38 -0700 Subject: Update more things to work with both Geth and Ganache --- packages/contracts/src/utils/assertions.ts | 36 ++++++++++++------------------ 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index 1ea071d01..c08bc7271 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -5,38 +5,30 @@ import { constants } from './constants'; const expect = chai.expect; -// throws if the given promise does not reject with one of two expected error -// messages. -export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { +function _expectEitherError(p: Promise, error1: string, error2: string): PromiseLike { return expect(p) .to.be.rejected() .then(e => { expect(e).to.satisfy( - (err: Error) => - _.includes(err.message, constants.REVERT) || _.includes(err.message, 'always failing transaction'), + (err: Error) => _.includes(err.message, error1) || _.includes(err.message, error2), + `expected promise to reject with error message that includes "${error1}" or "${error2}", but got: ` + + `"${e.message}"\n`, ); }); } export function expectInsufficientFunds(p: Promise): PromiseLike { - return expect(p) - .to.be.rejected() - .then(e => { - expect(e).to.satisfy( - (err: Error) => - _.includes(err.message, 'insufficient funds') || - _.includes(err.message, "sender doesn't have enough funds"), - ); - }); + return _expectEitherError(p, 'insufficient funds', "sender doesn't have enough funds"); +} + +export function expectRevertOrOtherError(p: Promise, otherError: string): PromiseLike { + return _expectEitherError(p, constants.REVERT, otherError); +} + +export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { + return expectRevertOrOtherError(p, 'always failing transaction'); } export function expectRevertOrContractCallFailed(p: Promise): PromiseLike { - return expect(p) - .to.be.rejected() - .then(e => { - expect(e).to.satisfy( - (err: Error) => - _.includes(err.message, constants.REVERT) || _.includes(err.message, 'Contract call failed'), - ); - }); + return expectRevertOrOtherError(p, 'Contract call failed'); } -- cgit From ba6806df5d2d4b31c125a0c58cc6cd65bf555933 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 16:45:37 -0700 Subject: Fix linter errors --- packages/contracts/src/utils/assertions.ts | 29 +++++++++++++++++++++++++++ packages/contracts/src/utils/increase_time.ts | 9 +++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index c08bc7271..fc57f93fb 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -17,18 +17,47 @@ function _expectEitherError(p: Promise, error1: string, error2: string): P }); } +/** + * Rejects if the given Promise does not reject with an error indicating + * insufficient funds. + * @param p the Promise which is expected to reject + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectInsufficientFunds(p: Promise): PromiseLike { return _expectEitherError(p, 'insufficient funds', "sender doesn't have enough funds"); } +/** + * Rejects if the given Promise does not reject with a "revert" error or the + * given otherError. + * @param p the Promise which is expected to reject + * @param otherError the other error which is accepted as a valid reject error. + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectRevertOrOtherError(p: Promise, otherError: string): PromiseLike { return _expectEitherError(p, constants.REVERT, otherError); } +/** + * Rejects if the given Promise does not reject with a "revert" or "always + * failing transaction" error. + * @param p the Promise which is expected to reject + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { return expectRevertOrOtherError(p, 'always failing transaction'); } +/** + * Rejects if the given Promise does not reject with a "revert" or "Contract + * call failed" error. + * @param p the Promise which is expected to reject + * @returns a new Promise which will reject if the conditions are not met and + * otherwise resolve with no value. + */ export function expectRevertOrContractCallFailed(p: Promise): PromiseLike { return expectRevertOrOtherError(p, 'Contract call failed'); } diff --git a/packages/contracts/src/utils/increase_time.ts b/packages/contracts/src/utils/increase_time.ts index 726a759f3..5336a180d 100644 --- a/packages/contracts/src/utils/increase_time.ts +++ b/packages/contracts/src/utils/increase_time.ts @@ -5,8 +5,13 @@ import { web3Wrapper } from './web3_wrapper'; let firstAccount: string | undefined; -// increases time by the given number of seconds and then mines a block so that -// the current block timestamp has the offset applied. +/** + * Increases time by the given number of seconds and then mines a block so that + * the current block timestamp has the offset applied. + * @param seconds the Promise which is expected to reject + * @returns a new Promise which will resolve with the new total time offset or + * reject if the time could not be increased. + */ export async function increaseTimeAndMineBlockAsync(seconds: number): Promise { if (_.isUndefined(firstAccount)) { const accounts = await web3Wrapper.getAvailableAddressesAsync(); -- cgit From 167a38e27d09af12af6c59f1b486c835420fbac1 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 16:56:16 -0700 Subject: Add Async suffix to relevant assertions --- packages/contracts/src/utils/assertions.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index fc57f93fb..615e648f3 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -5,7 +5,7 @@ import { constants } from './constants'; const expect = chai.expect; -function _expectEitherError(p: Promise, error1: string, error2: string): PromiseLike { +function _expectEitherErrorAsync(p: Promise, error1: string, error2: string): PromiseLike { return expect(p) .to.be.rejected() .then(e => { @@ -24,8 +24,8 @@ function _expectEitherError(p: Promise, error1: string, error2: string): P * @returns a new Promise which will reject if the conditions are not met and * otherwise resolve with no value. */ -export function expectInsufficientFunds(p: Promise): PromiseLike { - return _expectEitherError(p, 'insufficient funds', "sender doesn't have enough funds"); +export function expectInsufficientFundsAsync(p: Promise): PromiseLike { + return _expectEitherErrorAsync(p, 'insufficient funds', "sender doesn't have enough funds"); } /** @@ -36,8 +36,8 @@ export function expectInsufficientFunds(p: Promise): PromiseLike { * @returns a new Promise which will reject if the conditions are not met and * otherwise resolve with no value. */ -export function expectRevertOrOtherError(p: Promise, otherError: string): PromiseLike { - return _expectEitherError(p, constants.REVERT, otherError); +export function expectRevertOrOtherErrorAsync(p: Promise, otherError: string): PromiseLike { + return _expectEitherErrorAsync(p, constants.REVERT, otherError); } /** @@ -47,8 +47,8 @@ export function expectRevertOrOtherError(p: Promise, otherError: string): * @returns a new Promise which will reject if the conditions are not met and * otherwise resolve with no value. */ -export function expectRevertOrAlwaysFailingTransaction(p: Promise): PromiseLike { - return expectRevertOrOtherError(p, 'always failing transaction'); +export function expectRevertOrAlwaysFailingTransactionAsync(p: Promise): PromiseLike { + return expectRevertOrOtherErrorAsync(p, 'always failing transaction'); } /** @@ -58,6 +58,6 @@ export function expectRevertOrAlwaysFailingTransaction(p: Promise): Promis * @returns a new Promise which will reject if the conditions are not met and * otherwise resolve with no value. */ -export function expectRevertOrContractCallFailed(p: Promise): PromiseLike { - return expectRevertOrOtherError(p, 'Contract call failed'); +export function expectRevertOrContractCallFailedAsync(p: Promise): PromiseLike { + return expectRevertOrOtherErrorAsync(p, 'Contract call failed'); } -- cgit From 5d2f9d7a33c4494b06098f13fca487613fe83c73 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 6 Jun 2018 10:56:01 -0700 Subject: Use an enum for ProviderType in contracts/src/utils/web3_wrapper --- packages/contracts/src/utils/web3_wrapper.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts index 6df8ac073..63ce2c8cc 100644 --- a/packages/contracts/src/utils/web3_wrapper.ts +++ b/packages/contracts/src/utils/web3_wrapper.ts @@ -5,7 +5,25 @@ import { Provider } from 'ethereum-types'; import { coverage } from './coverage'; -const testProvider = process.env.TEST_PROVIDER || 'ganache'; +enum ProviderType { + Ganache = 'ganache', + Geth = 'geth', +} + +let testProvider: ProviderType; +switch (process.env.TEST_PROVIDER) { + case undefined: + testProvider = ProviderType.Ganache; + break; + case 'ganache': + testProvider = ProviderType.Ganache; + break; + case 'geth': + testProvider = ProviderType.Geth; + break; + default: + throw new Error(`Unknown TEST_PROVIDER: ${process.env.TEST_PROVIDER}`); +} const ganacheTxDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, @@ -14,7 +32,7 @@ const ganacheTxDefaults = { const gethTxDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, }; -export const txDefaults = testProvider === 'ganache' ? ganacheTxDefaults : gethTxDefaults; +export const txDefaults = testProvider === ProviderType.Ganache ? ganacheTxDefaults : gethTxDefaults; const gethConfigs = { shouldUseInProcessGanache: false, @@ -24,8 +42,7 @@ const gethConfigs = { const ganacheConfigs = { shouldUseInProcessGanache: true, }; - -const providerConfigs = testProvider === 'ganache' ? ganacheConfigs : gethConfigs; +const providerConfigs = testProvider === ProviderType.Ganache ? ganacheConfigs : gethConfigs; export const provider = web3Factory.getRpcProvider(providerConfigs); const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage); -- cgit From dd8727d3aebf1f4b552f8bad921b92107ad22936 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 6 Jun 2018 11:43:07 -0700 Subject: Apply various fixes based on PR feedback --- packages/contracts/src/utils/increase_time.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/increase_time.ts b/packages/contracts/src/utils/increase_time.ts index 5336a180d..4565d8dbc 100644 --- a/packages/contracts/src/utils/increase_time.ts +++ b/packages/contracts/src/utils/increase_time.ts @@ -8,7 +8,7 @@ let firstAccount: string | undefined; /** * Increases time by the given number of seconds and then mines a block so that * the current block timestamp has the offset applied. - * @param seconds the Promise which is expected to reject + * @param seconds the number of seconds by which to incrase the time offset. * @returns a new Promise which will resolve with the new total time offset or * reject if the time could not be increased. */ -- cgit From a97d77064aacda3de74b04894f110b05298c5ca8 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 6 Jun 2018 15:26:40 -0700 Subject: Get build and tests to pass --- packages/contracts/src/utils/log_decoder.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/log_decoder.ts b/packages/contracts/src/utils/log_decoder.ts index 79d41d2da..07127ba79 100644 --- a/packages/contracts/src/utils/log_decoder.ts +++ b/packages/contracts/src/utils/log_decoder.ts @@ -39,7 +39,8 @@ export class LogDecoder { } public decodeLogOrThrow(log: LogEntry): LogWithDecodedArgs | RawLog { const logWithDecodedArgsOrLog = this._abiDecoder.tryToDecodeLogOrNoop(log); - if (_.isUndefined((logWithDecodedArgsOrLog).args)) { + // tslint:disable-next-line:no-unnecessary-type-assertion + if (_.isUndefined((logWithDecodedArgsOrLog as LogWithDecodedArgs).args)) { throw new Error(`Unable to decode log: ${JSON.stringify(log)}`); } LogDecoder.wrapLogBigNumbers(logWithDecodedArgsOrLog); -- cgit