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

Add tests to verify AbciEvent match emitted events #363

Merged
merged 8 commits into from
Jan 24, 2023

Conversation

Farhad-Shabani
Copy link
Member

Closes: #163


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

@Farhad-Shabani Farhad-Shabani self-assigned this Jan 20, 2023
@codecov
Copy link

codecov bot commented Jan 20, 2023

Codecov Report

Base: 57.68% // Head: 60.00% // Increases project coverage by +2.32% 🎉

Coverage data is based on head (2354ef5) compared to base (7f62c1b).
Patch coverage: 97.01% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #363      +/-   ##
==========================================
+ Coverage   57.68%   60.00%   +2.32%     
==========================================
  Files         124      124              
  Lines       15333    15650     +317     
==========================================
+ Hits         8845     9391     +546     
+ Misses       6488     6259     -229     
Impacted Files Coverage Δ
...rc/core/ics04_channel/events/channel_attributes.rs 41.55% <ø> (+33.76%) ⬆️
crates/ibc/src/core/ics03_connection/events.rs 67.14% <95.60%> (+40.15%) ⬆️
crates/ibc/src/core/ics04_channel/events.rs 46.91% <97.01%> (+20.36%) ⬆️
crates/ibc/src/core/ics02_client/events.rs 74.03% <98.70%> (+38.93%) ⬆️
crates/ibc/src/core/ics03_connection/msgs.rs 100.00% <0.00%> (ø)
crates/ibc/src/core/ics03_connection/connection.rs 29.46% <0.00%> (+0.22%) ⬆️
.../ibc/src/core/ics04_channel/msgs/chan_open_init.rs 92.68% <0.00%> (+0.37%) ⬆️
...c/src/core/ics03_connection/msgs/conn_open_init.rs 91.48% <0.00%> (+0.37%) ⬆️
crates/ibc/src/core/ics04_channel/channel.rs 54.17% <0.00%> (+1.01%) ⬆️
crates/ibc/src/core/ics24_host/identifier.rs 62.38% <0.00%> (+1.37%) ⬆️
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Farhad-Shabani Farhad-Shabani changed the title Add tests to verify AbciEvent keys match emitted events Add tests to verify AbciEvent match emitted events Jan 20, 2023
@Farhad-Shabani Farhad-Shabani marked this pull request as ready for review January 23, 2023 14:52
crates/ibc/src/core/ics02_client/events.rs Outdated Show resolved Hide resolved
crates/ibc/src/core/ics02_client/events.rs Outdated Show resolved Hide resolved
Comment on lines 423 to 433
let expected_values = vec![
client_id.to_string(),
"9999-mock".to_string(),
consensus_height.to_string(),
consensus_heights
.iter()
.map(|h| h.to_string())
.collect::<Vec<_>>()
.join(","),
String::from_utf8(hex::encode(header.clone().value)).unwrap(),
];
Copy link
Contributor

Choose a reason for hiding this comment

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

This test doesn't give me the confidence that we're constructing the events in the exact same way as ibc-go. We're still using our own objects for the expected_values; we want hardcoded strings here too.

The best way to write this test is to

  1. run ibc-go's EmitCreateClientEvent() with a given set of arguments
  2. print the output events to the console
  3. copy/paste the strings to construct expected_values
  4. Recreate the same arguments in (1) for client_type, client_id, etc

Repeat for the connection/channel events tests.

Make sure to use the main branch for ibc-go; the "consensus_heights" attribute doesn't exist yet in 5.0.1, and I made the mistake of adding it to ibc-rs.

Copy link
Member Author

@Farhad-Shabani Farhad-Shabani Jan 24, 2023

Choose a reason for hiding this comment

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

Should be fine now dc20ce7
Just an issue I came across... Is it ok to have a default implementation for the ClientId (here)?
Therefore, the core module becomes chain-specific depending on a specific client. I think we should discard it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes let's discard it; and we have more Default implementations like that that we should discard at the same time. Can you create a new issue? Should be low priority though

Copy link
Member Author

Choose a reason for hiding this comment

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

of course

"consensus_heights",
"header",
];
let expected_values = vec!["07-tendermint-0", "07-tendermint", "0-5", "0-5,0-7"];
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, we're still missing the value for header

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, weird. let me fix it

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed, this header's expected value is checked using MockHeaderhere. In order to verify it later against an emitted ibc-go event, a PR has been opened (#374)

Comment on lines 1076 to 1079
let port_id = PortId::default();
let channel_id = ChannelId::default();
let connection_id = ConnectionId::default();
let counterparty_port_id = PortId::default();
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not use default() here too; we can just use new(). I don't like the use of default() in tests as they make it harder to verify correctness quickly (I need to go check the implementation for default() for each of these), for little gain.

Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

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

🙏

@plafer plafer merged commit 06abed0 into main Jan 24, 2023
@plafer plafer deleted the farhad/verify-abci-event-keys branch January 24, 2023 18:04
Farhad-Shabani added a commit that referenced this pull request Sep 9, 2024
* Verify AbciEvent keys match emitted events

* Add changelog entry

* Add expected value checks

* Hardcode attribute key constants

* Remove pub before channel attr key consts

* Hardcode expected values

* Fix version const

* Move away from default + Fix header issue
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.

Add tests that verify the AbciEvent keys match the events actually emitted by ibc-go.
2 participants