Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Ganache does not return a detailed exception #2935

Closed
dminglv opened this issue Apr 19, 2022 · 30 comments
Closed

Ganache does not return a detailed exception #2935

dminglv opened this issue Apr 19, 2022 · 30 comments

Comments

@dminglv
Copy link

dminglv commented Apr 19, 2022

Hi! I found an error that Ganache does not return a detailed exception when calling contract function.

I use Ganache in Docker trufflesuite/ganache:v7.0.4

And Run it how:

version: '3.7'

services:
  ganache:
    image: trufflesuite/ganache:v7.0.4
    restart: always
    volumes:
      - ./blockchain-data:/blockchain-data
    env_file:
      - .env
    ports:
      - "8545:8545"
    command:
      --database.dbPath=/blockchain-data --miner.blockGasLimit=0x3B9ACA00 --port 8545
      --account="0x${TEST_CLOUD_ACCOUNT_PRIVATE_KEY_1},1000000000000000000000000000"
      --account="0x${TEST_CLOUD_ACCOUNT_PRIVATE_KEY_2},1000000000000000000000000000"
      --account="0x${TEST_CLOUD_ACCOUNT_PRIVATE_KEY_3},1000000000000000000000000000"

Everything works, but does not return a detailed exception error when calling the contract.

What do I get instead of getting a Time Limit exception:

AssertionError: Expected transaction to be reverted with Time limit, but other exception was thrown: Error: missing revert data in call exception; Transaction reverted without a reason string [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (error={"name":"ProviderError","code":-32000,"_isProviderError":true,"data":"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a54696d65206c696d697400000000000000000000000000000000000000000000"}, data="0x", code=CALL_EXCEPTION, version=providers/5.6.4)

P.s in old package trufflesuite/ganache-cli everything works fine and I get a detailed error!

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

I also try to add flag --chain.vmErrorsOnRPCResponse true, but it doesn't work.

@davidmurdoch
Copy link
Member

What did it used to return for you?

@davidmurdoch
Copy link
Member

davidmurdoch commented Apr 19, 2022

This could be related to this recent change: https://github.com/trufflesuite/ganache/releases/tag/v7.0.1#user-content-v7.0.1-fixes-0

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

I use it for hardhat tests.

it("Faucet -> Check that we can't to get tokens twice", async () => {
   await expect(
     faucet.getCanTheAddressReceiveReward(await signers[0].getAddress()),
   ).to.be.revertedWith('Time limit');
 });

I can replace this with the following, but then I won't be able to track the exception error. This is very important for testing the operation of smart contracts!

it("Faucet -> Check that we can't to get tokens twice", async () => {
   await expect(
     faucet.getCanTheAddressReceiveReward(await signers[0].getAddress()),
   ).reverted;
 });

@davidmurdoch
Copy link
Member

davidmurdoch commented Apr 19, 2022

0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a54696d65206c696d697400000000000000000000000000000000000000000000 is "Time Limit":

08c379a means there is revert reason to follow
0...2...0 is just low-level RLP encoding things
0a is the length of the revert reason string in hex -> 10
54696d65206c696d6974 is hex representation of the ASCII string "Time limit".

My hunch is that this may be a Waffle bug.

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

But if I use the Ganache app on Mac or run tests on any public node, there are no errors.

Error only in trufflesuite/ganache

P.s in old package trufflesuite/ganache-cli everything works fine and I get a detailed error!

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

Just checked on the trufflesuite/ganache:v7.0.0.
Everything works there too.

The error is only in new versions!

I use the following package versions:

  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.5",
    "@nomiclabs/hardhat-etherscan": "^3.0.3",
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "@openzeppelin/hardhat-upgrades": "^1.17.0",
    "@typechain/ethers-v5": "^10.0.0",
    "@typechain/hardhat": "^6.0.0",
    "@types/chai": "^4.3.1",
    "@types/mocha": "^9.1.0",
    "@types/node": "^17.0.25",
    "@typescript-eslint/eslint-plugin": "^5.19.0",
    "@typescript-eslint/parser": "^5.19.0",
    "chai": "^4.3.6",
    "eslint": "^8.13.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-prettier": "^4.0.0",
    "ethereum-waffle": "^3.4.4",
    "ethers": "^5.6.4",
    "hardhat": "2.9.3",
    "hardhat-contract-sizer": "^2.5.1",
    "prettier": "^2.6.2",
    "solc": "^0.8.13",
    "solhint": "^3.3.7",
    "solidity-coverage": "^0.7.20",
    "ts-node": "^10.7.0",
    "typechain": "^8.0.0",
    "typescript": "^4.6.3"
  },
  "dependencies": {
    "@openzeppelin/contracts": "^4.5.0",
    "@openzeppelin/contracts-upgradeable": "^4.5.2",
    "@openzeppelin/hardhat-defender": "^1.6.0",
    "dotenv": "^16.0.0"
  },

@davidmurdoch
Copy link
Member

Ganache UI currently uses an old version of ganache.

The old version of ganache returned the revert reason string in a non-standard way, we now align with Geth. Tools like Waffle likely handled our non-standard format; I believe we now return the reason the same way Geth does.

So the error is in old versions, tools like waffle handled the non-standard formatting.

Have you tried the waffle alpha release (4.0.0-alpha.21)? https://www.npmjs.com/package/ethereum-waffle/v/4.0.0-alpha.21

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

It's also doesn't work on alpha version

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

When I tested via private Geth node, I also had no problems...

@davidmurdoch
Copy link
Member

It could be related to TrueFiEng/Waffle#646

Waffle doesn't detect the revert reason on a testnet.

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

I have no problems with Waffle. I also ran tests on my private Geth node. Everything went fine, the problem is only with ganache

@davidmurdoch
Copy link
Member

What Geth version are you running?

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

1.10.1

@davidmurdoch
Copy link
Member

davidmurdoch commented Apr 19, 2022

Ah, I didn't noticed ethers.js in the error the first time. Does ethers-io/ethers.js#2849 leave any clues?

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

Screenshot 2022-04-19 at 20 57 05

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

I add console log on tests on working version ganache (7.0.0)

    console.log(await expect(
      plushFaucet.getCanTheAddressReceiveReward(await signers[0].getAddress()),
    ).to.be.revertedWith('Time limit'));

Compare this with the first error in the screenshot in the message above!

Screenshot 2022-04-19 at 21 04 20

@dminglv dminglv closed this as completed Apr 19, 2022
@dminglv dminglv reopened this Apr 19, 2022
@davidmurdoch
Copy link
Member

davidmurdoch commented Apr 19, 2022

It appears Ganache is working as intended. The transaction is reverted with a reason string; it is returned as encoded (as it should be). The tools (either hardhat, ethers.js, or waffle) don't seem to be handling it correctly.

I'll discuss further with @MicaiahReid to be sure I'm not missing anything.

@dminglv
Copy link
Author

dminglv commented Apr 19, 2022

It's return reason string on version 7.0.0

@davidmurdoch
Copy link
Member

Ganache 7.0.0 and earlier returned this data incorrectly, this was fixed in 7.0.1. We do return a message property that contains the reason string: "VM Exception while processing transaction: revert {reason}". Something in your tool chain seems to be removing this message property before it gets to your test.

@lsqproduction
Copy link

Close for issue maintenance. Please open a new issue if needed.

@Silur
Copy link

Silur commented May 26, 2022

on version 7.2.0, revert reasons/messages are always undefined

@davidmurdoch
Copy link
Member

@Silur , can you open your own issue with reproduction steps?

@joelamouche
Copy link

I opened an issue in the hardhat repo because I still have the same problem: NomicFoundation/hardhat#3441

@joelamouche
Copy link

According to the hardhat dev, the issue still appears when using ethers.js without hardhat so I think we should reopen this issue (see NomicFoundation/hardhat#3441 for details and reproductivity)

@davidmurdoch
Copy link
Member

Are you sure this isn't an Ethers issue?

@joelamouche
Copy link

There is no issue when I'm using the hardhat testnet

@davidmurdoch
Copy link
Member

It sounds like they put in a workaround. I'm just unable to get to a computer for a few days to look into this further.

@davidmurdoch
Copy link
Member

@joelamouche can you run Ganache with the --verbose flag and then paste the ganache logs here?

@joelamouche
Copy link

 Transaction: 0xae0e75b0599e8c84a9c6f456194f65d578e408e11c73587be66162afc9f37b38
  Gas usage: 28596
  Block number: 16
  Block time: Mon Jan 02 2023 11:50:39 GMT+0100 (Central European Standard Time)

   >  eth_chainId: []
   >  eth_getTransactionByHash: [
   >   "0xae0e75b0599e8c84a9c6f456194f65d578e408e11c73587be66162afc9f37b38"
   > ]
   >  eth_chainId: []
   >  eth_getTransactionReceipt: [
   >   "0xae0e75b0599e8c84a9c6f456194f65d578e408e11c73587be66162afc9f37b38"
   > ]
   >  eth_chainId: []
   >  eth_getBlockByNumber: [
   >   "latest",
   >   false
   > ]
   >  eth_chainId: []
   >  eth_getTransactionReceipt: [
   >   "0x98fc1422bf6af37aed469b507d7c4a3477d2b0357471f2a9ef8f929dc603e4cb"
   > ]
   >  eth_chainId: []
   >  eth_call: [
   >   {
   >     "from": "0x4eb445887036a4994f505eb8a8e09d4438058ad4",
   >     "to": "0x792e0a8f2857f843a511537d7f1c607ca572d786",
   >     "data": "0x3e4f49e60000000000000000000000000000000000000000000000000000000000003039"
   >   },
   >   "latest"
   > ]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants