diff --git a/pallets/liquidity-pools-gateway/src/lib.rs b/pallets/liquidity-pools-gateway/src/lib.rs index f04b7c4543..f2a7925f46 100644 --- a/pallets/liquidity-pools-gateway/src/lib.rs +++ b/pallets/liquidity-pools-gateway/src/lib.rs @@ -40,7 +40,7 @@ use message::GatewayMessage; use orml_traits::GetByKey; pub use pallet::*; use parity_scale_codec::FullCodec; -use sp_arithmetic::traits::{BaseArithmetic, EnsureAddAssign, One}; +use sp_arithmetic::traits::{BaseArithmetic, EnsureAdd, EnsureAddAssign, One}; use sp_std::convert::TryInto; use crate::{message_processing::InboundEntry, weights::WeightInfo}; @@ -102,7 +102,7 @@ pub mod pallet { /// The Liquidity Pools message type. type Message: LPEncoding + Clone + Debug + PartialEq + MaxEncodedLen + TypeInfo + FullCodec; - /// The target of of the messages comming from this chain + /// The target of the messages coming from this chain type MessageSender: MessageSender; /// An identification of a router @@ -148,7 +148,6 @@ pub mod pallet { pub enum Event { /// The routers for a given domain were set. RoutersSet { - domain: Domain, router_ids: BoundedVec, session_id: T::SessionId, }, @@ -167,7 +166,6 @@ pub mod pallet { /// Message recovery was executed. MessageRecoveryExecuted { - domain: Domain, proof: Proof, router_id: T::RouterId, }, @@ -182,13 +180,13 @@ pub mod pallet { // pub type DomainRouters = StorageMap<_, Blake2_128Concat, Domain, // T::Router>; - /// Storage for routers specific for a domain. + /// Storage for routers. /// /// This can only be set by an admin. #[pallet::storage] #[pallet::getter(fn routers)] pub type Routers = - StorageMap<_, Blake2_128Concat, Domain, BoundedVec>; + StorageValue<_, BoundedVec, ValueQuery>; /// Storage that contains a limited number of whitelisted instances of /// deployed liquidity pools for a particular domain. @@ -227,11 +225,11 @@ pub mod pallet { InboundEntry, >; - /// Storage for the inbound message session IDs. - #[pallet::storage] - #[pallet::getter(fn inbound_message_sessions)] - pub type InboundMessageSessions = - StorageMap<_, Blake2_128Concat, Domain, T::SessionId>; + // /// Storage for the inbound message session IDs. + // #[pallet::storage] + // #[pallet::getter(fn inbound_message_sessions)] + // pub type InboundMessageSessions = + // StorageMap<_, Blake2_128Concat, Domain, T::SessionId>; /// Storage for inbound message session IDs. #[pallet::storage] @@ -279,8 +277,8 @@ pub mod pallet { /// Inbound domain session not found. InboundDomainSessionNotFound, - /// The router that sent the inbound message is unknown. - UnknownInboundMessageRouter, + /// Unknown router. + UnknownRouter, /// The router that sent the message is not the first one. MessageExpectedFromFirstRouter, @@ -309,35 +307,28 @@ pub mod pallet { /// Sets the router IDs used for a specific domain, #[pallet::weight(T::WeightInfo::set_domain_routers())] #[pallet::call_index(0)] - pub fn set_domain_routers( + pub fn set_routers( origin: OriginFor, - domain: Domain, router_ids: BoundedVec, ) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; - ensure!(domain != Domain::Centrifuge, Error::::DomainNotSupported); - - //TODO(cdamian): Outbound - Call router.init() for each router? + >::set(router_ids.clone()); - >::insert(domain.clone(), router_ids.clone()); + let (old_session_id, new_session_id) = SessionIdStore::::try_mutate(|n| { + let old_session_id = *n; + let new_session_id = n.ensure_add(One::one())?; - if let Some(old_session_id) = InboundMessageSessions::::get(domain.clone()) { - InvalidMessageSessions::::insert(old_session_id, ()); - } + *n = new_session_id; - let session_id = SessionIdStore::::try_mutate(|n| { - n.ensure_add_assign(One::one())?; - - Ok::(*n) + Ok::<(T::SessionId, T::SessionId), DispatchError>((old_session_id, new_session_id)) })?; - InboundMessageSessions::::insert(domain.clone(), session_id); + InvalidMessageSessions::::insert(old_session_id, ()); Self::deposit_event(Event::RoutersSet { - domain, router_ids, - session_id, + session_id: new_session_id, }); Ok(()) @@ -452,7 +443,7 @@ pub mod pallet { match PackedMessage::::take((&sender, &destination)) { Some(msg) if msg.submessages().is_empty() => Ok(()), //No-op - Some(message) => Self::queue_message(destination, message), + Some(message) => Self::queue_outbound_message(destination, message), None => Err(Error::::MessagePackingNotStarted.into()), } } @@ -465,20 +456,18 @@ pub mod pallet { #[pallet::call_index(11)] pub fn execute_message_recovery( origin: OriginFor, - domain: Domain, proof: Proof, router_id: T::RouterId, ) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; - let session_id = InboundMessageSessions::::get(&domain) - .ok_or(Error::::InboundDomainSessionNotFound)?; + let session_id = SessionIdStore::::get(); - let routers = Routers::::get(&domain).ok_or(Error::::RoutersNotFound)?; + let routers = Routers::::get(); ensure!( routers.iter().any(|x| x == &router_id), - Error::::UnknownInboundMessageRouter + Error::::UnknownRouter ); PendingInboundEntries::::try_mutate( @@ -501,11 +490,7 @@ pub mod pallet { }, )?; - Self::deposit_event(Event::::MessageRecoveryExecuted { - domain, - proof, - router_id, - }); + Self::deposit_event(Event::::MessageRecoveryExecuted { proof, router_id }); Ok(()) } @@ -528,7 +513,7 @@ pub mod pallet { PackedMessage::::mutate((&from, destination.clone()), |batch| match batch { Some(batch) => batch.pack_with(message), - None => Self::queue_message(destination, message), + None => Self::queue_outbound_message(destination, message), }) } } diff --git a/pallets/liquidity-pools-gateway/src/message_processing.rs b/pallets/liquidity-pools-gateway/src/message_processing.rs index ef46531522..acf99a5572 100644 --- a/pallets/liquidity-pools-gateway/src/message_processing.rs +++ b/pallets/liquidity-pools-gateway/src/message_processing.rs @@ -1,5 +1,7 @@ use cfg_primitives::LP_DEFENSIVE_WEIGHT; -use cfg_traits::liquidity_pools::{InboundMessageHandler, LPEncoding, MessageQueue, Proof}; +use cfg_traits::liquidity_pools::{ + InboundMessageHandler, LPEncoding, MessageQueue, MessageSender, Proof, RouterSupport, +}; use cfg_types::domain_address::{Domain, DomainAddress}; use frame_support::{ dispatch::DispatchResult, @@ -13,8 +15,8 @@ use sp_arithmetic::traits::{EnsureAddAssign, EnsureSub}; use sp_runtime::DispatchError; use crate::{ - message::GatewayMessage, Config, Error, InboundMessageSessions, InvalidMessageSessions, Pallet, - PendingInboundEntries, Routers, + message::GatewayMessage, Config, Error, InvalidMessageSessions, Pallet, PendingInboundEntries, + Routers, SessionIdStore, }; /// The limit used when clearing the `PendingInboundEntries` for invalid @@ -39,7 +41,7 @@ pub enum InboundEntry { #[derive(Clone)] pub struct InboundProcessingInfo { domain_address: DomainAddress, - routers: BoundedVec, + router_ids: Vec, current_session_id: T::SessionId, expected_proof_count_per_message: u32, } @@ -47,10 +49,10 @@ pub struct InboundProcessingInfo { impl Pallet { /// Calculates and returns the proof count required for processing one /// inbound message. - fn get_expected_proof_count(domain: &Domain) -> Result { - let routers = Routers::::get(domain).ok_or(Error::::RoutersNotFound)?; + fn get_expected_proof_count(domain: Domain) -> Result { + let routers_count = T::RouterId::for_domain(domain).len(); - let expected_proof_count = routers.len().ensure_sub(1)?; + let expected_proof_count = routers_count.ensure_sub(1)?; Ok(expected_proof_count as u32) } @@ -94,17 +96,17 @@ impl Pallet { router_id: &T::RouterId, inbound_entry: &InboundEntry, ) -> DispatchResult { - let routers = inbound_processing_info.routers.clone(); + let router_ids = inbound_processing_info.router_ids.clone(); ensure!( - routers.iter().any(|x| x == router_id), - Error::::UnknownInboundMessageRouter + router_ids.iter().any(|x| x == router_id), + Error::::UnknownRouter ); match inbound_entry { InboundEntry::Message { .. } => { ensure!( - routers.get(0) == Some(&router_id), + router_ids.get(0) == Some(&router_id), Error::::MessageExpectedFromFirstRouter ); @@ -112,7 +114,7 @@ impl Pallet { } InboundEntry::Proof { .. } => { ensure!( - routers.get(0) != Some(&router_id), + router_ids.get(0) != Some(&router_id), Error::::ProofNotExpectedFromFirstRouter ); @@ -202,12 +204,12 @@ impl Pallet { let mut message = None; let mut votes = 0; - for router in &inbound_processing_info.routers { + for router_id in &inbound_processing_info.router_ids { weight.saturating_accrue(T::DbWeight::get().reads(1)); match PendingInboundEntries::::get( inbound_processing_info.current_session_id, - (message_proof, router), + (message_proof, router_id), ) { // We expected one InboundEntry for each router, if that's not the case, // we can return. @@ -240,12 +242,12 @@ impl Pallet { message_proof: Proof, weight: &mut Weight, ) -> DispatchResult { - for router in &inbound_processing_info.routers { + for router_id in &inbound_processing_info.router_ids { weight.saturating_accrue(T::DbWeight::get().writes(1)); match PendingInboundEntries::::try_mutate( inbound_processing_info.current_session_id, - (message_proof, router), + (message_proof, router_id), |storage_entry| match storage_entry { None => Err(Error::::PendingInboundEntryNotFound.into()), Some(stored_inbound_entry) => match stored_inbound_entry { @@ -290,26 +292,24 @@ impl Pallet { /// Retrieves the information required for processing an inbound /// message. fn get_inbound_processing_info( - domain_address: DomainAddress, + domain: Domain, weight: &mut Weight, ) -> Result, DispatchError> { - let routers = - Routers::::get(domain_address.domain()).ok_or(Error::::RoutersNotFound)?; + let router_ids = T::RouterId::for_domain(domain.clone()); weight.saturating_accrue(T::DbWeight::get().reads(1)); - let current_session_id = InboundMessageSessions::::get(domain_address.domain()) - .ok_or(Error::::InboundDomainSessionNotFound)?; + let current_session_id = SessionIdStore::::get(); weight.saturating_accrue(T::DbWeight::get().reads(1)); - let expected_proof_count = Self::get_expected_proof_count(&domain_address.domain())?; + let expected_proof_count = Self::get_expected_proof_count(domain)?; weight.saturating_accrue(T::DbWeight::get().reads(1)); Ok(InboundProcessingInfo { domain_address, - routers, + router_ids, current_session_id, expected_proof_count_per_message: expected_proof_count, }) @@ -325,7 +325,7 @@ impl Pallet { let mut weight = Default::default(); let inbound_processing_info = - match Self::get_inbound_processing_info(domain_address.clone(), &mut weight) { + match Self::get_inbound_processing_info(domain_address.domain(), &mut weight) { Ok(i) => i, Err(e) => return (Err(e), weight), }; @@ -382,29 +382,21 @@ impl Pallet { message: T::Message, router_id: T::RouterId, ) -> (DispatchResult, Weight) { - let read_weight = T::DbWeight::get().reads(1); - - // TODO(cdamian): Update when the router refactor is done. - - // let Some(router) = Routers::::get(router_id) else { - // return (Err(Error::::RouterNotFound.into()), read_weight); - // }; - // - // let (result, router_weight) = match router.send(sender, message.serialize()) - // { Ok(dispatch_info) => (Ok(()), dispatch_info.actual_weight), - // Err(e) => (Err(e.error), e.post_info.actual_weight), - // }; - // - // (result, router_weight.unwrap_or(read_weight)) - - (Ok(()), read_weight) + let weight = LP_DEFENSIVE_WEIGHT; + + match T::MessageSender::send(router_id, sender, message.serialize()) { + Ok(_) => (Ok(()), weight), + Err(e) => (Err(e), weight), + } } /// Retrieves the IDs of the routers set for a domain and queues the /// message and proofs accordingly. - pub(crate) fn queue_message(destination: Domain, message: T::Message) -> DispatchResult { - let router_ids = - Routers::::get(destination.clone()).ok_or(Error::::RoutersNotFound)?; + pub(crate) fn queue_outbound_message( + destination: Domain, + message: T::Message, + ) -> DispatchResult { + let router_ids = T::RouterId::for_domain(destination); let message_proof = message.to_message_proof(); let mut message_opt = Some(message); diff --git a/pallets/liquidity-pools-gateway/src/mock.rs b/pallets/liquidity-pools-gateway/src/mock.rs index 157e06c3ed..ed9bd50f45 100644 --- a/pallets/liquidity-pools-gateway/src/mock.rs +++ b/pallets/liquidity-pools-gateway/src/mock.rs @@ -102,8 +102,8 @@ impl LPEncoding for Message { } } -#[derive(Default, Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] -pub struct RouterId(u32); +#[derive(Default, Debug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen, Hash)] +pub struct RouterId(pub u32); impl RouterSupport for RouterId { fn for_domain(_domain: Domain) -> Vec { diff --git a/pallets/liquidity-pools-gateway/src/tests.rs b/pallets/liquidity-pools-gateway/src/tests.rs index 7e01d1c45b..1fcbb1a7fd 100644 --- a/pallets/liquidity-pools-gateway/src/tests.rs +++ b/pallets/liquidity-pools-gateway/src/tests.rs @@ -11,7 +11,7 @@ use itertools::Itertools; use lazy_static::lazy_static; use parity_scale_codec::MaxEncodedLen; use sp_arithmetic::ArithmeticError::Overflow; -use sp_core::{bounded::BoundedVec, crypto::AccountId32, ByteArray, H160, H256}; +use sp_core::{bounded::BoundedVec, crypto::AccountId32, ByteArray, H160}; use sp_runtime::{ DispatchError, DispatchError::{Arithmetic, BadOrigin}, @@ -30,11 +30,9 @@ use crate::{message_processing::InboundEntry, GatewayMessage}; pub const TEST_DOMAIN_ADDRESS: DomainAddress = DomainAddress::EVM(0, [1; 20]); -lazy_static! { - static ref ROUTER_HASH_1: H256 = H256::from_low_u64_be(1); - static ref ROUTER_HASH_2: H256 = H256::from_low_u64_be(2); - static ref ROUTER_HASH_3: H256 = H256::from_low_u64_be(3); -} +pub const ROUTER_ID_1: RouterId = RouterId(1); +pub const ROUTER_ID_2: RouterId = RouterId(2); +pub const ROUTER_ID_3: RouterId = RouterId(3); mod utils { use super::*; @@ -67,12 +65,8 @@ mod set_domain_routers { let mut session_id = 1; - let router_id_1 = H256::from_low_u64_be(1); - let router_id_2 = H256::from_low_u64_be(2); - let router_id_3 = H256::from_low_u64_be(3); - let mut router_ids = - BoundedVec::try_from(vec![router_id_1, router_id_2, router_id_3]).unwrap(); + BoundedVec::try_from(vec![ROUTER_ID_1, ROUTER_ID_2, ROUTER_ID_3]).unwrap(); assert_ok!(LiquidityPoolsGateway::set_domain_routers( RuntimeOrigin::root(), @@ -93,7 +87,7 @@ mod set_domain_routers { session_id, }); - router_ids = BoundedVec::try_from(vec![router_id_3, router_id_2, router_id_1]).unwrap(); + router_ids = BoundedVec::try_from(vec![ROUTER_ID_3, ROUTER_ID_2, ROUTER_ID_1]).unwrap(); session_id += 1; @@ -340,7 +334,7 @@ mod receive_message_domain { let domain_address = DomainAddress::EVM(0, address.into()); let message = Message::Simple; - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; assert_ok!(LiquidityPoolsGateway::add_instance( RuntimeOrigin::root(), @@ -352,7 +346,7 @@ mod receive_message_domain { let gateway_message = GatewayMessage::Inbound { domain_address: domain_address.clone(), message: message.clone(), - router_id, + router_id: router_id.clone(), }; MockLiquidityPoolsGatewayQueue::mock_submit(move |mock_message| { @@ -373,7 +367,7 @@ mod receive_message_domain { new_test_ext().execute_with(|| { let encoded_msg = Message::Simple.serialize(); - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; assert_noop!( LiquidityPoolsGateway::receive_message( @@ -391,7 +385,7 @@ mod receive_message_domain { new_test_ext().execute_with(|| { let domain_address = DomainAddress::Centrifuge(get_test_account_id().into()); let encoded_msg = Message::Simple.serialize(); - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; assert_noop!( LiquidityPoolsGateway::receive_message( @@ -410,7 +404,7 @@ mod receive_message_domain { let address = H160::from_slice(&get_test_account_id().as_slice()[..20]); let domain_address = DomainAddress::EVM(0, address.into()); let encoded_msg = Message::Simple.serialize(); - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; assert_noop!( LiquidityPoolsGateway::receive_message( @@ -430,7 +424,7 @@ mod receive_message_domain { let domain_address = DomainAddress::EVM(0, address.into()); let message = Message::Simple; - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; assert_ok!(LiquidityPoolsGateway::add_instance( RuntimeOrigin::root(), @@ -444,7 +438,7 @@ mod receive_message_domain { let gateway_message = GatewayMessage::Inbound { domain_address: domain_address.clone(), message: message.clone(), - router_id, + router_id: router_id.clone(), }; MockLiquidityPoolsGatewayQueue::mock_submit(move |mock_message| { @@ -475,14 +469,14 @@ mod outbound_message_handler_impl { let msg = Message::Simple; let message_proof = msg.to_message_proof().get_message_proof().unwrap(); - let router_id_1 = H256::from_low_u64_be(1); - let router_id_2 = H256::from_low_u64_be(2); - let router_id_3 = H256::from_low_u64_be(3); + let router_id_1 = ROUTER_ID_1; + let router_id_2 = ROUTER_ID_2; + let router_id_3 = ROUTER_ID_3; //TODO(cdamian): Router init - // let router_hash_1 = H256::from_low_u64_be(1); - // let router_hash_2 = H256::from_low_u64_be(2); - // let router_hash_3 = H256::from_low_u64_be(3); + // let router_hash_1 = ROUTER_ID_1; + // let router_hash_2 = ROUTER_ID_2; + // let router_hash_3 = ROUTER_ID_3; // // let router_mock_1 = RouterMock::::default(); // let router_mock_2 = RouterMock::::default(); @@ -548,30 +542,14 @@ mod outbound_message_handler_impl { let sender = get_test_account_id(); let msg = Message::Simple; - let router_id_1 = H256::from_low_u64_be(1); - let router_id_2 = H256::from_low_u64_be(2); - let router_id_3 = H256::from_low_u64_be(3); - - //TODO(cdamian): Router init? - // let router_hash_1 = H256::from_low_u64_be(1); - // let router_hash_2 = H256::from_low_u64_be(2); - // let router_hash_3 = H256::from_low_u64_be(3); - // - // let router_mock_1 = RouterMock::::default(); - // let router_mock_2 = RouterMock::::default(); - // let router_mock_3 = RouterMock::::default(); - // - // router_mock_1.mock_init(move || Ok(())); - // router_mock_1.mock_hash(move || router_hash_1); - // router_mock_2.mock_init(move || Ok(())); - // router_mock_2.mock_hash(move || router_hash_2); - // router_mock_3.mock_init(move || Ok(())); - // router_mock_3.mock_hash(move || router_hash_3); + let router_id_1 = ROUTER_ID_1; + let router_id_2 = ROUTER_ID_2; + let router_id_3 = ROUTER_ID_3; assert_ok!(LiquidityPoolsGateway::set_domain_routers( RuntimeOrigin::root(), domain.clone(), - BoundedVec::try_from(vec![router_id_1, router_id_2, router_id_3]).unwrap(), + BoundedVec::try_from(vec![router_id_1.clone(), router_id_2, router_id_3]).unwrap(), )); let gateway_message = GatewayMessage::Outbound { @@ -713,20 +691,20 @@ mod message_processor_impl { /// Used for generating all `RouterMessage` combinations like: /// /// vec![ - /// (*ROUTER_HASH_1, Message::Simple), - /// (*ROUTER_HASH_1, Message::Simple), + /// (ROUTER_ID_1, Message::Simple), + /// (ROUTER_ID_1, Message::Simple), /// ] /// vec![ - /// (*ROUTER_HASH_1, Message::Simple), - /// (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + /// (ROUTER_ID_1, Message::Simple), + /// (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), /// ] /// vec![ - /// (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - /// (*ROUTER_HASH_1, Message::Simple), + /// (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + /// (ROUTER_ID_1, Message::Simple), /// ] /// vec![ - /// (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - /// (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + /// (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + /// (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), /// ] pub fn generate_test_combinations( t: T, @@ -744,11 +722,11 @@ mod message_processor_impl { } /// Type used for mapping a message to a router hash. - pub type RouterMessage = (H256, Message); + pub type RouterMessage = (RouterId, Message); /// Type used for aggregating tests for inbound messages. pub struct InboundMessageTestSuite { - pub routers: Vec, + pub routers: Vec, pub tests: Vec, } @@ -764,14 +742,14 @@ mod message_processor_impl { #[derive(Clone, Debug)] pub struct ExpectedTestResult { pub message_submitted_times: u32, - pub expected_storage_entries: Vec<(H256, Option>)>, + pub expected_storage_entries: Vec<(RouterId, Option>)>, } /// Generates the combinations of `RouterMessage` used when testing, /// maps the `ExpectedTestResult` for each and creates the /// `InboundMessageTestSuite`. pub fn generate_test_suite( - routers: Vec, + routers: Vec, test_data: Vec, expected_results: HashMap, ExpectedTestResult>, message_count: usize, @@ -811,16 +789,16 @@ mod message_processor_impl { let message_proof = message.to_message_proof().get_message_proof().unwrap(); let session_id = 1; let domain_address = DomainAddress::EVM(1, [1; 20]); - let router_hash = *ROUTER_HASH_1; + let router_id = ROUTER_ID_1; let gateway_message = GatewayMessage::Inbound { domain_address: domain_address.clone(), message: message.clone(), - router_id: router_hash, + router_id: router_id.clone(), }; Routers::::insert( domain_address.domain(), - BoundedVec::<_, _>::try_from(vec![router_hash]).unwrap(), + BoundedVec::<_, _>::try_from(vec![router_id.clone()]).unwrap(), ); InboundMessageSessions::::insert(domain_address.domain(), session_id); @@ -839,7 +817,7 @@ mod message_processor_impl { assert!(PendingInboundEntries::::get( session_id, - (message_proof, router_hash) + (message_proof, router_id) ) .is_none()); }); @@ -850,7 +828,7 @@ mod message_processor_impl { new_test_ext().execute_with(|| { let message = Message::Simple; let domain_address = DomainAddress::EVM(1, [1; 20]); - let router_hash = *ROUTER_HASH_1; + let router_hash = ROUTER_ID_1; let gateway_message = GatewayMessage::Inbound { domain_address: domain_address.clone(), message: message.clone(), @@ -867,16 +845,16 @@ mod message_processor_impl { new_test_ext().execute_with(|| { let message = Message::Simple; let domain_address = DomainAddress::EVM(1, [1; 20]); - let router_hash = *ROUTER_HASH_1; + let router_id = ROUTER_ID_1; let gateway_message = GatewayMessage::Inbound { domain_address: domain_address.clone(), message: message.clone(), - router_id: router_hash, + router_id: router_id.clone(), }; Routers::::insert( domain_address.domain(), - BoundedVec::<_, _>::try_from(vec![router_hash]).unwrap(), + BoundedVec::<_, _>::try_from(vec![router_id]).unwrap(), ); let (res, _) = LiquidityPoolsGateway::process(gateway_message); @@ -890,13 +868,13 @@ mod message_processor_impl { let message = Message::Simple; let session_id = 1; let domain_address = DomainAddress::EVM(1, [1; 20]); - let router_hash = *ROUTER_HASH_1; + let router_hash = ROUTER_ID_1; let gateway_message = GatewayMessage::Inbound { domain_address: domain_address.clone(), message: message.clone(), // The router stored has a different hash, this should trigger the expected // error. - router_id: *ROUTER_HASH_2, + router_id: ROUTER_ID_2, }; Routers::::insert( @@ -906,7 +884,7 @@ mod message_processor_impl { InboundMessageSessions::::insert(domain_address.domain(), session_id); let (res, _) = LiquidityPoolsGateway::process(gateway_message); - assert_noop!(res, Error::::UnknownInboundMessageRouter); + assert_noop!(res, Error::::UnknownRouter); }); } @@ -917,21 +895,21 @@ mod message_processor_impl { let message_proof = message.to_message_proof().get_message_proof().unwrap(); let session_id = 1; let domain_address = DomainAddress::EVM(1, [1; 20]); - let router_hash = *ROUTER_HASH_1; + let router_id = ROUTER_ID_1; let gateway_message = GatewayMessage::Inbound { domain_address: domain_address.clone(), message: message.clone(), - router_id: router_hash, + router_id: router_id.clone(), }; Routers::::insert( domain_address.domain(), - BoundedVec::<_, _>::try_from(vec![router_hash]).unwrap(), + BoundedVec::<_, _>::try_from(vec![router_id.clone()]).unwrap(), ); InboundMessageSessions::::insert(domain_address.domain(), session_id); PendingInboundEntries::::insert( session_id, - (message_proof, router_hash), + (message_proof, router_id), InboundEntry::::Proof { current_count: 0 }, ); @@ -949,8 +927,8 @@ mod message_processor_impl { lazy_static! { static ref TEST_DATA: Vec = vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ]; } @@ -965,35 +943,35 @@ mod message_processor_impl { HashMap::from([ ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), @@ -1003,34 +981,34 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ], }, ), ]); let suite = generate_test_suite( - vec![*ROUTER_HASH_1, *ROUTER_HASH_2], + vec![ROUTER_ID_1, ROUTER_ID_2], TEST_DATA.clone(), expected_results, MESSAGE_COUNT, @@ -1051,37 +1029,37 @@ mod message_processor_impl { HashMap::from([ ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 3, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 3, }), @@ -1091,58 +1069,58 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 1, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 1, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), @@ -1152,37 +1130,37 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 1, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), @@ -1192,16 +1170,16 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), @@ -1212,7 +1190,7 @@ mod message_processor_impl { ]); let suite = generate_test_suite( - vec![*ROUTER_HASH_1, *ROUTER_HASH_2], + vec![ROUTER_ID_1, ROUTER_ID_2], TEST_DATA.clone(), expected_results, MESSAGE_COUNT, @@ -1233,39 +1211,39 @@ mod message_processor_impl { HashMap::from([ ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 4, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 4, }), @@ -1275,195 +1253,195 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 2, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 2, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 2, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 2, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 2, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 2, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), @@ -1473,17 +1451,17 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), @@ -1493,17 +1471,17 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), @@ -1513,17 +1491,17 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), @@ -1534,7 +1512,7 @@ mod message_processor_impl { ]); let suite = generate_test_suite( - vec![*ROUTER_HASH_1, *ROUTER_HASH_2], + vec![ROUTER_ID_1, ROUTER_ID_2], TEST_DATA.clone(), expected_results, MESSAGE_COUNT, @@ -1555,8 +1533,7 @@ mod message_processor_impl { Routers::::insert( TEST_DOMAIN_ADDRESS.domain(), - BoundedVec::<_, _>::try_from(vec![*ROUTER_HASH_1, *ROUTER_HASH_2]) - .unwrap(), + BoundedVec::<_, _>::try_from(vec![ROUTER_ID_1, ROUTER_ID_2]).unwrap(), ); InboundMessageSessions::::insert( TEST_DOMAIN_ADDRESS.domain(), @@ -1566,7 +1543,7 @@ mod message_processor_impl { let gateway_message = GatewayMessage::Inbound { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, - router_id: *ROUTER_HASH_2, + router_id: ROUTER_ID_2, }; let (res, _) = LiquidityPoolsGateway::process(gateway_message); @@ -1581,8 +1558,7 @@ mod message_processor_impl { Routers::::insert( TEST_DOMAIN_ADDRESS.domain(), - BoundedVec::<_, _>::try_from(vec![*ROUTER_HASH_1, *ROUTER_HASH_2]) - .unwrap(), + BoundedVec::<_, _>::try_from(vec![ROUTER_ID_1, ROUTER_ID_2]).unwrap(), ); InboundMessageSessions::::insert( TEST_DOMAIN_ADDRESS.domain(), @@ -1592,7 +1568,7 @@ mod message_processor_impl { let gateway_message = GatewayMessage::Inbound { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Proof(MESSAGE_PROOF), - router_id: *ROUTER_HASH_1, + router_id: ROUTER_ID_1, }; let (res, _) = LiquidityPoolsGateway::process(gateway_message); @@ -1607,9 +1583,9 @@ mod message_processor_impl { lazy_static! { static ref TEST_DATA: Vec = vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ]; } @@ -1624,56 +1600,56 @@ mod message_processor_impl { HashMap::from([ ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 4, }), ), - (*ROUTER_HASH_2, None), - (*ROUTER_HASH_3, None), + (ROUTER_ID_2, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 2, }), @@ -1683,21 +1659,21 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -1707,21 +1683,21 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -1731,14 +1707,14 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, @@ -1746,34 +1722,34 @@ mod message_processor_impl { }), ), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -1783,23 +1759,23 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -1809,14 +1785,14 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, @@ -1824,34 +1800,34 @@ mod message_processor_impl { }), ), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -1862,7 +1838,7 @@ mod message_processor_impl { ]); let suite = generate_test_suite( - vec![*ROUTER_HASH_1, *ROUTER_HASH_2, *ROUTER_HASH_3], + vec![ROUTER_ID_1, ROUTER_ID_2, ROUTER_ID_3], TEST_DATA.clone(), expected_results, MESSAGE_COUNT, @@ -1883,59 +1859,59 @@ mod message_processor_impl { HashMap::from([ ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 6, }), ), - (*ROUTER_HASH_2, None), - (*ROUTER_HASH_3, None), + (ROUTER_ID_2, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 3, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 3, }), @@ -1945,15 +1921,15 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, @@ -1961,26 +1937,26 @@ mod message_processor_impl { }), ), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, @@ -1988,26 +1964,26 @@ mod message_processor_impl { }), ), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, @@ -2015,35 +1991,35 @@ mod message_processor_impl { }), ), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 2, }), @@ -2053,24 +2029,24 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 2, }), @@ -2080,24 +2056,24 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 2, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 2, }), @@ -2107,15 +2083,15 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, @@ -2123,26 +2099,26 @@ mod message_processor_impl { }), ), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, @@ -2150,35 +2126,35 @@ mod message_processor_impl { }), ), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 4, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -2188,15 +2164,15 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, @@ -2204,35 +2180,35 @@ mod message_processor_impl { }), ), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), - (*ROUTER_HASH_3, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 4, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -2242,24 +2218,24 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ ( - *ROUTER_HASH_1, + ROUTER_ID_1, Some(InboundEntry::::Message { domain_address: TEST_DOMAIN_ADDRESS, message: Message::Simple, expected_proof_count: 4, }), ), - (*ROUTER_HASH_2, None), + (ROUTER_ID_2, None), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -2269,112 +2245,112 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), - (*ROUTER_HASH_3, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), - (*ROUTER_HASH_3, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), - (*ROUTER_HASH_3, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), - (*ROUTER_HASH_3, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), - (*ROUTER_HASH_3, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_1, Message::Simple), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_1, Message::Simple), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 1, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), - (*ROUTER_HASH_2, None), - (*ROUTER_HASH_3, None), + (ROUTER_ID_1, None), + (ROUTER_ID_2, None), + (ROUTER_ID_3, None), ], }, ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), ), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -2384,22 +2360,22 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), ), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -2409,22 +2385,22 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 2, }), @@ -2434,22 +2410,22 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 2, }), @@ -2459,22 +2435,22 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 2, }), ), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 1, }), @@ -2484,22 +2460,22 @@ mod message_processor_impl { ), ( vec![ - (*ROUTER_HASH_2, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), - (*ROUTER_HASH_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_2, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), + (ROUTER_ID_3, Message::Proof(MESSAGE_PROOF)), ], ExpectedTestResult { message_submitted_times: 0, expected_storage_entries: vec![ - (*ROUTER_HASH_1, None), + (ROUTER_ID_1, None), ( - *ROUTER_HASH_2, + ROUTER_ID_2, Some(InboundEntry::::Proof { current_count: 1, }), ), ( - *ROUTER_HASH_3, + ROUTER_ID_3, Some(InboundEntry::::Proof { current_count: 2, }), @@ -2510,7 +2486,7 @@ mod message_processor_impl { ]); let suite = generate_test_suite( - vec![*ROUTER_HASH_1, *ROUTER_HASH_2, *ROUTER_HASH_3], + vec![ROUTER_ID_1, ROUTER_ID_2, ROUTER_ID_3], TEST_DATA.clone(), expected_results, MESSAGE_COUNT, @@ -2526,11 +2502,11 @@ mod message_processor_impl { new_test_ext().execute_with(|| { let domain_address = DomainAddress::EVM(1, [1; 20]); - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; Routers::::insert( domain_address.domain(), - BoundedVec::try_from(vec![router_id]).unwrap(), + BoundedVec::try_from(vec![router_id.clone()]).unwrap(), ); InboundMessageSessions::::insert(domain_address.domain(), 1); @@ -2562,33 +2538,15 @@ mod message_processor_impl { #[test] fn success() { new_test_ext().execute_with(|| { - let sender = get_test_account_id(); - let domain = Domain::EVM(1); + let sender = TEST_DOMAIN_ADDRESS; let message = Message::Simple; - let expected_sender = sender.clone(); - let expected_message = message.clone(); - let router_post_info = PostDispatchInfo { actual_weight: Some(Weight::from_parts(1, 1)), pays_fee: Pays::Yes, }; - let router_id = H256::from_low_u64_be(1); - - //TODO(cdamian): Drop mock? - // let router_hash = H256::from_low_u64_be(1); - // - // let router_mock = RouterMock::::default(); - // router_mock.mock_send(move |mock_sender, mock_message| { - // assert_eq!(mock_sender, expected_sender); - // assert_eq!(mock_message, expected_message.serialize()); - // - // Ok(router_post_info) - // }); - // router_mock.mock_hash(move || router_hash); - // - // DomainRouters::::insert(domain.clone(), router_mock); + let router_id = ROUTER_ID_1; let min_expected_weight = ::DbWeight::get() .reads(1) + router_post_info.actual_weight.unwrap() @@ -2619,7 +2577,7 @@ mod message_processor_impl { // let gateway_message = GatewayMessage::Outbound { // sender, // message, - // router_id: H256::from_low_u64_be(1), + // router_id: ROUTER_ID_1, // }; // // let (res, weight) = LiquidityPoolsGateway::process(gateway_message); @@ -2631,33 +2589,14 @@ mod message_processor_impl { #[test] fn router_error() { new_test_ext().execute_with(|| { - let sender = get_test_account_id(); - let domain = Domain::EVM(1); + let sender = TEST_DOMAIN_ADDRESS; let message = Message::Simple; - let expected_sender = sender.clone(); - let expected_message = message.clone(); - let router_post_info = PostDispatchInfo { actual_weight: Some(Weight::from_parts(1, 1)), pays_fee: Pays::Yes, }; - // let router_err = DispatchError::Unavailable; - // - // let router_mock = RouterMock::::default(); - // router_mock.mock_send(move |mock_sender, mock_message| { - // assert_eq!(mock_sender, expected_sender); - // assert_eq!(mock_message, expected_message.serialize()); - // - // Err(DispatchErrorWithPostInfo { - // post_info: router_post_info, - // error: router_err, - // }) - // }); - // - // DomainRouters::::insert(domain.clone(), router_mock); - let min_expected_weight = ::DbWeight::get() .reads(1) + router_post_info.actual_weight.unwrap() + Weight::from_parts(0, message.serialize().len() as u64); @@ -2665,7 +2604,7 @@ mod message_processor_impl { let gateway_message = GatewayMessage::Outbound { sender, message: message.clone(), - router_id: H256::from_low_u64_be(1), + router_id: ROUTER_ID_1, }; let (res, weight) = LiquidityPoolsGateway::process(gateway_message); @@ -2712,9 +2651,12 @@ mod batches { // Ok Batched assert_ok!(LiquidityPoolsGateway::handle(USER, DOMAIN, Message::Simple)); - let router_id_1 = H256::from_low_u64_be(1); + let router_id_1 = ROUTER_ID_1; - Routers::::insert(DOMAIN, BoundedVec::try_from(vec![router_id_1]).unwrap()); + Routers::::insert( + DOMAIN, + BoundedVec::try_from(vec![router_id_1.clone()]).unwrap(), + ); // Not batched, it belong to OTHER assert_ok!(LiquidityPoolsGateway::handle( @@ -2770,7 +2712,7 @@ mod batches { DispatchError::Other(MAX_PACKED_MESSAGES_ERR) ); - let router_id_1 = H256::from_low_u64_be(1); + let router_id_1 = ROUTER_ID_1; Routers::::insert(DOMAIN, BoundedVec::try_from(vec![router_id_1]).unwrap()); @@ -2812,7 +2754,7 @@ mod batches { let address = H160::from_slice(&get_test_account_id().as_slice()[..20]); let domain_address = DomainAddress::EVM(0, address.into()); - let router_id_1 = H256::from_low_u64_be(1); + let router_id_1 = ROUTER_ID_1; Routers::::insert( domain_address.domain(), @@ -2827,7 +2769,7 @@ mod batches { let (result, weight) = LiquidityPoolsGateway::process(GatewayMessage::Inbound { domain_address, message: Message::deserialize(&(1..=submessage_count).collect::>()).unwrap(), - router_id: *ROUTER_HASH_1, + router_id: ROUTER_ID_1, }); let expected_weight = Weight::default() @@ -2869,7 +2811,7 @@ mod batches { let address = H160::from_slice(&get_test_account_id().as_slice()[..20]); let domain_address = DomainAddress::EVM(0, address.into()); - let router_id_1 = H256::from_low_u64_be(1); + let router_id_1 = ROUTER_ID_1; Routers::::insert( domain_address.domain(), @@ -2889,7 +2831,7 @@ mod batches { let (result, _) = LiquidityPoolsGateway::process(GatewayMessage::Inbound { domain_address, message: Message::deserialize(&(1..=5).collect::>()).unwrap(), - router_id: *ROUTER_HASH_1, + router_id: ROUTER_ID_1, }); assert_err!(result, DispatchError::Unavailable); @@ -2906,12 +2848,12 @@ mod execute_message_recovery { fn success() { new_test_ext().execute_with(|| { let domain = Domain::EVM(0); - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; let session_id = 1; Routers::::insert( domain.clone(), - BoundedVec::try_from(vec![router_id]).unwrap(), + BoundedVec::try_from(vec![router_id.clone()]).unwrap(), ); InboundMessageSessions::::insert(domain.clone(), session_id); @@ -2919,7 +2861,7 @@ mod execute_message_recovery { RuntimeOrigin::root(), domain.clone(), MESSAGE_PROOF, - router_id + router_id.clone(), )); event_exists(Event::::MessageRecoveryExecuted { @@ -2928,9 +2870,11 @@ mod execute_message_recovery { router_id: router_id.clone(), }); - let inbound_entry = - PendingInboundEntries::::get(session_id, (MESSAGE_PROOF, router_id)) - .expect("inbound entry is stored"); + let inbound_entry = PendingInboundEntries::::get( + session_id, + (MESSAGE_PROOF, router_id.clone()), + ) + .expect("inbound entry is stored"); assert_eq!( inbound_entry, @@ -2941,12 +2885,14 @@ mod execute_message_recovery { RuntimeOrigin::root(), domain.clone(), MESSAGE_PROOF, - router_id + router_id.clone() )); - let inbound_entry = - PendingInboundEntries::::get(session_id, (MESSAGE_PROOF, router_id)) - .expect("inbound entry is stored"); + let inbound_entry = PendingInboundEntries::::get( + session_id, + (MESSAGE_PROOF, router_id.clone()), + ) + .expect("inbound entry is stored"); assert_eq!( inbound_entry, @@ -2956,7 +2902,7 @@ mod execute_message_recovery { event_exists(Event::::MessageRecoveryExecuted { domain: domain.clone(), proof: MESSAGE_PROOF, - router_id: router_id.clone(), + router_id, }); }); } @@ -2965,7 +2911,7 @@ mod execute_message_recovery { fn inbound_domain_session_not_found() { new_test_ext().execute_with(|| { let domain = Domain::EVM(0); - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; assert_noop!( LiquidityPoolsGateway::execute_message_recovery( @@ -2983,7 +2929,7 @@ mod execute_message_recovery { fn routers_not_found() { new_test_ext().execute_with(|| { let domain = Domain::EVM(0); - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; let session_id = 1; InboundMessageSessions::::insert(domain.clone(), session_id); @@ -3004,8 +2950,8 @@ mod execute_message_recovery { fn unknown_inbound_message_router() { new_test_ext().execute_with(|| { let domain = Domain::EVM(0); - let router_id_1 = H256::from_low_u64_be(1); - let router_id_2 = H256::from_low_u64_be(2); + let router_id_1 = ROUTER_ID_1; + let router_id_2 = ROUTER_ID_2; let session_id = 1; Routers::::insert( @@ -3021,7 +2967,7 @@ mod execute_message_recovery { MESSAGE_PROOF, router_id_2 ), - Error::::UnknownInboundMessageRouter + Error::::UnknownRouter ); }); } @@ -3030,17 +2976,17 @@ mod execute_message_recovery { fn proof_count_overflow() { new_test_ext().execute_with(|| { let domain = Domain::EVM(0); - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; let session_id = 1; Routers::::insert( domain.clone(), - BoundedVec::try_from(vec![router_id]).unwrap(), + BoundedVec::try_from(vec![router_id.clone()]).unwrap(), ); InboundMessageSessions::::insert(domain.clone(), session_id); PendingInboundEntries::::insert( session_id, - (MESSAGE_PROOF, router_id), + (MESSAGE_PROOF, router_id.clone()), InboundEntry::::Proof { current_count: u32::MAX, }, @@ -3062,17 +3008,17 @@ mod execute_message_recovery { fn expected_message_proof_type() { new_test_ext().execute_with(|| { let domain_address = TEST_DOMAIN_ADDRESS; - let router_id = H256::from_low_u64_be(1); + let router_id = ROUTER_ID_1; let session_id = 1; Routers::::insert( domain_address.domain(), - BoundedVec::try_from(vec![router_id]).unwrap(), + BoundedVec::try_from(vec![router_id.clone()]).unwrap(), ); InboundMessageSessions::::insert(domain_address.domain(), session_id); PendingInboundEntries::::insert( session_id, - (MESSAGE_PROOF, router_id), + (MESSAGE_PROOF, router_id.clone()), InboundEntry::::Message { domain_address: domain_address.clone(), message: Message::Simple,