#StackBounty: #solidity #testing #hardhat Testing an event with a timestamp arg

Bounty: 50

I’m trying to write a test using waffle, but I’m not sure how to assert that a timestamp is correct in an emitted event.

My event looks like this:

event BeginJourney (
    uint256 indexed departFrom,
    uint256 indexed arriveAt,
    uint256 indexed arrivalTime

which is emitted like this in the contract:

emit BeginJourney(currentId, newId, block.timestamp + travelTime);

My test so far looks like this:

await expect(city.connect(acc1).travelTo(1))
    .to.emit(city, "BeginJourney").withArgs(0, 1, ???);

Using Waffle’s .withArgs assertation, I can only check exact values. What I really want is to check that the 3rd timestamp arg is within a few seconds of the current epoch time plus some constant.

Is there any way to code this test?

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.