diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index 83c0953418489..b3c56cfd858b9 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -830,235 +830,6 @@ fn verify_and_decode_messages_proof, I: 'static>( }) } -// #[cfg(test)] -// mod tests { -// use super::*; -// use crate::{ -// mock::{ -// inbound_unrewarded_relayers_state, message, message_payload, run_test, -// unrewarded_relayer, AccountId, DbWeight, RuntimeEvent as TestEvent, RuntimeOrigin, -// TestDeliveryConfirmationPayments, TestDeliveryPayments, TestMessageDispatch, -// TestMessagesDeliveryProof, TestMessagesProof, TestOnMessagesDelivered, TestRelayer, -// TestRuntime, TestWeightInfo, MAX_OUTBOUND_PAYLOAD_SIZE, -// PAYLOAD_REJECTED_BY_TARGET_CHAIN, REGULAR_PAYLOAD, TEST_LANE_ID, TEST_LANE_ID_2, -// TEST_LANE_ID_3, TEST_RELAYER_A, TEST_RELAYER_B, -// }, -// outbound_lane::ReceptionConfirmationError, -// }; -// use bp_messages::{ -// source_chain::MessagesBridge, BridgeMessagesCall, UnrewardedRelayer, -// UnrewardedRelayersState, -// }; -// use bp_test_utils::generate_owned_bridge_module_tests; -// use frame_support::{ -// assert_noop, assert_ok, -// dispatch::Pays, -// storage::generator::{StorageMap, StorageValue}, -// traits::Hooks, -// weights::Weight, -// }; -// use frame_system::{EventRecord, Pallet as System, Phase}; -// use sp_runtime::DispatchError; -// -// fn get_ready_for_events() { -// System::::set_block_number(1); -// System::::reset_events(); -// } -// -// fn send_regular_message(lane_id: LaneId) { -// get_ready_for_events(); -// -// let outbound_lane = outbound_lane::(lane_id); -// let message_nonce = outbound_lane.data().latest_generated_nonce + 1; -// let prev_enqueued_messages = outbound_lane.data().queued_messages().saturating_len(); -// let valid_message = Pallet::::validate_message(lane_id, ®ULAR_PAYLOAD) -// .expect("validate_message has failed"); -// let artifacts = Pallet::::send_message(valid_message); -// assert_eq!(artifacts.enqueued_messages, prev_enqueued_messages + 1); -// -// // check event with assigned nonce -// assert_eq!( -// System::::events(), -// vec![EventRecord { -// phase: Phase::Initialization, -// event: TestEvent::Messages(Event::MessageAccepted { -// lane_id, -// nonce: message_nonce -// }), -// topics: vec![], -// }], -// ); -// } -// -// fn receive_messages_delivery_proof() { -// System::::set_block_number(1); -// System::::reset_events(); -// -// assert_ok!(Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { -// last_confirmed_nonce: 1, -// relayers: vec![UnrewardedRelayer { -// relayer: 0, -// messages: DeliveredMessages::new(1), -// }] -// .into_iter() -// .collect(), -// }, -// ))), -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 1, -// messages_in_oldest_entry: 1, -// total_messages: 1, -// last_delivered_nonce: 1, -// }, -// )); -// -// assert_eq!( -// System::::events(), -// vec![EventRecord { -// phase: Phase::Initialization, -// event: TestEvent::Messages(Event::MessagesDelivered { -// lane_id: TEST_LANE_ID, -// messages: DeliveredMessages::new(1), -// }), -// topics: vec![], -// }], -// ); -// } -// -// #[test] -// fn pallet_rejects_transactions_if_halted() { -// run_test(|| { -// // send message first to be able to check that delivery_proof fails later -// send_regular_message(TEST_LANE_ID); -// -// PalletOperatingMode::::put(MessagesOperatingMode::Basic( -// BasicOperatingMode::Halted, -// )); -// -// assert_noop!( -// Pallet::::validate_message(TEST_LANE_ID, ®ULAR_PAYLOAD), -// Error::::NotOperatingNormally, -// ); -// -// assert_noop!( -// Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// Ok(vec![message(2, REGULAR_PAYLOAD)]).into(), -// 1, -// REGULAR_PAYLOAD.declared_weight, -// ), -// Error::::BridgeModule(bp_runtime::OwnedBridgeModuleError::Halted), -// ); -// -// assert_noop!( -// Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { -// last_confirmed_nonce: 1, -// relayers: vec![unrewarded_relayer(1, 1, TEST_RELAYER_A)] -// .into_iter() -// .collect(), -// }, -// ))), -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 1, -// messages_in_oldest_entry: 1, -// total_messages: 1, -// last_delivered_nonce: 1, -// }, -// ), -// Error::::BridgeModule(bp_runtime::OwnedBridgeModuleError::Halted), -// ); -// }); -// } -// -// #[test] -// fn pallet_rejects_new_messages_in_rejecting_outbound_messages_operating_mode() { -// run_test(|| { -// // send message first to be able to check that delivery_proof fails later -// send_regular_message(TEST_LANE_ID); -// -// PalletOperatingMode::::put( -// MessagesOperatingMode::RejectingOutboundMessages, -// ); -// -// assert_noop!( -// Pallet::::validate_message(TEST_LANE_ID, ®ULAR_PAYLOAD), -// Error::::NotOperatingNormally, -// ); -// -// assert_ok!(Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// Ok(vec![message(1, REGULAR_PAYLOAD)]).into(), -// 1, -// REGULAR_PAYLOAD.declared_weight, -// ),); -// -// assert_ok!(Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { -// last_confirmed_nonce: 1, -// relayers: vec![unrewarded_relayer(1, 1, TEST_RELAYER_A)] -// .into_iter() -// .collect(), -// }, -// ))), -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 1, -// messages_in_oldest_entry: 1, -// total_messages: 1, -// last_delivered_nonce: 1, -// }, -// )); -// }); -// } -// -// #[test] -// fn send_message_works() { -// run_test(|| { -// send_regular_message(TEST_LANE_ID); -// }); -// } -// -// #[test] -// fn send_message_rejects_too_large_message() { -// run_test(|| { -// let mut message_payload = message_payload(1, 0); -// // the payload isn't simply extra, so it'll definitely overflow -// // `MAX_OUTBOUND_PAYLOAD_SIZE` if we add `MAX_OUTBOUND_PAYLOAD_SIZE` bytes to extra -// message_payload -// .extra -// .extend_from_slice(&[0u8; MAX_OUTBOUND_PAYLOAD_SIZE as usize]); -// assert_noop!( -// Pallet::::validate_message(TEST_LANE_ID, &message_payload.clone(),), -// Error::::MessageRejectedByPallet( -// VerificationError::MessageTooLarge -// ), -// ); -// -// // let's check that we're able to send `MAX_OUTBOUND_PAYLOAD_SIZE` messages -// while message_payload.encoded_size() as u32 > MAX_OUTBOUND_PAYLOAD_SIZE { -// message_payload.extra.pop(); -// } -// assert_eq!(message_payload.encoded_size() as u32, MAX_OUTBOUND_PAYLOAD_SIZE); -// -// let valid_message = -// Pallet::::validate_message(TEST_LANE_ID, &message_payload) -// .expect("validate_message has failed"); -// Pallet::::send_message(valid_message); -// }) -// } -// // #[test] // fn chain_verifier_rejects_invalid_message_in_send_message() { // run_test(|| { @@ -1076,87 +847,6 @@ fn verify_and_decode_messages_proof, I: 'static>( // } // // #[test] -// fn receive_messages_proof_works() { -// run_test(|| { -// assert_ok!(Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// Ok(vec![message(1, REGULAR_PAYLOAD)]).into(), -// 1, -// REGULAR_PAYLOAD.declared_weight, -// )); -// -// assert_eq!(InboundLanes::::get(TEST_LANE_ID).0.last_delivered_nonce(), 1); -// -// assert!(TestDeliveryPayments::is_reward_paid(1)); -// }); -// } -// -// #[test] -// fn receive_messages_proof_updates_confirmed_message_nonce() { -// run_test(|| { -// // say we have received 10 messages && last confirmed message is 8 -// InboundLanes::::insert( -// TEST_LANE_ID, -// InboundLaneData { -// last_confirmed_nonce: 8, -// relayers: vec![ -// unrewarded_relayer(9, 9, TEST_RELAYER_A), -// unrewarded_relayer(10, 10, TEST_RELAYER_B), -// ] -// .into_iter() -// .collect(), -// }, -// ); -// assert_eq!( -// inbound_unrewarded_relayers_state(TEST_LANE_ID), -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 2, -// messages_in_oldest_entry: 1, -// total_messages: 2, -// last_delivered_nonce: 10, -// }, -// ); -// -// // 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!(Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// message_proof, -// 1, -// REGULAR_PAYLOAD.declared_weight, -// )); -// -// assert_eq!( -// InboundLanes::::get(TEST_LANE_ID).0, -// InboundLaneData { -// last_confirmed_nonce: 9, -// relayers: vec![ -// unrewarded_relayer(10, 10, TEST_RELAYER_B), -// unrewarded_relayer(11, 11, TEST_RELAYER_A) -// ] -// .into_iter() -// .collect(), -// }, -// ); -// assert_eq!( -// inbound_unrewarded_relayers_state(TEST_LANE_ID), -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 2, -// messages_in_oldest_entry: 1, -// total_messages: 2, -// last_delivered_nonce: 11, -// }, -// ); -// }); -// } -// -// #[test] // fn receive_messages_fails_if_dispatcher_is_inactive() { // run_test(|| { // TestMessageDispatch::deactivate(); @@ -1174,293 +864,6 @@ fn verify_and_decode_messages_proof, I: 'static>( // } // // #[test] -// fn receive_messages_proof_does_not_accept_message_if_dispatch_weight_is_not_enough() { -// run_test(|| { -// let mut declared_weight = REGULAR_PAYLOAD.declared_weight; -// *declared_weight.ref_time_mut() -= 1; -// assert_noop!( -// Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// Ok(vec![message(1, REGULAR_PAYLOAD)]).into(), -// 1, -// declared_weight, -// ), -// Error::::InsufficientDispatchWeight -// ); -// assert_eq!(InboundLanes::::get(TEST_LANE_ID).last_delivered_nonce(), 0); -// }); -// } -// -// #[test] -// fn receive_messages_proof_rejects_invalid_proof() { -// run_test(|| { -// assert_noop!( -// Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// Err(()).into(), -// 1, -// Weight::zero(), -// ), -// Error::::InvalidMessagesProof, -// ); -// }); -// } -// -// #[test] -// fn receive_messages_proof_rejects_proof_with_too_many_messages() { -// run_test(|| { -// assert_noop!( -// Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// Ok(vec![message(1, REGULAR_PAYLOAD)]).into(), -// u32::MAX, -// Weight::zero(), -// ), -// Error::::TooManyMessagesInTheProof, -// ); -// }); -// } -// -// #[test] -// fn receive_messages_delivery_proof_works() { -// run_test(|| { -// send_regular_message(TEST_LANE_ID); -// receive_messages_delivery_proof(); -// -// assert_eq!( -// OutboundLanes::::get(TEST_LANE_ID).latest_received_nonce, -// 1, -// ); -// }); -// } -// -// #[test] -// fn receive_messages_delivery_proof_rewards_relayers() { -// run_test(|| { -// send_regular_message(TEST_LANE_ID); -// send_regular_message(TEST_LANE_ID); -// -// // this reports delivery of message 1 => reward is paid to TEST_RELAYER_A -// let single_message_delivery_proof = TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { -// relayers: vec![unrewarded_relayer(1, 1, TEST_RELAYER_A)].into_iter().collect(), -// ..Default::default() -// }, -// ))); -// let single_message_delivery_proof_size = single_message_delivery_proof.size(); -// let result = Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// single_message_delivery_proof, -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 1, -// messages_in_oldest_entry: 1, -// total_messages: 1, -// last_delivered_nonce: 1, -// }, -// ); -// assert_ok!(result); -// assert_eq!( -// result.unwrap().actual_weight.unwrap(), -// TestWeightInfo::receive_messages_delivery_proof_weight( -// &PreComputedSize(single_message_delivery_proof_size as _), -// &UnrewardedRelayersState { -// unrewarded_relayer_entries: 1, -// total_messages: 1, -// ..Default::default() -// }, -// ) -// ); -// assert!(TestDeliveryConfirmationPayments::is_reward_paid(TEST_RELAYER_A, 1)); -// assert!(!TestDeliveryConfirmationPayments::is_reward_paid(TEST_RELAYER_B, 1)); -// assert_eq!(TestOnMessagesDelivered::call_arguments(), Some((TEST_LANE_ID, 1))); -// -// // this reports delivery of both message 1 and message 2 => reward is paid only to -// // TEST_RELAYER_B -// let two_messages_delivery_proof = TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { -// relayers: vec![ -// unrewarded_relayer(1, 1, TEST_RELAYER_A), -// unrewarded_relayer(2, 2, TEST_RELAYER_B), -// ] -// .into_iter() -// .collect(), -// ..Default::default() -// }, -// ))); -// let two_messages_delivery_proof_size = two_messages_delivery_proof.size(); -// let result = Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// two_messages_delivery_proof, -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 2, -// messages_in_oldest_entry: 1, -// total_messages: 2, -// last_delivered_nonce: 2, -// }, -// ); -// assert_ok!(result); -// // even though the pre-dispatch weight was for two messages, the actual weight is -// // for single message only -// assert_eq!( -// result.unwrap().actual_weight.unwrap(), -// TestWeightInfo::receive_messages_delivery_proof_weight( -// &PreComputedSize(two_messages_delivery_proof_size as _), -// &UnrewardedRelayersState { -// unrewarded_relayer_entries: 1, -// total_messages: 1, -// ..Default::default() -// }, -// ) -// ); -// assert!(!TestDeliveryConfirmationPayments::is_reward_paid(TEST_RELAYER_A, 1)); -// assert!(TestDeliveryConfirmationPayments::is_reward_paid(TEST_RELAYER_B, 1)); -// assert_eq!(TestOnMessagesDelivered::call_arguments(), Some((TEST_LANE_ID, 0))); -// }); -// } -// -// #[test] -// fn receive_messages_delivery_proof_rejects_invalid_proof() { -// run_test(|| { -// assert_noop!( -// Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// TestMessagesDeliveryProof(Err(())), -// Default::default(), -// ), -// Error::::InvalidMessagesDeliveryProof, -// ); -// }); -// } -// -// #[test] -// fn receive_messages_delivery_proof_rejects_proof_if_declared_relayers_state_is_invalid() { -// run_test(|| { -// // when number of relayers entries is invalid -// assert_noop!( -// Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { -// relayers: vec![ -// unrewarded_relayer(1, 1, TEST_RELAYER_A), -// unrewarded_relayer(2, 2, TEST_RELAYER_B) -// ] -// .into_iter() -// .collect(), -// ..Default::default() -// } -// ))), -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 1, -// total_messages: 2, -// last_delivered_nonce: 2, -// ..Default::default() -// }, -// ), -// Error::::InvalidUnrewardedRelayersState, -// ); -// -// // when number of messages is invalid -// assert_noop!( -// Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { -// relayers: vec![ -// unrewarded_relayer(1, 1, TEST_RELAYER_A), -// unrewarded_relayer(2, 2, TEST_RELAYER_B) -// ] -// .into_iter() -// .collect(), -// ..Default::default() -// } -// ))), -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 2, -// total_messages: 1, -// last_delivered_nonce: 2, -// ..Default::default() -// }, -// ), -// Error::::InvalidUnrewardedRelayersState, -// ); -// -// // when last delivered nonce is invalid -// assert_noop!( -// Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { -// relayers: vec![ -// unrewarded_relayer(1, 1, TEST_RELAYER_A), -// unrewarded_relayer(2, 2, TEST_RELAYER_B) -// ] -// .into_iter() -// .collect(), -// ..Default::default() -// } -// ))), -// UnrewardedRelayersState { -// unrewarded_relayer_entries: 2, -// total_messages: 2, -// last_delivered_nonce: 8, -// ..Default::default() -// }, -// ), -// Error::::InvalidUnrewardedRelayersState, -// ); -// }); -// } -// -// #[test] -// fn receive_messages_accepts_single_message_with_invalid_payload() { -// run_test(|| { -// let mut invalid_message = message(1, REGULAR_PAYLOAD); -// invalid_message.payload = Vec::new(); -// -// assert_ok!(Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// Ok(vec![invalid_message]).into(), -// 1, -// Weight::zero(), /* weight may be zero in this case (all messages are -// * improperly encoded) */ -// ),); -// -// assert_eq!(InboundLanes::::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.payload = Vec::new(); -// -// assert_ok!(Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// Ok( -// vec![message(1, REGULAR_PAYLOAD), invalid_message, message(3, REGULAR_PAYLOAD),] -// ) -// .into(), -// 3, -// REGULAR_PAYLOAD.declared_weight + REGULAR_PAYLOAD.declared_weight, -// ),); -// -// assert_eq!(InboundLanes::::get(TEST_LANE_ID).last_delivered_nonce(), 3,); -// }); -// } -// -// #[test] // fn actual_dispatch_weight_does_not_overflow() { // run_test(|| { // let message1 = message(1, message_payload(0, u64::MAX / 2)); @@ -1483,148 +886,6 @@ fn verify_and_decode_messages_proof, I: 'static>( // } // // #[test] -// fn ref_time_refund_from_receive_messages_proof_works() { -// run_test(|| { -// fn submit_with_unspent_weight( -// nonce: MessageNonce, -// unspent_weight: u64, -// ) -> (Weight, Weight) { -// let mut payload = REGULAR_PAYLOAD; -// *payload.dispatch_result.unspent_weight.ref_time_mut() = unspent_weight; -// let proof = Ok(vec![message(nonce, payload)]).into(); -// let messages_count = 1; -// let pre_dispatch_weight = -// ::WeightInfo::receive_messages_proof_weight( -// &proof, -// messages_count, -// REGULAR_PAYLOAD.declared_weight, -// ); -// let result = Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// proof, -// messages_count, -// REGULAR_PAYLOAD.declared_weight, -// ) -// .expect("delivery has failed"); -// let post_dispatch_weight = -// result.actual_weight.expect("receive_messages_proof always returns Some"); -// -// // message delivery transactions are never free -// assert_eq!(result.pays_fee, Pays::Yes); -// -// (pre_dispatch_weight, post_dispatch_weight) -// } -// -// // when dispatch is returning `unspent_weight < declared_weight` -// let (pre, post) = submit_with_unspent_weight(1, 1); -// assert_eq!(post.ref_time(), pre.ref_time() - 1); -// -// // when dispatch is returning `unspent_weight = declared_weight` -// let (pre, post) = -// submit_with_unspent_weight(2, REGULAR_PAYLOAD.declared_weight.ref_time()); -// assert_eq!( -// post.ref_time(), -// pre.ref_time() - REGULAR_PAYLOAD.declared_weight.ref_time() -// ); -// -// // when dispatch is returning `unspent_weight > declared_weight` -// let (pre, post) = -// submit_with_unspent_weight(3, REGULAR_PAYLOAD.declared_weight.ref_time() + 1); -// assert_eq!( -// post.ref_time(), -// pre.ref_time() - REGULAR_PAYLOAD.declared_weight.ref_time() -// ); -// -// // when there's no unspent weight -// let (pre, post) = submit_with_unspent_weight(4, 0); -// assert_eq!(post.ref_time(), pre.ref_time()); -// -// // when dispatch is returning `unspent_weight < declared_weight` -// let (pre, post) = submit_with_unspent_weight(5, 1); -// assert_eq!(post.ref_time(), pre.ref_time() - 1); -// }); -// } -// -// #[test] -// fn proof_size_refund_from_receive_messages_proof_works() { -// run_test(|| { -// let max_entries = crate::mock::MaxUnrewardedRelayerEntriesAtInboundLane::get() as usize; -// -// // if there's maximal number of unrewarded relayer entries at the inbound lane, then -// // `proof_size` is unchanged in post-dispatch weight -// let proof: TestMessagesProof = Ok(vec![message(101, REGULAR_PAYLOAD)]).into(); -// let messages_count = 1; -// let pre_dispatch_weight = -// ::WeightInfo::receive_messages_proof_weight( -// &proof, -// messages_count, -// REGULAR_PAYLOAD.declared_weight, -// ); -// InboundLanes::::insert( -// TEST_LANE_ID, -// StoredInboundLaneData(InboundLaneData { -// relayers: vec![ -// UnrewardedRelayer { -// relayer: 42, -// messages: DeliveredMessages { begin: 0, end: 100 } -// }; -// max_entries -// ] -// .into_iter() -// .collect(), -// last_confirmed_nonce: 0, -// }), -// ); -// let post_dispatch_weight = Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// proof.clone(), -// messages_count, -// REGULAR_PAYLOAD.declared_weight, -// ) -// .unwrap() -// .actual_weight -// .unwrap(); -// assert_eq!(post_dispatch_weight.proof_size(), pre_dispatch_weight.proof_size()); -// -// // if count of unrewarded relayer entries is less than maximal, then some `proof_size` -// // must be refunded -// InboundLanes::::insert( -// TEST_LANE_ID, -// StoredInboundLaneData(InboundLaneData { -// relayers: vec![ -// UnrewardedRelayer { -// relayer: 42, -// messages: DeliveredMessages { begin: 0, end: 100 } -// }; -// max_entries - 1 -// ] -// .into_iter() -// .collect(), -// last_confirmed_nonce: 0, -// }), -// ); -// let post_dispatch_weight = Pallet::::receive_messages_proof( -// RuntimeOrigin::signed(1), -// TEST_RELAYER_A, -// proof, -// messages_count, -// REGULAR_PAYLOAD.declared_weight, -// ) -// .unwrap() -// .actual_weight -// .unwrap(); -// assert!( -// post_dispatch_weight.proof_size() < pre_dispatch_weight.proof_size(), -// "Expected post-dispatch PoV {} to be less than pre-dispatch PoV {}", -// post_dispatch_weight.proof_size(), -// pre_dispatch_weight.proof_size(), -// ); -// }); -// } -// -// #[test] // fn messages_delivered_callbacks_are_called() { // run_test(|| { // send_regular_message(TEST_LANE_ID); @@ -1684,75 +945,6 @@ fn verify_and_decode_messages_proof, I: 'static>( // } // // #[test] -// fn receive_messages_delivery_proof_rejects_proof_if_trying_to_confirm_more_messages_than_expected( -// ) { -// run_test(|| { -// // send message first to be able to check that delivery_proof fails later -// send_regular_message(TEST_LANE_ID); -// -// // 1) InboundLaneData declares that the `last_confirmed_nonce` is 1; -// // 2) InboundLaneData has no entries => `InboundLaneData::last_delivered_nonce()` -// // returns `last_confirmed_nonce`; -// // 3) it means that we're going to confirm delivery of messages 1..=1; -// // 4) so the number of declared messages (see `UnrewardedRelayersState`) is `0` and -// // number of actually confirmed messages is `1`. -// assert_noop!( -// Pallet::::receive_messages_delivery_proof( -// RuntimeOrigin::signed(1), -// TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { last_confirmed_nonce: 1, relayers: Default::default() }, -// ))), -// UnrewardedRelayersState { last_delivered_nonce: 1, ..Default::default() }, -// ), -// Error::::ReceptionConfirmation( -// ReceptionConfirmationError::TryingToConfirmMoreMessagesThanExpected -// ), -// ); -// }); -// } -// -// #[test] -// fn storage_keys_computed_properly() { -// assert_eq!( -// PalletOperatingMode::::storage_value_final_key().to_vec(), -// bp_messages::storage_keys::operating_mode_key("Messages").0, -// ); -// -// assert_eq!( -// OutboundMessages::::storage_map_final_key(MessageKey { -// lane_id: TEST_LANE_ID, -// nonce: 42 -// }), -// bp_messages::storage_keys::message_key("Messages", &TEST_LANE_ID, 42).0, -// ); -// -// assert_eq!( -// OutboundLanes::::storage_map_final_key(TEST_LANE_ID), -// bp_messages::storage_keys::outbound_lane_data_key("Messages", &TEST_LANE_ID).0, -// ); -// -// assert_eq!( -// InboundLanes::::storage_map_final_key(TEST_LANE_ID), -// bp_messages::storage_keys::inbound_lane_data_key("Messages", &TEST_LANE_ID).0, -// ); -// } -// -// #[test] -// fn inbound_message_details_works() { -// run_test(|| { -// assert_eq!( -// Pallet::::inbound_message_data( -// TEST_LANE_ID, -// REGULAR_PAYLOAD.encode(), -// OutboundMessageDetails { nonce: 0, dispatch_weight: Weight::zero(), size: 0 }, -// ), -// InboundMessageDetails { dispatch_weight: REGULAR_PAYLOAD.declared_weight }, -// ); -// }); -// } -// -// #[test] // fn on_idle_callback_respects_remaining_weight() { // run_test(|| { // send_regular_message(TEST_LANE_ID); @@ -1911,127 +1103,3 @@ fn verify_and_decode_messages_proof, I: 'static>( // ); // }); // } -// -// #[test] -// fn outbound_message_from_unconfigured_lane_is_rejected() { -// run_test(|| { -// assert_noop!( -// Pallet::::validate_message(TEST_LANE_ID_3, ®ULAR_PAYLOAD,), -// Error::::InactiveOutboundLane, -// ); -// }); -// } -// -// #[test] -// fn test_bridge_messages_call_is_correctly_defined() { -// let account_id = 1; -// let message_proof: TestMessagesProof = Ok(vec![message(1, REGULAR_PAYLOAD)]).into(); -// let message_delivery_proof = TestMessagesDeliveryProof(Ok(( -// TEST_LANE_ID, -// InboundLaneData { -// last_confirmed_nonce: 1, -// relayers: vec![UnrewardedRelayer { -// relayer: 0, -// messages: DeliveredMessages::new(1), -// }] -// .into_iter() -// .collect(), -// }, -// ))); -// let unrewarded_relayer_state = UnrewardedRelayersState { -// unrewarded_relayer_entries: 1, -// total_messages: 1, -// last_delivered_nonce: 1, -// ..Default::default() -// }; -// -// let direct_receive_messages_proof_call = Call::::receive_messages_proof { -// relayer_id_at_bridged_chain: account_id, -// proof: message_proof.clone(), -// messages_count: 1, -// dispatch_weight: REGULAR_PAYLOAD.declared_weight, -// }; -// let indirect_receive_messages_proof_call = BridgeMessagesCall::< -// AccountId, -// TestMessagesProof, -// TestMessagesDeliveryProof, -// >::receive_messages_proof { -// relayer_id_at_bridged_chain: account_id, -// proof: message_proof, -// messages_count: 1, -// dispatch_weight: REGULAR_PAYLOAD.declared_weight, -// }; -// assert_eq!( -// direct_receive_messages_proof_call.encode(), -// indirect_receive_messages_proof_call.encode() -// ); -// -// let direct_receive_messages_delivery_proof_call = -// Call::::receive_messages_delivery_proof { -// proof: message_delivery_proof.clone(), -// relayers_state: unrewarded_relayer_state.clone(), -// }; -// let indirect_receive_messages_delivery_proof_call = BridgeMessagesCall::< -// AccountId, -// TestMessagesProof, -// TestMessagesDeliveryProof, -// >::receive_messages_delivery_proof { -// proof: message_delivery_proof, -// relayers_state: unrewarded_relayer_state, -// }; -// assert_eq!( -// direct_receive_messages_delivery_proof_call.encode(), -// indirect_receive_messages_delivery_proof_call.encode() -// ); -// } -// -// generate_owned_bridge_module_tests!( -// MessagesOperatingMode::Basic(BasicOperatingMode::Normal), -// MessagesOperatingMode::Basic(BasicOperatingMode::Halted) -// ); -// -// #[test] -// fn inbound_storage_extra_proof_size_bytes_works() { -// fn relayer_entry() -> UnrewardedRelayer { -// UnrewardedRelayer { relayer: 42u64, messages: DeliveredMessages { begin: 0, end: 100 } } -// } -// -// fn storage(relayer_entries: usize) -> RuntimeInboundLaneStorage { -// RuntimeInboundLaneStorage { -// lane_id: Default::default(), -// cached_data: Some(InboundLaneData { -// relayers: vec![relayer_entry(); relayer_entries].into_iter().collect(), -// last_confirmed_nonce: 0, -// }), -// _phantom: Default::default(), -// } -// } -// -// let max_entries = crate::mock::MaxUnrewardedRelayerEntriesAtInboundLane::get() as usize; -// -// // when we have exactly `MaxUnrewardedRelayerEntriesAtInboundLane` unrewarded relayers -// assert_eq!(storage(max_entries).extra_proof_size_bytes(), 0); -// -// // when we have less than `MaxUnrewardedRelayerEntriesAtInboundLane` unrewarded relayers -// assert_eq!( -// storage(max_entries - 1).extra_proof_size_bytes(), -// relayer_entry().encode().len() as u64 -// ); -// assert_eq!( -// storage(max_entries - 2).extra_proof_size_bytes(), -// 2 * relayer_entry().encode().len() as u64 -// ); -// -// // when we have more than `MaxUnrewardedRelayerEntriesAtInboundLane` unrewarded relayers -// // (shall not happen in practice) -// assert_eq!(storage(max_entries + 1).extra_proof_size_bytes(), 0); -// } -// -// #[test] -// fn maybe_outbound_lanes_count_returns_correct_value() { -// assert_eq!( -// MaybeOutboundLanesCount::::get(), -// Some(mock::ActiveOutboundLanes::get().len() as u32) -// ); -// } -// } diff --git a/bridges/modules/xcm-bridge-hub/src/mock.rs b/bridges/modules/xcm-bridge-hub/src/mock.rs index 43a5536ecfed6..df72e7a3c4fcc 100644 --- a/bridges/modules/xcm-bridge-hub/src/mock.rs +++ b/bridges/modules/xcm-bridge-hub/src/mock.rs @@ -23,13 +23,7 @@ use bp_messages::{ ChainWithMessages, LaneId, MessageNonce, }; use bp_runtime::{messages::MessageDispatchResult, Chain, ChainId, HashOf}; -use bridge_runtime_common::{ - // messages::{ - // source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, - // BridgedChainWithMessages, HashOf, MessageBridge, ThisChainWithMessages, - // }, - messages_xcm_extension::{SenderAndLane, XcmBlobHauler}, -}; +use bridge_runtime_common::messages_xcm_extension::{SenderAndLane, XcmBlobHauler}; use codec::Encode; use frame_support::{derive_impl, parameter_types, weights::RuntimeDbWeight}; use sp_core::H256; diff --git a/bridges/primitives/runtime/src/storage_proof.rs b/bridges/primitives/runtime/src/storage_proof.rs index ae222d0ae5825..48b766fda1df4 100644 --- a/bridges/primitives/runtime/src/storage_proof.rs +++ b/bridges/primitives/runtime/src/storage_proof.rs @@ -21,8 +21,8 @@ use sp_core::{storage::TrackedStorageKey, RuntimeDebug}; use sp_runtime::{SaturatedConversion, StateVersion}; use sp_std::{default::Default, vec, vec::Vec}; use sp_trie::{ - generate_trie_proof, verify_trie_proof, LayoutV0, LayoutV1, PrefixedMemoryDB, StorageProof, - TrieDBBuilder, TrieHash, + generate_trie_proof, verify_trie_proof, LayoutV0, LayoutV1, StorageProof, TrieDBBuilder, + TrieHash, }; use codec::{Decode, Encode}; @@ -108,8 +108,10 @@ impl UnverifiedStorageProof { let keys: Vec<_> = entries.iter().map(|(key, _)| key.clone()).collect(); let entries: Vec<_> = entries.iter().cloned().map(|(key, val)| (None, vec![(key, val)])).collect(); - let backend = - sp_state_machine::TrieBackend::, H>::from((entries, state_version)); + let backend = sp_state_machine::TrieBackend::, H>::from(( + entries, + state_version, + )); let root = *backend.root(); Ok((root, UnverifiedStorageProof::try_from_db(backend.backend_storage(), root, keys)?)) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 5e8639eed36b9..d2822088fdba6 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -96,7 +96,7 @@ bp-parachains = { path = "../../../../../bridges/primitives/parachains", default bp-polkadot-bulletin = { path = "../../../../../bridges/chains/chain-polkadot-bulletin", default-features = false } bp-polkadot-core = { path = "../../../../../bridges/primitives/polkadot-core", default-features = false } bp-relayers = { path = "../../../../../bridges/primitives/relayers", default-features = false } -bp-runtime = { path = "../../../../../bridges/primitives/runtime", default-features = false } +bp-runtime = { path = "../../../../../bridges/primitives/runtime", default-features = false, features = ["test-helpers"] } bp-rococo = { path = "../../../../../bridges/chains/chain-rococo", default-features = false } bp-westend = { path = "../../../../../bridges/chains/chain-westend", default-features = false } pallet-bridge-grandpa = { path = "../../../../../bridges/modules/grandpa", default-features = false } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml index ba8e4cdc8147c..4b1799b576c18 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml @@ -89,7 +89,7 @@ bp-messages = { path = "../../../../../bridges/primitives/messages", default-fea bp-parachains = { path = "../../../../../bridges/primitives/parachains", default-features = false } bp-polkadot-core = { path = "../../../../../bridges/primitives/polkadot-core", default-features = false } bp-relayers = { path = "../../../../../bridges/primitives/relayers", default-features = false } -bp-runtime = { path = "../../../../../bridges/primitives/runtime", default-features = false } +bp-runtime = { path = "../../../../../bridges/primitives/runtime", default-features = false, features = ["test-helpers"] } bp-rococo = { path = "../../../../../bridges/chains/chain-rococo", default-features = false } bp-westend = { path = "../../../../../bridges/chains/chain-westend", default-features = false } pallet-bridge-grandpa = { path = "../../../../../bridges/modules/grandpa", default-features = false }