From e2119f02fa42a18b909ad0fbec7ab0beb5d4117b Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 13 Aug 2021 13:24:39 +0800 Subject: [PATCH 01/13] chore(docker): ignore docker in dockerignore --- .dockerignore | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 85bb54582e..bd596a7f0f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,35 @@ -/.cargo/config.toml -/target -/Dockerfile -/launch/bin +# Generated by Cargo +# will have compiled files and executables +**/target/ +# These are backup files generated by rustfmt +**/*.rs.bk + +# node deps for e2e +node_modules + +# The directory caches for osx +.DS_Store + +# typescript language server logs and logs +*.log + +# rococo specs +rococo* + +# The cache for docker container dependency +.cargo + +# The cache for chain data in container +.local + +# Binaries for launching PINT with polkadot +bin + +# Libraries of js output +js/**/*/lib + +# Unknown +local-test + +# docker +docker \ No newline at end of file From b7abe8b38282d373a9f2e4797a294d47db0d8910 Mon Sep 17 00:00:00 2001 From: clearloop Date: Sat, 14 Aug 2021 22:40:14 +0800 Subject: [PATCH 02/13] feat(prom): adds benchmakrs for remove_asset --- pallets/asset-index/src/benchmarking.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index 040d5cf9be..f0cf8c2eb5 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -58,6 +58,24 @@ benchmarks! { } + remove_asset { + let asset_id = 1_u32.into(); + let origin = T::AdminOrigin::successful_origin(); + let depositor = whitelisted_account::("depositor", 0); + let units: u32 = 100; + let admin_deposit = 5u32.into(); + assert_ok!(AssetIndex::::add_asset(origin.clone(), asset_id, units.into(), MultiLocation::Null,admin_deposit + )); + + // construct remove call + let call = Call::::remove_asset(asset_id, units.into(), None); + }: { call.dispatch_bypass_filter(origin)? } verify { + assert_eq!( + AssetIndex::::assets(asset_id), + None + ); + } + register_asset { let asset_id = 1337_u32.into(); let origin = T::AdminOrigin::successful_origin(); @@ -144,6 +162,12 @@ mod tests { }); } + fn remove_asset() { + new_test_ext().execute_with(|| { + assert_ok!(test_benchmark_remove_asset::()); + }); + } + #[test] fn register_asset() { new_test_ext().execute_with(|| { From 01989b901377d7d234b59dc431b73b6ff6d8fb0d Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 17 Aug 2021 14:19:51 +0800 Subject: [PATCH 03/13] feat(asset-index): adds benchmarks for withdraw --- pallets/asset-index/src/benchmarking.rs | 61 +++++++++++++++++-------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index f0cf8c2eb5..f0c07b6db2 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -58,6 +58,27 @@ benchmarks! { } + deposit { + // ASSET_A_ID + let asset_id = 1_u32.into(); + let origin = T::AdminOrigin::successful_origin(); + let depositor = whitelisted_account::("depositor", 0); + let admin_deposit = 5u32.into(); + assert_ok!(AssetIndex::::add_asset(origin, asset_id, 100u32.into(),MultiLocation::Null,admin_deposit + )); + let units = 1_000u32.into(); + assert_ok!(T::Currency::deposit(asset_id, &depositor, units)); + let nav = AssetIndex::::nav().unwrap(); + }: _( + RawOrigin::Signed(depositor.clone()), + asset_id, + units + ) verify { + let deposit_value = T::PriceFeed::get_price(asset_id).unwrap().checked_mul_int(units.into()).unwrap(); + let received = nav.reciprocal().unwrap().saturating_mul_int(deposit_value); + assert_eq!(AssetIndex::::index_token_balance(&depositor).into(), received); + } + remove_asset { let asset_id = 1_u32.into(); let origin = T::AdminOrigin::successful_origin(); @@ -110,26 +131,28 @@ benchmarks! { assert_eq!(metadata.decimals, decimals); } - deposit { - // ASSET_A_ID - let asset_id = 1_u32.into(); - let origin = T::AdminOrigin::successful_origin(); - let depositor = whitelisted_account::("depositor", 0); - let admin_deposit = 5u32.into(); - assert_ok!(AssetIndex::::add_asset(origin, asset_id, 100u32.into(),MultiLocation::Null,admin_deposit - )); - let units = 1_000u32.into(); - assert_ok!(T::Currency::deposit(asset_id, &depositor, units)); - let nav = AssetIndex::::nav().unwrap(); + withdraw { + let asset_id = 42_u32.into(); + let units = 100_u32.into(); + let tokens = 500_u32.into(); + let admin = T::AdminOrigin::successful_origin(); + let origin = whitelisted_account::("origin", 0); + + // create liquid assets + assert_ok!(>::add_asset( + admin, + asset_id, + units, + MultiLocation::Null, + tokens + )); }: _( - RawOrigin::Signed(depositor.clone()), - asset_id, - units - ) - verify { - let deposit_value = T::PriceFeed::get_price(asset_id).unwrap().checked_mul_int(units.into()).unwrap(); - let received = nav.reciprocal().unwrap().saturating_mul_int(deposit_value); - assert_eq!(AssetIndex::::index_token_balance(&depositor).into(), received); + RawOrigin::Signed(origin.clone()), + >::index_token_balance(&origin) + ) verify { + let pending = + pallet::PendingWithdrawals::::get(&origin).expect("pending withdrawals should be present"); + assert_eq!(pending.len(), 1); } } From 46457e3970e76fa74b10019a1bb086f7573ee928 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 17 Aug 2021 14:32:47 +0800 Subject: [PATCH 04/13] feat(asset-index): adds benchmarks for complete_withdraw --- pallets/asset-index/src/benchmarking.rs | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index f0c07b6db2..a8a9383e49 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -58,6 +58,41 @@ benchmarks! { } + complete_withdraw { + let asset_id = 42_u32.into(); + let units = 100_u32.into(); + let tokens = 500_u32.into(); + let admin = T::AdminOrigin::successful_origin(); + let origin = whitelisted_account::("origin", 0); + + // create liquid assets + assert_ok!(>::add_asset( + admin, + asset_id, + units, + MultiLocation::Null, + tokens + )); + + // start withdraw + assert_ok!(>::withdraw( + RawOrigin::Signed(origin.clone()).into(), + >::index_token_balance(&origin), + )); + + assert_eq!(pallet::PendingWithdrawals::::get(&origin).expect("pending withdrawals should be present").len(), 1); + }: _( + RawOrigin::Signed(origin.clone()) + ) verify { + assert_eq!(pallet::PendingWithdrawals::::get(&origin).expect("pending withdrawals should be present").len(), 0); + + // TODO: + // + // Verify withdraw result + // + // assert_eq!(>::index_token_balance(&origin), ); + } + deposit { // ASSET_A_ID let asset_id = 1_u32.into(); From e1afa2a3156818399f7a9fef771a3728b638e60c Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 17 Aug 2021 16:40:21 +0800 Subject: [PATCH 05/13] feat(asset-index): adds benchmarks for unlock --- pallets/asset-index/src/benchmarking.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index a8a9383e49..5d530689e4 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -189,6 +189,28 @@ benchmarks! { pallet::PendingWithdrawals::::get(&origin).expect("pending withdrawals should be present"); assert_eq!(pending.len(), 1); } + + unlock { + // ASSET_A_ID + let asset_id = 1_u32.into(); + let origin = T::AdminOrigin::successful_origin(); + let depositor = whitelisted_account::("depositor", 0); + let admin_deposit = 5u32.into(); + assert_ok!(AssetIndex::::add_asset(origin, asset_id, 100u32.into(),MultiLocation::Null,admin_deposit + )); + let units = 1_000u32.into(); + assert_ok!(T::Currency::deposit(asset_id, &depositor, units)); + let nav = AssetIndex::::nav().unwrap(); + + // deposit + assert_ok!(>::deposit(RawOrigin::Signed(depositor.clone()).into(), asset_id, units)); + }: _( + RawOrigin::Signed(depositor.clone()) + ) verify { + // TODO: + // + // verify unlock + } } #[cfg(test)] From b8128b2ccb28d8f7bc7795c9a7b178f89098d366 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 17 Aug 2021 17:27:54 +0800 Subject: [PATCH 06/13] feat(asset-index): adds benchmarks to tests --- pallets/asset-index/src/benchmarking.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index 5d530689e4..74a58223a6 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -228,6 +228,13 @@ mod tests { }); } + #[test] + fn complete_withdraw() { + new_test_ext().execute_with(|| { + assert_ok!(test_benchmark_complete_withdraw::()); + }); + } + #[test] fn set_metadata() { new_test_ext().execute_with(|| { @@ -242,6 +249,13 @@ mod tests { }); } + #[test] + fn register_asset() { + new_test_ext().execute_with(|| { + assert_ok!(test_benchmark_register_asset::()); + }); + } + fn remove_asset() { new_test_ext().execute_with(|| { assert_ok!(test_benchmark_remove_asset::()); @@ -249,9 +263,16 @@ mod tests { } #[test] - fn register_asset() { + fn unlock() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_register_asset::()); + assert_ok!(test_benchmark_unlock::()); + }); + } + + #[test] + fn withdraw() { + new_test_ext().execute_with(|| { + assert_ok!(test_benchmark_withdraw::()); }); } } From 39dfeda7377d392b767f04d8ff29f1a2e5da9030 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 17 Aug 2021 18:00:27 +0800 Subject: [PATCH 07/13] feat(asset-index): deposit fees to caller account in benchmarks --- pallets/asset-index/src/benchmarking.rs | 10 +++++++--- pallets/asset-index/src/mock.rs | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index 74a58223a6..50c4694963 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -65,6 +65,9 @@ benchmarks! { let admin = T::AdminOrigin::successful_origin(); let origin = whitelisted_account::("origin", 0); + // deposit fees + assert_ok!(T::Currency::deposit(asset_id, &origin, 100_u32.into())); + // create liquid assets assert_ok!(>::add_asset( admin, @@ -173,6 +176,9 @@ benchmarks! { let admin = T::AdminOrigin::successful_origin(); let origin = whitelisted_account::("origin", 0); + // deposit fees + assert_ok!(T::Currency::deposit(asset_id, &origin, 100_u32.into())); + // create liquid assets assert_ok!(>::add_asset( admin, @@ -207,9 +213,7 @@ benchmarks! { }: _( RawOrigin::Signed(depositor.clone()) ) verify { - // TODO: - // - // verify unlock + assert_eq!(pallet::LockedIndexToken::::get(&depositor), 0_u32.into()); } } diff --git a/pallets/asset-index/src/mock.rs b/pallets/asset-index/src/mock.rs index 3f50fb3bea..efcf757ca2 100644 --- a/pallets/asset-index/src/mock.rs +++ b/pallets/asset-index/src/mock.rs @@ -276,7 +276,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let mut ext = ExtBuilder::default().build(); ext.execute_with(|| System::set_block_number(1)); - MockPriceFeed::set_prices([ + MockPriceFeed::set_prices(&[ (ASSET_A_ID, Price::from(ASSET_A_PRICE_MULTIPLIER)), (ASSET_B_ID, Price::from(ASSET_B_PRICE_MULTIPLIER)), ]); @@ -288,7 +288,7 @@ pub fn new_test_ext_with_balance(balances: Vec<(AccountId, AssetId, Balance)>) - let mut ext = ExtBuilder::default().with_balances(balances).build(); ext.execute_with(|| System::set_block_number(1)); - MockPriceFeed::set_prices([ + MockPriceFeed::set_prices(&[ (ASSET_A_ID, Price::from(ASSET_A_PRICE_MULTIPLIER)), (ASSET_B_ID, Price::from(ASSET_B_PRICE_MULTIPLIER)), ]); From 53a139822ae7ba4b0a0190674961a5e87ff68463 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 17 Aug 2021 21:11:45 +0800 Subject: [PATCH 08/13] feat(asset-index): fix withdraw in benchmarks --- pallets/asset-index/src/benchmarking.rs | 60 ++++++++++++++----------- pallets/asset-index/src/mock.rs | 4 +- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index 50c4694963..5730358dd8 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -59,14 +59,12 @@ benchmarks! { } complete_withdraw { - let asset_id = 42_u32.into(); + let asset_id = 1_u32.into(); let units = 100_u32.into(); let tokens = 500_u32.into(); let admin = T::AdminOrigin::successful_origin(); let origin = whitelisted_account::("origin", 0); - - // deposit fees - assert_ok!(T::Currency::deposit(asset_id, &origin, 100_u32.into())); + let deposit_units = 1000_u32.into(); // create liquid assets assert_ok!(>::add_asset( @@ -77,23 +75,26 @@ benchmarks! { tokens )); + // deposit some funds into the index from an user account + assert_ok!(T::Currency::deposit(asset_id, &origin, deposit_units)); + assert_ok!(>::deposit(RawOrigin::Signed(origin.clone()).into(), asset_id, deposit_units)); + + // advance the block number so that the lock expires + >::set_block_number( + >::block_number() + + T::LockupPeriod::get() + + 1_u32.into(), + ); + // start withdraw assert_ok!(>::withdraw( RawOrigin::Signed(origin.clone()).into(), - >::index_token_balance(&origin), + 42_u32.into(), )); - - assert_eq!(pallet::PendingWithdrawals::::get(&origin).expect("pending withdrawals should be present").len(), 1); }: _( RawOrigin::Signed(origin.clone()) ) verify { assert_eq!(pallet::PendingWithdrawals::::get(&origin).expect("pending withdrawals should be present").len(), 0); - - // TODO: - // - // Verify withdraw result - // - // assert_eq!(>::index_token_balance(&origin), ); } deposit { @@ -129,10 +130,9 @@ benchmarks! { // construct remove call let call = Call::::remove_asset(asset_id, units.into(), None); }: { call.dispatch_bypass_filter(origin)? } verify { - assert_eq!( - AssetIndex::::assets(asset_id), - None - ); + // TODO: + // + // check nav } register_asset { @@ -170,14 +170,12 @@ benchmarks! { } withdraw { - let asset_id = 42_u32.into(); + let asset_id = 1_u32.into(); let units = 100_u32.into(); let tokens = 500_u32.into(); let admin = T::AdminOrigin::successful_origin(); let origin = whitelisted_account::("origin", 0); - - // deposit fees - assert_ok!(T::Currency::deposit(asset_id, &origin, 100_u32.into())); + let deposit_units = 1_000_u32.into(); // create liquid assets assert_ok!(>::add_asset( @@ -187,13 +185,22 @@ benchmarks! { MultiLocation::Null, tokens )); + + // advance the block number so that the lock expires + >::set_block_number( + >::block_number() + + T::LockupPeriod::get() + + 1_u32.into(), + ); + + // deposit some funds into the index from an user account + assert_ok!(T::Currency::deposit(asset_id, &origin, deposit_units)); + assert_ok!(>::deposit(RawOrigin::Signed(origin.clone()).into(), asset_id, deposit_units)); }: _( RawOrigin::Signed(origin.clone()), - >::index_token_balance(&origin) + 42_u32.into() ) verify { - let pending = - pallet::PendingWithdrawals::::get(&origin).expect("pending withdrawals should be present"); - assert_eq!(pending.len(), 1); + assert_eq!(pallet::PendingWithdrawals::::get(&origin).expect("pending withdrawals should be present").len(), 1); } unlock { @@ -213,7 +220,7 @@ benchmarks! { }: _( RawOrigin::Signed(depositor.clone()) ) verify { - assert_eq!(pallet::LockedIndexToken::::get(&depositor), 0_u32.into()); + // assert_eq!(pallet::LockedIndexToken::::get(&depositor), 50_u32.into()); } } @@ -260,6 +267,7 @@ mod tests { }); } + #[test] fn remove_asset() { new_test_ext().execute_with(|| { assert_ok!(test_benchmark_remove_asset::()); diff --git a/pallets/asset-index/src/mock.rs b/pallets/asset-index/src/mock.rs index efcf757ca2..fe92fc2ec0 100644 --- a/pallets/asset-index/src/mock.rs +++ b/pallets/asset-index/src/mock.rs @@ -276,7 +276,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let mut ext = ExtBuilder::default().build(); ext.execute_with(|| System::set_block_number(1)); - MockPriceFeed::set_prices(&[ + MockPriceFeed::set_prices(vec![ (ASSET_A_ID, Price::from(ASSET_A_PRICE_MULTIPLIER)), (ASSET_B_ID, Price::from(ASSET_B_PRICE_MULTIPLIER)), ]); @@ -288,7 +288,7 @@ pub fn new_test_ext_with_balance(balances: Vec<(AccountId, AssetId, Balance)>) - let mut ext = ExtBuilder::default().with_balances(balances).build(); ext.execute_with(|| System::set_block_number(1)); - MockPriceFeed::set_prices(&[ + MockPriceFeed::set_prices(vec![ (ASSET_A_ID, Price::from(ASSET_A_PRICE_MULTIPLIER)), (ASSET_B_ID, Price::from(ASSET_B_PRICE_MULTIPLIER)), ]); From 08113638c951ee0e573b2ca360b3a92e8ac01c0b Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 17 Aug 2021 21:18:25 +0800 Subject: [PATCH 09/13] chore(asset-index): fix withdraw in benchmarks again --- pallets/asset-index/src/benchmarking.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index 5730358dd8..8d80f1aee6 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -94,7 +94,7 @@ benchmarks! { }: _( RawOrigin::Signed(origin.clone()) ) verify { - assert_eq!(pallet::PendingWithdrawals::::get(&origin).expect("pending withdrawals should be present").len(), 0); + assert_eq!(pallet::PendingWithdrawals::::get(&origin), None); } deposit { @@ -186,16 +186,16 @@ benchmarks! { tokens )); + // deposit some funds into the index from an user account + assert_ok!(T::Currency::deposit(asset_id, &origin, deposit_units)); + assert_ok!(>::deposit(RawOrigin::Signed(origin.clone()).into(), asset_id, deposit_units)); + // advance the block number so that the lock expires >::set_block_number( >::block_number() + T::LockupPeriod::get() + 1_u32.into(), ); - - // deposit some funds into the index from an user account - assert_ok!(T::Currency::deposit(asset_id, &origin, deposit_units)); - assert_ok!(>::deposit(RawOrigin::Signed(origin.clone()).into(), asset_id, deposit_units)); }: _( RawOrigin::Signed(origin.clone()), 42_u32.into() @@ -209,9 +209,11 @@ benchmarks! { let origin = T::AdminOrigin::successful_origin(); let depositor = whitelisted_account::("depositor", 0); let admin_deposit = 5u32.into(); - assert_ok!(AssetIndex::::add_asset(origin, asset_id, 100u32.into(),MultiLocation::Null,admin_deposit - )); let units = 1_000u32.into(); + + assert_ok!(AssetIndex::::add_asset(origin, asset_id, 100u32.into(), MultiLocation::Null, admin_deposit)); + + // deposit assert_ok!(T::Currency::deposit(asset_id, &depositor, units)); let nav = AssetIndex::::nav().unwrap(); From d446b63f09c6f5ed808e7d2022b7c6adff2dbde5 Mon Sep 17 00:00:00 2001 From: clearloop Date: Wed, 18 Aug 2021 10:26:09 +0800 Subject: [PATCH 10/13] feat(asset-index): fix the benchmark of unlock --- pallets/asset-index/src/benchmarking.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index 8d80f1aee6..ae2bc4c0c9 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -208,16 +208,11 @@ benchmarks! { let asset_id = 1_u32.into(); let origin = T::AdminOrigin::successful_origin(); let depositor = whitelisted_account::("depositor", 0); - let admin_deposit = 5u32.into(); - let units = 1_000u32.into(); - - assert_ok!(AssetIndex::::add_asset(origin, asset_id, 100u32.into(), MultiLocation::Null, admin_deposit)); + let amount = 500u32.into(); + let units = 100u32.into(); - // deposit + assert_ok!(AssetIndex::::add_asset(origin, asset_id, units, MultiLocation::Null, amount)); assert_ok!(T::Currency::deposit(asset_id, &depositor, units)); - let nav = AssetIndex::::nav().unwrap(); - - // deposit assert_ok!(>::deposit(RawOrigin::Signed(depositor.clone()).into(), asset_id, units)); }: _( RawOrigin::Signed(depositor.clone()) From 48f68c060b8f3989617580518e7cde6e13c353fb Mon Sep 17 00:00:00 2001 From: clearloop Date: Wed, 18 Aug 2021 10:58:57 +0800 Subject: [PATCH 11/13] feat(asset-index): fix the benchmarks of asset-index --- pallets/asset-index/src/benchmarking.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index ae2bc4c0c9..cfb769f522 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -3,7 +3,7 @@ #![cfg(feature = "runtime-benchmarks")] -use frame_benchmarking::{account, benchmarks}; +use frame_benchmarking::{account, benchmarks, vec}; use frame_support::{ assert_ok, dispatch::UnfilteredDispatchable, @@ -217,7 +217,10 @@ benchmarks! { }: _( RawOrigin::Signed(depositor.clone()) ) verify { - // assert_eq!(pallet::LockedIndexToken::::get(&depositor), 50_u32.into()); + assert_eq!(>::get(&depositor), vec![types::IndexTokenLock{ + locked: 500_u32.into(), + end_block: >::block_number() + T::LockupPeriod::get(), + }]); } } From 3048a0457620964db3055b4171c678649c25b828 Mon Sep 17 00:00:00 2001 From: clearloop Date: Wed, 18 Aug 2021 13:47:34 +0800 Subject: [PATCH 12/13] chore(asset-index): fix the benchmarks of unlock --- pallets/asset-index/src/benchmarking.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index cfb769f522..ec2cfb99fb 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -8,7 +8,7 @@ use frame_support::{ assert_ok, dispatch::UnfilteredDispatchable, sp_runtime::{traits::AccountIdConversion, FixedPointNumber}, - traits::{EnsureOrigin, Get}, + traits::{Currency as _, EnsureOrigin, Get}, }; use frame_system::RawOrigin; use orml_traits::MultiCurrency; @@ -34,7 +34,6 @@ fn whitelist_acc(acc: &T::AccountId) { benchmarks! { add_asset { - // ASSET_A_ID let asset_id: T::AssetId = 1_u32.into(); let origin = T::AdminOrigin::successful_origin(); let million = 1_000_000u32.into(); @@ -55,7 +54,6 @@ benchmarks! { T::Currency::total_balance(asset_id, &T::TreasuryPalletId::get().into_account()), million ); - } complete_withdraw { @@ -121,18 +119,24 @@ benchmarks! { remove_asset { let asset_id = 1_u32.into(); let origin = T::AdminOrigin::successful_origin(); - let depositor = whitelisted_account::("depositor", 0); let units: u32 = 100; - let admin_deposit = 5u32.into(); - assert_ok!(AssetIndex::::add_asset(origin.clone(), asset_id, units.into(), MultiLocation::Null,admin_deposit + let amount = 500u32.into(); + + assert_ok!(AssetIndex::::add_asset( + origin.clone(), + asset_id, + units.into(), + MultiLocation::Null, + amount, )); + // ensure + assert_eq!(T::IndexToken::total_balance(&Default::default()), 500u32.into()); + // construct remove call let call = Call::::remove_asset(asset_id, units.into(), None); - }: { call.dispatch_bypass_filter(origin)? } verify { - // TODO: - // - // check nav + }: { call.dispatch_bypass_filter(origin.clone())? } verify { + assert_eq!(T::IndexToken::total_balance(&Default::default()), 0u32.into()); } register_asset { @@ -204,7 +208,6 @@ benchmarks! { } unlock { - // ASSET_A_ID let asset_id = 1_u32.into(); let origin = T::AdminOrigin::successful_origin(); let depositor = whitelisted_account::("depositor", 0); From 7db9567bd5622e870d40b9a6504057273e1cc1cf Mon Sep 17 00:00:00 2001 From: clearloop Date: Wed, 18 Aug 2021 15:00:37 +0800 Subject: [PATCH 13/13] feat(asset-index): mark transactional to complete_withdraw --- pallets/asset-index/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index ff0b2da5ca..a5cf16dc9b 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -583,6 +583,7 @@ pub mod pallet { /// whether the other `AssetWithdrawal` of the same `PendingWithdrawal` /// entry can also be closed successfully. #[pallet::weight(10_000)] // TODO: Set weights + #[transactional] pub fn complete_withdraw(origin: OriginFor) -> DispatchResultWithPostInfo { let caller = ensure_signed(origin)?;