diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-06-30 06:34:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-30 06:34:56 +0800 |
commit | 6a197a64e68dce4b1fd4e1d2f0e6ed46c279bd3e (patch) | |
tree | d57444961b42e129674865285422a21206643d93 /packages/contracts/src/utils | |
parent | e3521c63887be7c9ef1792e0af5e2d15f5f9ed55 (diff) | |
parent | 1e4c3ed22b2409c0f9581cbd763bd1abc4ddcc33 (diff) | |
download | dexon-sol-tools-6a197a64e68dce4b1fd4e1d2f0e6ed46c279bd3e.tar dexon-sol-tools-6a197a64e68dce4b1fd4e1d2f0e6ed46c279bd3e.tar.gz dexon-sol-tools-6a197a64e68dce4b1fd4e1d2f0e6ed46c279bd3e.tar.bz2 dexon-sol-tools-6a197a64e68dce4b1fd4e1d2f0e6ed46c279bd3e.tar.lz dexon-sol-tools-6a197a64e68dce4b1fd4e1d2f0e6ed46c279bd3e.tar.xz dexon-sol-tools-6a197a64e68dce4b1fd4e1d2f0e6ed46c279bd3e.tar.zst dexon-sol-tools-6a197a64e68dce4b1fd4e1d2f0e6ed46c279bd3e.zip |
Merge pull request #793 from 0xProject/feature/contracts/transferFromFallback
Optimize transferFrom (saves ~2000 gas /fill)
Diffstat (limited to 'packages/contracts/src/utils')
-rw-r--r-- | packages/contracts/src/utils/artifacts.ts | 2 | ||||
-rw-r--r-- | packages/contracts/src/utils/assertions.ts | 41 | ||||
-rw-r--r-- | packages/contracts/src/utils/constants.ts | 1 |
3 files changed, 38 insertions, 6 deletions
diff --git a/packages/contracts/src/utils/artifacts.ts b/packages/contracts/src/utils/artifacts.ts index d58e7973c..b25266409 100644 --- a/packages/contracts/src/utils/artifacts.ts +++ b/packages/contracts/src/utils/artifacts.ts @@ -8,6 +8,7 @@ import * as ERC20Proxy from '../artifacts/ERC20Proxy.json'; import * as ERC721Proxy from '../artifacts/ERC721Proxy.json'; import * as Exchange from '../artifacts/Exchange.json'; import * as ExchangeWrapper from '../artifacts/ExchangeWrapper.json'; +import * as IAssetProxy from '../artifacts/IAssetProxy.json'; import * as MixinAuthorizable from '../artifacts/MixinAuthorizable.json'; import * as MultiSigWallet from '../artifacts/MultiSigWallet.json'; import * as MultiSigWalletWithTimeLock from '../artifacts/MultiSigWalletWithTimeLock.json'; @@ -33,6 +34,7 @@ export const artifacts = { Exchange: (Exchange as any) as ContractArtifact, ExchangeWrapper: (ExchangeWrapper as any) as ContractArtifact, EtherToken: (EtherToken as any) as ContractArtifact, + IAssetProxy: (IAssetProxy as any) as ContractArtifact, MixinAuthorizable: (MixinAuthorizable as any) as ContractArtifact, MultiSigWallet: (MultiSigWallet as any) as ContractArtifact, MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts index e702a3200..baba892d3 100644 --- a/packages/contracts/src/utils/assertions.ts +++ b/packages/contracts/src/utils/assertions.ts @@ -1,8 +1,10 @@ import { RevertReason } from '@0xproject/types'; import * as chai from 'chai'; +import { TransactionReceipt, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; import { constants } from './constants'; +import { web3Wrapper } from './web3_wrapper'; const expect = chai.expect; @@ -53,18 +55,45 @@ export function expectRevertOrAlwaysFailingTransactionAsync<T>(p: Promise<T>): P } /** - * Rejects if the given Promise does not reject with the given revert reason or "always - * failing transaction" error. + * Rejects if at least one the following conditions is not met: + * 1) The given Promise rejects with the given revert reason. + * 2) The given Promise rejects with an error containing "always failing transaction" + * 3) The given Promise fulfills with a txReceipt that has a status of 0 or '0', indicating the transaction failed. + * 4) The given Promise fulfills with a txHash and corresponding txReceipt has a status of 0 or '0'. * @param p the Promise which is expected to reject * @param reason a specific revert reason * @returns a new Promise which will reject if the conditions are not met and * otherwise resolve with no value. */ -export function expectRevertReasonOrAlwaysFailingTransactionAsync<T>( - p: Promise<T>, +export async function expectRevertReasonOrAlwaysFailingTransactionAsync( + p: Promise<string | TransactionReceiptWithDecodedLogs | TransactionReceipt>, reason: RevertReason, -): PromiseLike<void> { - return _expectEitherErrorAsync(p, 'always failing transaction', reason); +): Promise<void> { + return p + .then(async result => { + let txReceiptStatus: string | 0 | 1 | null; + if (typeof result === 'string') { + // Result is a txHash. We need to make a web3 call to get the receipt. + const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(result); + txReceiptStatus = txReceipt.status; + } else if ('status' in result) { + // Result is a TransactionReceiptWithDecodedLogs or TransactionReceipt + // and status is a field of result. + txReceiptStatus = result.status; + } else { + throw new Error('Unexpected result type'); + } + expect(_.toString(txReceiptStatus)).to.equal( + '0', + 'transactionReceipt had a non-zero status, indicating success', + ); + }) + .catch(err => { + expect(err.message).to.satisfy( + (msg: string) => _.includes(msg, reason) || _.includes(msg, 'always failing transaction'), + `Expected ${reason} or 'always failing transaction' but error message was ${err.message}`, + ); + }); } /** diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts index 2b2bd2425..8e68f376d 100644 --- a/packages/contracts/src/utils/constants.ts +++ b/packages/contracts/src/utils/constants.ts @@ -27,6 +27,7 @@ export const constants = { MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, MAX_TOKEN_TRANSFERFROM_GAS: 80000, MAX_TOKEN_APPROVE_GAS: 60000, + TRANSFER_FROM_GAS: 150000, DUMMY_TOKEN_NAME: '', DUMMY_TOKEN_SYMBOL: '', DUMMY_TOKEN_DECIMALS: new BigNumber(18), |