livepeer / protocol

Livepeer protocol
MIT License
152 stars 45 forks source link

changed events testing pattern #480

Closed kautukkundan closed 3 years ago

kautukkundan commented 3 years ago

What does this pull request do? Explain your changes. (required)

The expect.to.emit accepts any kind of tx state as argument - tx promise, resolved tx, or even tx hash. Internally it actually waits for the tx to resolve if not already resolved and uses the transaction hash to check for events (also eliminating the need to do tx.wait after the event check).

In the official waffle docs and also in it's own test suite the following pattern is used.

const tx = Contract.method() // tx promise i.e no await
await expect(tx).to.emit("Event")

await is used with emit() as it uses promises inside itself. For https://github.com/livepeer/protocol/pull/475#discussion_r710460706 I guess it is now okay to say that the issue was caused due to missing await before expect

other test suites in projects like uniswap v3 tests and graph protocol tests also follow the same pattern.

Specific updates (required)

The tests were updated to follow the same common pattern except in cases where the tx receipt is needed to get additional data like "cumulativeGasUsed" like PoolUpdatesWithHints test case and PollCreator test case the transaction is resolved first, the tx receipt is extracted from the tx and then tx.hash is passed to the emit assertion.

Does this pull request close any open issues?

closes #476

Checklist: