diff --git a/packages/web3-core-method/lib/methods/transaction/AbstractObservedTransactionMethod.js b/packages/web3-core-method/lib/methods/transaction/AbstractObservedTransactionMethod.js index 29319ac8aef..e04ed8900bb 100644 --- a/packages/web3-core-method/lib/methods/transaction/AbstractObservedTransactionMethod.js +++ b/packages/web3-core-method/lib/methods/transaction/AbstractObservedTransactionMethod.js @@ -81,27 +81,27 @@ export default class AbstractObservedTransactionMethod extends AbstractMethod { receipt = transactionConfirmation.receipt; if (this.hasRevertReceiptStatus(receipt)) { - this.handleError( - new Error( - `Transaction has been reverted by the EVM:\n${JSON.stringify(receipt, null, 2)}` - ), - receipt, - confirmations - ); + if (this.parameters[0].gas === receipt.gasUsed) { + this.handleError( + new Error( + `Transaction ran out of gas. Please provide more gas:\n${JSON.stringify( + receipt, + null, + 2 + )}` + ), + receipt, + confirmations + ); + + transactionConfirmationSubscription.unsubscribe(); + + return; + } - transactionConfirmationSubscription.unsubscribe(); - - return; - } - - if (receipt.outOfGas) { this.handleError( new Error( - `Transaction ran out of gas. Please provide more gas:\n${JSON.stringify( - receipt, - null, - 2 - )}` + `Transaction has been reverted by the EVM:\n${JSON.stringify(receipt, null, 2)}` ), receipt, confirmations diff --git a/packages/web3-core-method/tests/lib/methods/transaction/AbstractObservedTransactionMethodTest.js b/packages/web3-core-method/tests/lib/methods/transaction/AbstractObservedTransactionMethodTest.js index 6469a26adcf..4f86a6513f8 100644 --- a/packages/web3-core-method/tests/lib/methods/transaction/AbstractObservedTransactionMethodTest.js +++ b/packages/web3-core-method/tests/lib/methods/transaction/AbstractObservedTransactionMethodTest.js @@ -152,36 +152,40 @@ describe('AbstractObservedTransactionMethodTest', () => { providerMock.send.mockReturnValueOnce(Promise.resolve('transactionHash')); observableMock.subscribe = jest.fn((next, error, complete) => { - next({count: 0, receipt: {status: '0x0'}}); + next({count: 0, receipt: {status: '0x0', gasUsed: 1}}); complete(); }); + method.parameters = [{gas: 0}]; + await expect(method.execute()).rejects.toThrow( - `Transaction has been reverted by the EVM:\n${JSON.stringify({status: '0x0'}, null, 2)}` + `Transaction has been reverted by the EVM:\n${JSON.stringify({status: '0x0', gasUsed: 1}, null, 2)}` ); - expect(providerMock.send).toHaveBeenCalledWith('rpcMethod', []); + expect(providerMock.send).toHaveBeenCalledWith('rpcMethod', method.parameters); }); it('calls execute and returns a rejected Promise because the transaction ran out of gas', async () => { providerMock.send.mockReturnValueOnce(Promise.resolve('transactionHash')); observableMock.subscribe = jest.fn((next, error, complete) => { - next({count: 0, receipt: {status: '0x1', outOfGas: true}}); + next({count: 0, receipt: {status: '0x0', gasUsed: 1}}); complete(); }); + method.parameters = [{gas: 1}]; + await expect(method.execute()).rejects.toThrow( `Transaction ran out of gas. Please provide more gas:\n${JSON.stringify( - {status: '0x1', outOfGas: true}, + {status: '0x0', gasUsed: 1}, null, 2 )}` ); - expect(providerMock.send).toHaveBeenCalledWith('rpcMethod', []); + expect(providerMock.send).toHaveBeenCalledWith('rpcMethod', method.parameters); }); it('calls execute and calls the given callback with the transaction hash', (done) => { @@ -192,7 +196,7 @@ describe('AbstractObservedTransactionMethodTest', () => { expect(transactionHash).toEqual('transactionHash'); - expect(providerMock.send).toHaveBeenCalledWith('rpcMethod', []); + expect(providerMock.send).toHaveBeenCalledWith('rpcMethod', method.parameters); expect(beforeExecutionMock).toHaveBeenCalledWith(moduleInstanceMock); diff --git a/packages/web3-eth-contract/src/methods/CallContractMethod.js b/packages/web3-eth-contract/src/methods/CallContractMethod.js index eea40abc975..29c62d04972 100644 --- a/packages/web3-eth-contract/src/methods/CallContractMethod.js +++ b/packages/web3-eth-contract/src/methods/CallContractMethod.js @@ -22,6 +22,7 @@ import {CallMethod} from 'web3-core-method'; +// TODO: Implement revert handling (AbstractContractMethod) export default class CallContractMethod extends CallMethod { /** * @param {Utils} utils diff --git a/packages/web3-eth-contract/src/methods/SendContractMethod.js b/packages/web3-eth-contract/src/methods/SendContractMethod.js index 9ac856bb9f4..9ac1a20a203 100644 --- a/packages/web3-eth-contract/src/methods/SendContractMethod.js +++ b/packages/web3-eth-contract/src/methods/SendContractMethod.js @@ -23,6 +23,7 @@ import isArray from 'lodash/isArray'; import {EthSendTransactionMethod} from 'web3-core-method'; +// TODO: Implement revert handling (AbstractContractMethod) export default class SendContractMethod extends EthSendTransactionMethod { /** * @param {Utils} utils