-
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 7 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<&'static str>, | ||
} | ||
|
||
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::new("ics20-1".to_string()); | ||
let expected_keys = vec![ | ||
"port_id", | ||
"channel_id", | ||
"counterparty_port_id", | ||
"counterparty_channel_id", | ||
"connection_id", | ||
"version", | ||
]; | ||
let expected_values = vec![ | ||
"defaultPort", | ||
"channel-0", | ||
"defaultPort", | ||
"channel-1", | ||
"connection-0", | ||
"ics20-1", | ||
]; | ||
|
||
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 { "" } else { v }) | ||
.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.
Oops, we're still missing the value for
header
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.
oh, weird. let me fix 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.
As discussed, this header's expected value is checked using
MockHeader
here. In order to verify it later against an emitted ibc-go event, a PR has been opened (#374)