Skip to content

Commit

Permalink
Make liquid staking pallet mocks compile successfully .ready to cover…
Browse files Browse the repository at this point in the history
… lsd with unit tests (#4273)
  • Loading branch information
RustNinja authored Nov 1, 2023
2 parents 17f8108 + 4ef0ee5 commit 24342eb
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 114 deletions.
1 change: 1 addition & 0 deletions code/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions code/parachain/frame/liquid-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }

Expand Down
4 changes: 2 additions & 2 deletions code/parachain/frame/liquid-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use pallet_xcm_helper::ump::RewardDestination;

// mod benchmarking;

// #[cfg(test)]
// mod mock;
#[cfg(test)]
mod mock;
// #[cfg(test)]
// mod tests;

Expand Down
231 changes: 119 additions & 112 deletions code/parachain/frame/liquid-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(),
}
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 24342eb

Please sign in to comment.