diff options
author | Fabio Berger <me@fabioberger.com> | 2018-05-11 21:23:34 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-05-11 21:23:34 +0800 |
commit | 461e74d8be17b0a1582e7c11de01b43a45399fcc (patch) | |
tree | 4171e1ff8bc11b200bb1e40470b86e507bab626b /packages | |
parent | a7daea172865b099e4e457f91602eeec767b231f (diff) | |
download | dexon-sol-tools-461e74d8be17b0a1582e7c11de01b43a45399fcc.tar.gz dexon-sol-tools-461e74d8be17b0a1582e7c11de01b43a45399fcc.tar.zst dexon-sol-tools-461e74d8be17b0a1582e7c11de01b43a45399fcc.zip |
Throw if tx reverts
Diffstat (limited to 'packages')
-rw-r--r-- | packages/fill-scenarios/src/index.ts | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/packages/fill-scenarios/src/index.ts b/packages/fill-scenarios/src/index.ts index 14d5a2614..0c62ef410 100644 --- a/packages/fill-scenarios/src/index.ts +++ b/packages/fill-scenarios/src/index.ts @@ -146,7 +146,7 @@ export class FillScenarios { const [orderAddresses, orderValues] = formatters.getOrderAddressesAndValues(signedOrder); - await exchangeInstance.fillOrder.sendTransactionAsync( + const txHash = await exchangeInstance.fillOrder.sendTransactionAsync( orderAddresses, orderValues, partialFillAmount, @@ -156,6 +156,10 @@ export class FillScenarios { signedOrder.ecSignature.s, { from: takerAddress }, ); + const txReceipt = await this._web3Wrapper.awaitTransactionMinedAsync(txHash); + if (txReceipt.status !== 1) { + throw new Error(`FillOrder tx reverted. TxHash: ${txReceipt.transactionHash}`); + } return signedOrder; } private async _createAsymmetricFillableSignedOrderWithFeesAsync( @@ -215,9 +219,13 @@ export class FillScenarios { this._web3Wrapper.getProvider(), this._web3Wrapper.getContractDefaults(), ); - await token.transfer.sendTransactionAsync(address, amount, { + const txHash = await token.transfer.sendTransactionAsync(address, amount, { from: this._coinbase, }); + const txReceipt = await this._web3Wrapper.awaitTransactionMinedAsync(txHash); + if (txReceipt.status !== 1) { + throw new Error(`Transfer tx reverted. TxHash: ${txReceipt.transactionHash}`); + } } private async _increaseAllowanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise<void> { const tokenInstance = new TokenContract( @@ -234,8 +242,12 @@ export class FillScenarios { const oldMakerAllowance = await tokenInstance.allowance.callAsync(address, proxyAddress); const newMakerAllowance = oldMakerAllowance.plus(amount); - await tokenInstance.approve.sendTransactionAsync(proxyAddress, newMakerAllowance, { + const txHash = await tokenInstance.approve.sendTransactionAsync(proxyAddress, newMakerAllowance, { from: address, }); + const txReceipt = await this._web3Wrapper.awaitTransactionMinedAsync(txHash); + if (txReceipt.status !== 1) { + throw new Error(`Approve tx reverted. TxHash: ${txReceipt.transactionHash}`); + } } } |