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
feat(event): add assertion for indexed dynamic size parameters #413
Conversation
@sz-piotr I would greatly appreciate your input on this 🙏 |
@@ -27,7 +27,9 @@ describe('INTEGRATION: Events', () => { | |||
}); | |||
|
|||
it('Emit two: success', async () => { | |||
await expect(events.emitTwo()).to.emit(events, 'Two'); | |||
await expect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format as:
await expect(events.emitTwo())
.to.emit(events, 'Two')
.withArgs(2, 'Two');
@@ -16,8 +17,16 @@ export const EVENTS_SOURCE = ` | |||
emit One(1, "DifferentKindOfOne", 0x0000000000000000000000000000000000000000000000000000000000000001); | |||
} | |||
|
|||
function emitIndex() public { | |||
emit Index("Three", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a newline after (
it('Emit index: success', async () => { | ||
const bytes = ethers.utils.hexlify(ethers.utils.toUtf8Bytes('Three')); | ||
const hash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('Three')); | ||
await expect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format as:
await expect(events.emitIndex())
.to.emit(events, 'Index')
.withArgs(
hash,
'Three',
bytes,
hash,
'0x00cfbbaf7ddb3a1476767101c12a0162e241fbad2a0162e2410cfbbaf7162123'
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make more sense for the expectation to look like this?
Under the hood the matcher would hash the required arguments. In this way the user doesn't have to figure out the hashing themselves. Alternatively we can support both - if a hash is provided it is checked directly, otherwise a hash is computed on the fly.
.withArgs(
"Three",
"Three",
bytes,
bytes,
'0x00cFBbaF7DDB3a1476767101c12a0162e241fbAD2a0162e2410cFBbaF7162123'
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes as you can see in the commit that is more or less what i did in the previous commit I will update it. What prettier conf / eslint rules are you using exactly ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sz-piotr done
@zgorizzo69 Thanks for submitting the PR. I have requested some changes and I also welcome your opinion on them. |
Looks good. Would you do a bit of docs before release? |
@marekkirejczyk can you check here if it follows your standards ? If it is too long we could only leave the |
Released in 3.2.2 |
The current to.emit().withArgs() matcher does not support indexed (variable length) arrays.
To fix that we check if the argument is indexed and if there is a
hash
propertyIf it exist we assert equal based on that
hash
propertylinked to #87