Skip to content

Commit

Permalink
Fix conn open ack tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorenesduarte committed Feb 19, 2021
1 parent fc6a238 commit 4da1d34
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum Kind {
#[error("consensus height claimed by the client on the other party is too advanced: {0} (host chain current height: {1})")]
InvalidConsensusHeight(Height, Height),

#[error("consensus height claimed by the client on the other party falls outside of trusting period: {0} (host chain current height: {1})")]
#[error("consensus height claimed by the client on the other party has been pruned: {0} (host chain oldest height: {1})")]
StaleConsensusHeight(Height, Height),

#[error("identifier error")]
Expand Down
20 changes: 13 additions & 7 deletions modules/src/ics03_connection/handler/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ mod tests {
use crate::ics24_host::identifier::{ChainId, ClientId};
use crate::mock::context::MockContext;
use crate::mock::host::HostType;
use crate::Height;

#[test]
fn conn_open_ack_msg_processing() {
Expand All @@ -131,11 +130,13 @@ mod tests {

// Parametrize the host chain to have a height at least as recent as the
// the height of the proofs in the Ack msg.
let latest_height = proof_height.increment();
let max_history_size = 5;
let default_context = MockContext::new(
ChainId::new("mockgaia".to_string(), 1),
ChainId::new("mockgaia".to_string(), latest_height.revision_number),
HostType::Mock,
5,
Height::new(1, msg_ack.proofs().height().increment().revision_height),
max_history_size,
latest_height,
);

// A connection end that will exercise the successful path.
Expand Down Expand Up @@ -188,7 +189,7 @@ mod tests {
},
Test {
name: "Processing fails because the connection does not exist in the context".to_string(),
ctx: MockContext::default(), // Empty context
ctx: default_context.clone(),
msg: ConnectionMsg::ConnectionOpenAck(Box::new(msg_ack.clone())),
want_pass: false,
error_kind: Some(Kind::UninitializedConnection(conn_id.clone())),
Expand Down Expand Up @@ -216,12 +217,14 @@ mod tests {
Test {
name: "Processing fails due to mismatching counterparty conn id".to_string(),
ctx: default_context
.clone()
.with_client(&client_id, proof_height)
.with_connection(conn_id.clone(), conn_end_cparty),
msg: ConnectionMsg::ConnectionOpenAck(Box::new(msg_ack.clone())),
want_pass: false,
error_kind: Some(Kind::ConnectionMismatch(conn_id.clone()))
},
/*
Test {
name: "Processing fails due to MissingLocalConsensusState".to_string(),
ctx: MockContext::default()
Expand All @@ -231,6 +234,7 @@ mod tests {
want_pass: false,
error_kind: Some(Kind::MissingLocalConsensusState)
},
*/
];

for test in tests {
Expand All @@ -257,7 +261,6 @@ mod tests {
}
}
Err(e) => {
println!("Error for {:?} was {:#?}", test.name, e.kind());
assert_eq!(
test.want_pass,
false,
Expand All @@ -272,7 +275,10 @@ mod tests {
assert_eq!(
&expected_kind,
e.kind(),
"conn_open_ack: expected error kind mismatches thrown error kind"
"conn_open_ack: failed for test: {}\nexpected error kind: {:?}\nfound: {:?}",
test.name,
expected_kind,
e.kind()
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/handler/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub fn check_client_consensus_height(

if claimed_height < ctx.host_oldest_height() {
// Fail if the consensus height is too old (has been pruned).
return Err(Kind::StaleConsensusHeight(claimed_height, ctx.host_current_height()).into());
return Err(Kind::StaleConsensusHeight(claimed_height, ctx.host_oldest_height()).into());
}

// Height check is within normal bounds, check passes.
Expand Down
4 changes: 2 additions & 2 deletions modules/src/mock/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ pub struct MockContext {
impl Default for MockContext {
fn default() -> Self {
Self::new(
ChainId::new("mockgaia".to_string(), 1),
ChainId::new("mockgaia".to_string(), 0),
HostType::Mock,
5,
Height::new(1, 5),
Height::new(0, 5),
)
}
}
Expand Down

0 comments on commit 4da1d34

Please sign in to comment.