hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

solidity receive event sometimes work, sometimes not in no condition change.

Open jwbda opened this issue 9 months ago • 0 comments

Version of Hardhat

2.22.3

What happened?

solidity receive event sometimes work, sometimes not in no condition change.

After runing the "## command entry shell code ", the result sometimes is :

Event emitted: undefined

which is failed result.


other time is

>>> aUint -> 7777777n ContractEventPayload {
  filter: 'Message',
  emitter: <ref *1> BaseContract {
    target: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
    interface: Interface {
      fragments: [Array],
      deploy: [ConstructorFragment],
      fallback: null,
      receive: true
    },
    runner: HardhatEthersSigner {
      _gasLimit: 30000000,
      address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
      provider: [HardhatEthersProvider]
    },
    filters: {},
    fallback: [AsyncFunction: method] {
      _contract: [Circular *1],
      estimateGas: [AsyncFunction: estimateGas],
      populateTransaction: [AsyncFunction: populateTransaction],
      send: [AsyncFunction: send],
      staticCall: [AsyncFunction: staticCall]
    },
    [Symbol(_ethersInternal_contract)]: {}
  },
  log: EventLog {
    provider: HardhatEthersProvider {
      _hardhatProvider: [LazyInitializationProviderAdapter],
      _networkName: 'hardhat',
      _blockListeners: [Array],
      _transactionHashListeners: Map(0) {},
      _eventListeners: [Array],
      _isHardhatNetworkCached: true,
      _latestBlockNumberPolled: 2,
      _blockPollingInterval: Timeout {
        _idleTimeout: 50,
        _idlePrev: [TimersList],
        _idleNext: [TimersList],
        _idleStart: 1475,
        _onTimeout: [AsyncFunction (anonymous)],
        _timerArgs: undefined,
        _repeat: 50,
        _destroyed: false,
        [Symbol(refed)]: true,
        [Symbol(kHasPrimitive)]: false,
        [Symbol(asyncId)]: 302,
        [Symbol(triggerId)]: 0
      }
    },
    transactionHash: '0x57e06f4250ed6c521dcfa404caf3c479601a8fb1e3dd98d42406d44f409da869',
    blockHash: '0xa470beaa31296685146f9d12a6659c269b34a1780a1b0d242006ad53df4d5a01',
    blockNumber: 2,
    removed: false,
    address: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
    data: '0x000000000000000000000000000000000000000000000000000000000076adf1',
    topics: [
      '0xdb5c17b17041a00e40c40ddc3406875c8676803e3a2a50a47f7c56109b884653'
    ],
    index: 0,
    transactionIndex: 0,
    interface: Interface {
      fragments: [Array],
      deploy: [ConstructorFragment],
      fallback: null,
      receive: true
    },
    fragment: EventFragment {
      type: 'event',
      inputs: [Array],
      name: 'Message',
      anonymous: false
    },
    args: Result(1) [ 7777777n ]
  },
  args: Result(1) [ 7777777n ],
  fragment: EventFragment {
    type: 'event',
    inputs: [ [ParamType] ],
    name: 'Message',
    anonymous: false
  }
}
Event emitted: undefined

which is my expect result, where in one or two times in ten of "## command entry shell code"

Minimal reproduction steps

// hardhat.config.ts
const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.24",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    }
  },
};
// solidity code
contract G {
    event Message(uint a);
    constructor() public payable {
        emit Message(111111);
    }
    function a() public payable {}
    receive() external payable {
        emit Message(66666);
    }
    function gb() public {
        // return block.timestamp;
        uint aUint = 7777777;
        emit Message(aUint);
    }
}
// deploy task code 
task("test3", "test3").setAction(async (args, hre: HardhatRuntimeEnvironment) => {
    const amount = hre.ethers.parseEther("1");
    const G = await hre.ethers.getContractFactory("G");
    const g = await G.deploy({ value: amount });
    await g.waitForDeployment();
    g.on("Message", (a, event) => {
        console.log(">>> aUint ->", a, event);
    })
    const tx = await g.gb();
    await tx.wait();

    console.log('Event emitted:', tx.events);
}

command entry shell code

clear && npx hardhat typechain && npx hardhat test3

Search terms

hardhat event not console in terminal, https://github.com/NomicFoundation/hardhat/issues/3935

jwbda avatar May 18 '24 15:05 jwbda