Skip to content

expectEvent() not capturing expected event #195

@inmarelibero

Description

@inmarelibero

expectEvent() is not capturing an expected event (SmartContract is correct and tested in other ways)

in expectEvent() I has to put:

return ({ event: receipt.events[name].event, args: receipt.events[name].args });

instead of:

return ({ event: name, args: receipt.events[name].returnValues });

I guess because of the different Event format expected. In concrete, Event names are expected to be the array keys (which are not: they are _item_.event), and args are expected to be _item.returnValues (I have _item_.args instead)

I attach here a sample of the transaction receipt I get:

{
  to: '...',
  from: '0x709...97970C51812dc3A010C7d01b50e0d17dc79C8',
  ...
  logs: [
    ...,
    {
      transactionIndex: 0,
      blockNumber: 23,
      transactionHash: '0xe8fe248cc5334ee1bb2b3fabf069409724ff05dde5594316387864fd871d7bd8',
      address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
      topics: [Array],
      data: '0x',
      logIndex: 2,
      blockHash: '0x7a8251b36220cdc989df062d06f882b0560d174ac43baa27e63fe3601badf8a6'
    }
  ],
  ...
  events: [
    ...,
    {
      transactionIndex: 0,
      blockNumber: 23,
      transactionHash: '0xe8fe248cc5334ee1bb2b3fabf069409724ff05dde5594316387864fd871d7bd8',
      address: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
      topics: [Array],
      data: '0x',
      logIndex: 2,
      blockHash: '0x7a8251b36220cdc989df062d06f882b0560d174ac43baa27e63fe3601badf8a6',
      args: [Array],
      decode: [Function (anonymous)],
      event: 'MintElementsEvent',
      eventSignature: 'MintElementsEvent(uint32[],address)',
      removeListener: [Function (anonymous)],
      getBlock: [Function (anonymous)],
      getTransaction: [Function (anonymous)],
      getTransactionReceipt: [Function (anonymous)]
    }
  ]
}

My environment:

Solidity: 0.8.17


"hardhat": "^2.12.4",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@openzeppelin/test-helpers": "^0.5.16",
"@typechain/hardhat": "^6.1.5",
"ethers": "^5.0.0",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions