Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When an error is thrown during a transaction the object error.receipt is undefined. #6320

Closed
Muhammad-Altabba opened this issue Jul 31, 2023 · 7 comments
Assignees
Labels
4.x 4.0 related Bug Addressing a bug Discussion

Comments

@Muhammad-Altabba
Copy link
Contributor

In 1.x, the object error.receipt used to contain the receipt. But it is no longer at 4.x.
This for example cause some tests to fail at Truffle when migrating to 4.x. Like this one:
https://github.com/nazarhussain/truffle/blob/nh/web3-4x-upgrade/packages/debugger/test/stacktrace.js

try {
  await instance.run(0); //this will throw because of the revert
} catch (error) {
  console.log(error);
  // throws: TypeError: Cannot read properties of undefined (reading 'transactionHash')
  txHash = error.receipt.transactionHash; 
}
@Muhammad-Altabba Muhammad-Altabba added Bug Addressing a bug Discussion 4.x 4.0 related labels Jul 31, 2023
@jdevcs jdevcs self-assigned this Sep 5, 2023
@jdevcs
Copy link
Contributor

jdevcs commented Sep 7, 2023

This seems issue with backend ganache as exception happens without using 4.x even:

If you deploy stackTrace contract on ganache node and do following rpc:

curl --location --request POST 'HTTP://127.0.0.1:7545' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "id": "81b0bd09-c2c3-4119-8eae-5e089cdea101",
    "method": "eth_estimateGas",
    "params": [
        {
            "from": "0xDE96CA0CA62A886848CBdEa95277a3Bac8A918B3",
            "to": "0xA97f34e2ab6D0823Fc8EE6Cef356550f70dF779C",
            "data": "0xa444f5e90000000000000000000000000000000000000000000000000000000000000000"
        },
        "latest"
    ]
}'

ganache throws error:

{
    "id": "81b0bd09-c2c3-4119-8eae-5e089cdea101",
    "jsonrpc": "2.0",
    "error": {
        "message": "VM Exception while processing transaction: revert requirement failed",
        "stack": "RuntimeError: VM Exception while processing transaction: revert requirement failed\n    at exactimate (/tmp/.mount_ganachrJNAFx/resources/static/node/node_modules/ganache/dist/node/1.js:2:182136)",
        "code": -32000,
        "name": "RuntimeError",
        "data": {
            "hash": null,
            "programCounter": 1676,
            "result": "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000012726571756972656d656e74206661696c65640000000000000000000000000000",
            "reason": "requirement failed",
            "message": "revert"
        }
    }
}

Above exception happens when running test, and at line https://github.com/nazarhussain/truffle/blob/nh/web3-4x-upgrade/packages/debugger/test/stacktrace.js#L198 there is internal estimate_gas call here:
https://github.com/nazarhussain/truffle/blob/nh/web3-4x-upgrade/packages/contract/lib/execute.js#L33 that throws above error before tx execution so there is no tx receipt available.

@Muhammad-Altabba
Copy link
Contributor Author

Thanks @jdevcs for sharing the findings,
Yes, the transaction is expected to fail when executed at Ganache. As it is a calling to a function that will revert with the message "requirement failed". This is the base of the test.
But I do not know if the estimateGas was not throwing with version 1.x. This is, I think, needs to be investigated.

@jdevcs
Copy link
Contributor

jdevcs commented Sep 11, 2023

With above scenario 1.x also throws same error, this error is happening independent of lib.

@jdevcs
Copy link
Contributor

jdevcs commented Sep 12, 2023

created issue in ganache for this: trufflesuite/ganache#4526

@jdevcs jdevcs closed this as completed Sep 12, 2023
@jdevcs jdevcs reopened this Sep 14, 2023
@jdevcs
Copy link
Contributor

jdevcs commented Sep 14, 2023

So above exception happens with 1.x, 4.x, or even without web3.js lib as mentioned above.

  1. @Muhammad-Altabba if you rebase your branch with truffle dev there is default gas being passed . so Solution: rebase your branch for this/or update this test.

  2. After that 4.x by default attempts to eth_call transaction before sending for looking any revert first, in this case tx will never be mined and you will not get tx.receipt, so pass { checkRevertBeforeSending: false } in options to sendTransaction for above await instance.run(0);

  3. Finally when tx is send in tests of this file, in case of ganache provider injected, 4.x cannot subscribe due to following error:

"TypeError: provider.supportsSubscriptions is not a function"

at this line.

with above fixes I am locally able to get err.receipt.transactionHash in case of error:

{
  innerError: undefined,
  name: "TransactionRevertedWithoutReasonError",
  receipt: {
    transactionHash: "0xc17b039b6dc405d9be0f9a4fd3380e160d6cfaed2f586ff976c6fb31ad8d7d1d",
    transactionIndex: 0n,
    blockNumber: 5n,
    blockHash: "0x36266fb0721510a59c4903e0a09cdc1190a9223858d86db9e0febf05352802a6",
    from: "0xde96ca0ca62a886848cbdea95277a3bac8a918b3",
    to: "0xe3e3b13426f1d19e2dd691b3447f5db5d52871e8",
    cumulativeGasUsed: 34241n,
    gasUsed: 34241n,
    logs: [
    ],
    logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    status: 0n,
    effectiveGasPrice: 2000000000n,
    type: 0n,
    rawLogs: [
    ],
  },
  code: 405,
}

@Muhammad-Altabba
Copy link
Contributor Author

Muhammad-Altabba commented Sep 19, 2023

Many thanks @jdevcs for sharing.
I will fix the error "TypeError: provider.supportsSubscriptions is not a function" here: #6439

@Muhammad-Altabba
Copy link
Contributor Author

Changes applied here: trufflesuite/truffle@70250d8
Thanks @jdevcs ,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Bug Addressing a bug Discussion
Projects
None yet
Development

No branches or pull requests

2 participants