diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 422b6c4420..c7c634ea83 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -120,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, ], }, @@ -532,5 +532,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 ( 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 277805a9fa..635b97019e 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. @@ -1034,8 +1035,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(()) @@ -1140,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 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,