From 4ef0ee5c0d4d8dc9e04797ed87edef0a5ab146e9 Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 1 Nov 2023 23:29:01 +0000 Subject: [PATCH] liquid staking pallet mocks compiles. ready to cover with unit tests --- code/Cargo.lock | 1 + .../parachain/frame/liquid-staking/Cargo.toml | 1 + .../parachain/frame/liquid-staking/src/lib.rs | 4 +- .../frame/liquid-staking/src/mock.rs | 231 +++++++++--------- 4 files changed, 123 insertions(+), 114 deletions(-) diff --git a/code/Cargo.lock b/code/Cargo.lock index 79c86a1ba3d..8c06ff0bfdc 100644 --- a/code/Cargo.lock +++ b/code/Cargo.lock @@ -10504,6 +10504,7 @@ dependencies = [ "pallet-assets 1.0.0", "pallet-babe", "pallet-balances", + "pallet-message-queue", "pallet-session", "pallet-staking", "pallet-timestamp", diff --git a/code/parachain/frame/liquid-staking/Cargo.toml b/code/parachain/frame/liquid-staking/Cargo.toml index b225b9f05ef..79a6a18649a 100644 --- a/code/parachain/frame/liquid-staking/Cargo.toml +++ b/code/parachain/frame/liquid-staking/Cargo.toml @@ -61,6 +61,7 @@ orml-unknown-tokens = { workspace = true, default-features = false } pallet-assets = { path = "../assets" } orml-tokens = { workspace = true } composable-support = { path = "../composable-support", default-features = false } +pallet-message-queue = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.43" } # pallet-currency-adapter = { workspace = true, features = ['std'] } diff --git a/code/parachain/frame/liquid-staking/src/lib.rs b/code/parachain/frame/liquid-staking/src/lib.rs index 9576e0e1dc8..0b946ca5071 100644 --- a/code/parachain/frame/liquid-staking/src/lib.rs +++ b/code/parachain/frame/liquid-staking/src/lib.rs @@ -31,8 +31,8 @@ use pallet_xcm_helper::ump::RewardDestination; // mod benchmarking; -// #[cfg(test)] -// mod mock; +#[cfg(test)] +mod mock; // #[cfg(test)] // mod tests; diff --git a/code/parachain/frame/liquid-staking/src/mock.rs b/code/parachain/frame/liquid-staking/src/mock.rs index fd28c220cca..13a909ee49f 100644 --- a/code/parachain/frame/liquid-staking/src/mock.rs +++ b/code/parachain/frame/liquid-staking/src/mock.rs @@ -742,68 +742,68 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities { let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| { - Assets::force_create(RuntimeOrigin::root(), KSM.into(), Id(ALICE), true, 1).unwrap(); - Assets::force_set_metadata( - RuntimeOrigin::root(), - KSM.into(), - b"Kusama".to_vec(), - b"KSM".to_vec(), - 12, - false, - ) - .unwrap(); - Assets::force_create(RuntimeOrigin::root(), SKSM.into(), Id(ALICE), true, 1).unwrap(); - Assets::force_set_metadata( - RuntimeOrigin::root(), - SKSM.into(), - b"Parallel Kusama".to_vec(), - b"sKSM".to_vec(), - 12, - false, - ) - .unwrap(); - Assets::force_create(RuntimeOrigin::root(), KSM_U.into(), Id(ALICE), true, 1).unwrap(); - Assets::force_set_metadata( - RuntimeOrigin::root(), - KSM_U.into(), - b"Kusama Ubonding".to_vec(), - b"KSM_U".to_vec(), - 12, - false, - ) - .unwrap(); - - Assets::mint( - RuntimeOrigin::signed(ALICE), - KSM.into(), - Id(ALICE), - ksm(100f64), - ) - .unwrap(); - Assets::mint( - RuntimeOrigin::signed(ALICE), - SKSM.into(), - Id(ALICE), - ksm(100f64), - ) - .unwrap(); - Assets::mint( - RuntimeOrigin::signed(ALICE), - KSM.into(), - Id(BOB), - ksm(20000f64), - ) - .unwrap(); + // Assets::force_create(RuntimeOrigin::root(), KSM.into(), Id(ALICE), true, 1).unwrap(); + // Assets::force_set_metadata( + // RuntimeOrigin::root(), + // KSM.into(), + // b"Kusama".to_vec(), + // b"KSM".to_vec(), + // 12, + // false, + // ) + // .unwrap(); + // Assets::force_create(RuntimeOrigin::root(), SKSM.into(), Id(ALICE), true, 1).unwrap(); + // Assets::force_set_metadata( + // RuntimeOrigin::root(), + // SKSM.into(), + // b"Parallel Kusama".to_vec(), + // b"sKSM".to_vec(), + // 12, + // false, + // ) + // .unwrap(); + // Assets::force_create(RuntimeOrigin::root(), KSM_U.into(), Id(ALICE), true, 1).unwrap(); + // Assets::force_set_metadata( + // RuntimeOrigin::root(), + // KSM_U.into(), + // b"Kusama Ubonding".to_vec(), + // b"KSM_U".to_vec(), + // 12, + // false, + // ) + // .unwrap(); + + // Assets::mint( + // RuntimeOrigin::signed(ALICE), + // KSM.into(), + // Id(ALICE), + // ksm(100f64), + // ) + // .unwrap(); + // Assets::mint( + // RuntimeOrigin::signed(ALICE), + // SKSM.into(), + // Id(ALICE), + // ksm(100f64), + // ) + // .unwrap(); + // Assets::mint( + // RuntimeOrigin::signed(ALICE), + // KSM.into(), + // Id(BOB), + // ksm(20000f64), + // ) + // .unwrap(); LiquidStaking::update_staking_ledger_cap(RuntimeOrigin::signed(BOB), ksm(10000f64)) .unwrap(); - Assets::mint( - RuntimeOrigin::signed(ALICE), - KSM.into(), - Id(XcmHelper::account_id()), - ksm(100f64), - ) - .unwrap(); + // Assets::mint( + // RuntimeOrigin::signed(ALICE), + // KSM.into(), + // Id(XcmHelper::account_id()), + // ksm(100f64), + // ) + // .unwrap(); // Loans::add_market(RuntimeOrigin::root(), KSM, market_mock(PKSM)).unwrap(); // Loans::activate_market(RuntimeOrigin::root(), KSM).unwrap(); @@ -827,10 +827,17 @@ decl_test_parachain! { } } +use pallet_message_queue; +use xcm_simulator::TestExt; + decl_test_relay_chain! { pub struct Relay { Runtime = kusama_runtime::Runtime, - XcmConfig = kusama_runtime::xcm_config::XcmConfig, + RuntimeCall = kusama_runtime::RuntimeCall, + RuntimeEvent = kusama_runtime::RuntimeEvent, + XcmConfig = kusama_runtime::xcm_config::XcmConfig, + MessageQueue = kusama_runtime::MessageQueue, + System = kusama_runtime::System, new_ext = relay_ext(), } } @@ -881,58 +888,58 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| { - Assets::force_create(RuntimeOrigin::root(), KSM.into(), Id(ALICE), true, 1).unwrap(); - Assets::force_set_metadata( - RuntimeOrigin::root(), - KSM.into(), - b"Kusama".to_vec(), - b"KSM".to_vec(), - 12, - false, - ) - .unwrap(); - Assets::force_create(RuntimeOrigin::root(), SKSM.into(), Id(ALICE), true, 1).unwrap(); - Assets::force_set_metadata( - RuntimeOrigin::root(), - SKSM.into(), - b"Parallel Kusama".to_vec(), - b"sKSM".to_vec(), - 12, - false, - ) - .unwrap(); - Assets::force_create(RuntimeOrigin::root(), KSM_U.into(), Id(ALICE), true, 1).unwrap(); - Assets::force_set_metadata( - RuntimeOrigin::root(), - KSM_U.into(), - b"Kusama Ubonding".to_vec(), - b"KSM_U".to_vec(), - 12, - false, - ) - .unwrap(); - - Assets::mint( - RuntimeOrigin::signed(ALICE), - KSM.into(), - Id(ALICE), - ksm(10000f64), - ) - .unwrap(); - Assets::mint( - RuntimeOrigin::signed(ALICE), - KSM.into(), - Id(BOB), - ksm(20000f64), - ) - .unwrap(); - Assets::mint( - RuntimeOrigin::signed(ALICE), - KSM.into(), - Id(XcmHelper::account_id()), - ksm(30f64), - ) - .unwrap(); + // Assets::force_create(RuntimeOrigin::root(), KSM.into(), Id(ALICE), true, 1).unwrap(); + // Assets::force_set_metadata( + // RuntimeOrigin::root(), + // KSM.into(), + // b"Kusama".to_vec(), + // b"KSM".to_vec(), + // 12, + // false, + // ) + // .unwrap(); + // Assets::force_create(RuntimeOrigin::root(), SKSM.into(), Id(ALICE), true, 1).unwrap(); + // Assets::force_set_metadata( + // RuntimeOrigin::root(), + // SKSM.into(), + // b"Parallel Kusama".to_vec(), + // b"sKSM".to_vec(), + // 12, + // false, + // ) + // .unwrap(); + // Assets::force_create(RuntimeOrigin::root(), KSM_U.into(), Id(ALICE), true, 1).unwrap(); + // Assets::force_set_metadata( + // RuntimeOrigin::root(), + // KSM_U.into(), + // b"Kusama Ubonding".to_vec(), + // b"KSM_U".to_vec(), + // 12, + // false, + // ) + // .unwrap(); + + // Assets::mint( + // RuntimeOrigin::signed(ALICE), + // KSM.into(), + // Id(ALICE), + // ksm(10000f64), + // ) + // .unwrap(); + // Assets::mint( + // RuntimeOrigin::signed(ALICE), + // KSM.into(), + // Id(BOB), + // ksm(20000f64), + // ) + // .unwrap(); + // Assets::mint( + // RuntimeOrigin::signed(ALICE), + // KSM.into(), + // Id(XcmHelper::account_id()), + // ksm(30f64), + // ) + // .unwrap(); // Loans::add_market(RuntimeOrigin::root(), KSM, market_mock(PKSM)).unwrap(); // Loans::activate_market(RuntimeOrigin::root(), KSM).unwrap();