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

Add tests that check the value of MQCs #2351

Merged
3 commits merged into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ impl<T: Config> Module<T> {
#[cfg(test)]
mod tests {
use super::*;
use hex_literal::hex;
use primitives::v1::BlockNumber;
use frame_support::StorageValue;
use frame_support::traits::{OnFinalize, OnInitialize};
Expand Down Expand Up @@ -322,6 +323,25 @@ mod tests {
});
}

#[test]
fn dmp_mqc_head_fixture() {
let a = ParaId::from(2000);

new_test_ext(default_genesis_config()).execute_with(|| {
run_to_block(2, None);
assert!(Dmp::dmq_mqc_head(a).is_zero());
queue_downward_message(a, vec![1, 2, 3]).unwrap();

run_to_block(3, None);
queue_downward_message(a, vec![4, 5, 6]).unwrap();

assert_eq!(
Dmp::dmq_mqc_head(a),
hex!["88dc00db8cc9d22aa62b87807705831f164387dfa49f80a8600ed1cbe1704b6b"].into(),
);
});
}

#[test]
fn check_processed_downward_messages() {
let a = ParaId::from(1312);
Expand Down
37 changes: 37 additions & 0 deletions runtime/parachains/src/hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,43 @@ mod tests {
});
}

#[test]
fn hrmp_mqc_head_fixture() {
let para_a = 2000.into();
let para_b = 2024.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(1, Some(vec![1]));
Hrmp::init_open_channel(para_a, para_b, 2, 20).unwrap();
Hrmp::accept_open_channel(para_b, para_a).unwrap();

run_to_block(2, Some(vec![2]));
let _ = Hrmp::queue_outbound_hrmp(para_a, vec![OutboundHrmpMessage {
recipient: para_b,
data: vec![1, 2, 3],
}]);

run_to_block(3, None);
let _ = Hrmp::queue_outbound_hrmp(para_a, vec![OutboundHrmpMessage {
recipient: para_b,
data: vec![4, 5, 6],
}]);

assert_eq!(
Hrmp::hrmp_mqc_heads(para_b),
vec![
(para_a, hex_literal::hex!["88dc00db8cc9d22aa62b87807705831f164387dfa49f80a8600ed1cbe1704b6b"].into()),
],
);
});
}

#[test]
fn accept_incoming_request_and_offboard() {
let para_a = 32.into();
Expand Down