Skip to content

Commit

Permalink
lp-gateway: Update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Aug 16, 2024
1 parent 4b6cc1d commit 2fc0470
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 62 deletions.
4 changes: 2 additions & 2 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ pub trait LPMessage: Sized {
///
/// Hash - hash of the message that should be recovered.
/// Router - the address of the recovery router.
fn initiate_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self;
fn initiate_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self;

/// Creates a message used for disputing message recovery.
///
/// Hash - hash of the message that should be disputed.
/// Router - the address of the recovery router.
fn dispute_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self;
fn dispute_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self;
}

pub trait RouterProvider<Domain>: Sized {
Expand Down
12 changes: 6 additions & 6 deletions pallets/liquidity-pools-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ pub mod pallet {
MessageRecoveryInitiated {
domain: Domain,
message_hash: MessageHash,
recovery_router: [u8; 20],
recovery_router: [u8; 32],
messaging_router: T::RouterId,
},

/// Message recovery was disputed.
MessageRecoveryDisputed {
domain: Domain,
message_hash: MessageHash,
recovery_router: [u8; 20],
recovery_router: [u8; 32],
messaging_router: T::RouterId,
},
}
Expand Down Expand Up @@ -513,14 +513,14 @@ pub mod pallet {
origin: OriginFor<T>,
domain: Domain,
message_hash: MessageHash,
recovery_router: [u8; 20],
recovery_router: [u8; 32],
messaging_router: T::RouterId,
) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;

let message = T::Message::initiate_recovery_message(message_hash, recovery_router);

Self::send_recovery_message(domain.clone(), message, messaging_router.clone())?;
Self::send_recovery_message(domain, message, messaging_router.clone())?;

Self::deposit_event(Event::<T>::MessageRecoveryInitiated {
domain,
Expand All @@ -542,14 +542,14 @@ pub mod pallet {
origin: OriginFor<T>,
domain: Domain,
message_hash: MessageHash,
recovery_router: [u8; 20],
recovery_router: [u8; 32],
messaging_router: T::RouterId,
) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;

let message = T::Message::dispute_recovery_message(message_hash, recovery_router);

Self::send_recovery_message(domain.clone(), message, messaging_router.clone())?;
Self::send_recovery_message(domain, message, messaging_router.clone())?;

Self::deposit_event(Event::<T>::MessageRecoveryDisputed {
domain,
Expand Down
10 changes: 5 additions & 5 deletions pallets/liquidity-pools-gateway/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{pallet as pallet_liquidity_pools_gateway, EnsureLocal, GatewayMessag

pub const TEST_SESSION_ID: u32 = 1;
pub const TEST_EVM_CHAIN: EVMChainId = 1;
pub const TEST_DOMAIN: Domain = Domain::EVM(TEST_EVM_CHAIN);
pub const TEST_DOMAIN: Domain = Domain::Evm(TEST_EVM_CHAIN);
pub const TEST_DOMAIN_ADDRESS: DomainAddress =
DomainAddress::Evm(TEST_EVM_CHAIN, H160::repeat_byte(1));

Expand All @@ -37,8 +37,8 @@ pub enum Message {
Simple,
Pack(Vec<Message>),
Proof([u8; 32]),
InitiateMessageRecovery(([u8; 32], [u8; 20])),
DisputeMessageRecovery(([u8; 32], [u8; 20])),
InitiateMessageRecovery(([u8; 32], [u8; 32])),
DisputeMessageRecovery(([u8; 32], [u8; 32])),
}

impl Debug for Message {
Expand Down Expand Up @@ -116,11 +116,11 @@ impl LPMessage for Message {
}
}

fn initiate_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self {
fn initiate_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self {
Self::InitiateMessageRecovery((hash, router))
}

fn dispute_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self {
fn dispute_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self {
Self::DisputeMessageRecovery((hash, router))
}
}
Expand Down
20 changes: 10 additions & 10 deletions pallets/liquidity-pools-gateway/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ mod extrinsics {
#[test]
fn success() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

Routers::<Runtime>::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap());

Expand Down Expand Up @@ -911,7 +911,7 @@ mod extrinsics {
#[test]
fn bad_origin() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

assert_noop!(
LiquidityPoolsGateway::initiate_message_recovery(
Expand All @@ -929,7 +929,7 @@ mod extrinsics {
#[test]
fn not_enough_routers_for_domain() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

assert_noop!(
LiquidityPoolsGateway::initiate_message_recovery(
Expand All @@ -947,7 +947,7 @@ mod extrinsics {
#[test]
fn messaging_router_not_found() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

Routers::<Runtime>::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap());

Expand Down Expand Up @@ -979,7 +979,7 @@ mod extrinsics {
#[test]
fn message_sender_error() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

Routers::<Runtime>::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap());

Expand Down Expand Up @@ -1017,7 +1017,7 @@ mod extrinsics {
#[test]
fn success() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

Routers::<Runtime>::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap());

Expand Down Expand Up @@ -1053,7 +1053,7 @@ mod extrinsics {
#[test]
fn bad_origin() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

assert_noop!(
LiquidityPoolsGateway::dispute_message_recovery(
Expand All @@ -1071,7 +1071,7 @@ mod extrinsics {
#[test]
fn not_enough_routers_for_domain() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

assert_noop!(
LiquidityPoolsGateway::dispute_message_recovery(
Expand All @@ -1089,7 +1089,7 @@ mod extrinsics {
#[test]
fn messaging_router_not_found() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

Routers::<Runtime>::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap());

Expand Down Expand Up @@ -1121,7 +1121,7 @@ mod extrinsics {
#[test]
fn message_sender_error() {
new_test_ext().execute_with(|| {
let recovery_router = [1u8; 20];
let recovery_router = [1u8; 32];

Routers::<Runtime>::set(BoundedVec::try_from(vec![ROUTER_ID_1]).unwrap());

Expand Down
8 changes: 4 additions & 4 deletions pallets/liquidity-pools/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub enum Message<BatchContent = BatchMessages> {
/// The hash of the message which shall be recovered
hash: [u8; 32],
/// The address of the router
router: [u8; 20],
router: [u8; 32],
},
/// Dispute the recovery of a message.
///
Expand All @@ -237,7 +237,7 @@ pub enum Message<BatchContent = BatchMessages> {
/// The hash of the message which shall be disputed
hash: [u8; 32],
/// The address of the router
router: [u8; 20],
router: [u8; 32],
},
/// A batch of ordered messages.
/// Don't allow nested batch messages.
Expand Down Expand Up @@ -575,11 +575,11 @@ impl LPMessage for Message {
Message::MessageProof { hash }
}

fn initiate_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self {
fn initiate_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self {
Message::InitiateMessageRecovery { hash, router }
}

fn dispute_recovery_message(hash: [u8; 32], router: [u8; 20]) -> Self {
fn dispute_recovery_message(hash: [u8; 32], router: [u8; 32]) -> Self {
Message::DisputeMessageRecovery { hash, router }
}
}
Expand Down
23 changes: 1 addition & 22 deletions runtime/integration-tests/src/cases/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,15 +1026,12 @@ mod foreign_investments {

let nonce = MessageNonceStore::<T>::get();

let sender = T::Sender::get();

// Clearing of foreign InvestState should be dispatched
assert!(frame_system::Pallet::<T>::events().iter().any(|e| {
e.event
== pallet_liquidity_pools_gateway_queue::Event::MessageSubmitted {
nonce,
message: GatewayMessage::Outbound {
sender: sender.clone(),
router_id: DEFAULT_ROUTER_ID,
message: LiquidityPoolMessage::FulfilledDepositRequest {
pool_id,
Expand Down Expand Up @@ -1130,14 +1127,11 @@ mod foreign_investments {

let nonce = MessageNonceStore::<T>::get();

let sender = T::Sender::get();

assert!(frame_system::Pallet::<T>::events().iter().any(|e| {
e.event
== pallet_liquidity_pools_gateway_queue::Event::<T>::MessageSubmitted {
nonce,
message: GatewayMessage::Outbound {
sender: sender.clone(),
router_id: DEFAULT_ROUTER_ID,
message: Message::FulfilledDepositRequest {
pool_id,
Expand Down Expand Up @@ -1230,7 +1224,6 @@ mod foreign_investments {
== pallet_liquidity_pools_gateway_queue::Event::<T>::MessageSubmitted {
nonce,
message: GatewayMessage::Outbound {
sender: sender.clone(),
router_id: DEFAULT_ROUTER_ID,
message: LiquidityPoolMessage::FulfilledDepositRequest {
pool_id,
Expand Down Expand Up @@ -1265,12 +1258,11 @@ mod foreign_investments {
pallet_liquidity_pools_gateway_queue::Event::MessageSubmitted {
message:
GatewayMessage::Outbound {
sender: event_sender,
router_id: event_router_id,
message: Message::FulfilledDepositRequest { .. },
},
..
} => event_sender == sender && event_router_id == DEFAULT_ROUTER_ID,
} => event_router_id == DEFAULT_ROUTER_ID,
_ => false,
}
} else {
Expand Down Expand Up @@ -1502,14 +1494,11 @@ mod foreign_investments {

let nonce = MessageNonceStore::<T>::get();

let sender = T::Sender::get();

assert!(frame_system::Pallet::<T>::events().iter().any(|e| {
e.event
== pallet_liquidity_pools_gateway_queue::Event::<T>::MessageSubmitted {
nonce,
message: GatewayMessage::Outbound {
sender: sender.clone(),
router_id: DEFAULT_ROUTER_ID,
message: LiquidityPoolMessage::FulfilledRedeemRequest {
pool_id,
Expand Down Expand Up @@ -1599,7 +1588,6 @@ mod foreign_investments {
== pallet_liquidity_pools_gateway_queue::Event::<T>::MessageSubmitted {
nonce,
message: GatewayMessage::Outbound {
sender: sender.clone(),
router_id: DEFAULT_ROUTER_ID,
message: LiquidityPoolMessage::FulfilledRedeemRequest {
pool_id,
Expand Down Expand Up @@ -1940,14 +1928,11 @@ mod foreign_investments {

let nonce = MessageNonceStore::<T>::get();

let sender = T::Sender::get();

assert!(frame_system::Pallet::<T>::events().iter().any(|e| {
e.event
== pallet_liquidity_pools_gateway_queue::Event::<T>::MessageSubmitted {
nonce,
message: GatewayMessage::Outbound {
sender: sender.clone(),
router_id: DEFAULT_ROUTER_ID,
message: LiquidityPoolMessage::FulfilledDepositRequest {
pool_id,
Expand Down Expand Up @@ -2091,14 +2076,11 @@ mod foreign_investments {

let nonce = MessageNonceStore::<T>::get();

let sender = <T as pallet_liquidity_pools_gateway::Config>::Sender::get();

assert!(frame_system::Pallet::<T>::events().iter().any(|e| {
e.event
== pallet_liquidity_pools_gateway_queue::Event::<T>::MessageSubmitted {
nonce,
message: GatewayMessage::Outbound {
sender: sender.clone(),
router_id: DEFAULT_ROUTER_ID,
message: LiquidityPoolMessage::FulfilledCancelDepositRequest {
pool_id,
Expand Down Expand Up @@ -2202,14 +2184,11 @@ mod foreign_investments {

let nonce = MessageNonceStore::<T>::get();

let sender = <T as pallet_liquidity_pools_gateway::Config>::Sender::get();

assert!(frame_system::Pallet::<T>::events().iter().any(|e| {
e.event
== pallet_liquidity_pools_gateway_queue::Event::<T>::MessageSubmitted {
nonce,
message: GatewayMessage::Outbound {
sender: sender.clone(),
router_id: DEFAULT_ROUTER_ID,
message: LiquidityPoolMessage::FulfilledCancelDepositRequest {
pool_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use cfg_primitives::AccountId;
use cfg_traits::liquidity_pools::MessageQueue;
use cfg_types::domain_address::DomainAddress;
use frame_support::{assert_ok, traits::OriginTrait};
Expand Down Expand Up @@ -72,7 +71,6 @@ fn outbound<T: Runtime + FudgeSupport>() {

let nonce = <T as pallet_liquidity_pools_gateway_queue::Config>::MessageNonce::one();
let message = GatewayMessage::Outbound {
sender: DomainAddress::Centrifuge(AccountId::new([1; 32])),
router_id: DEFAULT_ROUTER_ID,
message: Message::Invalid,
};
Expand Down
10 changes: 1 addition & 9 deletions runtime/integration-tests/src/cases/lp/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,7 @@ pub fn process_gateway_message<T: Runtime>(

match msg {
GatewayMessage::Inbound { message, .. } => verifier(message),
GatewayMessage::Outbound {
sender,
router_id,
message,
} => {
assert_eq!(
sender,
<T as pallet_liquidity_pools_gateway::Config>::Sender::get()
);
GatewayMessage::Outbound { router_id, message } => {
assert_eq!(router_id, EVM_ROUTER_ID);
verifier(message)
}
Expand Down
3 changes: 1 addition & 2 deletions runtime/integration-tests/src/cases/routers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use runtime_common::{
account_conversion::AccountConverter, evm::precompile::LP_AXELAR_GATEWAY,
gateway::get_gateway_domain_address, routing::RouterId,
};
use sp_core::{Get, H160, H256, U256};
use sp_core::{H160, H256, U256};
use sp_runtime::traits::{BlakeTwo256, Hash};

use crate::{
Expand Down Expand Up @@ -139,7 +139,6 @@ mod axelar_evm {
));

let gateway_message = GatewayMessage::Outbound {
sender: T::Sender::get(),
router_id: TEST_ROUTER_ID,
message: Message::Invalid,
};
Expand Down

0 comments on commit 2fc0470

Please sign in to comment.