trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.31k forks source link

Truffle does not catch ganache error #2512

Open hanstf opened 5 years ago

hanstf commented 5 years ago

I have submitted my issue in ganache here but seems there is no feedback about it, so I am trying to submit it here since it can be error from the truffle contract.

Issue

truffle contract always resolve ganache error with undefined tx and stack trace as receipt

{
      "stack": "n: Exceeds block gas limit\n    at k._queueTransaction (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:578780)\n    at k.queueRawTransaction (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:577344)\n    at b.eth_sendRawTransaction (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:567858)\n    at b.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:564744)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at a.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:563051)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at c.f.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:556029)\n    at c.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:553855)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at s.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:562065)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at a.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:561512)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at d._handleAsync (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439074)\n    at Timeout._onTimeout (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:438499)",
      "name": "n"
    }

Steps to Reproduce

  1. Running ./node_modules/.bin/ganache-cli -m 'blame left final crime wing curious actual light drip trip patient daughter' -p 9988 --verbose
  2. running ./node_modules/.bin/truffle migrate --network docker. the migrated smart contract, is just a normal ERC721 token
  3. run instance.mintWithTokenURI(toWalletAddress, productId, url, { gas: 123232323 }) (assuming that the truffle contract was deployed)
  4. since I was testing for error, so I expected that it should return me error and rejected the promiEvent in truffle-contract, but it was resolved and returning this
    { tx: undefined,
      receipt:
       { stack:
          'n: Exceeds block gas limit\n    at k._queueTransaction (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:578780)\n    at k.queueRawTransaction (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:577344)\n    at b.eth_sendRawTransaction (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:567858)\n    at b.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:564744)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at a.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:563051)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at c.f.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:556029)\n    at c.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:553855)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at s.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:562065)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at a.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:561512)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at d._handleAsync (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439074)\n    at Timeout._onTimeout (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:438499)',
         name: 'n',
         rawLogs: undefined,
         logs: [] },
      logs: [] }
  5. To move forward, when I try to run the function twice but with lower gas as shown below

    instance.mintWithTokenURI(toWalletAddress, productId, url, { gas: 123232323 })
    instance.mintWithTokenURI(toWalletAddress, productId, url, { gas: 8015600 })

    I will be getting uncaught error from truffle contract

    TypeError: this.removeListener is not a function
    
    at Object.receipt (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/@truffle/contract/lib/handlers.js:133:10)
    at Function.start (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/@truffle/contract/lib/override.js:56:24)
    at deferred.catch (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/@truffle/contract/lib/execute.js:197:56)

Expected Behavior

Rejected promiEvent instead of resolved with undefined tx receipt

Actual Results

TypeError: this.removeListener is not a function

    at Object.receipt (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/@truffle/contract/lib/handlers.js:133:10)
    at Function.start (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/@truffle/contract/lib/override.js:56:24)
    at deferred.catch (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/@truffle/contract/lib/execute.js:197:56)

Environment

gnidan commented 5 years ago

Hm, thanks for this. We'll have to dig into it, but we're about to release #2466, which should fix at least the undefined transaction hash. I don't expect it will fix the other issues you describe, but we'll see!

hanstf commented 5 years ago

@gnidan sure thing! will try that version out and let you know. Thanks.

cgewecke commented 5 years ago

@hanstf I am seeing this too but with Geth 1.9.6 (stable). If you move down to a lower Truffle version than 5.0.41 does this go away?

cgewecke commented 5 years ago

Couple of triage notes. Not sure why this isn't being caught by the tests here, but this line:

https://github.com/trufflesuite/truffle/blob/8fdd56f7c45f2b36baeaa71e94f74d956cde1e79/packages/contract/lib/override.js#L53

is not bound correctly to an event emitter. You can see how that's typically done in the handlers.js.

There's also an (unrelated?) problem in override.extractReceipt where the error message is incorrectly split by an open parenthesis. This won't work if there are sub-parentheses in the printed receipt. https://github.com/trufflesuite/truffle/blob/8fdd56f7c45f2b36baeaa71e94f74d956cde1e79/packages/contract/lib/override.js#L14-L26

A better split point is the EVM: (believe it or not!)

Mea culpa as usual.

hanstf commented 5 years ago

@gnidan Updated to the latest truffle contract 4.0.37 but it still happening I am still receiving this

    { tx: undefined,
      receipt:
       { stack:
          'n: Exceeds block gas limit\n    at k._queueTransaction (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:578780)\n    at k.queueRawTransaction (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:577344)\n    at b.eth_sendRawTransaction (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:567858)\n    at b.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:564744)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at a.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:563051)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at c.f.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:556029)\n    at c.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:553855)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at s.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:562065)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at a.handleRequest (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:561512)\n    at t (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439038)\n    at d._handleAsync (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:439074)\n    at Timeout._onTimeout (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:438499)',
         name: 'n',
         rawLogs: undefined,
         logs: [] },
      logs: [] }
hanstf commented 5 years ago

@cgewecke tried the truffle contract v4.0.32 but is shows the same?

I was looking at that too, the extractReceipt is checking too general.

But what I also don't understand is in testnet, I was getting a js object but then in ganache, I got an js Error with stack trace in its message. I also waiting the feedback from ganache, maybe this because ganache does not return standard error object?

cgewecke commented 5 years ago

@hanstf Thanks for checking the truffle version (Do you mean 5.0.32?) Also are you running ganache-cli with --noVMErrorsOnRPCResponse?

That flag is described as:

--noVMErrorsOnRPCResponse: Do not transmit transaction failures as RPC errors. Enable this flag for error reporting behaviour which is compatible with other clients such as geth and Parity.

hanstf commented 5 years ago

@cgewecke I am not sure which truffle version was it, I tried it with https://www.npmjs.com/package/@truffle/contract/v/4.0.32

actually that flag does not make any difference. It gave me exactly the same error either way.

I also test different function that will revert because of this

    modifier onlyMinter() {
        require(isMinter(msg.sender));
        _;
    }

after checking my ganache logs, I don't even see any eth_sendRawTransaction. I guess the error was since the

params.gas = await execute.getGasEstimate.call(
              constructor,
              params,
              network.blockLimit
            );

but it was always resolved in getGasEstimate function. Below was the last logs in my ganache, after that it was only eth_getBlockByNumber calls.

eth_estimateGas
   > {
   >   "id": 4,
   >   "jsonrpc": "2.0",
   >   "params": [
   >     {
   >       "from": "0x0a0d381d407bb53201616e5a085a7cfde8be8975",
   >       "to": "0x38825d339c071e479f382a16ac8032b16d8a690c",
   >       "data": "0x50bb4e7f000000000000000000000000c510bd27cb758084196ddb3f025638f559340f8d00000000000000000000000000000000000000000000000000000000000325740000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000f72616e646f6d5f75726c5f323836360000000000000000000000000000000000"
   >     }
   >   ],
   >   "method": "eth_estimateGas"
   > }
 <   {
 <     "id": 4,
 <     "jsonrpc": "2.0",
 <     "error": {
 <       "message": "execution error: revert",
 <       "code": -32000,
 <       "data": {
 <         "stack": "Error: execution error: revert\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:69:18800\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:61:657175\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:2:19209\n    at i (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:2:34308)\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:1762711\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:2:93723\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:25:392\n    at s (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:25:5516)\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:25:317\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:61:675236\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:2:16307\n    at o (/home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:2:19731)\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:2:19209\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:61:668716\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:61:666579\n    at /home/hanstf/Documents/projects/erc721-smartcontract-lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:61:676052",
 <         "name": "Error"
 <       }
 <     }
 <   }

Also the error from truffle that was catch inside the override.start was also exactly the same error.