Truffle test - Error: revert - no transaction hash given #5774
-
Hello! I'm using ganache with fork and the transaction is not seen/mined by it. I guess truffle-test is simulating a contract-transaction before sending and already aborts on revert. But this means i'm not getting a tx-hash usable then by the debugger. So, i can't debug failing transactions. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@krellsebastian, you can set the gas parameter when interacting with your Edit: add gist Testcontract("Solid", function (accounts) {
it("should get the value", async function () {
const s = await Solid.deployed();
// If you specify the gas parameter, ethEstimate gas
// won't be called and the failed transaction will be recorded.
// Specify the gas parameter here --vvvvvvvvvvvv
await s.inc(1, {from: accounts[1], gas: 0xfffff}),
// fails because owner is accounts[0]
assert.equal(
await s.value(),
14,
"oops"
);
}); Contract// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
contract Counter {
address public owner = msg.sender;
uint256 public value;
constructor(uint256 _value) { value = _value; }
function inc(uint256 step) public {
require(msg.sender == owner, "not owner");
value += step;
}
} Test outputYou can see there is a transaction associated with the test. Note, this is only 1) Contract: Solid
should get the value:
Transaction: 0xee91ee6b275212da4970c071439d2ebbc92f196fc7a455c0fabdf72288df4e71 exited with an error (status 0). Reason given: not owner.
Please check that the transaction:
- satisfies all conditions set by Solidity `require` statements.
- does not trigger a Solidity `revert` statement. Full test output$ truffle test
Compiling your contracts...
===========================
> Compiling ./contracts/Solid.sol
> Artifacts written to /tmp/test--1155707-7rg7vEWvm2Nu
> Compiled successfully using:
- solc: 0.8.17+commit.8df45f5f.Emscripten.clang
Contract: Solid
1) should get the value
> No events were emitted
0 passing (66ms)
1 failing
1) Contract: Solid
should get the value:
Transaction: 0xee91ee6b275212da4970c071439d2ebbc92f196fc7a455c0fabdf72288df4e71 exited with an error (status 0). Reason given: not owner.
Please check that the transaction:
- satisfies all conditions set by Solidity `require` statements.
- does not trigger a Solidity `revert` statement.
StatusError: Transaction: 0xee91ee6b275212da4970c071439d2ebbc92f196fc7a455c0fabdf72288df4e71 exited with an error (status 0). Reason given: not owner.
at Context.<anonymous> (test/counter.js:9:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5) |
Beta Was this translation helpful? Give feedback.
@krellsebastian, you can set the gas parameter when interacting with your
contract? For example, look at this test, which fails if
msg.sender
isnot
accounts[0]
.Edit: add gist
Test
Contract
// SPDX-License-Identifier…