Newer
Older
unrewarded_relayer_entries: 2,
messages_in_oldest_entry: 1,
Svyatoslav Nikolsky
committed
total_messages: 2,
},
);
// message proof includes outbound lane state with latest confirmed message updated to 9
let mut message_proof: TestMessagesProof = Ok(vec![message(11, REGULAR_PAYLOAD)]).into();
message_proof.result.as_mut().unwrap()[0].1.lane_state = Some(OutboundLaneData {
latest_received_nonce: 9,
..Default::default()
});
assert_ok!(Module::<TestRuntime>::receive_messages_proof(
Origin::signed(1),
TEST_RELAYER_A,
message_proof,
REGULAR_PAYLOAD.1,
));
assert_eq!(
InboundLanes::<TestRuntime>::get(TEST_LANE_ID),
InboundLaneData {
last_confirmed_nonce: 9,
relayers: vec![(10, 10, TEST_RELAYER_B), (11, 11, TEST_RELAYER_A)]
.into_iter()
.collect(),
},
assert_eq!(
Module::<TestRuntime>::inbound_unrewarded_relayers_state(TEST_LANE_ID),
UnrewardedRelayersState {
unrewarded_relayer_entries: 2,
messages_in_oldest_entry: 1,
Svyatoslav Nikolsky
committed
total_messages: 2,
},
);
});
}
#[test]
fn receive_messages_proof_rejects_invalid_dispatch_weight() {
run_test(|| {
assert_noop!(
Module::<TestRuntime>::receive_messages_proof(
Origin::signed(1),
TEST_RELAYER_A,
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
REGULAR_PAYLOAD.1 - 1,
),
Error::<TestRuntime, DefaultInstance>::InvalidMessagesDispatchWeight,
);
});
}
#[test]
fn receive_messages_proof_rejects_invalid_proof() {
run_test(|| {
assert_noop!(
Module::<TestRuntime, DefaultInstance>::receive_messages_proof(
Origin::signed(1),
TEST_RELAYER_A,
Err(()).into(),
Error::<TestRuntime, DefaultInstance>::InvalidMessagesProof,
);
});
}
#[test]
fn receive_messages_delivery_proof_works() {
run_test(|| {
send_regular_message();
receive_messages_delivery_proof();
assert_eq!(
OutboundLanes::<DefaultInstance>::get(&TEST_LANE_ID).latest_received_nonce,
1,
);
});
}
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
#[test]
fn receive_messages_delivery_proof_rewards_relayers() {
run_test(|| {
assert_ok!(Module::<TestRuntime>::send_message(
Origin::signed(1),
TEST_LANE_ID,
REGULAR_PAYLOAD,
1000,
));
assert_ok!(Module::<TestRuntime>::send_message(
Origin::signed(1),
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(),
..Default::default()
}
)),
Svyatoslav Nikolsky
committed
UnrewardedRelayersState {
unrewarded_relayer_entries: 1,
total_messages: 1,
..Default::default()
},
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
));
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(),
..Default::default()
}
)),
Svyatoslav Nikolsky
committed
UnrewardedRelayersState {
unrewarded_relayer_entries: 2,
total_messages: 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!(
Svyatoslav Nikolsky
committed
Module::<TestRuntime>::receive_messages_delivery_proof(Origin::signed(1), Err(()), Default::default(),),
Error::<TestRuntime, DefaultInstance>::InvalidMessagesDeliveryProof,
);
});
}
Svyatoslav Nikolsky
committed
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
#[test]
fn receive_messages_delivery_proof_rejects_proof_if_declared_relayers_state_is_invalid() {
run_test(|| {
// when number of relayers entires is invalid
assert_noop!(
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(),
..Default::default()
}
)),
UnrewardedRelayersState {
unrewarded_relayer_entries: 1,
total_messages: 2,
..Default::default()
},
),
Error::<TestRuntime, DefaultInstance>::InvalidUnrewardedRelayersState,
);
// when number of messages is invalid
assert_noop!(
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(),
..Default::default()
}
)),
UnrewardedRelayersState {
unrewarded_relayer_entries: 2,
total_messages: 1,
..Default::default()
},
),
Error::<TestRuntime, DefaultInstance>::InvalidUnrewardedRelayersState,
);
});
}
#[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).last_delivered_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).last_delivered_nonce(),
3,
);
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
#[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(),
);
}