Open mrwillis opened 4 years ago
Thanks for bringing this up! Sounds like we need an extra try
/catch
somewhere. Will get this on our backlog for investigation, or anyone feel free to take a look and open a PR! 🙇
I'm also having this problem and what I noticed is the weird string being thrown instead of an Error object. The string is abort(...something...). Build with -s ASSERTIONS=1 for more info.
, which I think comes from here:
https://github.com/emscripten-core/emscripten/blob/8d265e61d4313246b0682c6298b42c640aaaf046/src/preamble.js#L722
And this crashes the test because mocha doesn't support strings being thrown (https://github.com/mochajs/mocha/pull/3321)
Do you have a specific example that I could use to reproduce this error? If I just make a Solidity function that reverts it doesn't crash the test runner.
Workaround: Add
if (typeof(err) === 'string') {
err = Error(err);
}
after the line
Runner.prototype.uncaught = function(err) {
of ./node_modules/truffle/node_modules/mocha/lib/runner.js
(around line 730).
I almost always get this when moving common code into an async helper method and a contract method fails there. Example:
async function foo() {
assert.fail("always");
}
it("test mocha", async () => { await foo(); }
@mrwillis @digulla can you provide specific reproduction steps for this so we can dig in and see what's going on? Thanks so much!
I am using: Truffle v5.1.30 (core: 5.1.30) Solidity - 0.6.10 (solc-js) Node v12.18.0 Web3.js v1.2.1
And I can confirm that transaction reverts in Solidity code crashes and exits the truffle environment
@fainashalts Here is ~an~ another example:
it("should not allow owner to participate", async function () {
try {
await instance.participate("test", {
from: accounts[0],
value: 1
});
assert(false);
} catch (error) {
assert.ok(true);
}
});
this is how it ends up 😅
1) Contract: TestContact
should not allow owner to participate:
Uncaught TypeError: Cannot use 'in' operator to search for 'result' in 0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000086973206f776e6572000000000000000000000000000000000000000000000000
at Object._extract (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/packages/contract/lib/reason.js:31:1)
at /home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/packages/contract/lib/reason.js:79:1
at /home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:107:1
at XMLHttpRequest.request.onreadystatechange (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-http/lib/index.js:98:1)
at XMLHttpRequestEventTarget.dispatchEvent (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)
at IncomingMessage.<anonymous> (/home/ahmed/.nvm/versions/node/v16.13.2/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)
at IncomingMessage.emit (node:events:402:35)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Hey @ashajjar this looks kind of similar to a bug we had in a recent version or two of Truffle. Can you upgrade to the latest Truffle (v5.4.31) and see if you still get the error?
I was only one patch behind 😅 v5.4.30 ... now it works on v5.4.31 🎉
I took me 24 hours of scratching my head!!
Sorry to cause you trouble! That was the release that included the next major release of Ganache (v7) and we had a bug or two to iron out. Glad your problem was resolved!
Thanks a lot :)
Is this still an issue?
Issue
What the issue is, in broad strokes.
Code:
Truffle test with chai cannot catch revert reason. The try catch block does not work and it crashes the entire runner
Steps to Reproduce
Please provide the shortest amount of steps to reproduce your issue.
Expected Behavior
What you expected to happen.
The test passes
Actual Results
What actually happened. Please give examples and support it with screenshots, copied output or error messages.
Output from ganache-cli:
Related:
https://github.com/mochajs/mocha/issues/3320
The issue seems to be that this thing is throwing a string, an not an object.
Environment
Operating System: ubuntu 18.04
Ethereum client: Ganache CLI v6.7.0-beta.0 (ganache-core: 2.8.0-beta.0)
Truffle version (
truffle version
): Truffle v5.0.41 (core: 5.0.41) Solidity v0.5.8 (solc-js) Node v10.5.0 Web3.js v1.2.1node version (
node --version
): v10.5.0npm version (
npm --version
): 6.12.0