Skip to content
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

Merged
merged 5 commits into from Dec 21, 2020

Conversation

zgorizzo69
Copy link
Contributor

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 property
If it exist we assert equal based on that hash property
linked to #87

@zgorizzo69
Copy link
Contributor Author

@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(
Copy link
Contributor

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",
Copy link
Contributor

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(
Copy link
Contributor

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'
  )

Copy link
Contributor

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'
);

Copy link
Contributor Author

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sz-piotr done

@sz-piotr
Copy link
Contributor

@zgorizzo69 Thanks for submitting the PR. I have requested some changes and I also welcome your opinion on them.

@marekkirejczyk marekkirejczyk merged commit 9a921bd into TrueFiEng:master Dec 21, 2020
@marekkirejczyk
Copy link
Contributor

Looks good. Would you do a bit of docs before release?

@zgorizzo69
Copy link
Contributor Author

zgorizzo69 commented Jan 13, 2021

@marekkirejczyk can you check here if it follows your standards ? If it is too long we could only leave the note block

@marekkirejczyk
Copy link
Contributor

Released in 3.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants