From d9cac0213f22e2e8eea372bb8c5b9bf740ccdc55 Mon Sep 17 00:00:00 2001 From: Cosmin Damian <17934949+cdamian@users.noreply.github.com> Date: Wed, 31 Jul 2024 23:55:57 +0300 Subject: [PATCH] integration-tests: Adapt existing tests to LP gateway queue usage, add specific inbound tests --- runtime/altair/src/lib.rs | 13 +- runtime/centrifuge/src/lib.rs | 13 +- runtime/development/src/lib.rs | 7 +- .../src/cases/liquidity_pools.rs | 278 +++++++++++------- .../cases/liquidity_pools_gateway_queue.rs | 137 +++++++-- .../src/cases/lp/investments.rs | 104 ++++--- .../src/cases/lp/transfers.rs | 21 +- .../integration-tests/src/cases/lp/utils.rs | 18 +- .../integration-tests/src/cases/routers.rs | 17 +- runtime/integration-tests/src/config.rs | 3 +- runtime/integration-tests/src/env.rs | 3 +- 11 files changed, 392 insertions(+), 222 deletions(-) diff --git a/runtime/altair/src/lib.rs b/runtime/altair/src/lib.rs index 8d6ff67352..83fa047a5a 100644 --- a/runtime/altair/src/lib.rs +++ b/runtime/altair/src/lib.rs @@ -24,8 +24,8 @@ use cfg_primitives::{ liquidity_pools::GeneralCurrencyPrefix, types::{ AccountId, Address, AuraId, Balance, BlockNumber, CollectionId, Hash, Hashing, Header, - IBalance, InvestmentId, ItemId, LoanId, Nonce, OrderId, OutboundMessageNonce, PalletIndex, - PoolEpochId, PoolFeeId, PoolId, Signature, TrancheId, TrancheWeight, + IBalance, InvestmentId, ItemId, LoanId, Nonce, OrderId, PalletIndex, PoolEpochId, + PoolFeeId, PoolId, Signature, TrancheId, TrancheWeight, }, LPGatewayQueueMessageNonce, }; @@ -81,6 +81,7 @@ use pallet_evm::{ Runner, }; use pallet_investments::OrderType; +use pallet_liquidity_pools_gateway::message::GatewayMessage; pub use pallet_loans::entities::{input::PriceCollectionInput, loans::ActiveLoanInfo}; use pallet_loans::types::cashflow::CashflowPayment; use pallet_pool_system::{ @@ -1790,7 +1791,7 @@ impl pallet_liquidity_pools::Config for Runtime { type ForeignInvestment = ForeignInvestments; type GeneralCurrencyPrefix = GeneralCurrencyPrefix; type MarketRatio = OrderBook; - type OutboundQueue = LiquidityPoolsGateway; + type OutboundMessageHandler = LiquidityPoolsGateway; type Permission = Permissions; type PoolId = PoolId; type PoolInspect = PoolSystem; @@ -1811,12 +1812,12 @@ parameter_types! { impl pallet_liquidity_pools_gateway::Config for Runtime { type AdminOrigin = EnsureRoot; - type InboundQueue = LiquidityPools; + type InboundMessageHandler = LiquidityPools; type LocalEVMOrigin = pallet_liquidity_pools_gateway::EnsureLocal; type MaxIncomingMessageSize = MaxIncomingMessageSize; type Message = pallet_liquidity_pools::Message; + type MessageQueue = LiquidityPoolsGatewayQueue; type OriginRecovery = LiquidityPoolsAxelarGateway; - type OutboundMessageNonce = OutboundMessageNonce; type Router = liquidity_pools_gateway_routers::DomainRouter; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; @@ -1825,7 +1826,7 @@ impl pallet_liquidity_pools_gateway::Config for Runtime { } impl pallet_liquidity_pools_gateway_queue::Config for Runtime { - type Message = pallet_liquidity_pools::Message; + type Message = GatewayMessage; type MessageNonce = LPGatewayQueueMessageNonce; type MessageProcessor = LiquidityPoolsGateway; type RuntimeEvent = RuntimeEvent; diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index 0fb700e34d..a3abdd908a 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -24,8 +24,8 @@ use cfg_primitives::{ liquidity_pools::GeneralCurrencyPrefix, types::{ AccountId, Address, AuraId, Balance, BlockNumber, CollectionId, Hash, Hashing, Header, - IBalance, InvestmentId, ItemId, LoanId, Nonce, OrderId, OutboundMessageNonce, PalletIndex, - PoolEpochId, PoolFeeId, PoolId, Signature, TrancheId, TrancheWeight, + IBalance, InvestmentId, ItemId, LoanId, Nonce, OrderId, PalletIndex, PoolEpochId, + PoolFeeId, PoolId, Signature, TrancheId, TrancheWeight, }, LPGatewayQueueMessageNonce, }; @@ -82,6 +82,7 @@ use pallet_evm::{ Runner, }; use pallet_investments::OrderType; +use pallet_liquidity_pools_gateway::message::GatewayMessage; pub use pallet_loans::entities::{input::PriceCollectionInput, loans::ActiveLoanInfo}; use pallet_loans::types::cashflow::CashflowPayment; use pallet_pool_system::{ @@ -1870,7 +1871,7 @@ impl pallet_liquidity_pools::Config for Runtime { type ForeignInvestment = ForeignInvestments; type GeneralCurrencyPrefix = GeneralCurrencyPrefix; type MarketRatio = OrderBook; - type OutboundQueue = LiquidityPoolsGateway; + type OutboundMessageHandler = LiquidityPoolsGateway; type Permission = Permissions; type PoolId = PoolId; type PoolInspect = PoolSystem; @@ -1907,12 +1908,12 @@ parameter_types! { impl pallet_liquidity_pools_gateway::Config for Runtime { type AdminOrigin = EnsureAccountOrRootOr; - type InboundQueue = LiquidityPools; + type InboundMessageHandler = LiquidityPools; type LocalEVMOrigin = pallet_liquidity_pools_gateway::EnsureLocal; type MaxIncomingMessageSize = MaxIncomingMessageSize; type Message = pallet_liquidity_pools::Message; + type MessageQueue = LiquidityPoolsGatewayQueue; type OriginRecovery = LiquidityPoolsAxelarGateway; - type OutboundMessageNonce = OutboundMessageNonce; type Router = liquidity_pools_gateway_routers::DomainRouter; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; @@ -1921,7 +1922,7 @@ impl pallet_liquidity_pools_gateway::Config for Runtime { } impl pallet_liquidity_pools_gateway_queue::Config for Runtime { - type Message = pallet_liquidity_pools::Message; + type Message = GatewayMessage; type MessageNonce = LPGatewayQueueMessageNonce; type MessageProcessor = LiquidityPoolsGateway; type RuntimeEvent = RuntimeEvent; diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 5e57ea572f..3cb667892a 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -24,8 +24,8 @@ use cfg_primitives::{ liquidity_pools::GeneralCurrencyPrefix, types::{ AccountId, Address, AuraId, Balance, BlockNumber, CollectionId, Hash, Hashing, Header, - IBalance, InvestmentId, ItemId, LoanId, Nonce, OrderId, OutboundMessageNonce, PalletIndex, - PoolEpochId, PoolFeeId, PoolId, Signature, TrancheId, TrancheWeight, + IBalance, InvestmentId, ItemId, LoanId, Nonce, OrderId, PalletIndex, PoolEpochId, + PoolFeeId, PoolId, Signature, TrancheId, TrancheWeight, }, LPGatewayQueueMessageNonce, }; @@ -84,6 +84,7 @@ use pallet_evm::{ Runner, }; use pallet_investments::OrderType; +use pallet_liquidity_pools_gateway::message::GatewayMessage; pub use pallet_loans::entities::{input::PriceCollectionInput, loans::ActiveLoanInfo}; use pallet_loans::types::cashflow::CashflowPayment; use pallet_pool_system::{ @@ -1926,7 +1927,7 @@ impl pallet_liquidity_pools_gateway::Config for Runtime { } impl pallet_liquidity_pools_gateway_queue::Config for Runtime { - type Message = pallet_liquidity_pools::Message; + type Message = GatewayMessage; type MessageNonce = LPGatewayQueueMessageNonce; type MessageProcessor = LiquidityPoolsGateway; type RuntimeEvent = RuntimeEvent; diff --git a/runtime/integration-tests/src/cases/liquidity_pools.rs b/runtime/integration-tests/src/cases/liquidity_pools.rs index 23c6d8c488..76385dd359 100644 --- a/runtime/integration-tests/src/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/cases/liquidity_pools.rs @@ -2,7 +2,7 @@ use cfg_primitives::{ currency_decimals, parachains, AccountId, Balance, InvestmentId, OrderId, PoolId, TrancheId, }; use cfg_traits::{ - investments::OrderManager, liquidity_pools::InboundQueue, IdentityCurrencyConversion, + investments::OrderManager, liquidity_pools::InboundMessageHandler, IdentityCurrencyConversion, Permissions, PoolInspect, PoolMutate, Seconds, }; use cfg_types::{ @@ -28,6 +28,8 @@ use liquidity_pools_gateway_routers::{ use pallet_foreign_investments::ForeignInvestmentInfo; use pallet_investments::CollectOutcome; use pallet_liquidity_pools::Message; +use pallet_liquidity_pools_gateway::message::GatewayMessage; +use pallet_liquidity_pools_gateway_queue::MessageNonceStore; use pallet_pool_system::tranches::{TrancheInput, TrancheLoc, TrancheType}; use runtime_common::{ account_conversion::AccountConverter, foreign_investments::IdentityPoolCurrencyConverter, @@ -81,7 +83,7 @@ pub const DEFAULT_OTHER_DOMAIN_ADDRESS: DomainAddress = pub type LiquidityPoolMessage = Message; -mod utils { +pub(crate) mod utils { use cfg_types::oracles::OracleKey; use frame_support::weights::Weight; use runtime_common::oracle::Feeder; @@ -424,7 +426,7 @@ mod utils { // investment after the swap was fulfilled if currency_id == pool_currency { assert_noop!( - pallet_liquidity_pools::Pallet::::submit( + pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg.clone() ), @@ -455,7 +457,7 @@ mod utils { .expect("Should not overflow when incrementing amount"); // Execute byte message - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg )); @@ -526,7 +528,7 @@ mod utils { // Should fail if investor does not have investor role yet assert_noop!( - pallet_liquidity_pools::Pallet::::submit( + pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg.clone() ), @@ -540,7 +542,7 @@ mod utils { PoolRole::TrancheInvestor(default_tranche_id::(pool_id), DEFAULT_VALIDITY), ); - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg )); @@ -672,10 +674,10 @@ mod utils { .filter(|e1| !events_before.iter().any(|e2| e1 == e2)) .any(|e| { if let Ok(event) = e.event.clone().try_into() - as Result, _> + as Result, _> { match event { - pallet_liquidity_pools_gateway::Event::OutboundMessageSubmitted { + pallet_liquidity_pools_gateway_queue::Event::MessageSubmitted { .. } => true, _ => false, @@ -740,7 +742,7 @@ mod foreign_investments { currency: general_currency_index::(currency_id), amount, }; - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg )); @@ -787,7 +789,7 @@ mod foreign_investments { // Expect failure if transferability is disabled since this is required for // preparing the `FulfilledCancelDepositRequest` message. assert_noop!( - pallet_liquidity_pools::Pallet::::submit( + pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg.clone() ), @@ -796,7 +798,7 @@ mod foreign_investments { enable_liquidity_pool_transferability::(currency_id); // Execute byte message - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg )); @@ -886,7 +888,7 @@ mod foreign_investments { // Expect failure if transferability is disabled since this is required for // preparing the `FulfilledCancelDepositRequest` message. assert_noop!( - pallet_liquidity_pools::Pallet::::submit( + pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg.clone() ), @@ -896,7 +898,7 @@ mod foreign_investments { enable_liquidity_pool_transferability::(currency_id); // Execute byte message - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg )); @@ -1056,21 +1058,26 @@ mod foreign_investments { .into() })); + let nonce = MessageNonceStore::::get(); + let sender = ::Sender::get(); // Clearing of foreign InvestState should be dispatched assert!(frame_system::Pallet::::events().iter().any(|e| { e.event - == pallet_liquidity_pools_gateway::Event::::OutboundMessageSubmitted { - sender: sender.clone(), - domain: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), - message: LiquidityPoolMessage::FulfilledDepositRequest { - pool_id, - tranche_id: default_tranche_id::(pool_id), - investor: investor.clone().into(), - currency: general_currency_index::(currency_id), - currency_payout: amount, - tranche_tokens_payout: amount, + == pallet_liquidity_pools_gateway_queue::Event::MessageSubmitted { + nonce, + message: GatewayMessage::Outbound { + sender: sender.clone(), + destination: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), + message: LiquidityPoolMessage::FulfilledDepositRequest { + pool_id, + tranche_id: default_tranche_id::(pool_id), + investor: investor.clone().into(), + currency: general_currency_index::(currency_id), + currency_payout: amount, + tranche_tokens_payout: amount, + }, }, } .into() @@ -1156,20 +1163,25 @@ mod foreign_investments { .into() })); + let nonce = MessageNonceStore::::get(); + let sender = ::Sender::get(); assert!(frame_system::Pallet::::events().iter().any(|e| { e.event - == pallet_liquidity_pools_gateway::Event::::OutboundMessageSubmitted { - sender: sender.clone(), - domain: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), - message: pallet_liquidity_pools::Message::FulfilledDepositRequest { - pool_id, - tranche_id: default_tranche_id::(pool_id), - investor: investor.clone().into(), - currency: general_currency_index::(currency_id), - currency_payout: invest_amount / 2, - tranche_tokens_payout: invest_amount * 2, + == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { + nonce, + message: GatewayMessage::Outbound { + sender: sender.clone(), + destination: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), + message: Message::FulfilledDepositRequest { + pool_id, + tranche_id: default_tranche_id::(pool_id), + investor: investor.clone().into(), + currency: general_currency_index::(currency_id), + currency_payout: invest_amount / 2, + tranche_tokens_payout: invest_amount * 2, + }, }, } .into() @@ -1246,18 +1258,23 @@ mod foreign_investments { .into() })); + let nonce = MessageNonceStore::::get(); + assert!(frame_system::Pallet::::events().iter().any(|e| { e.event - == pallet_liquidity_pools_gateway::Event::::OutboundMessageSubmitted { - sender: sender.clone(), - domain: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), - message: LiquidityPoolMessage::FulfilledDepositRequest { - pool_id, - tranche_id: default_tranche_id::(pool_id), - investor: investor.clone().into(), - currency: general_currency_index::(currency_id), - currency_payout: invest_amount / 2, - tranche_tokens_payout: invest_amount, + == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { + nonce, + message: GatewayMessage::Outbound { + sender: sender.clone(), + destination: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), + message: LiquidityPoolMessage::FulfilledDepositRequest { + pool_id, + tranche_id: default_tranche_id::(pool_id), + investor: investor.clone().into(), + currency: general_currency_index::(currency_id), + currency_payout: invest_amount / 2, + tranche_tokens_payout: invest_amount, + }, }, } .into() @@ -1277,19 +1294,23 @@ mod foreign_investments { .filter(|e1| !events_before.iter().any(|e2| e1 == e2)) .any(|e| { if let Ok(event) = e.event.clone().try_into() - as Result, _> + as Result, _> { match event { - pallet_liquidity_pools_gateway::Event::OutboundMessageSubmitted { - sender: event_sender, - domain: event_domain, - message: Message::FulfilledDepositRequest { .. }, - } => { - event_sender == sender - && event_domain == DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain() + pallet_liquidity_pools_gateway_queue::Event::MessageSubmitted { + message: + GatewayMessage::Outbound { + sender: event_sender, + destination: event_domain, + message: Message::FulfilledDepositRequest { .. }, + }, + .. + } => { + event_sender == sender + && event_domain == DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain() + } + _ => false, } - _ => false, - } } else { false } @@ -1347,7 +1368,7 @@ mod foreign_investments { currency: general_currency_index::(currency_id), amount, }; - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg )); @@ -1400,7 +1421,7 @@ mod foreign_investments { }; // Execute byte message - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg )); @@ -1520,20 +1541,25 @@ mod foreign_investments { .into() })); + let nonce = MessageNonceStore::::get(); + let sender = ::Sender::get(); assert!(frame_system::Pallet::::events().iter().any(|e| { e.event - == pallet_liquidity_pools_gateway::Event::::OutboundMessageSubmitted { - sender: sender.clone(), - domain: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), - message: LiquidityPoolMessage::FulfilledRedeemRequest { - pool_id, - tranche_id: default_tranche_id::(pool_id), - investor: investor.clone().into(), - currency: general_currency_index::(currency_id), - currency_payout: redeem_amount / 8, - tranche_tokens_payout: redeem_amount / 2, + == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { + nonce, + message: GatewayMessage::Outbound { + sender: sender.clone(), + destination: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), + message: LiquidityPoolMessage::FulfilledRedeemRequest { + pool_id, + tranche_id: default_tranche_id::(pool_id), + investor: investor.clone().into(), + currency: general_currency_index::(currency_id), + currency_payout: redeem_amount / 8, + tranche_tokens_payout: redeem_amount / 2, + }, }, } .into() @@ -1605,19 +1631,25 @@ mod foreign_investments { amount: redeem_amount / 4 } .into())); + + let nonce = MessageNonceStore::::get(); + // Clearing of foreign RedeemState should have been dispatched exactly once assert!(frame_system::Pallet::::events().iter().any(|e| { e.event - == pallet_liquidity_pools_gateway::Event::::OutboundMessageSubmitted { - sender: sender.clone(), - domain: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), - message: LiquidityPoolMessage::FulfilledRedeemRequest { - pool_id, - tranche_id: default_tranche_id::(pool_id), - investor: investor.clone().into(), - currency: general_currency_index::(currency_id), - currency_payout: redeem_amount / 4, - tranche_tokens_payout: redeem_amount / 2, + == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { + nonce, + message: GatewayMessage::Outbound { + sender: sender.clone(), + destination: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), + message: LiquidityPoolMessage::FulfilledRedeemRequest { + pool_id, + tranche_id: default_tranche_id::(pool_id), + investor: investor.clone().into(), + currency: general_currency_index::(currency_id), + currency_payout: redeem_amount / 4, + tranche_tokens_payout: redeem_amount / 2, + }, }, } .into() @@ -1687,7 +1719,7 @@ mod foreign_investments { amount: AUSD_ED, }; assert_noop!( - pallet_liquidity_pools::Pallet::::submit( + pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, increase_msg ), @@ -1702,7 +1734,7 @@ mod foreign_investments { currency: general_currency_index::(currency_id), }; assert_noop!( - pallet_liquidity_pools::Pallet::::submit( + pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, decrease_msg ), @@ -1774,7 +1806,7 @@ mod foreign_investments { amount: 1, }; assert_noop!( - pallet_liquidity_pools::Pallet::::submit( + pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, increase_msg ), @@ -1789,7 +1821,7 @@ mod foreign_investments { currency: general_currency_index::(currency_id), }; assert_noop!( - pallet_liquidity_pools::Pallet::::submit( + pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, decrease_msg ), @@ -1847,7 +1879,7 @@ mod foreign_investments { currency: general_currency_index::(foreign_currency), }; assert_noop!( - pallet_liquidity_pools::Pallet::::submit( + pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, decrease_msg ), @@ -1860,6 +1892,8 @@ mod foreign_investments { } mod mismatching_currencies { + use pallet_liquidity_pools_gateway_queue::MessageNonceStore; + use super::*; #[test_runtimes([development])] @@ -1918,7 +1952,7 @@ mod foreign_investments { currency: general_currency_index::(foreign_currency), amount: invest_amount_foreign_denominated, }; - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg )); @@ -1952,20 +1986,25 @@ mod foreign_investments { invest_amount_pool_denominated * 2 ); + let nonce = MessageNonceStore::::get(); + let sender = ::Sender::get(); assert!(frame_system::Pallet::::events().iter().any(|e| { e.event - == pallet_liquidity_pools_gateway::Event::::OutboundMessageSubmitted { - sender: sender.clone(), - domain: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), - message: LiquidityPoolMessage::FulfilledDepositRequest { - pool_id, - tranche_id: default_tranche_id::(pool_id), - investor: investor.clone().into(), - currency: general_currency_index::(foreign_currency), - currency_payout: invest_amount_foreign_denominated, - tranche_tokens_payout: 2 * invest_amount_pool_denominated, + == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { + nonce, + message: GatewayMessage::Outbound { + sender: sender.clone(), + destination: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), + message: LiquidityPoolMessage::FulfilledDepositRequest { + pool_id, + tranche_id: default_tranche_id::(pool_id), + investor: investor.clone().into(), + currency: general_currency_index::(foreign_currency), + currency_payout: invest_amount_foreign_denominated, + tranche_tokens_payout: 2 * invest_amount_pool_denominated, + }, }, } .into() @@ -2050,7 +2089,7 @@ mod foreign_investments { // FulfilledCancel message dispatch blocked until pool currency is swapped back // to foreign assert!(!outbound_message_dispatched::(|| { - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, msg.clone() )); @@ -2098,20 +2137,26 @@ mod foreign_investments { } .into() })); + + let nonce = MessageNonceStore::::get(); + let sender = ::Sender::get(); assert!(frame_system::Pallet::::events().iter().any(|e| { e.event - == pallet_liquidity_pools_gateway::Event::::OutboundMessageSubmitted { - sender: sender.clone(), - domain: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), - message: LiquidityPoolMessage::FulfilledCancelDepositRequest { - pool_id, - tranche_id: default_tranche_id::(pool_id), - investor: investor.clone().into(), - currency: general_currency_index::(foreign_currency), - currency_payout: invest_amount_foreign_denominated, - fulfilled_invest_amount: invest_amount_foreign_denominated, + == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { + nonce, + message: GatewayMessage::Outbound { + sender: sender.clone(), + destination: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), + message: LiquidityPoolMessage::FulfilledCancelDepositRequest { + pool_id, + tranche_id: default_tranche_id::(pool_id), + investor: investor.clone().into(), + currency: general_currency_index::(foreign_currency), + currency_payout: invest_amount_foreign_denominated, + fulfilled_invest_amount: invest_amount_foreign_denominated, + }, }, } .into() @@ -2193,7 +2238,7 @@ mod foreign_investments { currency: general_currency_index::(foreign_currency), }; - assert_ok!(pallet_liquidity_pools::Pallet::::submit( + assert_ok!(pallet_liquidity_pools::Pallet::::handle( DEFAULT_DOMAIN_ADDRESS_MOONBEAM, cancel_msg )); @@ -2205,18 +2250,25 @@ mod foreign_investments { invest_amount_pool_denominated / 2 )); + let nonce = MessageNonceStore::::get(); + + let sender = ::Sender::get(); + assert!(frame_system::Pallet::::events().iter().any(|e| { e.event - == pallet_liquidity_pools_gateway::Event::::OutboundMessageSubmitted { - sender: ::Sender::get(), - domain: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), - message: LiquidityPoolMessage::FulfilledCancelDepositRequest { - pool_id, - tranche_id: default_tranche_id::(pool_id), - investor: investor.clone().into(), - currency: general_currency_index::(foreign_currency), - currency_payout: invest_amount_foreign_denominated / 2, - fulfilled_invest_amount: invest_amount_foreign_denominated / 2, + == pallet_liquidity_pools_gateway_queue::Event::::MessageSubmitted { + nonce, + message: GatewayMessage::Outbound { + sender: sender.clone(), + destination: DEFAULT_DOMAIN_ADDRESS_MOONBEAM.domain(), + message: LiquidityPoolMessage::FulfilledCancelDepositRequest { + pool_id, + tranche_id: default_tranche_id::(pool_id), + investor: investor.clone().into(), + currency: general_currency_index::(foreign_currency), + currency_payout: invest_amount_foreign_denominated / 2, + fulfilled_invest_amount: invest_amount_foreign_denominated / 2, + }, }, } .into() diff --git a/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs b/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs index 11712d92b1..b58301b2c9 100644 --- a/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs +++ b/runtime/integration-tests/src/cases/liquidity_pools_gateway_queue.rs @@ -1,41 +1,128 @@ +use cfg_primitives::currency_decimals; use cfg_traits::liquidity_pools::MessageQueue as MessageQueueT; use frame_support::assert_ok; +use pallet_liquidity_pools::Message; +use pallet_liquidity_pools_gateway::message::GatewayMessage; +use runtime_common::account_conversion::AccountConverter; use sp_runtime::traits::One; use crate::{ + cases::liquidity_pools::{ + utils::*, AUSD_CURRENCY_ID, DEFAULT_BALANCE_GLMR, DEFAULT_DOMAIN_ADDRESS_MOONBEAM, + DOMAIN_MOONBEAM, GLMR_CURRENCY_ID, POOL_ID, + }, config::Runtime, env::{Blocks, Env}, envs::fudge_env::{FudgeEnv, FudgeSupport}, - utils::{currency::cfg, genesis, genesis::Genesis}, + utils::{accounts::Keyring, currency::cfg, genesis, genesis::Genesis}, }; -#[test_runtimes(all)] -fn submit_and_process() { - let mut env = FudgeEnv::::from_parachain_storage( - Genesis::default() - .add(genesis::balances::(cfg(1_000))) - .storage(), - ); - - let expected_event = env.parachain_state_mut(|| { - let message = pallet_liquidity_pools::Message::AddPool { pool_id: 1 }; - let nonce = ::MessageNonce::one(); - - assert_ok!( - as MessageQueueT>::submit( - message.clone() - ) +mod inbound { + use super::*; + + /// This test is basically `increase_deposit_request` but instead of + /// handling the message directly via the LP pallet, we submit it via + /// the LP Gateway Queue and confirm that it's processed accordingly. + #[test_runtimes([development])] + fn success() { + let mut env = FudgeEnv::::from_parachain_storage( + Genesis::default() + .add(genesis::balances::(cfg(1_000))) + .add(genesis::tokens::(vec![( + GLMR_CURRENCY_ID, + DEFAULT_BALANCE_GLMR, + )])) + .storage(), ); - let stored_message = pallet_liquidity_pools_gateway_queue::MessageQueue::::get(nonce); + setup_test(&mut env); + + let expected_event = env.parachain_state_mut(|| { + let pool_id = POOL_ID; + let amount = 10 * decimals(12); + let investor = + AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id()); + let currency_id = AUSD_CURRENCY_ID; + let currency_decimals = currency_decimals::AUSD; + + // Create new pool + create_currency_pool::(pool_id, currency_id, currency_decimals.into()); + + // Set permissions and execute initial investment + do_initial_increase_investment::(pool_id, amount, investor.clone(), currency_id); + + // Verify the order was updated to the amount + assert_eq!( + pallet_investments::Pallet::::acc_active_invest_order( + default_investment_id::(), + ) + .amount, + amount + ); + + // Increasing again should just bump invest_amount + let nonce = ::MessageNonce::one(); + let message = GatewayMessage::Inbound { + domain_address: DEFAULT_DOMAIN_ADDRESS_MOONBEAM, + message: Message::DepositRequest { + pool_id, + tranche_id: default_tranche_id::(pool_id), + investor: investor.clone().into(), + currency: general_currency_index::(currency_id), + amount, + }, + }; + + assert_ok!( + as MessageQueueT>::submit( + message.clone() + ) + ); + + pallet_liquidity_pools_gateway_queue::Event::::MessageExecutionSuccess { + nonce, + message, + } + }); + + env.pass(Blocks::UntilEvent { + event: expected_event.into(), + limit: 3, + }); + } + + #[test_runtimes([development])] + fn failure() { + let mut env = FudgeEnv::::from_parachain_storage(Genesis::default().storage()); + + let expected_event = env.parachain_state_mut(|| { + let nonce = ::MessageNonce::one(); + + let message = GatewayMessage::Inbound { + domain_address: DEFAULT_DOMAIN_ADDRESS_MOONBEAM, + message: Message::TransferAssets { + currency: 1, + receiver: [2; 32], + amount: 0, + }, + }; - assert_eq!(stored_message, Some(message.clone())); + assert_ok!( + as MessageQueueT>::submit( + message.clone() + ) + ); - pallet_liquidity_pools_gateway_queue::Event::::MessageExecutionSuccess { nonce, message } - }); + pallet_liquidity_pools_gateway_queue::Event::::MessageExecutionFailure { + nonce, + message, + error: pallet_liquidity_pools::Error::::InvalidTransferAmount.into(), + } + }); - env.pass(Blocks::UntilEvent { - event: expected_event.into(), - limit: 3, - }); + env.pass(Blocks::UntilEvent { + event: expected_event.into(), + limit: 3, + }); + } } diff --git a/runtime/integration-tests/src/cases/lp/investments.rs b/runtime/integration-tests/src/cases/lp/investments.rs index 11509a3d0b..99899f7fb7 100644 --- a/runtime/integration-tests/src/cases/lp/investments.rs +++ b/runtime/integration-tests/src/cases/lp/investments.rs @@ -30,7 +30,7 @@ use crate::{ const DEFAULT_INVESTMENT_AMOUNT: Balance = 100 * DECIMALS_6; mod utils { - use cfg_primitives::{AccountId, Balance, InvestmentId, PoolId, TrancheId}; + use cfg_primitives::{AccountId, InvestmentId, PoolId, TrancheId}; use cfg_traits::HasLocalAssetRepresentation; use ethabi::Token; use pallet_foreign_investments::Action; @@ -320,10 +320,12 @@ mod with_pool_currency { } mod with_foreign_currency { - use cfg_types::fixed_point::Quantity; + use cfg_types::{domain_address::Domain, fixed_point::Quantity}; use cfg_utils::vec_to_fixed_array; use pallet_foreign_investments::Action; use pallet_liquidity_pools::Message; + use pallet_liquidity_pools_gateway::message::GatewayMessage; + use sp_core::Get; use sp_runtime::{ traits::{EnsureFixedPointNumber, EnsureSub, One}, FixedPointNumber, @@ -332,7 +334,7 @@ mod with_foreign_currency { use super::{utils, *}; use crate::cases::lp::{ investments::utils::close_and_collect, utils as lp_utils, utils::pool_a_tranche_1_id, - POOL_A, + EVM_DOMAIN_CHAIN_ID, POOL_A, }; #[test_runtimes([development], ignore = "solidity mismatch")] @@ -458,16 +460,20 @@ mod with_foreign_currency { lp_utils::process_outbound::(|msg| { assert_eq!( msg, - pallet_liquidity_pools::Message::FulfilledCancelDepositRequest { - pool_id: POOL_A, - tranche_id: pool_a_tranche_1_id::(), - investor: vec_to_fixed_array(lp::utils::remote_account_of::( - Keyring::TrancheInvestor(1) - )), - currency: utils::index_lp(evm, names::USDC), - currency_payout: DEFAULT_INVESTMENT_AMOUNT, - fulfilled_invest_amount: DEFAULT_INVESTMENT_AMOUNT, - } + GatewayMessage::Outbound { + sender: ::Sender::get(), + destination: Domain::EVM(EVM_DOMAIN_CHAIN_ID), + message: Message::FulfilledCancelDepositRequest { + pool_id: POOL_A, + tranche_id: pool_a_tranche_1_id::(), + investor: vec_to_fixed_array(lp::utils::remote_account_of::( + Keyring::TrancheInvestor(1) + )), + currency: utils::index_lp(evm, names::USDC), + currency_payout: DEFAULT_INVESTMENT_AMOUNT, + fulfilled_invest_amount: DEFAULT_INVESTMENT_AMOUNT, + }, + }, ) }); @@ -561,16 +567,20 @@ mod with_foreign_currency { lp_utils::process_outbound::(|msg| { assert_eq!( msg, - pallet_liquidity_pools::Message::FulfilledCancelDepositRequest { - pool_id: POOL_A, - tranche_id: pool_a_tranche_1_id::(), - investor: vec_to_fixed_array(lp::utils::remote_account_of::( - Keyring::TrancheInvestor(1) - )), - currency: utils::index_lp(evm, names::USDC), - currency_payout: DEFAULT_INVESTMENT_AMOUNT, - fulfilled_invest_amount: DEFAULT_INVESTMENT_AMOUNT, - } + GatewayMessage::Outbound { + sender: ::Sender::get(), + destination: Domain::EVM(EVM_DOMAIN_CHAIN_ID), + message: Message::FulfilledCancelDepositRequest { + pool_id: POOL_A, + tranche_id: pool_a_tranche_1_id::(), + investor: vec_to_fixed_array(lp::utils::remote_account_of::( + Keyring::TrancheInvestor(1) + )), + currency: utils::index_lp(evm, names::USDC), + currency_payout: DEFAULT_INVESTMENT_AMOUNT, + fulfilled_invest_amount: DEFAULT_INVESTMENT_AMOUNT, + }, + }, ) }); @@ -653,16 +663,20 @@ mod with_foreign_currency { lp_utils::process_outbound::(|msg| { assert_eq!( msg, - Message::FulfilledDepositRequest { - pool_id: POOL_A, - tranche_id: pool_a_tranche_1_id::(), - investor: vec_to_fixed_array(lp::utils::remote_account_of::( - Keyring::TrancheInvestor(1) - )), - currency: utils::index_lp(evm, names::USDC), - currency_payout: partial_amount, - tranche_tokens_payout: partial_amount, - } + GatewayMessage::Outbound { + sender: ::Sender::get(), + destination: Domain::EVM(EVM_DOMAIN_CHAIN_ID), + message: Message::FulfilledDepositRequest { + pool_id: POOL_A, + tranche_id: pool_a_tranche_1_id::(), + investor: vec_to_fixed_array(lp::utils::remote_account_of::( + Keyring::TrancheInvestor(1) + )), + currency: utils::index_lp(evm, names::USDC), + currency_payout: partial_amount, + tranche_tokens_payout: partial_amount, + }, + }, ) }); @@ -706,16 +720,20 @@ mod with_foreign_currency { lp_utils::process_outbound::(|msg| { assert_eq!( msg, - pallet_liquidity_pools::Message::FulfilledCancelDepositRequest { - pool_id: POOL_A, - tranche_id: pool_a_tranche_1_id::(), - investor: vec_to_fixed_array(lp::utils::remote_account_of::( - Keyring::TrancheInvestor(1) - )), - currency: utils::index_lp(evm, names::USDC), - currency_payout: DEFAULT_INVESTMENT_AMOUNT, - fulfilled_invest_amount: DEFAULT_INVESTMENT_AMOUNT, - } + GatewayMessage::Outbound { + sender: ::Sender::get(), + destination: Domain::EVM(EVM_DOMAIN_CHAIN_ID), + message: Message::FulfilledCancelDepositRequest { + pool_id: POOL_A, + tranche_id: pool_a_tranche_1_id::(), + investor: vec_to_fixed_array(lp::utils::remote_account_of::( + Keyring::TrancheInvestor(1) + )), + currency: utils::index_lp(evm, names::USDC), + currency_payout: DEFAULT_INVESTMENT_AMOUNT, + fulfilled_invest_amount: DEFAULT_INVESTMENT_AMOUNT, + }, + }, ) }); diff --git a/runtime/integration-tests/src/cases/lp/transfers.rs b/runtime/integration-tests/src/cases/lp/transfers.rs index 29cccca6d0..9475dafd98 100644 --- a/runtime/integration-tests/src/cases/lp/transfers.rs +++ b/runtime/integration-tests/src/cases/lp/transfers.rs @@ -19,7 +19,8 @@ use ethabi::{ethereum_types::U256, Token}; use frame_support::traits::OriginTrait; use frame_system::pallet_prelude::OriginFor; use pallet_liquidity_pools::Message; -use sp_core::ByteArray; +use pallet_liquidity_pools_gateway::message::GatewayMessage; +use sp_core::{ByteArray, Get}; use crate::{ cases::lp::{ @@ -282,13 +283,17 @@ fn transfer_tranche_tokens_domain_to_local_to_domain() { lp::utils::process_outbound::(|msg| { assert_eq!( msg, - Message::TransferTrancheTokens { - pool_id: POOL_A, - tranche_id: pool_a_tranche_1_id::(), - domain: Domain::EVM(EVM_DOMAIN_CHAIN_ID).into(), - receiver: as_h160_32bytes(Keyring::TrancheInvestor(2)), - amount: AMOUNT, - } + GatewayMessage::Outbound { + sender: ::Sender::get(), + destination: Domain::EVM(EVM_DOMAIN_CHAIN_ID), + message: Message::TransferTrancheTokens { + pool_id: POOL_A, + tranche_id: pool_a_tranche_1_id::(), + domain: Domain::EVM(EVM_DOMAIN_CHAIN_ID).into(), + receiver: as_h160_32bytes(Keyring::TrancheInvestor(2)), + amount: AMOUNT, + }, + }, ); }); }); diff --git a/runtime/integration-tests/src/cases/lp/utils.rs b/runtime/integration-tests/src/cases/lp/utils.rs index c2fc84de57..fcc4904a17 100644 --- a/runtime/integration-tests/src/cases/lp/utils.rs +++ b/runtime/integration-tests/src/cases/lp/utils.rs @@ -103,17 +103,17 @@ pub fn verify_outbound_failure_on_lp(to: H160) { assert_eq!(status.to.unwrap().0, to.0); assert!(!receipt_ok(receipt)); assert!(matches!( - last_event::>(), - pallet_liquidity_pools_gateway::Event::::OutboundMessageExecutionFailure { .. } + last_event::>(), + pallet_liquidity_pools_gateway_queue::Event::::MessageExecutionFailure { .. } )); } pub fn verify_outbound_success( - message: ::Message, + message: ::Message, ) { assert!(matches!( - last_event::>(), - pallet_liquidity_pools_gateway::Event::::OutboundMessageExecutionSuccess { + last_event::>(), + pallet_liquidity_pools_gateway_queue::Event::::MessageExecutionSuccess { message: processed_message, .. } if processed_message == message @@ -121,17 +121,17 @@ pub fn verify_outbound_success( } pub fn process_outbound( - mut verifier: impl FnMut(::Message), + mut verifier: impl FnMut(::Message), ) { - let msgs = pallet_liquidity_pools_gateway::OutboundMessageQueue::::iter() - .map(|(nonce, (_, _, msg))| (nonce, msg)) + let msgs = pallet_liquidity_pools_gateway_queue::MessageQueue::::iter() + .map(|(nonce, msg)| (nonce, msg)) .collect::>(); // The function should panic if there is nothing to be processed. assert!(msgs.len() > 0); msgs.into_iter().for_each(|(nonce, msg)| { - pallet_liquidity_pools_gateway::Pallet::::process_outbound_message( + pallet_liquidity_pools_gateway_queue::Pallet::::process_message( OriginFor::::signed(Keyring::Alice.into()), nonce, ) diff --git a/runtime/integration-tests/src/cases/routers.rs b/runtime/integration-tests/src/cases/routers.rs index 55d392806f..b56d7daf3d 100644 --- a/runtime/integration-tests/src/cases/routers.rs +++ b/runtime/integration-tests/src/cases/routers.rs @@ -1,5 +1,5 @@ use cfg_primitives::Balance; -use cfg_traits::liquidity_pools::OutboundQueue; +use cfg_traits::liquidity_pools::OutboundMessageHandler; use cfg_types::{ domain_address::Domain, tokens::{AssetMetadata, CurrencyId}, @@ -10,6 +10,7 @@ use liquidity_pools_gateway_routers::{ FeeValues, XCMRouter, XcmDomain, }; use pallet_liquidity_pools::Message; +use pallet_liquidity_pools_gateway::message::GatewayMessage; use polkadot_core_primitives::BlakeTwo256; use runtime_common::gateway::get_gateway_h160_account; use sp_core::{Get, H160, U256}; @@ -115,18 +116,20 @@ fn check_submission(mut env: impl Env, domain_router: DomainRoute }; assert_ok!( - as OutboundQueue>::submit( + as OutboundMessageHandler>::handle( Keyring::Alice.into(), TEST_DOMAIN, msg.clone(), ) ); - pallet_liquidity_pools_gateway::Event::::OutboundMessageExecutionSuccess { - sender: T::Sender::get(), - domain: TEST_DOMAIN, - message: msg, - nonce: T::OutboundMessageNonce::one(), + pallet_liquidity_pools_gateway_queue::Event::::MessageExecutionSuccess { + message: GatewayMessage::Outbound { + sender: ::Sender::get(), + destination: TEST_DOMAIN, + message: msg, + }, + nonce: T::MessageNonce::one(), } }); diff --git a/runtime/integration-tests/src/config.rs b/runtime/integration-tests/src/config.rs index 8126ffbe4f..3fa6da2632 100644 --- a/runtime/integration-tests/src/config.rs +++ b/runtime/integration-tests/src/config.rs @@ -22,6 +22,7 @@ use frame_support::{ }; use liquidity_pools_gateway_routers::DomainRouter; use pallet_liquidity_pools::Message; +use pallet_liquidity_pools_gateway::message::GatewayMessage; use pallet_transaction_payment::CurrencyAdapter; use parity_scale_codec::Codec; use runtime_common::{ @@ -136,7 +137,7 @@ pub trait Runtime: TrancheId = TrancheId, BalanceRatio = Ratio, > + pallet_liquidity_pools_gateway::Config, Message = Message> - + pallet_liquidity_pools_gateway_queue::Config + + pallet_liquidity_pools_gateway_queue::Config> + pallet_xcm_transactor::Config + pallet_ethereum::Config + pallet_ethereum_transaction::Config diff --git a/runtime/integration-tests/src/env.rs b/runtime/integration-tests/src/env.rs index dc1eb757ff..3c55821356 100644 --- a/runtime/integration-tests/src/env.rs +++ b/runtime/integration-tests/src/env.rs @@ -155,7 +155,8 @@ pub trait Env: Default { fn check_event(&self, event: impl Into) -> Option<()> { self.parachain_state(|| { let event = event.into(); - frame_system::Pallet::::events() + let events = frame_system::Pallet::::events(); + events .into_iter() .rev() .find(|record| record.event == event)