diff --git a/js/e2e/index.ts b/js/e2e/index.ts index 23d0af767b..fc42a8c1dd 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"; @@ -15,12 +14,15 @@ 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: number = 1; -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(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; const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { @@ -65,40 +67,220 @@ 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" + ); + }, + }, + /* orml_tokens */ + { + required: ["priceFeed.mapAssetPriceFeed"], + 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, + pallet: "chainlinkFeed", + call: "createFeed", + args: [ + PINT.mul(new BN(100)), + 0, + [1, 100], + 1, + 0, + "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, 1], + verify: async () => { + assert( + (await api.query.chainlinkFeed.rounds(0, 1)).isEmpty, + "Create feed failed" + ); + }, + }, + /* price-feed */ + { + required: ["propose.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" + ); + }, + }, + { + required: ["propose.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" + ); + }, + }, + /* 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.assetIndex.setMetadata"], + 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, - // 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, pallet: "assetIndex", - call: "addAsset", + call: "registerAsset", args: [ ASSET_ID_A, - ASSET_ID_A_UNITS, - PARENT_LOCATION, - ASSET_ID_A_VALUE, + api.createType("AssetAvailability" as any, { + Liquid: PARENT_LOCATION, + }), ], verify: async () => { assert( @@ -109,90 +291,172 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => { }, }, { + required: ["propose.assetIndex.registerAsset"], + 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" + ); + }, + }, + { + required: ["propose.assetIndex.setDepositRange"], proposal: true, - required: ["votes.priceFeed.mapAssetPriceFeed"], + 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 (before: Balance) => { + const current = ( + await api.query.system.account(config.alice.address) + ).data.free; + assert( + current.sub(before).div(PINT).toNumber() === + ASSET_ID_A_AMOUNT.sub(new BN(1)).toNumber(), + "assetIndex.addAsset failed" + ); + }, + }, + { + proposal: true, + required: ["tokens.setBalance"], 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" - // ); + 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: ["propose.assetIndex.deposit"], signed: config.alice, pallet: "assetIndex", call: "withdraw", - args: [PINT.mul(BALANCE_THOUSAND).div(new BN(4))], + args: [PINT.mul(ASSET_ID_A_AMOUNT)], verify: async () => { - // assert( - // ( - // ( - // await api.query.assetIndex.pendingWithdrawals( - // config.alice.address - // ) - // ).toHuman() as any - // ).length === 1, - // "assetIndex.withdraw failed" - // ); + assert( + ( + ( + await api.query.assetIndex.pendingWithdrawals( + config.alice.address + ) + ).toHuman() as any + ).length === 1, + "assetIndex.withdraw failed" + ); }, }, - // { - // 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)...` - // ); + { + proposal: true, + required: ["close.saftRegistry.addSaft"], + shared: async () => { + const currentBlock = ( + await api.derive.chain.bestNumber() + ).toNumber(); + 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 + ? end - currentBlock - WITHDRAWALS_PERIOD + : 0; + + 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: ["propose.assetIndex.completeWithdraw"], + 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" + ); + }, + }, + // TODO: XCM // - // await waitBlock(needsToWait); - // }, + // { + // // proposal: true, + // // required: ["votes.priceFeed.unmapAssetPriceFeed"], + // required: ["assetIndex.setMetadata"], // 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" - // // ); - // }, + // call: "removeAsset", + // args: [ASSET_ID_A, BALANCE_THOUSAND, null], // }, - /* remote-asset-manager*/ + /* remote-asset-manager */ // { // required: ["assetIndex.addAsset"], // signed: config.alice, @@ -249,172 +513,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, - // 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/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 e1ef0b364a..dc46d6208e 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; @@ -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,142 +179,111 @@ 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.pallet}.${this.call}`; - const proposal = new Extrinsic( - { - id: `propose.${id}`, - 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(); - + const id = this.id ? this.id : `${this.pallet}.${this.call}`; queue.push( new Extrinsic( { - 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: [ - async (hash: string): Promise => { - return { - 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), - ], - }; - }, - async (hash: string): Promise => { - return { - 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( { required: [`votes.${id}.dave`], - id: `close.${this.pallet}.${this.call}`, + id: `close.${id}`, shared: async () => { - return new Promise(async (resolve) => { - 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; - console.log( - `\t | waiting for the end of voting peirod ( ${needsToWait} blocks )` - ); - - await waitBlock(needsToWait > 0 ? needsToWait : 0); - resolve(hash); - }); + 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 + 1; + console.log( + `\t | waiting for the end of voting peirod ( ${needsToWait} blocks )` + ); + + await waitBlock(needsToWait > 0 ? needsToWait : 1); + if (this.shared && typeof this.shared === "function") { + return await this.shared(); + } }, signed: config.alice, pallet: "committee", call: "close", - args: [(hash: string) => hash], + args: [() => proposals[this.id]], verify: this.verify, }, this.api, @@ -325,17 +298,24 @@ export class Extrinsic { * @param {ex} Extrinsic */ public async run( + proposals: Record, finished: string[], errors: string[], nonce: number ): Promise { 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( (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; @@ -343,7 +323,13 @@ 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}`); + + // FIX ME: + // + // for test now + process.exit(1); }); } @@ -351,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 221f712501..7671938ec5 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"; @@ -47,6 +46,7 @@ export default class Runner implements Config { public finished: string[]; public nonce: number; public config: ExtrinsicConfig; + public proposals: Record; /** * run E2E tests @@ -158,6 +158,7 @@ export default class Runner implements Config { this.nonce = 0; this.finished = []; this.config = config.config; + this.proposals = {}; } /** @@ -188,12 +189,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; } @@ -204,32 +207,16 @@ export default class Runner implements Config { continue; } - // 1. Build shared data - if (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)); } } } 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); } @@ -264,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(() => { 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",