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

Truffle does not catch ganache error #2512

Open
hanstf opened this issue Oct 30, 2019 · 8 comments
Open

Truffle does not catch ganache error #2512

hanstf opened this issue Oct 30, 2019 · 8 comments

Comments

@hanstf
Copy link

hanstf commented Oct 30, 2019

  • [X ] I've asked for help in the Truffle Gitter before filing this issue.

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: [] }
  1. 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

  • Operating System:
  • Ethereum client: ganache-cli 6.7.0
  • Truffle version (truffle version): 5.0.41
  • node version (node --version): 10.10.0
  • npm version (npm --version): 6.4.1
@gnidan
Copy link
Contributor

gnidan commented Oct 30, 2019

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
Copy link
Author

hanstf commented Oct 30, 2019

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

@cgewecke
Copy link
Contributor

cgewecke commented Oct 31, 2019

@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
Copy link
Contributor

cgewecke commented Oct 31, 2019

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

await handlers.receipt(context, receipt);

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.

extractReceipt(message) {
const hasReceipt = message && message.includes("{");
message.includes("}");
if (hasReceipt) {
const receiptString = "{" + message.split("{")[1].trim();
try {
return JSON.parse(receiptString);
} catch (err) {
// ignore
}
}
},

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

Mea culpa as usual.

@hanstf
Copy link
Author

hanstf commented Oct 31, 2019

@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
Copy link
Author

hanstf commented Oct 31, 2019

@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
Copy link
Contributor

@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
Copy link
Author

hanstf commented Oct 31, 2019

@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.

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

No branches or pull requests

4 participants