From 1639ca0d3f80f30b086d8670be178b6f5c4c4854 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 27 Sep 2021 10:00:15 +0200 Subject: [PATCH 01/10] fix: use token transfer --- pallets/asset-index/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index 277805a9fa..af7f66d1fe 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -1034,8 +1034,8 @@ pub mod pallet { } // native asset can't be added Self::ensure_not_native_asset(&asset_id)?; - // mint asset into the treasury account - T::Currency::deposit(asset_id, &Self::treasury_account(), units)?; + // transfer the asset from the caller to treasury account + T::Currency::transfer(asset_id, caller, &Self::treasury_account(), units)?; // mint PINT into caller's balance increasing the total issuance T::IndexToken::deposit_creating(caller, nav); Ok(()) From 6aac2fce4913dce736becbd9cd2935319338c13f Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 28 Sep 2021 13:07:51 +0200 Subject: [PATCH 02/10] test: fix failing tests --- pallets/asset-index/src/lib.rs | 5 +++-- pallets/remote-asset-manager/src/tests.rs | 2 ++ pallets/saft-registry/src/mock.rs | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index af7f66d1fe..ff5bea0b86 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -349,8 +349,9 @@ pub mod pallet { /// The amount of PINT minted and awarded to the LP is specified as part /// of the associated proposal /// Caller's balance is updated to allocate the correct amount of the - /// IndexToken. If the asset does not exist yet, it will get - /// created with the given location. + /// IndexToken. + /// The given amount of assets must already exist in the caller's account, + /// they are then transferred to the treasury account. /// /// The Governance committee decides the tokens that comprise the index, /// as well as the allocation of each and their value. diff --git a/pallets/remote-asset-manager/src/tests.rs b/pallets/remote-asset-manager/src/tests.rs index 57c8db204a..57abf2828c 100644 --- a/pallets/remote-asset-manager/src/tests.rs +++ b/pallets/remote-asset-manager/src/tests.rs @@ -173,6 +173,8 @@ fn can_transact_staking() { Para::execute_with(|| { register_relay(); + // mint some funds first to cover the transfer + assert_ok!(para::Currency::deposit(RELAY_CHAIN_ASSET, &ADMIN_ACCOUNT, 1_000_000)); // fails to bond extra, no initial bond assert_noop!( diff --git a/pallets/saft-registry/src/mock.rs b/pallets/saft-registry/src/mock.rs index 6faafe9847..50f4661f4d 100644 --- a/pallets/saft-registry/src/mock.rs +++ b/pallets/saft-registry/src/mock.rs @@ -17,7 +17,7 @@ use frame_support::{ PalletId, }; use frame_system as system; -use orml_traits::parameter_type_with_key; +use orml_traits::{parameter_type_with_key, MultiCurrency}; use pallet_price_feed::{AssetPricePair, Price, PriceFeed}; use xcm::v0::MultiLocation; @@ -234,6 +234,9 @@ pub fn new_test_ext() -> sp_io::TestExternalities { LIQUID_ASSET_ID, AssetAvailability::Liquid(MultiLocation::Null) )); + // mint initial supply first into admin's account + assert_ok!(Currency::deposit(LIQUID_ASSET_ID, &ADMIN_ACCOUNT_ID, initial_liquid_supply)); + assert_ok!(AssetIndex::add_asset( Origin::signed(ADMIN_ACCOUNT_ID), LIQUID_ASSET_ID, From 6b7648a91dc72397e5fbc3a4ca6b90ca5b459b56 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 29 Sep 2021 12:08:16 +0200 Subject: [PATCH 03/10] test: fix failing benchmark tests --- pallets/asset-index/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index ff5bea0b86..635b97019e 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -1141,8 +1141,10 @@ pub mod pallet { amount: T::Balance, ) -> DispatchResult { let origin = T::AdminOrigin::successful_origin(); - let origin_account_id = T::AdminOrigin::ensure_origin(origin.clone())?; + let origin_account_id = T::AdminOrigin::ensure_origin(origin)?; + // also mint the funds + T::Currency::deposit(asset_id, &origin_account_id, amount)?; T::PriceFeedBenchmarks::create_feed(origin_account_id, asset_id).map_err(|e| e.error)?; // the tests of benchmarks register assets by default From c18d899002fd8a06dbcf1539b1ced96e5995b6da Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 1 Oct 2021 19:02:03 +0800 Subject: [PATCH 04/10] feat(asset-index): fix all benchmarks --- pallets/asset-index/src/benchmarking.rs | 11 +++++++++++ pallets/asset-index/src/lib.rs | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index 86de8da873..26e988d5c5 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -27,6 +27,7 @@ benchmarks! { add_asset { let asset_id :T::AssetId = T::try_convert(2u8).unwrap(); let origin = T::AdminOrigin::successful_origin(); + let origin_account_id = T::AdminOrigin::ensure_origin(origin.clone())?; let million = 1_000_000u32.into(); let location = MultiLocation::Null; @@ -37,6 +38,9 @@ benchmarks! { AssetAvailability::Liquid(MultiLocation::Null) ) ); + + T::Currency::deposit(asset_id, &origin_account_id, million)?; + let call = Call::::add_asset( asset_id, million, @@ -68,6 +72,8 @@ benchmarks! { asset_id, AssetAvailability::Liquid(MultiLocation::Null) )); + + T::Currency::deposit(asset_id, &origin_account_id, tokens)?; assert_ok!(AssetIndex::::add_asset( origin.clone(), asset_id, @@ -111,6 +117,8 @@ benchmarks! { asset_id, AssetAvailability::Liquid(MultiLocation::Null) )); + + T::Currency::deposit(asset_id, &origin_account_id, admin_deposit.into())?; assert_ok!(AssetIndex::::add_asset( origin.clone(), asset_id, @@ -228,6 +236,7 @@ benchmarks! { asset_id, AssetAvailability::Liquid(MultiLocation::Null) )); + T::Currency::deposit(asset_id, &origin_account_id, deposit_units)?; assert_ok!(AssetIndex::::add_asset( origin.clone(), asset_id, @@ -269,6 +278,8 @@ benchmarks! { asset_id, AssetAvailability::Liquid(MultiLocation::Null) )); + + T::Currency::deposit(asset_id, &origin_account_id, amount)?; assert_ok!(AssetIndex::::add_asset(origin.clone(), asset_id, units, amount)); assert_ok!(T::Currency::deposit(asset_id, &origin_account_id, units)); assert_ok!(AssetIndex::::deposit(origin.clone(), asset_id, units)); diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index 635b97019e..7b1f212c28 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -649,8 +649,8 @@ pub mod pallet { .into_iter() .filter_map(|mut redemption| { // only try to close if the lockup period is over - if redemption.end_block >= current_block && - Self::do_complete_redemption(&caller, &mut redemption.assets) + if redemption.end_block >= current_block + && Self::do_complete_redemption(&caller, &mut redemption.assets) { // all individual redemptions withdrawn, can remove them from storage Self::deposit_event(Event::WithdrawalCompleted(caller.clone(), redemption.assets)); @@ -1035,6 +1035,11 @@ pub mod pallet { } // native asset can't be added Self::ensure_not_native_asset(&asset_id)?; + + frame_support::sp_std::if_std! { + println!("{:?}", T::Currency::total_balance(asset_id, caller)); + } + // transfer the asset from the caller to treasury account T::Currency::transfer(asset_id, caller, &Self::treasury_account(), units)?; // mint PINT into caller's balance increasing the total issuance From ad48069bdb2f375746779df3a8e9ba60b27c1de3 Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 1 Oct 2021 20:14:14 +0800 Subject: [PATCH 05/10] feat(e2e): try fix benchmarks --- js/e2e/index.ts | 13 ++++++++++++- js/e2e/src/extrinsic.ts | 19 ++++++------------- js/e2e/src/runner.ts | 34 +++++++++++++++------------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 422b6c4420..02bb7ba70d 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -40,6 +40,12 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }); return [ + /* orml_currencies */ + { + pallet: "currencies", + call: "updateBalance", + args: [config.alice.address, ASSET_ID_A, ASSET_ID_A_AMOUNT], + }, /* balance */ { signed: config.alice, @@ -532,5 +538,10 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { // main (async () => { - await Runner.run(TESTS); + try { + await Runner.run(TESTS); + } catch (error) { + throw error; + process.exit(1); + } })(); diff --git a/js/e2e/src/extrinsic.ts b/js/e2e/src/extrinsic.ts index 543fdb1841..699c1c5332 100644 --- a/js/e2e/src/extrinsic.ts +++ b/js/e2e/src/extrinsic.ts @@ -180,8 +180,6 @@ export class Extrinsic { */ public async propose( proposals: Record, - finished: string[], - errors: string[], queue: Extrinsic[], config: ExtrinsicConfig ): Promise { @@ -304,18 +302,18 @@ export class Extrinsic { nonce: number ): Promise { console.log(`-> queue extrinsic ${nonce}: ${this.id}...`); - const tx = await this.build(); + const tx = await this.build().catch((err) => { + console.log( + `====> Error: extrinsic build failed ${this.id} failed: ${err}` + ); + process.exit(1); + }); // get res const res = (await this.send(tx, nonce, this.signed).catch( (err: any) => { console.log(`====> Error: ${this.id} failed: ${err}`); errors.push(`====> Error: ${this.id} failed: ${err}`); - - // FIX ME: - // - // for test now - process.exit(1); } )) as TxResult; @@ -325,11 +323,6 @@ export class Extrinsic { await this.verify(this.shared).catch((err: any) => { console.log(`====> Error: ${this.id} verify failed: ${err}`); errors.push(`====> Error: ${this.id} verify failed: ${err}`); - - // FIX ME: - // - // for test now - process.exit(1); }); } diff --git a/js/e2e/src/runner.ts b/js/e2e/src/runner.ts index 7671938ec5..0799bb5c36 100644 --- a/js/e2e/src/runner.ts +++ b/js/e2e/src/runner.ts @@ -64,12 +64,13 @@ export default class Runner implements Config { console.log("bootstrap e2e tests..."); console.log("establishing ws connections... (around 2 mins)"); const ps = await launch("pipe"); + let runner: Runner | undefined = undefined; if (ps.stdout) { ps.stdout.on("data", async (chunk: Buffer) => { process.stdout.write(chunk.toString()); if (chunk.includes(LAUNCH_COMPLETE)) { console.log("COMPLETE LAUNCH!"); - const runner = await Runner.build(exs, ws, uri); + runner = await Runner.build(exs, ws, uri); await runner.runTxs(); } }); @@ -84,6 +85,12 @@ export default class Runner implements Config { // Kill all processes when exiting. process.on("exit", () => { + if (runner && runner.errors.length > 0) { + console.log(`Failed tests: ${runner.errors.length}`); + for (const error of runner.errors) { + console.log(error); + } + } console.log("-> exit polkadot-launch..."); killAll(ps, Number(process.exitCode)); }); @@ -132,13 +139,12 @@ export default class Runner implements Config { BalanceLock: "OrmlBalanceLock", }, }, - types: Object.assign( - { - ...ChainlinkTypes, - ...OrmlTypes, - }, - (definitions.types as any)[0].types - ), + types: { + AmountOf: "Amount", + ...ChainlinkTypes, + ...OrmlTypes, + ...(definitions.types as any)[0].types, + }, }); // new Runner @@ -172,10 +178,6 @@ export default class Runner implements Config { } if (this.errors.length > 0) { - console.log(`Failed tests: ${this.errors.length}`); - for (const error of this.errors) { - console.log(error); - } process.exit(1); } console.log("COMPLETE TESTS!"); @@ -252,13 +254,7 @@ export default class Runner implements Config { }) .map((e) => { if (e.proposal) { - return e.propose( - this.proposals, - this.finished, - this.errors, - this.exs, - this.config - ); + return e.propose(this.proposals, this.exs, this.config); } else { let n = -1; if ( From ddbcaf85bfe4d8d9647f13224edcd13028fd2f26 Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 1 Oct 2021 20:36:09 +0800 Subject: [PATCH 06/10] feat(asset-index): make clippy happy --- pallets/asset-index/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index 7b1f212c28..296d7a06f5 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -649,8 +649,8 @@ pub mod pallet { .into_iter() .filter_map(|mut redemption| { // only try to close if the lockup period is over - if redemption.end_block >= current_block - && Self::do_complete_redemption(&caller, &mut redemption.assets) + if redemption.end_block >= current_block && + Self::do_complete_redemption(&caller, &mut redemption.assets) { // all individual redemptions withdrawn, can remove them from storage Self::deposit_event(Event::WithdrawalCompleted(caller.clone(), redemption.assets)); From 633a9b0f319534b7a02ad60d5beb5f5632d0798e Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 1 Oct 2021 21:53:59 +0800 Subject: [PATCH 07/10] chore(e2e): timeout withdraw --- js/e2e/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 02bb7ba70d..50675a1514 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -382,7 +382,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.assetIndex.deposit"], + required: ["votes.assetIndex.deposit"], signed: config.alice, pallet: "assetIndex", call: "withdraw", From 8b503b8b488953d8681f4f352aba6e14307c47fb Mon Sep 17 00:00:00 2001 From: clearloop Date: Sat, 2 Oct 2021 16:10:34 +0800 Subject: [PATCH 08/10] feat(e2e): enough tokens for testing --- js/e2e/index.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 50675a1514..c7c634ea83 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -40,12 +40,6 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }); return [ - /* orml_currencies */ - { - pallet: "currencies", - call: "updateBalance", - args: [config.alice.address, ASSET_ID_A, ASSET_ID_A_AMOUNT], - }, /* balance */ { signed: config.alice, @@ -126,7 +120,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { args: [ config.alice.address, ASSET_ID_A, - PINT.mul(new BN(ASSET_ID_A_UNITS)), + PINT.mul(ASSET_ID_A_UNITS).mul(new BN(3)), 0, ], }, @@ -382,7 +376,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["votes.assetIndex.deposit"], + required: ["propose.assetIndex.deposit"], signed: config.alice, pallet: "assetIndex", call: "withdraw", From d5e79679dfef2b1af2b3d66bebc887f68d7d863d Mon Sep 17 00:00:00 2001 From: clearloop Date: Sat, 2 Oct 2021 18:32:44 +0800 Subject: [PATCH 09/10] chore(asset-index): clean logs --- pallets/asset-index/src/lib.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index 296d7a06f5..bba1428e1e 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -649,8 +649,8 @@ pub mod pallet { .into_iter() .filter_map(|mut redemption| { // only try to close if the lockup period is over - if redemption.end_block >= current_block && - Self::do_complete_redemption(&caller, &mut redemption.assets) + if redemption.end_block >= current_block + && Self::do_complete_redemption(&caller, &mut redemption.assets) { // all individual redemptions withdrawn, can remove them from storage Self::deposit_event(Event::WithdrawalCompleted(caller.clone(), redemption.assets)); @@ -1035,11 +1035,6 @@ pub mod pallet { } // native asset can't be added Self::ensure_not_native_asset(&asset_id)?; - - frame_support::sp_std::if_std! { - println!("{:?}", T::Currency::total_balance(asset_id, caller)); - } - // transfer the asset from the caller to treasury account T::Currency::transfer(asset_id, caller, &Self::treasury_account(), units)?; // mint PINT into caller's balance increasing the total issuance From abb892662a620fceebddd414b8d62d619def5a14 Mon Sep 17 00:00:00 2001 From: clearloop Date: Sat, 2 Oct 2021 19:25:11 +0800 Subject: [PATCH 10/10] make clippy happy --- pallets/asset-index/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index bba1428e1e..635b97019e 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -649,8 +649,8 @@ pub mod pallet { .into_iter() .filter_map(|mut redemption| { // only try to close if the lockup period is over - if redemption.end_block >= current_block - && Self::do_complete_redemption(&caller, &mut redemption.assets) + if redemption.end_block >= current_block && + Self::do_complete_redemption(&caller, &mut redemption.assets) { // all individual redemptions withdrawn, can remove them from storage Self::deposit_event(Event::WithdrawalCompleted(caller.clone(), redemption.assets));