Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract event listener is not firing for indexed value and for multiple events #4098

Closed
6be709c0 opened this issue Jul 2, 2023 · 2 comments · Fixed by #4114
Closed

Contract event listener is not firing for indexed value and for multiple events #4098

6be709c0 opened this issue Jul 2, 2023 · 2 comments · Fixed by #4114
Assignees
Labels
area:hardhat-ethers status:ready This issue is ready to be worked on type:bug Something isn't working

Comments

@6be709c0
Copy link

6be709c0 commented Jul 2, 2023

Version of Hardhat

2.16.1

What happened?

Update of #4044. After the fix, new issues are:

  • Doesn't trigger when you have an indexed value
  • If you trigger multiple events, the first one is emitted.

Contact

contract ContractA {
    event EventNumber(uint amount);
    event EventAddress(address player);
    event EventAddressIndexed(address indexed player);

    function testWithNumber(uint amount) public {
        emit EventNumber(amount);
    }

    function testWithEventAddress() public {
        emit EventAddress(msg.sender);
    }

    function testWithEventAddressIndexed() public {
        emit EventAddressIndexed(msg.sender);
    }

    function testWithMultipleEvents() public {
        emit EventNumber(1337);
        emit EventNumber(5);
        emit EventAddress(msg.sender);
    }
}

Using the following test:

await new Promise(async (resolve) => {
      contractA.on("EventNumber", (amount: BigNumber) => {
        console.log(`- Received events testWithNumber with amount: ${amount}`);
      });
      contractA.on("EventAddress", (address) => {
        console.log(
          `- Received events testWithEventAddress with value: ${address}`
        );
      });
      contractA.on("EventAddressIndexed", (address) => {
        console.log(
          `- Received events testWithEventAddressIndexed with value: ${address}`
        );
      });

      console.log("\n## Triggering test event with a number...");
      await contractA.testWithNumber(123);
      await wait(1000);
      console.log("\n## Triggering test event with an address...");
      await contractA.testWithEventAddress();
      await wait(1000);
      console.log("\n## Triggering test event with an address indexed...");
      await contractA.testWithEventAddressIndexed();
      await wait(1000);
      console.log("\n## Triggering test with 2 events...");
      await contractA.testWithMultipleEvents();
      await wait(1000);
    });

Actual behavior:

## Triggering test event with a number...
- Received events testWithNumber with amount: 123

## Triggering test event with an address...
- Received events testWithEventAddress with value: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

## Triggering test event with an address indexed...

## Triggering test with 2 events...
- Received events testWithNumber with amount: 1337

Expected Behavior:

## Triggering test event with a number...
- Received events testWithNumber with amount: 123

## Triggering test event with an address...
- Received events testWithEventAddress with value: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

## Triggering test event with an address indexed...
- Received events testWithEventAddressIndexed with value: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

## Triggering test with 2 events...
- Received events testWithNumber with amount: 1337
- Received events testWithNumber with amount: 5
- Received events testWithEventAddress with value: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

Minimal reproduction steps

git clone -b issue-2 https://github.com/lescaudr/ethers-event-issue

  • pnpm install
  • npx hardhat compile
  • npx hardhat test

Search terms

No response

@fvictorio
Copy link
Member

Hi @lescaudr, thanks for reporting this. I can confirm the bug is on our side, I'll work on it asap.

@fvictorio
Copy link
Member

Fixed in the latest version of hardhat-ethers

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:hardhat-ethers status:ready This issue is ready to be worked on type:bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants