zemse / hardhat-tracer

🕵️ allows you to see internal calls, events and storage operations in the console
MIT License
351 stars 36 forks source link

No logs on a reverted transaction #7

Closed snapple42 closed 1 year ago

snapple42 commented 2 years ago

I have a small contract, and when a transaction is reverted, there are no logs displayed..

I run the contract with a good, non-reverted function call, and all the logs are displayed.

since, I can't upload a "sol" file:
contracts/test.sol

// SPDX-License-Identifier: None
pragma solidity >=0.8.7;

contract test {
    event Received(address sender, uint amount);

    function good() public payable returns (uint) {
        emit Received(msg.sender, msg.value);
        return msg.value;
    }

    function bad() public payable returns (uint) {
        emit Received(msg.sender, msg.value);
        revert("Bad call");        
    }
}

And the test script:
test/test.js

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Test", function () {
    it("Should perform tests", async function () {
        const Test = await ethers.getContractFactory("test");
        const test = await Test.deploy();
        expect(await test.deployed(),"Not deployed");
        console.log("GOOD CALL");
        await test.good({value: "10000000000000000000"});
        console.log("BAD CALL");
        await test.bad({value: "10000000000000000000"});
  });
});

run with:

npx hardhat test --logs

Relavant output expecting "[Receiver] Received(from=[Sender], amount=10000000000000000000)" in both calls:

  Test
GOOD CALL
[Receiver] Received(from=[Sender], amount=10000000000000000000)
BAD CALL
    1) Should perform tests

  0 passing (3s)
  1 failing

  1) Test
       Should perform tests:
     Error: VM Exception while processing transaction: reverted with reason string 'Bad call'
zemse commented 2 years ago

Just rewrote the plugin over the weekend. And now logs should be displayed in reverted transactions as well. If you can, please try v1.1.0-rc.1 if it works for you.

zemse commented 1 year ago

I believe this has been fixed. You can also try the latest v2, which prints the view function calls and only to see reverted calls or txs, --traceError can be used.

(closing, but feel free to reopen if you are running into any problems)