Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
TEST_LANE_ID,
REGULAR_PAYLOAD,
2000,
));
// this reports delivery of message 1 => reward is paid to TEST_RELAYER_A
assert_ok!(Module::<TestRuntime>::receive_messages_delivery_proof(
Origin::signed(1),
Ok((
TEST_LANE_ID,
InboundLaneData {
relayers: vec![(1, 1, TEST_RELAYER_A)].into_iter().collect(),
latest_received_nonce: 1,
..Default::default()
}
)),
));
assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(
TEST_RELAYER_A,
1000
));
assert!(!TestMessageDeliveryAndDispatchPayment::is_reward_paid(
TEST_RELAYER_B,
2000
));
// this reports delivery of both message 1 and message 2 => reward is paid only to TEST_RELAYER_B
assert_ok!(Module::<TestRuntime>::receive_messages_delivery_proof(
Origin::signed(1),
Ok((
TEST_LANE_ID,
InboundLaneData {
relayers: vec![(1, 1, TEST_RELAYER_A), (2, 2, TEST_RELAYER_B)]
.into_iter()
.collect(),
latest_received_nonce: 2,
..Default::default()
}
)),
));
assert!(!TestMessageDeliveryAndDispatchPayment::is_reward_paid(
TEST_RELAYER_A,
1000
));
assert!(TestMessageDeliveryAndDispatchPayment::is_reward_paid(
TEST_RELAYER_B,
2000
));
});
}
#[test]
fn receive_messages_delivery_proof_rejects_invalid_proof() {
run_test(|| {
assert_noop!(
Module::<TestRuntime>::receive_messages_delivery_proof(Origin::signed(1), Err(()),),
Error::<TestRuntime, DefaultInstance>::InvalidMessagesDeliveryProof,
);
});
}
#[test]
fn receive_messages_accepts_single_message_with_invalid_payload() {
run_test(|| {
let mut invalid_message = message(1, REGULAR_PAYLOAD);
invalid_message.data.payload = Vec::new();
assert_ok!(Module::<TestRuntime, DefaultInstance>::receive_messages_proof(
Origin::signed(1),
TEST_RELAYER_A,
Ok(vec![invalid_message]).into(),
0, // weight may be zero in this case (all messages are improperly encoded)
),);
assert_eq!(InboundLanes::<TestRuntime>::get(&TEST_LANE_ID).latest_received_nonce, 1,);
});
}
#[test]
fn receive_messages_accepts_batch_with_message_with_invalid_payload() {
run_test(|| {
let mut invalid_message = message(2, REGULAR_PAYLOAD);
invalid_message.data.payload = Vec::new();
assert_ok!(Module::<TestRuntime, DefaultInstance>::receive_messages_proof(
Origin::signed(1),
Ok(vec![
message(1, REGULAR_PAYLOAD),
invalid_message,
message(3, REGULAR_PAYLOAD),
REGULAR_PAYLOAD.1 + REGULAR_PAYLOAD.1,
),);
assert_eq!(InboundLanes::<TestRuntime>::get(&TEST_LANE_ID).latest_received_nonce, 3,);
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
#[test]
fn storage_message_key_computed_properly() {
// If this test fails, then something has been changed in module storage that is breaking all
// previously crafted messages proofs.
assert_eq!(
storage_keys::message_key::<TestRuntime, DefaultInstance>(&*b"test", 42).0,
hex!("87f1ffe31b52878f09495ca7482df1a48a395e6242c6813b196ca31ed0547ea79446af0e09063bd4a7874aef8a997cec746573742a00000000000000").to_vec(),
);
}
#[test]
fn outbound_lane_data_key_computed_properly() {
// If this test fails, then something has been changed in module storage that is breaking all
// previously crafted outbound lane state proofs.
assert_eq!(
storage_keys::outbound_lane_data_key::<DefaultInstance>(&*b"test").0,
hex!("87f1ffe31b52878f09495ca7482df1a496c246acb9b55077390e3ca723a0ca1f44a8995dd50b6657a037a7839304535b74657374").to_vec(),
);
}
#[test]
fn inbound_lane_data_key_computed_properly() {
// If this test fails, then something has been changed in module storage that is breaking all
// previously crafted inbound lane state proofs.
assert_eq!(
storage_keys::inbound_lane_data_key::<TestRuntime, DefaultInstance>(&*b"test").0,
hex!("87f1ffe31b52878f09495ca7482df1a4e5f83cf83f2127eb47afdc35d6e43fab44a8995dd50b6657a037a7839304535b74657374").to_vec(),
);
}