-
Notifications
You must be signed in to change notification settings - Fork 80
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
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
392155c
Verify AbciEvent keys match emitted events
Farhad-Shabani b2839f4
Add changelog entry
Farhad-Shabani 9d0021d
Add expected value checks
Farhad-Shabani ffa0bbc
Hardcode attribute key constants
Farhad-Shabani 817a440
Remove pub before channel attr key consts
Farhad-Shabani dc20ce7
Hardcode expected values
Farhad-Shabani 13b434a
Fix version const
Farhad-Shabani 2354ef5
Move away from default + Fix header issue
Farhad-Shabani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
.changelog/unreleased/improvements/163-verify-ibc-to-abci-event.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Add tests to verify `AbciEvent` match the expected Ibc events | ||
([#163](https://github.com/cosmos/ibc-rs/issues/163)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1058,3 +1058,149 @@ impl TryFrom<TimeoutPacket> for abci::Event { | |
}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use tendermint::abci::Event as AbciEvent; | ||
|
||
#[test] | ||
fn ibc_to_abci_channel_events() { | ||
struct Test { | ||
kind: IbcEventType, | ||
event: AbciEvent, | ||
expected_keys: Vec<&'static str>, | ||
expected_values: Vec<String>, | ||
} | ||
|
||
let port_id = PortId::default(); | ||
let channel_id = ChannelId::default(); | ||
let connection_id = ConnectionId::default(); | ||
let counterparty_port_id = PortId::default(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not use |
||
let counterparty_channel_id = ChannelId::new(1); | ||
let version = Version::default(); | ||
let expected_keys = vec![ | ||
"port_id", | ||
"channel_id", | ||
"counterparty_port_id", | ||
"counterparty_channel_id", | ||
"connection_id", | ||
"version", | ||
]; | ||
let expected_values = vec![ | ||
port_id.to_string(), | ||
channel_id.to_string(), | ||
counterparty_port_id.to_string(), | ||
counterparty_channel_id.to_string(), | ||
connection_id.to_string(), | ||
version.to_string(), | ||
]; | ||
|
||
let tests: Vec<Test> = vec![ | ||
Test { | ||
kind: IbcEventType::OpenInitChannel, | ||
event: OpenInit::new( | ||
port_id.clone(), | ||
channel_id.clone(), | ||
counterparty_port_id.clone(), | ||
connection_id.clone(), | ||
version.clone(), | ||
) | ||
.into(), | ||
expected_keys: expected_keys.clone(), | ||
expected_values: expected_values | ||
.iter() | ||
.enumerate() | ||
.map(|(i, v)| if i == 3 { "".to_string() } else { v.clone() }) | ||
.collect(), | ||
}, | ||
Test { | ||
kind: IbcEventType::OpenTryChannel, | ||
event: OpenTry::new( | ||
port_id.clone(), | ||
channel_id.clone(), | ||
counterparty_port_id.clone(), | ||
counterparty_channel_id.clone(), | ||
connection_id.clone(), | ||
version, | ||
) | ||
.into(), | ||
expected_keys: expected_keys.clone(), | ||
expected_values: expected_values.clone(), | ||
}, | ||
Test { | ||
kind: IbcEventType::OpenAckChannel, | ||
event: OpenAck::new( | ||
port_id.clone(), | ||
channel_id.clone(), | ||
counterparty_port_id.clone(), | ||
counterparty_channel_id.clone(), | ||
connection_id.clone(), | ||
) | ||
.into(), | ||
expected_keys: expected_keys[0..5].to_vec(), | ||
expected_values: expected_values[0..5].to_vec(), | ||
}, | ||
Test { | ||
kind: IbcEventType::OpenConfirmChannel, | ||
event: OpenConfirm::new( | ||
port_id.clone(), | ||
channel_id.clone(), | ||
counterparty_port_id.clone(), | ||
counterparty_channel_id.clone(), | ||
connection_id.clone(), | ||
) | ||
.into(), | ||
expected_keys: expected_keys[0..5].to_vec(), | ||
expected_values: expected_values[0..5].to_vec(), | ||
}, | ||
Test { | ||
kind: IbcEventType::CloseInitChannel, | ||
event: CloseInit::new( | ||
port_id.clone(), | ||
channel_id.clone(), | ||
counterparty_port_id.clone(), | ||
counterparty_channel_id.clone(), | ||
connection_id.clone(), | ||
) | ||
.into(), | ||
expected_keys: expected_keys[0..5].to_vec(), | ||
expected_values: expected_values[0..5].to_vec(), | ||
}, | ||
Test { | ||
kind: IbcEventType::CloseConfirmChannel, | ||
event: CloseConfirm::new( | ||
port_id, | ||
channel_id, | ||
counterparty_port_id, | ||
counterparty_channel_id, | ||
connection_id, | ||
) | ||
.into(), | ||
expected_keys: expected_keys[0..5].to_vec(), | ||
expected_values: expected_values[0..5].to_vec(), | ||
}, | ||
]; | ||
|
||
for t in tests { | ||
assert_eq!(t.kind.as_str(), t.event.kind); | ||
assert_eq!(t.expected_keys.len(), t.event.attributes.len()); | ||
for (i, key) in t.expected_keys.iter().enumerate() { | ||
assert_eq!( | ||
t.event.attributes[i].key, | ||
*key, | ||
"key mismatch for {:?}", | ||
t.kind.as_str() | ||
); | ||
} | ||
for (i, value) in t.expected_values.iter().enumerate() { | ||
assert_eq!( | ||
t.event.attributes[i].value, | ||
*value, | ||
"value mismatch for {:?}", | ||
t.kind.as_str() | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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
EmitCreateClientEvent()
with a given set of argumentsexpected_values
client_type
,client_id
, etcRepeat 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.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.
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 specificclient
. I think we should discard it.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 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 thoughThere 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.
of course