Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
add hrmp test
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier committed May 13, 2023
1 parent fdbd705 commit 31f7608
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
7 changes: 0 additions & 7 deletions runtime/parachains/src/hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1599,11 +1599,4 @@ impl<T: Config> Pallet<T> {
}
}
}

// TODO [now]
// Test that `check_hrmp_watermark` passes when the new watermark is equal to
// the relay-parent number and the old one is too.
//
// Also test that `prune_hrmp` where the new watermark is equal to the relay-parent
// number and the previous one is the same is a no-op.
}
51 changes: 51 additions & 0 deletions runtime/parachains/src/hrmp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,54 @@ fn cancel_pending_open_channel_request() {
Hrmp::assert_storage_consistency_exhaustive();
});
}

// TODO [now]
// Test that `check_hrmp_watermark` passes when the new watermark is equal to
// the relay-parent number and the old one is too.
//
// Also test that `prune_hrmp` where the new watermark is equal to the relay-parent
// number and the previous one is the same is a no-op.
#[test]
fn watermark_maxed_out_at_relay_parent() {
let para_a = 32.into();
let para_b = 64.into();

let mut genesis = GenesisConfigBuilder::default();
genesis.hrmp_channel_max_message_size = 20;
genesis.hrmp_channel_max_total_size = 20;
new_test_ext(genesis.build()).execute_with(|| {
register_parachain(para_a);
register_parachain(para_b);

run_to_block(5, Some(vec![4, 5]));
Hrmp::init_open_channel(para_a, para_b, 2, 20).unwrap();
Hrmp::accept_open_channel(para_b, para_a).unwrap();

// On Block 6:
// A sends a message to B
run_to_block(6, Some(vec![6]));
assert!(channel_exists(para_a, para_b));
let msgs: HorizontalMessages =
vec![OutboundHrmpMessage { recipient: para_b, data: b"this is an emergency".to_vec() }]
.try_into()
.unwrap();
let config = Configuration::config();
assert!(Hrmp::check_outbound_hrmp(&config, para_a, &msgs).is_ok());
let _ = Hrmp::queue_outbound_hrmp(para_a, msgs);
Hrmp::assert_storage_consistency_exhaustive();

// On block 8:
// B receives the message sent by A. B sets the watermark to 7.
run_to_block(8, None);
assert!(Hrmp::check_hrmp_watermark(para_b, 7, 7).is_ok());
let _ = Hrmp::prune_hrmp(para_b, 7);
Hrmp::assert_storage_consistency_exhaustive();

// On block 9:
// B includes a candidate with the same relay parent as before.
run_to_block(9, None);
assert!(Hrmp::check_hrmp_watermark(para_b, 7, 7).is_ok());
let _ = Hrmp::prune_hrmp(para_b, 7);
Hrmp::assert_storage_consistency_exhaustive();
});
}

0 comments on commit 31f7608

Please sign in to comment.