From 83238b71b2d66e8ad4ae1e0d0416fe770dd77210 Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 9 Sep 2021 17:38:26 +0800 Subject: [PATCH 01/23] chore(e2e): reorder tests from easy to hard --- js/e2e/index.ts | 338 ++++++++++++++++++++++++------------------------ 1 file changed, 172 insertions(+), 166 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 23d0af767b..1339a77633 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -16,10 +16,11 @@ import BN from "bn.js"; const ASSET_ID_A: number = 42; const ASSET_ID_A_UNITS: number = 1; -const ASSET_ID_A_VALUE: number = 1; +const ASSET_ID_A_VALUE: BN = new BN(10000); const ASSET_ID_A_DEPOSIT: BN = new BN(10000); const ASSET_ID_B: number = 43; const BALANCE_THOUSAND: BN = new BN(1000); +const BALANCE_HUNDRED: BN = new BN(100); const VOTING_PERIOD: number = 10; const WITHDRAWALS_PERIOD: number = 10; @@ -65,30 +66,109 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, ], }, + /* committee */ + { + pallet: "committee", + call: "addConstituent", + args: [config.ziggy.address], + verify: async () => { + assert( + ( + (await api.query.committee.members( + config.ziggy.address + )) as any + ).isSome, + "Add constituent failed" + ); + }, + }, + /* local_treasury */ + { + pallet: "localTreasury", + call: "withdraw", + args: [500000000000, config.ziggy.address], + verify: async () => { + assert( + ( + await api.derive.balances.all(config.ziggy.address) + ).freeBalance.toNumber() === 500000000000, + "localTreasury.withdraw failed" + ); + }, + }, + /* chainlink_feed */ + { + signed: config.alice, + pallet: "chainlinkFeed", + call: "createFeed", + args: [ + 100000000000, + 0, + [100000000000, 100000000000], + 1, + 9, + "test_feed", + 0, + [[config.alice.address, config.bob.address]], + null, + null, + ], + verify: async () => { + assert( + (await api.query.chainlinkFeed.feeds.entries()).length === + 1, + "Create feed failed" + ); + }, + }, + { + required: ["chainlinkFeed.createFeed"], + signed: config.alice, + pallet: "chainlinkFeed", + call: "submit", + args: [0, 1, 100000000000], + verify: async () => { + assert( + (await api.query.chainlinkFeed.rounds(0, 1)).isEmpty, + "Create feed failed" + ); + }, + }, + /* price-feed */ + { + proposal: true, + signed: config.alice, + required: ["votes.assetIndex.addAsset"], + pallet: "priceFeed", + call: "mapAssetPriceFeed", + args: [ASSET_ID_A, 0], + verify: async () => { + assert( + Number( + ( + await api.query.priceFeed.assetFeeds(ASSET_ID_A) + ).toHuman() + ) === 0, + "map feed failed" + ); + }, + }, + { + proposal: true, + required: ["votes.assetIndex.withdraw"], + pallet: "priceFeed", + call: "unmapAssetPriceFeed", + args: [ASSET_ID_A], + verify: async () => { + assert( + ((await api.query.priceFeed.assetFeeds(ASSET_ID_A)) as any) + .isNone, + "unmap price feed failed" + ); + }, + }, /* asset-index */ - // { - // proposal: true, - // signed: config.alice, - // required: ["votes.priceFeed.mapAssetPriceFeed"], - // pallet: "assetIndex", - // call: "setMetadata", - // args: [ASSET_ID_A, "PINT_TEST", "P", 9], - // verify: async () => { - // assert( - // JSON.stringify( - // ( - // await api.query.assetIndex.metadata(ASSET_ID_A) - // ).toHuman() - // ) === - // JSON.stringify({ - // name: "PINT_TEST", - // symbol: "P", - // decimals: "9", - // }), - // "assetIndex.setMetadata failed" - // ); - // }, - // }, + { proposal: true, signed: config.alice, @@ -118,42 +198,46 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { signed: config.alice, pallet: "assetIndex", call: "deposit", - args: [ASSET_ID_A, PINT.mul(ASSET_ID_A_DEPOSIT)], - verify: async (_before: Balance) => { - // const current = ( - // await api.query.system.account(config.alice.address) - // ).data.free; - // - // // cover weight fee - // assert( - // current.sub(before).div(PINT).toNumber() === - // ASSET_ID_A_DEPOSIT.toNumber() - 1, - // "assetIndex.deposit failed" - // ); - }, - }, - { - proposal: true, - required: ["close.assetIndex.deposit"], - signed: config.alice, - pallet: "assetIndex", - call: "withdraw", - args: [PINT.mul(BALANCE_THOUSAND).div(new BN(4))], - verify: async () => { - // assert( - // ( - // ( - // await api.query.assetIndex.pendingWithdrawals( - // config.alice.address - // ) - // ).toHuman() as any - // ).length === 1, - // "assetIndex.withdraw failed" - // ); + args: [ASSET_ID_A, ASSET_ID_A_DEPOSIT], + verify: async (before: Balance) => { + const current = ( + await api.query.system.account(config.alice.address) + ).data.free; + + console.log(before); + console.log(current); + + // cover weight fee + assert( + current.sub(before).div(PINT).toNumber() === + ASSET_ID_A_DEPOSIT.toNumber() - 1, + "assetIndex.deposit failed" + ); }, }, // { - // required: ["assetIndex.withdraw"], + // proposal: true, + // required: ["close.assetIndex.deposit"], + // signed: config.alice, + // pallet: "assetIndex", + // call: "withdraw", + // args: [PINT.mul(BALANCE_HUNDRED)], + // verify: async () => { + // assert( + // ( + // ( + // await api.query.assetIndex.pendingWithdrawals( + // config.alice.address + // ) + // ).toHuman() as any + // ).length === 1, + // "assetIndex.withdraw failed" + // ); + // }, + // }, + // { + // proposal: true, + // required: ["close.assetIndex.withdraw"], // shared: async () => { // const currentBlock = ( // await api.derive.chain.bestNumber() @@ -182,14 +266,37 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { // call: "completeWithdraw", // args: [], // verify: async () => { - // // assert( - // // ( - // // (await api.query.assetIndex.pendingWithdrawals( - // // config.alice.address - // // )) as any - // // ).isNone, - // // "assetIndex.completeWithdraw failed" - // // ); + // assert( + // ( + // (await api.query.assetIndex.pendingWithdrawals( + // config.alice.address + // )) as any + // ).isNone, + // "assetIndex.completeWithdraw failed" + // ); + // }, + // }, + // { + // proposal: true, + // signed: config.alice, + // required: ["votes.priceFeed.mapAssetPriceFeed"], + // pallet: "assetIndex", + // call: "setMetadata", + // args: [ASSET_ID_A, "PINT_TEST", "P", 9], + // verify: async () => { + // assert( + // JSON.stringify( + // ( + // await api.query.assetIndex.metadata(ASSET_ID_A) + // ).toHuman() + // ) === + // JSON.stringify({ + // name: "PINT_TEST", + // symbol: "P", + // decimals: "9", + // }), + // "assetIndex.setMetadata failed" + // ); // }, // }, /* remote-asset-manager*/ @@ -249,107 +356,6 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { // ); // }, // }, - /* committee */ - // { - // pallet: "committee", - // call: "addConstituent", - // args: [config.ziggy.address], - // verify: async () => { - // assert( - // ( - // (await api.query.committee.members( - // config.ziggy.address - // )) as any - // ).isSome, - // "Add constituent failed" - // ); - // }, - // }, - /* local_treasury */ - // { - // pallet: "localTreasury", - // call: "withdraw", - // args: [500000000000, config.ziggy.address], - // verify: async () => { - // assert( - // ( - // await api.derive.balances.all(config.ziggy.address) - // ).freeBalance.toNumber() === 500000000000, - // "localTreasury.withdraw failed" - // ); - // }, - // }, - /* chainlink_feed */ - { - signed: config.alice, - pallet: "chainlinkFeed", - call: "createFeed", - args: [ - 100000000000, - 0, - [100000000000, 100000000000], - 1, - 9, - "test_feed", - 0, - [[config.alice.address, config.bob.address]], - null, - null, - ], - verify: async () => { - assert( - (await api.query.chainlinkFeed.feeds.entries()).length === - 1, - "Create feed failed" - ); - }, - }, - { - required: ["chainlinkFeed.createFeed"], - signed: config.alice, - pallet: "chainlinkFeed", - call: "submit", - args: [0, 1, 100000000000], - verify: async () => { - assert( - (await api.query.chainlinkFeed.rounds(0, 1)).isEmpty, - "Create feed failed" - ); - }, - }, - /* price-feed */ - { - proposal: true, - signed: config.alice, - required: ["votes.assetIndex.addAsset"], - pallet: "priceFeed", - call: "mapAssetPriceFeed", - args: [ASSET_ID_A, 0], - verify: async () => { - // assert( - // Number( - // ( - // await api.query.priceFeed.assetFeeds(ASSET_ID_A) - // ).toHuman() - // ) === 0, - // "map feed failed" - // ); - }, - }, - // { - // proposal: true, - // required: ["votes.assetIndex.withdraw"], - // pallet: "priceFeed", - // call: "unmapAssetPriceFeed", - // args: [ASSET_ID_A], - // verify: async () => { - // assert( - // ((await api.query.priceFeed.assetFeeds(ASSET_ID_A)) as any) - // .isNone, - // "unmap price feed failed" - // ); - // }, - // }, /* saft-registry */ // { // signed: config.alice, From cc8d1dd5871df251a2c7832e6918bdf62e0347e4 Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 9 Sep 2021 21:11:53 +0800 Subject: [PATCH 02/23] feat(e2e): sets tokens before depositing --- js/e2e/index.ts | 217 ++++++++++++++++++++-------------------- js/e2e/src/extrinsic.ts | 2 + js/e2e/src/runner.ts | 28 +++--- runtime/dev/src/lib.rs | 5 +- 4 files changed, 127 insertions(+), 125 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 1339a77633..b3f2b973ee 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -15,9 +15,8 @@ import { Balance } from "@polkadot/types/interfaces/runtime"; import BN from "bn.js"; const ASSET_ID_A: number = 42; -const ASSET_ID_A_UNITS: number = 1; -const ASSET_ID_A_VALUE: BN = new BN(10000); -const ASSET_ID_A_DEPOSIT: BN = new BN(10000); +const ASSET_ID_A_UNITS: BN = new BN(100); +const ASSET_ID_A_AMOUNT: BN = new BN(1000000); const ASSET_ID_B: number = 43; const BALANCE_THOUSAND: BN = new BN(1000); const BALANCE_HUNDRED: BN = new BN(100); @@ -40,59 +39,73 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { return [ /* balance */ + // { + // signed: config.alice, + // pallet: "balances", + // call: "transfer", + // args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)], + // with: [ + // { + // signed: config.alice, + // pallet: "balances", + // call: "transfer", + // args: [config.bob.address, PINT.mul(BALANCE_THOUSAND)], + // }, + // { + // signed: config.alice, + // pallet: "balances", + // call: "transfer", + // args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)], + // }, + // { + // signed: config.alice, + // pallet: "balances", + // call: "transfer", + // args: [config.dave.address, PINT.mul(BALANCE_THOUSAND)], + // }, + // ], + // }, + // /* committee */ + // { + // pallet: "committee", + // call: "addConstituent", + // args: [config.ziggy.address], + // verify: async () => { + // assert( + // ( + // (await api.query.committee.members( + // config.ziggy.address + // )) as any + // ).isSome, + // "Add constituent failed" + // ); + // }, + // }, + // /* local_treasury */ + // { + // pallet: "localTreasury", + // call: "withdraw", + // args: [500000000000, config.ziggy.address], + // verify: async () => { + // assert( + // ( + // await api.derive.balances.all(config.ziggy.address) + // ).freeBalance.toNumber() === 500000000000, + // "localTreasury.withdraw failed" + // ); + // }, + // }, + /* orml_tokens */ { - signed: config.alice, - pallet: "balances", - call: "transfer", - args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)], - with: [ - { - signed: config.alice, - pallet: "balances", - call: "transfer", - args: [config.bob.address, PINT.mul(BALANCE_THOUSAND)], - }, - { - signed: config.alice, - pallet: "balances", - call: "transfer", - args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)], - }, - { - signed: config.alice, - pallet: "balances", - call: "transfer", - args: [config.dave.address, PINT.mul(BALANCE_THOUSAND)], - }, - ], - }, - /* committee */ - { - pallet: "committee", - call: "addConstituent", - args: [config.ziggy.address], - verify: async () => { - assert( - ( - (await api.query.committee.members( - config.ziggy.address - )) as any - ).isSome, - "Add constituent failed" - ); - }, - }, - /* local_treasury */ - { - pallet: "localTreasury", - call: "withdraw", - args: [500000000000, config.ziggy.address], + required: ["assetIndex.addAsset"], + pallet: "tokens", + call: "setBalance", + args: [config.alice.address, ASSET_ID_A, PINT.mul(new BN(100)), 0], verify: async () => { - assert( + console.log( ( - await api.derive.balances.all(config.ziggy.address) - ).freeBalance.toNumber() === 500000000000, - "localTreasury.withdraw failed" + await api.query.tokens.accounts(config.alice.address) + ).toHuman() ); }, }, @@ -102,11 +115,11 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { pallet: "chainlinkFeed", call: "createFeed", args: [ - 100000000000, + PINT.mul(new BN(100)), 0, - [100000000000, 100000000000], + [1, 100], 1, - 9, + 0, "test_feed", 0, [[config.alice.address, config.bob.address]], @@ -126,7 +139,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { signed: config.alice, pallet: "chainlinkFeed", call: "submit", - args: [0, 1, 100000000000], + args: [0, 1, 1], verify: async () => { assert( (await api.query.chainlinkFeed.rounds(0, 1)).isEmpty, @@ -136,9 +149,8 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, /* price-feed */ { - proposal: true, - signed: config.alice, - required: ["votes.assetIndex.addAsset"], + // required: ["votes.assetIndex.addAsset"], + required: ["assetIndex.addAsset"], pallet: "priceFeed", call: "mapAssetPriceFeed", args: [ASSET_ID_A, 0], @@ -153,32 +165,31 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ); }, }, - { - proposal: true, - required: ["votes.assetIndex.withdraw"], - pallet: "priceFeed", - call: "unmapAssetPriceFeed", - args: [ASSET_ID_A], - verify: async () => { - assert( - ((await api.query.priceFeed.assetFeeds(ASSET_ID_A)) as any) - .isNone, - "unmap price feed failed" - ); - }, - }, + // { + // // required: ["votes.assetIndex.withdraw"], + // required: ["assetIndex.withdraw"], + // pallet: "priceFeed", + // call: "unmapAssetPriceFeed", + // args: [ASSET_ID_A], + // verify: async () => { + // assert( + // ((await api.query.priceFeed.assetFeeds(ASSET_ID_A)) as any) + // .isNone, + // "unmap price feed failed" + // ); + // }, + // }, /* asset-index */ - { - proposal: true, + // proposal: true, signed: config.alice, pallet: "assetIndex", call: "addAsset", args: [ ASSET_ID_A, - ASSET_ID_A_UNITS, + PINT.mul(ASSET_ID_A_UNITS), PARENT_LOCATION, - ASSET_ID_A_VALUE, + PINT.mul(ASSET_ID_A_AMOUNT), ], verify: async () => { assert( @@ -188,36 +199,28 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ); }, }, - { - proposal: true, - required: ["votes.priceFeed.mapAssetPriceFeed"], - shared: async () => { - return (await api.query.system.account(config.alice.address)) - .data.free; - }, - signed: config.alice, - pallet: "assetIndex", - call: "deposit", - args: [ASSET_ID_A, ASSET_ID_A_DEPOSIT], - verify: async (before: Balance) => { - const current = ( - await api.query.system.account(config.alice.address) - ).data.free; - - console.log(before); - console.log(current); - - // cover weight fee - assert( - current.sub(before).div(PINT).toNumber() === - ASSET_ID_A_DEPOSIT.toNumber() - 1, - "assetIndex.deposit failed" - ); - }, - }, // { - // proposal: true, - // required: ["close.assetIndex.deposit"], + // // proposal: true, + // // required: ["votes.priceFeed.mapAssetPriceFeed"], + // required: ["priceFeed.mapAssetPriceFeed"], + // signed: config.alice, + // pallet: "assetIndex", + // call: "deposit", + // args: [ASSET_ID_A, PINT.mul(ASSET_ID_A_DEPOSIT)], + // verify: async () => { + // console.log( + // ( + // await api.query.assetIndex.deposits( + // config.alice.address + // ) + // ).toHuman() + // ); + // }, + // }, + // { + // // proposal: true, + // // required: ["close.assetIndex.deposit"], + // required: ["assetIndex.deposit"], // signed: config.alice, // pallet: "assetIndex", // call: "withdraw", diff --git a/js/e2e/src/extrinsic.ts b/js/e2e/src/extrinsic.ts index e1ef0b364a..095c618953 100644 --- a/js/e2e/src/extrinsic.ts +++ b/js/e2e/src/extrinsic.ts @@ -335,6 +335,7 @@ export class Extrinsic { // 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}`); } )) as TxResult; @@ -343,6 +344,7 @@ export class Extrinsic { if (this.verify) { console.log(`\t | verify: ${this.id}`); await this.verify(this.shared).catch((err: any) => { + console.log(`====> Error: ${this.id} verify failed: ${err}`); errors.push(`====> Error: ${this.id} verify failed: ${err}`); }); } diff --git a/js/e2e/src/runner.ts b/js/e2e/src/runner.ts index 221f712501..0a161294d0 100644 --- a/js/e2e/src/runner.ts +++ b/js/e2e/src/runner.ts @@ -170,15 +170,15 @@ export default class Runner implements Config { await this.queue().catch(console.error); } - 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!"); - process.exit(0); + // 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!"); + // process.exit(0); } /** @@ -188,12 +188,14 @@ export default class Runner implements Config { */ public async queue(): Promise { const queue: Extrinsic[] = []; + let missed = []; for (const e of this.exs) { // 0. check if required ex with ids has finished let requiredFinished = true; if (e.required) { for (const r of e.required) { if (!this.finished.includes(r)) { + missed.push(r); requiredFinished = false; break; } @@ -223,13 +225,7 @@ export default class Runner implements Config { } if (queue.length === 0) { - console.error( - `Error: some required extrinsics missed: \n\t ${JSON.stringify( - this.finished, - null, - 2 - )}` - ); + console.error(`Error: required extrinsics missed: ${missed}`); process.exit(1); } diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 1ce2194841..182f2d4b44 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -429,7 +429,8 @@ impl pallet_remote_treasury::Config for Runtime { } impl pallet_saft_registry::Config for Runtime { - type AdminOrigin = CommitteeOrigin; + // type AdminOrigin = CommitteeOrigin; + type AdminOrigin = EnsureSigned; type AssetRecorder = AssetIndex; #[cfg(feature = "runtime-benchmarks")] type AssetRecorderBenchmarks = AssetIndex; @@ -477,7 +478,7 @@ impl pallet_chainlink_feed::Config for Runtime { } impl pallet_asset_index::Config for Runtime { - type AdminOrigin = CommitteeOrigin; + type AdminOrigin = EnsureSigned; type IndexToken = Balances; type Balance = Balance; type MaxActiveDeposits = MaxActiveDeposits; From 05f557b20d2faea5ead142952072a2dba08ccdd5 Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 9 Sep 2021 21:30:00 +0800 Subject: [PATCH 03/23] feat(e2e): fix tests of asset-index --- js/e2e/index.ts | 368 ++++++++++++++++++++++++------------------------ 1 file changed, 185 insertions(+), 183 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index b3f2b973ee..c14ca55ff3 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -16,10 +16,9 @@ import BN from "bn.js"; const ASSET_ID_A: number = 42; const ASSET_ID_A_UNITS: BN = new BN(100); -const ASSET_ID_A_AMOUNT: BN = new BN(1000000); +const ASSET_ID_A_AMOUNT: BN = new BN(100); const ASSET_ID_B: number = 43; const BALANCE_THOUSAND: BN = new BN(1000); -const BALANCE_HUNDRED: BN = new BN(100); const VOTING_PERIOD: number = 10; const WITHDRAWALS_PERIOD: number = 10; @@ -39,76 +38,74 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { return [ /* balance */ - // { - // signed: config.alice, - // pallet: "balances", - // call: "transfer", - // args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)], - // with: [ - // { - // signed: config.alice, - // pallet: "balances", - // call: "transfer", - // args: [config.bob.address, PINT.mul(BALANCE_THOUSAND)], - // }, - // { - // signed: config.alice, - // pallet: "balances", - // call: "transfer", - // args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)], - // }, - // { - // signed: config.alice, - // pallet: "balances", - // call: "transfer", - // args: [config.dave.address, PINT.mul(BALANCE_THOUSAND)], - // }, - // ], - // }, - // /* committee */ - // { - // pallet: "committee", - // call: "addConstituent", - // args: [config.ziggy.address], - // verify: async () => { - // assert( - // ( - // (await api.query.committee.members( - // config.ziggy.address - // )) as any - // ).isSome, - // "Add constituent failed" - // ); - // }, - // }, - // /* local_treasury */ - // { - // pallet: "localTreasury", - // call: "withdraw", - // args: [500000000000, config.ziggy.address], - // verify: async () => { - // assert( - // ( - // await api.derive.balances.all(config.ziggy.address) - // ).freeBalance.toNumber() === 500000000000, - // "localTreasury.withdraw failed" - // ); - // }, - // }, - /* orml_tokens */ { - required: ["assetIndex.addAsset"], - pallet: "tokens", - call: "setBalance", - args: [config.alice.address, ASSET_ID_A, PINT.mul(new BN(100)), 0], + signed: config.alice, + pallet: "balances", + call: "transfer", + args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)], + with: [ + { + signed: config.alice, + pallet: "balances", + call: "transfer", + args: [config.bob.address, PINT.mul(BALANCE_THOUSAND)], + }, + { + signed: config.alice, + pallet: "balances", + call: "transfer", + args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)], + }, + { + signed: config.alice, + pallet: "balances", + call: "transfer", + args: [config.dave.address, PINT.mul(BALANCE_THOUSAND)], + }, + ], + }, + /* committee */ + { + pallet: "committee", + call: "addConstituent", + args: [config.ziggy.address], verify: async () => { - console.log( + assert( + ( + (await api.query.committee.members( + config.ziggy.address + )) as any + ).isSome, + "Add constituent failed" + ); + }, + }, + /* local_treasury */ + { + pallet: "localTreasury", + call: "withdraw", + args: [500000000000, config.ziggy.address], + verify: async () => { + assert( ( - await api.query.tokens.accounts(config.alice.address) - ).toHuman() + await api.derive.balances.all(config.ziggy.address) + ).freeBalance.toNumber() === 500000000000, + "localTreasury.withdraw failed" ); }, }, + /* orml_tokens */ + { + required: ["assetIndex.addAsset"], + pallet: "tokens", + call: "setBalance", + args: [ + config.alice.address, + ASSET_ID_A, + PINT.mul(new BN(ASSET_ID_A_UNITS)), + 0, + ], + }, /* chainlink_feed */ { signed: config.alice, @@ -165,20 +162,20 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ); }, }, - // { - // // required: ["votes.assetIndex.withdraw"], - // required: ["assetIndex.withdraw"], - // pallet: "priceFeed", - // call: "unmapAssetPriceFeed", - // args: [ASSET_ID_A], - // verify: async () => { - // assert( - // ((await api.query.priceFeed.assetFeeds(ASSET_ID_A)) as any) - // .isNone, - // "unmap price feed failed" - // ); - // }, - // }, + { + // required: ["votes.assetIndex.withdraw"], + required: ["assetIndex.setMetadata"], + pallet: "priceFeed", + call: "unmapAssetPriceFeed", + args: [ASSET_ID_A], + verify: async () => { + assert( + ((await api.query.priceFeed.assetFeeds(ASSET_ID_A)) as any) + .isNone, + "unmap price feed failed" + ); + }, + }, /* asset-index */ { // proposal: true, @@ -199,109 +196,114 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ); }, }, - // { - // // proposal: true, - // // required: ["votes.priceFeed.mapAssetPriceFeed"], - // required: ["priceFeed.mapAssetPriceFeed"], - // signed: config.alice, - // pallet: "assetIndex", - // call: "deposit", - // args: [ASSET_ID_A, PINT.mul(ASSET_ID_A_DEPOSIT)], - // verify: async () => { - // console.log( - // ( - // await api.query.assetIndex.deposits( - // config.alice.address - // ) - // ).toHuman() - // ); - // }, - // }, - // { - // // proposal: true, - // // required: ["close.assetIndex.deposit"], - // required: ["assetIndex.deposit"], - // signed: config.alice, - // pallet: "assetIndex", - // call: "withdraw", - // args: [PINT.mul(BALANCE_HUNDRED)], - // verify: async () => { - // assert( - // ( - // ( - // await api.query.assetIndex.pendingWithdrawals( - // config.alice.address - // ) - // ).toHuman() as any - // ).length === 1, - // "assetIndex.withdraw failed" - // ); - // }, - // }, - // { - // proposal: true, - // required: ["close.assetIndex.withdraw"], - // shared: async () => { - // const currentBlock = ( - // await api.derive.chain.bestNumber() - // ).toNumber(); - // const pendingWithdrawls = - // await api.query.assetIndex.pendingWithdrawals( - // config.alice.address - // ); - // - // const end = (pendingWithdrawls as any).toHuman()[0].end_block; - // const needsToWait = - // end - currentBlock > WITHDRAWALS_PERIOD - // ? end - currentBlock - WITHDRAWALS_PERIOD - // : 0; - // - // console.log( - // `\t | waiting for the withdrawls peirod (around ${Math.floor( - // (needsToWait * 12) / 60 - // )} mins)...` - // ); - // - // await waitBlock(needsToWait); - // }, - // signed: config.alice, - // pallet: "assetIndex", - // call: "completeWithdraw", - // args: [], - // verify: async () => { - // assert( - // ( - // (await api.query.assetIndex.pendingWithdrawals( - // config.alice.address - // )) as any - // ).isNone, - // "assetIndex.completeWithdraw failed" - // ); - // }, - // }, - // { - // proposal: true, - // signed: config.alice, - // required: ["votes.priceFeed.mapAssetPriceFeed"], - // pallet: "assetIndex", - // call: "setMetadata", - // args: [ASSET_ID_A, "PINT_TEST", "P", 9], - // verify: async () => { - // assert( - // JSON.stringify( - // ( - // await api.query.assetIndex.metadata(ASSET_ID_A) - // ).toHuman() - // ) === - // JSON.stringify({ - // name: "PINT_TEST", - // symbol: "P", - // decimals: "9", - // }), - // "assetIndex.setMetadata failed" - // ); - // }, - // }, + { + // proposal: true, + // required: ["votes.priceFeed.mapAssetPriceFeed"], + required: ["priceFeed.mapAssetPriceFeed"], + signed: config.alice, + pallet: "assetIndex", + call: "deposit", + args: [ASSET_ID_A, PINT.mul(ASSET_ID_A_UNITS)], + verify: async () => { + assert( + ( + ( + await api.query.assetIndex.deposits( + config.alice.address + ) + ).toJSON() as any + ).length == 1, + "assetIndex.deposit failed" + ); + }, + }, + { + // proposal: true, + // required: ["close.assetIndex.deposit"], + required: ["assetIndex.deposit"], + signed: config.alice, + pallet: "assetIndex", + call: "withdraw", + args: [PINT.mul(BALANCE_THOUSAND)], + verify: async () => { + assert( + ( + ( + await api.query.assetIndex.pendingWithdrawals( + config.alice.address + ) + ).toHuman() as any + ).length === 1, + "assetIndex.withdraw failed" + ); + }, + }, + { + // proposal: true, + // required: ["close.assetIndex.withdraw"], + required: ["assetIndex.withdraw"], + shared: async () => { + const currentBlock = ( + await api.derive.chain.bestNumber() + ).toNumber(); + const pendingWithdrawls = + await api.query.assetIndex.pendingWithdrawals( + config.alice.address + ); + + const end = (pendingWithdrawls as any).toHuman()[0].end_block; + const needsToWait = + end - currentBlock > WITHDRAWALS_PERIOD + ? end - currentBlock - WITHDRAWALS_PERIOD + : 0; + + console.log( + `\t | waiting for the withdrawls peirod (around ${Math.floor( + (needsToWait * 12) / 60 + )} mins)...` + ); + + await waitBlock(needsToWait); + }, + signed: config.alice, + pallet: "assetIndex", + call: "completeWithdraw", + args: [], + verify: async () => { + assert( + ( + (await api.query.assetIndex.pendingWithdrawals( + config.alice.address + )) as any + ).isNone, + "assetIndex.completeWithdraw failed" + ); + }, + }, + { + // proposal: true, + signed: config.alice, + // required: ["votes.priceFeed.mapAssetPriceFeed"], + required: ["priceFeed.mapAssetPriceFeed"], + pallet: "assetIndex", + call: "setMetadata", + args: [ASSET_ID_A, "PINT_TEST", "P", 9], + verify: async () => { + assert( + JSON.stringify( + ( + await api.query.assetIndex.metadata(ASSET_ID_A) + ).toHuman() + ) === + JSON.stringify({ + name: "PINT_TEST", + symbol: "P", + decimals: "9", + }), + "assetIndex.setMetadata failed" + ); + }, + }, /* remote-asset-manager*/ // { // required: ["assetIndex.addAsset"], From 5bf60443d44e6cc626a2ce6facc30002b1ef7d78 Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 9 Sep 2021 23:43:34 +0800 Subject: [PATCH 04/23] feat(e2e): fix tests of pallet-asset-index and saft-registry --- js/e2e/index.ts | 134 ++++++++++++++++++++----------------------- js/e2e/src/runner.ts | 18 +++--- 2 files changed, 70 insertions(+), 82 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index c14ca55ff3..a9f9a9bf86 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -18,6 +18,8 @@ const ASSET_ID_A: number = 42; const ASSET_ID_A_UNITS: BN = new BN(100); const ASSET_ID_A_AMOUNT: BN = new BN(100); const ASSET_ID_B: number = 43; +const ASSET_ID_B_NAV: BN = new BN(100); +const ASSET_ID_B_UNITS: BN = new BN(100); const BALANCE_THOUSAND: BN = new BN(1000); const VOTING_PERIOD: number = 10; const WITHDRAWALS_PERIOD: number = 10; @@ -257,12 +259,6 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ? end - currentBlock - WITHDRAWALS_PERIOD : 0; - console.log( - `\t | waiting for the withdrawls peirod (around ${Math.floor( - (needsToWait * 12) / 60 - )} mins)...` - ); - await waitBlock(needsToWait); }, signed: config.alice, @@ -284,7 +280,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { // proposal: true, signed: config.alice, // required: ["votes.priceFeed.mapAssetPriceFeed"], - required: ["priceFeed.mapAssetPriceFeed"], + required: ["assetIndex.completeWithdraw"], pallet: "assetIndex", call: "setMetadata", args: [ASSET_ID_A, "PINT_TEST", "P", 9], @@ -304,7 +300,64 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ); }, }, - /* remote-asset-manager*/ + // TODO: XCM + // + // { + // // proposal: true, + // // required: ["votes.priceFeed.unmapAssetPriceFeed"], + // required: ["assetIndex.setMetadata"], + // signed: config.alice, + // pallet: "assetIndex", + // call: "removeAsset", + // args: [ASSET_ID_A, BALANCE_THOUSAND, null], + // }, + /* saft-registry */ + { + required: ["assetIndex.deposit"], + signed: config.alice, + pallet: "saftRegistry", + call: "addSaft", + args: [ASSET_ID_B, ASSET_ID_B_NAV, ASSET_ID_B_UNITS], + verify: async () => { + assert( + ((await api.query.assetIndex.assets(ASSET_ID_B)) as any) + .isSome, + "Add saft failed" + ); + }, + }, + { + required: ["saftRegistry.addSaft"], + signed: config.alice, + pallet: "saftRegistry", + call: "reportNav", + args: [ASSET_ID_B, 0, ASSET_ID_B_NAV], + verify: async () => { + const saft = ( + (await api.query.saftRegistry.activeSAFTs( + ASSET_ID_B, + 0 + )) as any + ).toJSON(); + + console.log(saft); + // const expect = { + // nav: 336, + // units: 42, + // }; + // assert( + // JSON.stringify(saft[0]) === + // JSON.stringify({ + // nav: 336, + // units: 42, + // }), + // `Report nav failed, expect: ${JSON.stringify( + // expect + // )}, result: ${JSON.stringify(saft[0])}` + // ); + }, + }, + /* remote-asset-manager */ // { // required: ["assetIndex.addAsset"], // signed: config.alice, @@ -361,71 +414,6 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { // ); // }, // }, - /* saft-registry */ - // { - // signed: config.alice, - // pallet: "saftRegistry", - // call: "addSaft", - // args: [ASSET_ID_B, 168, 42], - // verify: async () => { - // assert( - // ((await api.query.assetIndex.assets(ASSET_ID_B)) as any) - // .isSome, - // "Add saft failed" - // ); - // }, - // }, - // { - // required: ["saftRegistry.addSaft"], - // signed: config.alice, - // pallet: "saftRegistry", - // call: "reportNav", - // args: [ASSET_ID_B, 0, 336], - // verify: async () => { - // const saft = ( - // (await api.query.saftRegistry.activeSAFTs( - // ASSET_ID_B, - // Number( - // ( - // await api.query.saftRegistry.sAFTCounter( - // ASSET_ID_B - // ) - // ).toHuman() - // ) - // )) as any - // ).toJSON(); - // const expect = { - // nav: 336, - // units: 42, - // }; - // assert( - // JSON.stringify(saft[0]) === - // JSON.stringify({ - // nav: 336, - // units: 42, - // }), - // `Report nav failed, expect: ${JSON.stringify( - // expect - // )}, result: ${JSON.stringify(saft[0])}` - // ); - // }, - // }, - /* asset-index */ - // { - // proposal: true, - // required: ["votes.priceFeed.unmapAssetPriceFeed"], - // signed: config.alice, - // pallet: "assetIndex", - // call: "removeAsset", - // args: [ASSET_ID_A, BALANCE_THOUSAND, null], - // verify: async () => { - // assert( - // ((await api.query.assetIndex.assets(ASSET_ID_A)) as any) - // .isNone, - // "assetIndex.removeAsset failed" - // ); - // }, - // }, ].map((e) => new Extrinsic(expandId(e), api, config.alice)); }; diff --git a/js/e2e/src/runner.ts b/js/e2e/src/runner.ts index 0a161294d0..a2d3071e86 100644 --- a/js/e2e/src/runner.ts +++ b/js/e2e/src/runner.ts @@ -170,15 +170,15 @@ export default class Runner implements Config { await this.queue().catch(console.error); } - // 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!"); - // process.exit(0); + 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!"); + process.exit(0); } /** From 545ad32affcb24974ea2f6a9c2c0a05350d64e64 Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 10 Sep 2021 10:23:11 +0800 Subject: [PATCH 05/23] feat(e2e): fix saft-registry --- js/e2e/index.ts | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index a9f9a9bf86..8ac6d6a820 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -339,22 +339,17 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { 0 )) as any ).toJSON(); + const expect = { + nav: 100, + units: 100, + }; - console.log(saft); - // const expect = { - // nav: 336, - // units: 42, - // }; - // assert( - // JSON.stringify(saft[0]) === - // JSON.stringify({ - // nav: 336, - // units: 42, - // }), - // `Report nav failed, expect: ${JSON.stringify( - // expect - // )}, result: ${JSON.stringify(saft[0])}` - // ); + assert( + JSON.stringify(saft[0]) === JSON.stringify(expect), + `Report nav failed, expect: ${JSON.stringify( + expect + )}, result: ${JSON.stringify(saft[0])}` + ); }, }, /* remote-asset-manager */ From a3650876711d259f5144655ef016aaed8a66c511 Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 10 Sep 2021 14:26:41 +0800 Subject: [PATCH 06/23] feat(e2e): register asset in asset-index --- js/e2e/index.ts | 32 +++++++++++++++++++++++++++++--- js/pint-types-bundle/index.ts | 4 ++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 8ac6d6a820..1070de2f54 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -179,21 +179,47 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, }, /* asset-index */ + { + // proposal: true, + signed: config.alice, + pallet: "assetIndex", + call: "registerAsset", + args: [ + ASSET_ID_A, + api.createType("AssetAvailability" as any, { + Liquid: PARENT_LOCATION, + }), + ], + verify: async () => { + assert( + ((await api.query.assetIndex.assets(ASSET_ID_A)) as any) + .isSome, + "assetIndex.addAsset failed" + ); + }, + }, { // proposal: true, signed: config.alice, pallet: "assetIndex", call: "addAsset", + shared: async () => { + return (await api.query.system.account(config.alice.address)) + .data.free; + }, args: [ ASSET_ID_A, PINT.mul(ASSET_ID_A_UNITS), PARENT_LOCATION, PINT.mul(ASSET_ID_A_AMOUNT), ], - verify: async () => { + verify: async (before: Balance) => { + const current = ( + await api.query.system.account(config.alice.address) + ).data.free; assert( - ((await api.query.assetIndex.assets(ASSET_ID_A)) as any) - .isSome, + current.sub(before).div(PINT).toNumber() === + ASSET_ID_A_AMOUNT.sub(new BN(1)).toNumber(), "assetIndex.addAsset failed" ); }, diff --git a/js/pint-types-bundle/index.ts b/js/pint-types-bundle/index.ts index 6feb1ce4d0..cc891720d4 100644 --- a/js/pint-types-bundle/index.ts +++ b/js/pint-types-bundle/index.ts @@ -63,6 +63,10 @@ export const definitions = { }, CurrencyId: "AssetId", CurrencyIdOf: "CurrencyId", + DepositRange: { + minimum: "Balance", + maximum: "Balance", + }, FeeRate: { numerator: "u32", denominator: "u32", From 439257e1a8896054d67223808bfafca729e72f53 Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 10 Sep 2021 15:29:37 +0800 Subject: [PATCH 07/23] feat(e2e): complete tests of asset-index --- js/e2e/index.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 1070de2f54..f62960bccf 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -198,6 +198,28 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ); }, }, + { + // proposal: true, + signed: config.alice, + pallet: "assetIndex", + call: "setDepositRange", + args: [ + api.createType("DepositRange" as any, { + minimum: PINT.mul(new BN(1)), + maximum: PINT.mul(new BN(10000000)), + }), + ], + verify: async () => { + const range = ( + await api.query.assetIndex.indexTokenDepositRange() + ).toHuman() as any; + assert( + range.minimum === "1.0000 Unit" && + range.maximum === "10.0000 MUnit", + "verify assetIndex.setDepositRange failed" + ); + }, + }, { // proposal: true, signed: config.alice, From 57c0b21566ab75dfdae9dee2ad26bb23ce52b818 Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 10 Sep 2021 15:53:44 +0800 Subject: [PATCH 08/23] feat(e2e): add test for remove saft --- js/e2e/index.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index f62960bccf..53c84da91f 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -20,6 +20,9 @@ const ASSET_ID_A_AMOUNT: BN = new BN(100); const ASSET_ID_B: number = 43; const ASSET_ID_B_NAV: BN = new BN(100); const ASSET_ID_B_UNITS: BN = new BN(100); +const ASSET_ID_C: number = 43; +const ASSET_ID_C_NAV: BN = new BN(100); +const ASSET_ID_C_UNITS: BN = new BN(100); const BALANCE_THOUSAND: BN = new BN(1000); const VOTING_PERIOD: number = 10; const WITHDRAWALS_PERIOD: number = 10; @@ -373,6 +376,25 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { "Add saft failed" ); }, + with: [ + { + id: "saftRegistry.addSaft.C", + signed: config.alice, + pallet: "saftRegistry", + call: "addSaft", + args: [ASSET_ID_C, ASSET_ID_C_NAV, ASSET_ID_C_UNITS], + verify: async () => { + assert( + ( + (await api.query.assetIndex.assets( + ASSET_ID_C + )) as any + ).isSome, + "Add saft failed" + ); + }, + }, + ], }, { required: ["saftRegistry.addSaft"], @@ -400,6 +422,20 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ); }, }, + { + required: ["saftRegistry.reportNav"], + signed: config.alice, + pallet: "saftRegistry", + call: "removeSaft", + args: [ASSET_ID_B, 0], + verify: async () => { + assert( + (await api.query.saftRegistry.activeSAFTs(ASSET_ID_B, 0)) + .isEmpty, + "verify saftRegistry.removeSaft failed" + ); + }, + }, /* remote-asset-manager */ // { // required: ["assetIndex.addAsset"], From 49a152df1916a5963244c3b64ecb5626128860f0 Mon Sep 17 00:00:00 2001 From: clearloop Date: Fri, 10 Sep 2021 16:56:38 +0800 Subject: [PATCH 09/23] feat(e2e): all tests of saft-registry --- js/e2e/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 53c84da91f..9de72e6549 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -378,6 +378,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, with: [ { + required: ["saftRegistry.addSaft"], id: "saftRegistry.addSaft.C", signed: config.alice, pallet: "saftRegistry", @@ -436,6 +437,20 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ); }, }, + { + required: ["saftRegistry.removeSaft"], + signed: config.alice, + pallet: "saftRegistry", + call: "convertToLiquid", + args: [ASSET_ID_C, PARENT_LOCATION], + verify: async () => { + assert( + ((await api.query.assetIndex.assets(ASSET_ID_C)) as any) + .isSome, + "assetIndex.addAsset failed" + ); + }, + }, /* remote-asset-manager */ // { // required: ["assetIndex.addAsset"], From 61f209de2d415bbda629b040e721199325853ad6 Mon Sep 17 00:00:00 2001 From: clearloop Date: Sun, 12 Sep 2021 20:03:12 +0800 Subject: [PATCH 10/23] feat(e2e): testing asset-index with committee origin --- js/e2e/index.ts | 225 ++++++++++++++++++++-------------------- js/e2e/src/config.ts | 2 +- js/e2e/src/extrinsic.ts | 97 ++++++++--------- js/e2e/src/runner.ts | 11 +- runtime/dev/src/lib.rs | 5 +- 5 files changed, 164 insertions(+), 176 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 9de72e6549..89fa92d83e 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -7,7 +7,6 @@ import { expandId, Extrinsic, ExtrinsicConfig, - IExtrinsic, waitBlock, } from "./src"; import { ApiPromise } from "@polkadot/api"; @@ -24,7 +23,6 @@ const ASSET_ID_C: number = 43; const ASSET_ID_C_NAV: BN = new BN(100); const ASSET_ID_C_UNITS: BN = new BN(100); const BALANCE_THOUSAND: BN = new BN(1000); -const VOTING_PERIOD: number = 10; const WITHDRAWALS_PERIOD: number = 10; const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { @@ -101,7 +99,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, /* orml_tokens */ { - required: ["assetIndex.addAsset"], + required: ["close.assetIndex.addAsset"], pallet: "tokens", call: "setBalance", args: [ @@ -151,8 +149,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, /* price-feed */ { - // required: ["votes.assetIndex.addAsset"], - required: ["assetIndex.addAsset"], + required: ["propose.assetIndex.addAsset"], pallet: "priceFeed", call: "mapAssetPriceFeed", args: [ASSET_ID_A, 0], @@ -168,8 +165,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, }, { - // required: ["votes.assetIndex.withdraw"], - required: ["assetIndex.setMetadata"], + required: ["propose.assetIndex.setMetadata"], pallet: "priceFeed", call: "unmapAssetPriceFeed", args: [ASSET_ID_A], @@ -183,7 +179,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, /* asset-index */ { - // proposal: true, + proposal: true, signed: config.alice, pallet: "assetIndex", call: "registerAsset", @@ -202,7 +198,8 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, }, { - // proposal: true, + required: ["propose.assetIndex.registerAsset"], + proposal: true, signed: config.alice, pallet: "assetIndex", call: "setDepositRange", @@ -224,7 +221,8 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, }, { - // proposal: true, + required: ["propose.assetIndex.setDepositRange"], + proposal: true, signed: config.alice, pallet: "assetIndex", call: "addAsset", @@ -250,9 +248,8 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, }, { - // proposal: true, - // required: ["votes.priceFeed.mapAssetPriceFeed"], - required: ["priceFeed.mapAssetPriceFeed"], + proposal: true, + required: ["tokens.setBalance"], signed: config.alice, pallet: "assetIndex", call: "deposit", @@ -271,13 +268,12 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, }, { - // proposal: true, - // required: ["close.assetIndex.deposit"], - required: ["assetIndex.deposit"], + proposal: true, + required: ["close.assetIndex.deposit"], signed: config.alice, pallet: "assetIndex", call: "withdraw", - args: [PINT.mul(BALANCE_THOUSAND)], + args: [PINT.mul(ASSET_ID_A_AMOUNT)], verify: async () => { assert( ( @@ -292,18 +288,24 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, }, { - // proposal: true, - // required: ["close.assetIndex.withdraw"], - required: ["assetIndex.withdraw"], + proposal: true, + required: ["propose.assetIndex.withdraw"], shared: async () => { const currentBlock = ( await api.derive.chain.bestNumber() ).toNumber(); - const pendingWithdrawls = + let pendingWithdrawls = await api.query.assetIndex.pendingWithdrawals( config.alice.address ); + while (!pendingWithdrawls) { + pendingWithdrawls = + await api.query.assetIndex.pendingWithdrawals( + config.alice.address + ); + } + const end = (pendingWithdrawls as any).toHuman()[0].end_block; const needsToWait = end - currentBlock > WITHDRAWALS_PERIOD @@ -328,10 +330,9 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, }, { - // proposal: true, + proposal: true, signed: config.alice, - // required: ["votes.priceFeed.mapAssetPriceFeed"], - required: ["assetIndex.completeWithdraw"], + required: ["propose.assetIndex.completeWithdraw"], pallet: "assetIndex", call: "setMetadata", args: [ASSET_ID_A, "PINT_TEST", "P", 9], @@ -363,94 +364,94 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { // args: [ASSET_ID_A, BALANCE_THOUSAND, null], // }, /* saft-registry */ - { - required: ["assetIndex.deposit"], - signed: config.alice, - pallet: "saftRegistry", - call: "addSaft", - args: [ASSET_ID_B, ASSET_ID_B_NAV, ASSET_ID_B_UNITS], - verify: async () => { - assert( - ((await api.query.assetIndex.assets(ASSET_ID_B)) as any) - .isSome, - "Add saft failed" - ); - }, - with: [ - { - required: ["saftRegistry.addSaft"], - id: "saftRegistry.addSaft.C", - signed: config.alice, - pallet: "saftRegistry", - call: "addSaft", - args: [ASSET_ID_C, ASSET_ID_C_NAV, ASSET_ID_C_UNITS], - verify: async () => { - assert( - ( - (await api.query.assetIndex.assets( - ASSET_ID_C - )) as any - ).isSome, - "Add saft failed" - ); - }, - }, - ], - }, - { - required: ["saftRegistry.addSaft"], - signed: config.alice, - pallet: "saftRegistry", - call: "reportNav", - args: [ASSET_ID_B, 0, ASSET_ID_B_NAV], - verify: async () => { - const saft = ( - (await api.query.saftRegistry.activeSAFTs( - ASSET_ID_B, - 0 - )) as any - ).toJSON(); - const expect = { - nav: 100, - units: 100, - }; - - assert( - JSON.stringify(saft[0]) === JSON.stringify(expect), - `Report nav failed, expect: ${JSON.stringify( - expect - )}, result: ${JSON.stringify(saft[0])}` - ); - }, - }, - { - required: ["saftRegistry.reportNav"], - signed: config.alice, - pallet: "saftRegistry", - call: "removeSaft", - args: [ASSET_ID_B, 0], - verify: async () => { - assert( - (await api.query.saftRegistry.activeSAFTs(ASSET_ID_B, 0)) - .isEmpty, - "verify saftRegistry.removeSaft failed" - ); - }, - }, - { - required: ["saftRegistry.removeSaft"], - signed: config.alice, - pallet: "saftRegistry", - call: "convertToLiquid", - args: [ASSET_ID_C, PARENT_LOCATION], - verify: async () => { - assert( - ((await api.query.assetIndex.assets(ASSET_ID_C)) as any) - .isSome, - "assetIndex.addAsset failed" - ); - }, - }, + // { + // required: ["assetIndex.deposit"], + // signed: config.alice, + // pallet: "saftRegistry", + // call: "addSaft", + // args: [ASSET_ID_B, ASSET_ID_B_NAV, ASSET_ID_B_UNITS], + // verify: async () => { + // assert( + // ((await api.query.assetIndex.assets(ASSET_ID_B)) as any) + // .isSome, + // "Add saft failed" + // ); + // }, + // with: [ + // { + // required: ["saftRegistry.addSaft"], + // id: "saftRegistry.addSaft.C", + // signed: config.alice, + // pallet: "saftRegistry", + // call: "addSaft", + // args: [ASSET_ID_C, ASSET_ID_C_NAV, ASSET_ID_C_UNITS], + // verify: async () => { + // assert( + // ( + // (await api.query.assetIndex.assets( + // ASSET_ID_C + // )) as any + // ).isSome, + // "Add saft failed" + // ); + // }, + // }, + // ], + // }, + // { + // required: ["saftRegistry.addSaft"], + // signed: config.alice, + // pallet: "saftRegistry", + // call: "reportNav", + // args: [ASSET_ID_B, 0, ASSET_ID_B_NAV], + // verify: async () => { + // const saft = ( + // (await api.query.saftRegistry.activeSAFTs( + // ASSET_ID_B, + // 0 + // )) as any + // ).toJSON(); + // const expect = { + // nav: 100, + // units: 100, + // }; + // + // assert( + // JSON.stringify(saft[0]) === JSON.stringify(expect), + // `Report nav failed, expect: ${JSON.stringify( + // expect + // )}, result: ${JSON.stringify(saft[0])}` + // ); + // }, + // }, + // { + // required: ["saftRegistry.reportNav"], + // signed: config.alice, + // pallet: "saftRegistry", + // call: "removeSaft", + // args: [ASSET_ID_B, 0], + // verify: async () => { + // assert( + // (await api.query.saftRegistry.activeSAFTs(ASSET_ID_B, 0)) + // .isEmpty, + // "verify saftRegistry.removeSaft failed" + // ); + // }, + // }, + // { + // required: ["saftRegistry.removeSaft"], + // signed: config.alice, + // pallet: "saftRegistry", + // call: "convertToLiquid", + // args: [ASSET_ID_C, PARENT_LOCATION], + // verify: async () => { + // assert( + // ((await api.query.assetIndex.assets(ASSET_ID_C)) as any) + // .isSome, + // "assetIndex.addAsset failed" + // ); + // }, + // }, /* remote-asset-manager */ // { // required: ["assetIndex.addAsset"], diff --git a/js/e2e/src/config.ts b/js/e2e/src/config.ts index c4fabc551c..840106a8db 100644 --- a/js/e2e/src/config.ts +++ b/js/e2e/src/config.ts @@ -43,5 +43,5 @@ export interface IExtrinsic { /// Required calls or functions before this extrinsic required?: string[]; /// Calls or functions with this extrinsic - with?: (IExtrinsic | ((shared?: any) => Promise))[]; + with?: IExtrinsic[]; } diff --git a/js/e2e/src/extrinsic.ts b/js/e2e/src/extrinsic.ts index 095c618953..3455a2ae6e 100644 --- a/js/e2e/src/extrinsic.ts +++ b/js/e2e/src/extrinsic.ts @@ -41,7 +41,7 @@ export class Extrinsic { /// Required calls or functions before this extrinsic required?: string[]; /// Calls or functions with this extrinsic - with?: (IExtrinsic | ((shared?: any) => Promise))[]; + with?: IExtrinsic[]; constructor(e: IExtrinsic, api: ApiPromise, pair: KeyringPair) { this.api = api; @@ -237,41 +237,26 @@ export class Extrinsic { call: "vote", args: [hash, this.api.createType("Vote" as any)], with: [ - async (hash: string): Promise => { - return { - id: `votes.${id}.bob`, - signed: config.bob, - pallet: "committee", - call: "vote", - args: [ - hash, - this.api.createType("Vote" as any), - ], - }; + { + id: `votes.${id}.bob`, + signed: config.bob, + pallet: "committee", + call: "vote", + args: [hash, this.api.createType("Vote" as any)], }, - async (hash: string): Promise => { - return { - id: `votes.${id}.charlie`, - signed: config.charlie, - pallet: "committee", - call: "vote", - args: [ - hash, - this.api.createType("Vote" as any), - ], - }; + { + id: `votes.${id}.charlie`, + signed: config.charlie, + pallet: "committee", + call: "vote", + args: [hash, this.api.createType("Vote" as any)], }, - async (hash: string): Promise => { - return { - id: `votes.${id}.dave`, - signed: config.dave, - pallet: "committee", - call: "vote", - args: [ - hash, - this.api.createType("Vote" as any), - ], - }; + { + id: `votes.${id}.dave`, + signed: config.dave, + pallet: "committee", + call: "vote", + args: [hash, this.api.createType("Vote" as any)], }, ], }, @@ -287,30 +272,30 @@ export class Extrinsic { required: [`votes.${id}.dave`], id: `close.${this.pallet}.${this.call}`, shared: async () => { - return new Promise(async (resolve) => { - const currentBlock = ( - await this.api.derive.chain.bestNumber() - ).toNumber(); + const currentBlock = ( + await this.api.derive.chain.bestNumber() + ).toNumber(); - const end = ( - ( - await this.api.query.committee.votes(hash) - ).toJSON() as any - ).end as number; + const end = ( + ( + await this.api.query.committee.votes(hash) + ).toJSON() as any + ).end as number; - const needsToWait = end - currentBlock; - console.log( - `\t | waiting for the end of voting peirod ( ${needsToWait} blocks )` - ); + const needsToWait = end - currentBlock; + console.log( + `\t | waiting for the end of voting peirod ( ${needsToWait} blocks )` + ); - await waitBlock(needsToWait > 0 ? needsToWait : 0); - resolve(hash); - }); + await waitBlock(needsToWait > 0 ? needsToWait : 0); + if (this.shared && typeof this.shared === "function") { + return await this.shared(); + } }, signed: config.alice, pallet: "committee", call: "close", - args: [(hash: string) => hash], + args: [hash], verify: this.verify, }, this.api, @@ -337,6 +322,11 @@ export class Extrinsic { (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; @@ -346,6 +336,11 @@ 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 a2d3071e86..2ce57234a9 100644 --- a/js/e2e/src/runner.ts +++ b/js/e2e/src/runner.ts @@ -9,7 +9,6 @@ import { definitions } from "@pint/types"; import { Config, ExtrinsicConfig } from "./config"; import { Extrinsic } from "./extrinsic"; import { launch } from "./launch"; -import { expandId } from "./util"; import { ChildProcess } from "child_process"; import OrmlTypes from "@open-web3/orml-types"; @@ -206,20 +205,14 @@ export default class Runner implements Config { continue; } - // 1. Build shared data - if (typeof e.shared === "function") { + if (!e.proposal && typeof e.shared === "function") { e.shared = await e.shared.call(this); } - // 2. Pend transactions queue.push(e); if (e.with) { for (const w of e.with) { - const ex = - typeof w === "function" - ? expandId(await w(e.shared)) - : w; - queue.push(new Extrinsic(ex, this.api, this.pair)); + queue.push(new Extrinsic(w, this.api, this.pair)); } } } diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 182f2d4b44..1ce2194841 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -429,8 +429,7 @@ impl pallet_remote_treasury::Config for Runtime { } impl pallet_saft_registry::Config for Runtime { - // type AdminOrigin = CommitteeOrigin; - type AdminOrigin = EnsureSigned; + type AdminOrigin = CommitteeOrigin; type AssetRecorder = AssetIndex; #[cfg(feature = "runtime-benchmarks")] type AssetRecorderBenchmarks = AssetIndex; @@ -478,7 +477,7 @@ impl pallet_chainlink_feed::Config for Runtime { } impl pallet_asset_index::Config for Runtime { - type AdminOrigin = EnsureSigned; + type AdminOrigin = CommitteeOrigin; type IndexToken = Balances; type Balance = Balance; type MaxActiveDeposits = MaxActiveDeposits; From 76f200fbd656756455d2149de6994b60d451f264 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 13 Sep 2021 02:31:37 +0800 Subject: [PATCH 11/23] feat(e2e): try fix saft registry --- js/e2e/index.ts | 179 ++++++++++++++++++++-------------------- js/e2e/src/extrinsic.ts | 4 +- 2 files changed, 94 insertions(+), 89 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 89fa92d83e..07c8d8b618 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -364,94 +364,97 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { // args: [ASSET_ID_A, BALANCE_THOUSAND, null], // }, /* saft-registry */ - // { - // required: ["assetIndex.deposit"], - // signed: config.alice, - // pallet: "saftRegistry", - // call: "addSaft", - // args: [ASSET_ID_B, ASSET_ID_B_NAV, ASSET_ID_B_UNITS], - // verify: async () => { - // assert( - // ((await api.query.assetIndex.assets(ASSET_ID_B)) as any) - // .isSome, - // "Add saft failed" - // ); - // }, - // with: [ - // { - // required: ["saftRegistry.addSaft"], - // id: "saftRegistry.addSaft.C", - // signed: config.alice, - // pallet: "saftRegistry", - // call: "addSaft", - // args: [ASSET_ID_C, ASSET_ID_C_NAV, ASSET_ID_C_UNITS], - // verify: async () => { - // assert( - // ( - // (await api.query.assetIndex.assets( - // ASSET_ID_C - // )) as any - // ).isSome, - // "Add saft failed" - // ); - // }, - // }, - // ], - // }, - // { - // required: ["saftRegistry.addSaft"], - // signed: config.alice, - // pallet: "saftRegistry", - // call: "reportNav", - // args: [ASSET_ID_B, 0, ASSET_ID_B_NAV], - // verify: async () => { - // const saft = ( - // (await api.query.saftRegistry.activeSAFTs( - // ASSET_ID_B, - // 0 - // )) as any - // ).toJSON(); - // const expect = { - // nav: 100, - // units: 100, - // }; - // - // assert( - // JSON.stringify(saft[0]) === JSON.stringify(expect), - // `Report nav failed, expect: ${JSON.stringify( - // expect - // )}, result: ${JSON.stringify(saft[0])}` - // ); - // }, - // }, - // { - // required: ["saftRegistry.reportNav"], - // signed: config.alice, - // pallet: "saftRegistry", - // call: "removeSaft", - // args: [ASSET_ID_B, 0], - // verify: async () => { - // assert( - // (await api.query.saftRegistry.activeSAFTs(ASSET_ID_B, 0)) - // .isEmpty, - // "verify saftRegistry.removeSaft failed" - // ); - // }, - // }, - // { - // required: ["saftRegistry.removeSaft"], - // signed: config.alice, - // pallet: "saftRegistry", - // call: "convertToLiquid", - // args: [ASSET_ID_C, PARENT_LOCATION], - // verify: async () => { - // assert( - // ((await api.query.assetIndex.assets(ASSET_ID_C)) as any) - // .isSome, - // "assetIndex.addAsset failed" - // ); - // }, - // }, + { + proposal: true, + required: ["propose.assetIndex.deposit"], + signed: config.alice, + pallet: "saftRegistry", + call: "addSaft", + args: [ASSET_ID_B, ASSET_ID_B_NAV, ASSET_ID_B_UNITS], + verify: async () => { + assert( + ((await api.query.assetIndex.assets(ASSET_ID_B)) as any) + .isSome, + "Add saft failed" + ); + }, + }, + { + proposal: true, + required: ["propose.saftRegistry.addSaft.C"], + signed: config.alice, + pallet: "saftRegistry", + call: "reportNav", + args: [ASSET_ID_B, 0, ASSET_ID_B_NAV], + verify: async () => { + const saft = ( + (await api.query.saftRegistry.activeSAFTs( + ASSET_ID_B, + 0 + )) as any + ).toJSON(); + const expect = { + nav: 100, + units: 100, + }; + + assert( + JSON.stringify(saft[0]) === JSON.stringify(expect), + `Report nav failed, expect: ${JSON.stringify( + expect + )}, result: ${JSON.stringify(saft[0])}` + ); + }, + }, + { + proposal: true, + required: ["propose.saftRegistry.reportNav"], + signed: config.alice, + pallet: "saftRegistry", + call: "removeSaft", + args: [ASSET_ID_B, 0], + verify: async () => { + assert( + (await api.query.saftRegistry.activeSAFTs(ASSET_ID_B, 0)) + .isEmpty, + "verify saftRegistry.removeSaft failed" + ); + }, + }, + { + proposal: true, + required: ["propose.saftRegistry.removeSaft"], + id: "saftRegistry.addSaft.C", + signed: config.alice, + pallet: "saftRegistry", + call: "addSaft", + args: [ASSET_ID_C, ASSET_ID_C_NAV, ASSET_ID_C_UNITS], + verify: async () => { + assert( + ((await api.query.assetIndex.assets(ASSET_ID_C)) as any) + .isSome, + "Add saft failed" + ); + }, + }, + { + proposal: true, + required: ["propose.saftRegistry.removeSaft"], + signed: config.alice, + pallet: "saftRegistry", + call: "convertToLiquid", + args: [ASSET_ID_C, PARENT_LOCATION], + verify: async () => { + console.log( + (await api.query.assetIndex.assets(ASSET_ID_C)).toHuman() + ); + // assert( + // ((await api.query.assetIndex.assets(ASSET_ID_C)) as any) + // .isSome, + // "assetIndex.addAsset failed" + // ); + }, + }, /* remote-asset-manager */ // { // required: ["assetIndex.addAsset"], diff --git a/js/e2e/src/extrinsic.ts b/js/e2e/src/extrinsic.ts index 3455a2ae6e..9fa3a4014d 100644 --- a/js/e2e/src/extrinsic.ts +++ b/js/e2e/src/extrinsic.ts @@ -181,10 +181,11 @@ export class Extrinsic { queue: Extrinsic[], config: ExtrinsicConfig ): Promise { - const id = `${this.pallet}.${this.call}`; + const id = this.id ? this.id : `${this.pallet}.${this.call}`; const proposal = new Extrinsic( { id: `propose.${id}`, + required: this.required, signed: this.signed, pallet: "committee", call: "propose", @@ -200,6 +201,7 @@ export class Extrinsic { queue.push( new Extrinsic( { + required: [`propose.${id}`], id: `votes.${id}`, shared: async () => { return new Promise(async (resolve) => { From ac667165e0fa7322718415cc764e0b6db545d28f Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 13 Sep 2021 09:47:14 +0800 Subject: [PATCH 12/23] chore(e2e): order convertToLiquid --- 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 07c8d8b618..f8cc29df82 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -439,7 +439,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.saftRegistry.removeSaft"], + required: ["saftRegistry.addSaft.C"], signed: config.alice, pallet: "saftRegistry", call: "convertToLiquid", From 1e09f8b8163a14756508603851d8d53ec3870700 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 13 Sep 2021 10:49:57 +0800 Subject: [PATCH 13/23] feat(e2e): use bob for saft registry --- js/e2e/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index f8cc29df82..b88c2f36d6 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -381,7 +381,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.saftRegistry.addSaft.C"], + required: ["propose.saftRegistry.addSaft"], signed: config.alice, pallet: "saftRegistry", call: "reportNav", @@ -409,7 +409,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { { proposal: true, required: ["propose.saftRegistry.reportNav"], - signed: config.alice, + signed: config.bob, pallet: "saftRegistry", call: "removeSaft", args: [ASSET_ID_B, 0], @@ -425,7 +425,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { proposal: true, required: ["propose.saftRegistry.removeSaft"], id: "saftRegistry.addSaft.C", - signed: config.alice, + signed: config.bob, pallet: "saftRegistry", call: "addSaft", args: [ASSET_ID_C, ASSET_ID_C_NAV, ASSET_ID_C_UNITS], @@ -439,8 +439,8 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["saftRegistry.addSaft.C"], - signed: config.alice, + required: ["propose.saftRegistry.addSaft.C"], + signed: config.bob, pallet: "saftRegistry", call: "convertToLiquid", args: [ASSET_ID_C, PARENT_LOCATION], From f5e79ef2745436f956c1a4f2317b9a719fe3d292 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 13 Sep 2021 12:46:25 +0800 Subject: [PATCH 14/23] feat(e2e): make proposals sync --- js/e2e/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index b88c2f36d6..ba03880c48 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -366,7 +366,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { /* saft-registry */ { proposal: true, - required: ["propose.assetIndex.deposit"], + required: ["propose.assetIndex.setMetadata"], signed: config.alice, pallet: "saftRegistry", call: "addSaft", @@ -408,8 +408,8 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.saftRegistry.reportNav"], - signed: config.bob, + required: ["propose.assetIndex.reportNav"], + signed: config.alice, pallet: "saftRegistry", call: "removeSaft", args: [ASSET_ID_B, 0], @@ -423,9 +423,9 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.saftRegistry.removeSaft"], + required: ["propose.assetIndex.setMetadata"], id: "saftRegistry.addSaft.C", - signed: config.bob, + signed: config.alice, pallet: "saftRegistry", call: "addSaft", args: [ASSET_ID_C, ASSET_ID_C_NAV, ASSET_ID_C_UNITS], @@ -440,7 +440,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { { proposal: true, required: ["propose.saftRegistry.addSaft.C"], - signed: config.bob, + signed: config.alice, pallet: "saftRegistry", call: "convertToLiquid", args: [ASSET_ID_C, PARENT_LOCATION], From c0776db8d4f61014c1dedfe492fc515e3debb7b9 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 13 Sep 2021 14:04:09 +0800 Subject: [PATCH 15/23] feat(e2e): trigger from close to force sync --- js/e2e/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index ba03880c48..46f43b18f5 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -381,7 +381,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.saftRegistry.addSaft"], + required: ["close.saftRegistry.addSaft"], signed: config.alice, pallet: "saftRegistry", call: "reportNav", @@ -408,7 +408,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.assetIndex.reportNav"], + required: ["close.assetIndex.reportNav"], signed: config.alice, pallet: "saftRegistry", call: "removeSaft", @@ -423,7 +423,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.assetIndex.setMetadata"], + required: ["propose.assetIndex.reportNav"], id: "saftRegistry.addSaft.C", signed: config.alice, pallet: "saftRegistry", @@ -439,7 +439,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.saftRegistry.addSaft.C"], + required: ["close.saftRegistry.addSaft.C"], signed: config.alice, pallet: "saftRegistry", call: "convertToLiquid", From 8498d863ae61a364a815557cc44aaa85b61567ed Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 13 Sep 2021 14:29:50 +0800 Subject: [PATCH 16/23] chore(e2e): wait more --- js/e2e/src/extrinsic.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/e2e/src/extrinsic.ts b/js/e2e/src/extrinsic.ts index 9fa3a4014d..b1d16ce996 100644 --- a/js/e2e/src/extrinsic.ts +++ b/js/e2e/src/extrinsic.ts @@ -284,12 +284,12 @@ export class Extrinsic { ).toJSON() as any ).end as number; - const needsToWait = end - currentBlock; + const needsToWait = end - currentBlock + 1; console.log( `\t | waiting for the end of voting peirod ( ${needsToWait} blocks )` ); - await waitBlock(needsToWait > 0 ? needsToWait : 0); + await waitBlock(needsToWait > 0 ? needsToWait : 1); if (this.shared && typeof this.shared === "function") { return await this.shared(); } From 13cd83955609eda3c431c8a9c70a7bd9631ad384 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 13 Sep 2021 15:13:34 +0800 Subject: [PATCH 17/23] feat(e2e): withdraw in the end --- js/e2e/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 46f43b18f5..614804027b 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -269,7 +269,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["close.assetIndex.deposit"], + required: ["close.saftRegistry.convertToLiquid"], signed: config.alice, pallet: "assetIndex", call: "withdraw", @@ -366,7 +366,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { /* saft-registry */ { proposal: true, - required: ["propose.assetIndex.setMetadata"], + required: ["propose.assetIndex.deposit"], signed: config.alice, pallet: "saftRegistry", call: "addSaft", @@ -381,7 +381,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["close.saftRegistry.addSaft"], + required: ["propose.saftRegistry.addSaft"], signed: config.alice, pallet: "saftRegistry", call: "reportNav", @@ -408,7 +408,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["close.assetIndex.reportNav"], + required: ["propose.saftRegistry.reportNav"], signed: config.alice, pallet: "saftRegistry", call: "removeSaft", @@ -423,7 +423,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.assetIndex.reportNav"], + required: ["propose.saftRegistry.removeSaft"], id: "saftRegistry.addSaft.C", signed: config.alice, pallet: "saftRegistry", From 4e1d9589f4a1fedd49798384f77b514466afcd90 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 13 Sep 2021 17:19:55 +0800 Subject: [PATCH 18/23] feat(e2e): assert reportNav --- js/e2e/index.ts | 13 ++++++------- js/e2e/src/extrinsic.ts | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 614804027b..efda8343b6 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -445,14 +445,13 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { call: "convertToLiquid", args: [ASSET_ID_C, PARENT_LOCATION], verify: async () => { - console.log( - (await api.query.assetIndex.assets(ASSET_ID_C)).toHuman() + assert( + ( + ( + await api.query.assetIndex.assets(ASSET_ID_C) + ).toHuman() as any + ).Liquid && true ); - // assert( - // ((await api.query.assetIndex.assets(ASSET_ID_C)) as any) - // .isSome, - // "assetIndex.addAsset failed" - // ); }, }, /* remote-asset-manager */ diff --git a/js/e2e/src/extrinsic.ts b/js/e2e/src/extrinsic.ts index b1d16ce996..bd311c7103 100644 --- a/js/e2e/src/extrinsic.ts +++ b/js/e2e/src/extrinsic.ts @@ -272,7 +272,7 @@ export class Extrinsic { new Extrinsic( { required: [`votes.${id}.dave`], - id: `close.${this.pallet}.${this.call}`, + id: `close.${id}`, shared: async () => { const currentBlock = ( await this.api.derive.chain.bestNumber() From fe308945edf9f02433c81496770e2a04f49c609c Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 13 Sep 2021 23:46:43 +0800 Subject: [PATCH 19/23] chore(e2e): saftRegistry after withdraw --- js/e2e/index.ts | 190 ++++++++++++++++++++++++------------------------ 1 file changed, 96 insertions(+), 94 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index efda8343b6..d3b35e8eb3 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -99,7 +99,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, /* orml_tokens */ { - required: ["close.assetIndex.addAsset"], + required: ["priceFeed.mapAssetPriceFeed"], pallet: "tokens", call: "setBalance", args: [ @@ -177,6 +177,99 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { ); }, }, + /* saft-registry */ + { + proposal: true, + required: ["propose.assetIndex.withdraw"], + signed: config.alice, + pallet: "saftRegistry", + call: "addSaft", + args: [ASSET_ID_B, ASSET_ID_B_NAV, ASSET_ID_B_UNITS], + verify: async () => { + assert( + ((await api.query.assetIndex.assets(ASSET_ID_B)) as any) + .isSome, + "Add saft failed" + ); + }, + }, + { + proposal: true, + required: ["propose.saftRegistry.addSaft"], + signed: config.alice, + + pallet: "saftRegistry", + call: "reportNav", + args: [ASSET_ID_B, 0, ASSET_ID_B_NAV], + verify: async () => { + const saft = ( + (await api.query.saftRegistry.activeSAFTs( + ASSET_ID_B, + 0 + )) as any + ).toJSON(); + const expect = { + nav: 100, + units: 100, + }; + + assert( + JSON.stringify(saft[0]) === JSON.stringify(expect), + `Report nav failed, expect: ${JSON.stringify( + expect + )}, result: ${JSON.stringify(saft[0])}` + ); + }, + }, + { + proposal: true, + required: ["propose.saftRegistry.reportNav"], + signed: config.alice, + pallet: "saftRegistry", + call: "removeSaft", + args: [ASSET_ID_B, 0], + verify: async () => { + assert( + (await api.query.saftRegistry.activeSAFTs(ASSET_ID_B, 0)) + .isEmpty, + "verify saftRegistry.removeSaft failed" + ); + }, + }, + { + proposal: true, + required: ["propose.saftRegistry.removeSaft"], + id: "saftRegistry.addSaft.C", + signed: config.alice, + pallet: "saftRegistry", + call: "addSaft", + args: [ASSET_ID_C, ASSET_ID_C_NAV, ASSET_ID_C_UNITS], + verify: async () => { + assert( + ((await api.query.assetIndex.assets(ASSET_ID_C)) as any) + .isSome, + "Add saft failed" + ); + }, + }, + { + proposal: true, + required: ["close.saftRegistry.addSaft.C"], + signed: config.alice, + pallet: "saftRegistry", + call: "convertToLiquid", + args: [ASSET_ID_C, PARENT_LOCATION], + verify: async () => { + assert( + ( + ( + await api.query.assetIndex.assets(ASSET_ID_C) + ).toHuman() as any + ).Liquid && true, + "saftRegistry.convertToLiquid failed" + ); + }, + }, /* asset-index */ { proposal: true, @@ -269,7 +362,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["close.saftRegistry.convertToLiquid"], + required: ["propose.assetIndex.deposit"], signed: config.alice, pallet: "assetIndex", call: "withdraw", @@ -289,7 +382,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.assetIndex.withdraw"], + required: ["votes.saftRegistry.addSaft"], shared: async () => { const currentBlock = ( await api.derive.chain.bestNumber() @@ -363,97 +456,6 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { // call: "removeAsset", // args: [ASSET_ID_A, BALANCE_THOUSAND, null], // }, - /* saft-registry */ - { - proposal: true, - required: ["propose.assetIndex.deposit"], - signed: config.alice, - pallet: "saftRegistry", - call: "addSaft", - args: [ASSET_ID_B, ASSET_ID_B_NAV, ASSET_ID_B_UNITS], - verify: async () => { - assert( - ((await api.query.assetIndex.assets(ASSET_ID_B)) as any) - .isSome, - "Add saft failed" - ); - }, - }, - { - proposal: true, - required: ["propose.saftRegistry.addSaft"], - signed: config.alice, - pallet: "saftRegistry", - call: "reportNav", - args: [ASSET_ID_B, 0, ASSET_ID_B_NAV], - verify: async () => { - const saft = ( - (await api.query.saftRegistry.activeSAFTs( - ASSET_ID_B, - 0 - )) as any - ).toJSON(); - const expect = { - nav: 100, - units: 100, - }; - - assert( - JSON.stringify(saft[0]) === JSON.stringify(expect), - `Report nav failed, expect: ${JSON.stringify( - expect - )}, result: ${JSON.stringify(saft[0])}` - ); - }, - }, - { - proposal: true, - required: ["propose.saftRegistry.reportNav"], - signed: config.alice, - pallet: "saftRegistry", - call: "removeSaft", - args: [ASSET_ID_B, 0], - verify: async () => { - assert( - (await api.query.saftRegistry.activeSAFTs(ASSET_ID_B, 0)) - .isEmpty, - "verify saftRegistry.removeSaft failed" - ); - }, - }, - { - proposal: true, - required: ["propose.saftRegistry.removeSaft"], - id: "saftRegistry.addSaft.C", - signed: config.alice, - pallet: "saftRegistry", - call: "addSaft", - args: [ASSET_ID_C, ASSET_ID_C_NAV, ASSET_ID_C_UNITS], - verify: async () => { - assert( - ((await api.query.assetIndex.assets(ASSET_ID_C)) as any) - .isSome, - "Add saft failed" - ); - }, - }, - { - proposal: true, - required: ["close.saftRegistry.addSaft.C"], - signed: config.alice, - pallet: "saftRegistry", - call: "convertToLiquid", - args: [ASSET_ID_C, PARENT_LOCATION], - verify: async () => { - assert( - ( - ( - await api.query.assetIndex.assets(ASSET_ID_C) - ).toHuman() as any - ).Liquid && true - ); - }, - }, /* remote-asset-manager */ // { // required: ["assetIndex.addAsset"], From 43544ac1d6e05e50170db0cb21e31912b12c83a7 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 14 Sep 2021 00:25:10 +0800 Subject: [PATCH 20/23] feat(e2e): block voting --- js/e2e/index.ts | 2 +- js/e2e/src/extrinsic.ts | 11 ++++++++++- js/e2e/src/runner.ts | 8 +++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index d3b35e8eb3..e38a798691 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -223,7 +223,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.saftRegistry.reportNav"], + required: ["propose.saftRegistry.completeWithdraw"], signed: config.alice, pallet: "saftRegistry", call: "removeSaft", diff --git a/js/e2e/src/extrinsic.ts b/js/e2e/src/extrinsic.ts index bd311c7103..4107ea3146 100644 --- a/js/e2e/src/extrinsic.ts +++ b/js/e2e/src/extrinsic.ts @@ -314,8 +314,17 @@ export class Extrinsic { public async run( finished: string[], errors: string[], - nonce: number + nonce: number, + voting?: boolean ): Promise { + while (voting) { + await waitBlock(1); + } + + if (this.id.includes("votes")) { + voting = true; + } + console.log(`-> queue extrinsic ${nonce}: ${this.id}...`); const tx = this.build(); diff --git a/js/e2e/src/runner.ts b/js/e2e/src/runner.ts index 2ce57234a9..986eb18c3c 100644 --- a/js/e2e/src/runner.ts +++ b/js/e2e/src/runner.ts @@ -46,6 +46,7 @@ export default class Runner implements Config { public finished: string[]; public nonce: number; public config: ExtrinsicConfig; + public voting: boolean; /** * run E2E tests @@ -268,7 +269,12 @@ export default class Runner implements Config { this.config ); } else { - return e.run(this.finished, this.errors, n); + return e.run( + this.finished, + this.errors, + n, + this.voting + ); } }) ).then(() => { From c06c4bb6389bdb5a3640b85514632cc31e731ba7 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 14 Sep 2021 00:34:00 +0800 Subject: [PATCH 21/23] feat(e2e): async shared data --- js/e2e/src/extrinsic.ts | 11 +++-------- js/e2e/src/runner.ts | 12 +----------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/js/e2e/src/extrinsic.ts b/js/e2e/src/extrinsic.ts index 4107ea3146..5917110b9d 100644 --- a/js/e2e/src/extrinsic.ts +++ b/js/e2e/src/extrinsic.ts @@ -314,15 +314,10 @@ export class Extrinsic { public async run( finished: string[], errors: string[], - nonce: number, - voting?: boolean + nonce: number ): Promise { - while (voting) { - await waitBlock(1); - } - - if (this.id.includes("votes")) { - voting = true; + if (typeof this.shared === "function") { + this.shared = await this.shared(); } console.log(`-> queue extrinsic ${nonce}: ${this.id}...`); diff --git a/js/e2e/src/runner.ts b/js/e2e/src/runner.ts index 986eb18c3c..c7b77ca5d6 100644 --- a/js/e2e/src/runner.ts +++ b/js/e2e/src/runner.ts @@ -46,7 +46,6 @@ export default class Runner implements Config { public finished: string[]; public nonce: number; public config: ExtrinsicConfig; - public voting: boolean; /** * run E2E tests @@ -206,10 +205,6 @@ export default class Runner implements Config { continue; } - if (!e.proposal && typeof e.shared === "function") { - e.shared = await e.shared.call(this); - } - queue.push(e); if (e.with) { for (const w of e.with) { @@ -269,12 +264,7 @@ export default class Runner implements Config { this.config ); } else { - return e.run( - this.finished, - this.errors, - n, - this.voting - ); + return e.run(this.finished, this.errors, n); } }) ).then(() => { From 7bac91ccb115b55608b116f7fad34a69d1247e33 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 14 Sep 2021 05:09:53 +0800 Subject: [PATCH 22/23] feat(e2e): run faster --- js/e2e/index.ts | 4 +- js/e2e/src/extrinsic.ts | 155 +++++++++++++++++++--------------------- js/e2e/src/runner.ts | 25 ++++--- 3 files changed, 91 insertions(+), 93 deletions(-) diff --git a/js/e2e/index.ts b/js/e2e/index.ts index e38a798691..273f482f25 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -223,7 +223,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.saftRegistry.completeWithdraw"], + required: ["propose.assetIndex.completeWithdraw"], signed: config.alice, pallet: "saftRegistry", call: "removeSaft", @@ -382,7 +382,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["votes.saftRegistry.addSaft"], + required: ["close.saftRegistry.addSaft"], shared: async () => { const currentBlock = ( await api.derive.chain.bestNumber() diff --git a/js/e2e/src/extrinsic.ts b/js/e2e/src/extrinsic.ts index 5917110b9d..dc46d6208e 100644 --- a/js/e2e/src/extrinsic.ts +++ b/js/e2e/src/extrinsic.ts @@ -64,7 +64,11 @@ export class Extrinsic { * @param {ex} Extrinsic * @returns {Transaction} */ - public build(): Transaction { + public async build(): Promise { + if (typeof this.shared === "function") { + this.shared = await this.shared(); + } + // flush arguments const args: any[] = []; for (const arg of this.args) { @@ -175,98 +179,79 @@ export class Extrinsic { * Run extrinsic with proposal */ public async propose( + proposals: Record, finished: string[], errors: string[], - nonce: number, queue: Extrinsic[], config: ExtrinsicConfig ): Promise { const id = this.id ? this.id : `${this.pallet}.${this.call}`; - const proposal = new Extrinsic( - { - id: `propose.${id}`, - required: this.required, - signed: this.signed, - pallet: "committee", - call: "propose", - args: [this.api.tx[this.pallet][this.call](...this.args)], - }, - this.api, - this.pair - ); - - await proposal.run(finished, errors, nonce); - const hash = await this.getLastestProposal(); - queue.push( new Extrinsic( { - required: [`propose.${id}`], - id: `votes.${id}`, - shared: async () => { - return new Promise(async (resolve) => { - await waitBlock(1); - const currentBlock = ( - await this.api.derive.chain.bestNumber() - ).toNumber(); - - const end = ( - ( - await this.api.query.committee.votes(hash) - ).toJSON() as any - ).end as number; - - const needsToWait = - end - currentBlock > VOTING_PERIOD - ? end - currentBlock - VOTING_PERIOD - : 0; - - console.log( - `\t | voting ${this.pallet}.${this.call}` - ); - console.log( - `\t | waiting for the voting peirod (around ${Math.floor( - (needsToWait * 12) / 60 - )} mins)...` - ); - - await waitBlock(needsToWait); - resolve(hash); - }); - }, - signed: config.alice, + id: `propose.${id}`, + required: this.required, + signed: this.signed, pallet: "committee", - call: "vote", - args: [hash, this.api.createType("Vote" as any)], - with: [ - { - id: `votes.${id}.bob`, - signed: config.bob, - pallet: "committee", - call: "vote", - args: [hash, this.api.createType("Vote" as any)], - }, - { - id: `votes.${id}.charlie`, - signed: config.charlie, - pallet: "committee", - call: "vote", - args: [hash, this.api.createType("Vote" as any)], - }, - { - id: `votes.${id}.dave`, - signed: config.dave, - pallet: "committee", - call: "vote", - args: [hash, this.api.createType("Vote" as any)], - }, - ], + call: "propose", + args: [this.api.tx[this.pallet][this.call](...this.args)], }, this.api, this.pair ) ); + for (const account of ["alice", "bob", "charlie", "dave"]) { + queue.push( + new Extrinsic( + { + required: [`propose.${id}`], + id: `votes.${id}.${account}`, + shared: async () => { + return new Promise(async (resolve) => { + const hash = proposals[this.id]; + const currentBlock = ( + await this.api.derive.chain.bestNumber() + ).toNumber(); + + const end = ( + ( + await this.api.query.committee.votes( + hash + ) + ).toJSON() as any + ).end as number; + + const needsToWait = + end - currentBlock > VOTING_PERIOD + ? end - currentBlock - VOTING_PERIOD + : 0; + + console.log(`\t | voting ${id}...`); + console.log( + `\t | waiting for the voting peirod (around ${Math.floor( + (needsToWait * 12) / 60 + )} mins)...` + ); + + await waitBlock(needsToWait); + resolve(hash); + }); + }, + signed: (config as any)[account], + pallet: "committee", + call: "vote", + args: [ + () => proposals[this.id], + this.api.createType("Vote" as any), + ], + }, + this.api, + this.pair + ) + ); + } + // push close and verification queue.push( new Extrinsic( @@ -274,6 +259,7 @@ export class Extrinsic { required: [`votes.${id}.dave`], id: `close.${id}`, shared: async () => { + const hash = proposals[this.id]; const currentBlock = ( await this.api.derive.chain.bestNumber() ).toNumber(); @@ -297,7 +283,7 @@ export class Extrinsic { signed: config.alice, pallet: "committee", call: "close", - args: [hash], + args: [() => proposals[this.id]], verify: this.verify, }, this.api, @@ -312,16 +298,13 @@ export class Extrinsic { * @param {ex} Extrinsic */ public async run( + proposals: Record, finished: string[], errors: string[], nonce: number ): Promise { - if (typeof this.shared === "function") { - this.shared = await this.shared(); - } - console.log(`-> queue extrinsic ${nonce}: ${this.id}...`); - const tx = this.build(); + const tx = await this.build(); // get res const res = (await this.send(tx, nonce, this.signed).catch( @@ -354,6 +337,12 @@ export class Extrinsic { (await res.unsub)(); } + // push hash if is proposal + if (this.id.includes("propose.")) { + proposals[this.id.split("propose.")[1]] = + await this.getLastestProposal(); + } + finished.push(this.id); } } diff --git a/js/e2e/src/runner.ts b/js/e2e/src/runner.ts index c7b77ca5d6..7671938ec5 100644 --- a/js/e2e/src/runner.ts +++ b/js/e2e/src/runner.ts @@ -46,6 +46,7 @@ export default class Runner implements Config { public finished: string[]; public nonce: number; public config: ExtrinsicConfig; + public proposals: Record; /** * run E2E tests @@ -157,6 +158,7 @@ export default class Runner implements Config { this.nonce = 0; this.finished = []; this.config = config.config; + this.proposals = {}; } /** @@ -249,22 +251,29 @@ export default class Runner implements Config { return isFunction; }) .map((e) => { - let n = -1; - if (!e.signed || e.signed.address === this.pair.address) { - n = Number(currentNonce); - currentNonce += 1; - } - if (e.proposal) { return e.propose( + this.proposals, this.finished, this.errors, - n, this.exs, this.config ); } else { - return e.run(this.finished, this.errors, n); + let n = -1; + if ( + !e.signed || + e.signed.address === this.pair.address + ) { + n = Number(currentNonce); + currentNonce += 1; + } + return e.run( + this.proposals, + this.finished, + this.errors, + n + ); } }) ).then(() => { From d1fbf663607f982365b97e941d7be2f076c02e30 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 14 Sep 2021 05:58:49 +0800 Subject: [PATCH 23/23] feat(e2e): after setMetadata --- 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 273f482f25..fc42a8c1dd 100644 --- a/js/e2e/index.ts +++ b/js/e2e/index.ts @@ -223,7 +223,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, { proposal: true, - required: ["propose.assetIndex.completeWithdraw"], + required: ["propose.assetIndex.setMetadata"], signed: config.alice, pallet: "saftRegistry", call: "removeSaft",