difftreelog
feat westmint playgrounds
in: master
3 files changed
tests/src/util/playgrounds/index.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import {Context} from 'mocha';8import config from '../../config';9import '../../interfaces/augment-api-events';10import {ChainHelperBase} from './unique';11import {ILogger} from './types';12import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper} from './unique.dev';1314chai.use(chaiAsPromised);15export const expect = chai.expect;1617async function usingPlaygroundsGeneral<T extends ChainHelperBase>(helperType: new(logger: ILogger) => T, url: string, code: (helper: T, privateKey: (seed: string) => IKeyringPair) => Promise<void>) {18 const silentConsole = new SilentConsole();19 silentConsole.enable();2021 const helper = new helperType(new SilentLogger());2223 try {24 await helper.connect(url);25 const ss58Format = helper.chain.getChainProperties().ss58Format;26 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);27 await code(helper, privateKey);28 }29 finally {30 await helper.disconnect();31 silentConsole.disable();32 }33}3435export const usingPlaygrounds = (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>, url: string = config.substrateUrl) => {36 return usingPlaygroundsGeneral<DevUniqueHelper>(DevUniqueHelper, url, code);37};3839// TODO specific type40export const usingStatemintPlaygrounds = async (url: string, code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {41 return usingPlaygroundsGeneral<DevUniqueHelper>(DevUniqueHelper, url, code);42};4344export const usingRelayPlaygrounds = async (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {45 return usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);46};4748export const usingAcalaPlaygrounds = async (url: string, code: (helper: DevAcalaHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {49 return usingPlaygroundsGeneral<DevAcalaHelper>(DevAcalaHelper, url, code);50};5152export const usingKaruraPlaygrounds = async (url: string, code: (helper: DevKaruraHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {53 return usingPlaygroundsGeneral<DevKaruraHelper>(DevAcalaHelper, url, code);54};5556export const usingMoonbeamPlaygrounds = async (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {57 return usingPlaygroundsGeneral<DevMoonbeamHelper>(DevMoonbeamHelper, url, code);58};5960export const usingMoonriverPlaygrounds = async (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {61 return usingPlaygroundsGeneral<DevMoonriverHelper>(DevMoonriverHelper, url, code);62};6364export enum Pallets {65 Inflation = 'inflation',66 RmrkCore = 'rmrkcore',67 RmrkEquip = 'rmrkequip',68 ReFungible = 'refungible',69 Fungible = 'fungible',70 NFT = 'nonfungible',71 Scheduler = 'scheduler',72 AppPromotion = 'apppromotion',73}7475export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {76 const missingPallets = helper.fetchMissingPalletNames(requiredPallets);77 78 if (missingPallets.length > 0) {79 const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;80 console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);81 test.skip();82 }83}8485export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {86 (opts.only ? it.only : 87 opts.skip ? it.skip : it)(name, async function () {88 await usingPlaygrounds(async (helper, privateKey) => {89 if (opts.requiredPallets) {90 requirePalletsOrSkip(this, helper, opts.requiredPallets);91 }92 93 await cb({helper, privateKey});94 });95 });96}97export async function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {98 return itSub(name, cb, {requiredPallets: required, ...opts});99}100itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});101itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});102103itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {only: true});104itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});105itSub.ifWithPallets = itSubIfWithPallet;106107export const describeXcm = (108 process.env.RUN_XCM_TESTS109 ? describe110 : describe.skip111);1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import {Context} from 'mocha';8import config from '../../config';9import '../../interfaces/augment-api-events';10import {ChainHelperBase} from './unique';11import {ILogger} from './types';12import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper} from './unique.dev';1314chai.use(chaiAsPromised);15export const expect = chai.expect;1617async function usingPlaygroundsGeneral<T extends ChainHelperBase>(helperType: new(logger: ILogger) => T, url: string, code: (helper: T, privateKey: (seed: string) => IKeyringPair) => Promise<void>) {18 const silentConsole = new SilentConsole();19 silentConsole.enable();2021 const helper = new helperType(new SilentLogger());2223 try {24 await helper.connect(url);25 const ss58Format = helper.chain.getChainProperties().ss58Format;26 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);27 await code(helper, privateKey);28 }29 finally {30 await helper.disconnect();31 silentConsole.disable();32 }33}3435export const usingPlaygrounds = (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>, url: string = config.substrateUrl) => {36 return usingPlaygroundsGeneral<DevUniqueHelper>(DevUniqueHelper, url, code);37};3839export const usingWestmintPlaygrounds = async (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {40 return usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);41};4243export const usingRelayPlaygrounds = async (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {44 return usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);45};4647export const usingAcalaPlaygrounds = async (url: string, code: (helper: DevAcalaHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {48 return usingPlaygroundsGeneral<DevAcalaHelper>(DevAcalaHelper, url, code);49};5051export const usingKaruraPlaygrounds = async (url: string, code: (helper: DevKaruraHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {52 return usingPlaygroundsGeneral<DevKaruraHelper>(DevAcalaHelper, url, code);53};5455export const usingMoonbeamPlaygrounds = async (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {56 return usingPlaygroundsGeneral<DevMoonbeamHelper>(DevMoonbeamHelper, url, code);57};5859export const usingMoonriverPlaygrounds = async (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {60 return usingPlaygroundsGeneral<DevMoonriverHelper>(DevMoonriverHelper, url, code);61};6263export enum Pallets {64 Inflation = 'inflation',65 RmrkCore = 'rmrkcore',66 RmrkEquip = 'rmrkequip',67 ReFungible = 'refungible',68 Fungible = 'fungible',69 NFT = 'nonfungible',70 Scheduler = 'scheduler',71 AppPromotion = 'apppromotion',72}7374export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {75 const missingPallets = helper.fetchMissingPalletNames(requiredPallets);76 77 if (missingPallets.length > 0) {78 const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;79 console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);80 test.skip();81 }82}8384export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {85 (opts.only ? it.only : 86 opts.skip ? it.skip : it)(name, async function () {87 await usingPlaygrounds(async (helper, privateKey) => {88 if (opts.requiredPallets) {89 requirePalletsOrSkip(this, helper, opts.requiredPallets);90 }91 92 await cb({helper, privateKey});93 });94 });95}96export async function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {97 return itSub(name, cb, {requiredPallets: required, ...opts});98}99itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});100itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});101102itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {only: true});103itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});104itSub.ifWithPallets = itSubIfWithPallet;105106export const describeXcm = (107 process.env.RUN_XCM_TESTS108 ? describe109 : describe.skip110);tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import {mnemonicGenerate} from '@polkadot/util-crypto';
-import {UniqueHelper, MoonbeamHelper, ChainHelperBase, AcalaHelper, RelayHelper} from './unique';
+import {UniqueHelper, MoonbeamHelper, ChainHelperBase, AcalaHelper, RelayHelper, WestmintHelper} from './unique';
import {ApiPromise, Keyring, WsProvider} from '@polkadot/api';
import * as defs from '../../interfaces/definitions';
import {IKeyringPair} from '@polkadot/types/types';
@@ -110,6 +110,17 @@
export class DevRelayHelper extends RelayHelper {}
+export class DevWestmintHelper extends WestmintHelper {
+ wait: WaitGroup;
+
+ constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {
+ options.helperBase = options.helperBase ?? DevWestmintHelper;
+
+ super(logger, options);
+ this.wait = new WaitGroup(this);
+ }
+}
+
export class DevMoonbeamHelper extends MoonbeamHelper {
account: MoonbeamAccountGroup;
wait: WaitGroup;
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2468,6 +2468,10 @@
async transferMultiasset(signer: TSigner, asset: any, destination: any, destWeight: number) {
await this.helper.executeExtrinsic(signer, 'api.tx.xTokens.transferMultiasset', [asset, destination, destWeight], true);
}
+
+ async transferMulticurrencies(signer: TSigner, currencies: any[], feeItem: number, destLocation: any, destWeight: number) {
+ await this.helper.executeExtrinsic(signer, 'api.tx.xTokens.transferMulticurrencies', [currencies, feeItem, destLocation, destWeight], true);
+ }
}
class TokensGroup<T extends ChainHelperBase> extends HelperGroup<T> {
@@ -2477,6 +2481,32 @@
}
}
+class AssetsGroup<T extends ChainHelperBase> extends HelperGroup<T> {
+ async create(signer: TSigner, assetId: number, admin: string, minimalBalance: bigint) {
+ await this.helper.executeExtrinsic(signer, 'api.tx.assets.create', [assetId, admin, minimalBalance], true);
+ }
+
+ async setMetadata(signer: TSigner, assetId: number, name: string, symbol: string, decimals: number) {
+ await this.helper.executeExtrinsic(signer, 'api.tx.assets.setMetadata', [assetId, name, symbol, decimals], true);
+ }
+
+ async mint(signer: TSigner, assetId: number, beneficiary: string, amount: bigint) {
+ await this.helper.executeExtrinsic(signer, 'api.tx.assets.mint', [assetId, beneficiary, amount], true);
+ }
+
+ async account(assetId: string | number, address: string) {
+ const accountAsset = (
+ await this.helper.callRpc('api.query.assets.account', [assetId, address])
+ ).toJSON()! as any;
+
+ if (accountAsset !== null) {
+ return BigInt(accountAsset['balance']);
+ } else {
+ return null;
+ }
+ }
+}
+
class AcalaAssetRegistryGroup extends HelperGroup<AcalaHelper> {
async registerForeignAsset(signer: TSigner, destination: any, metadata: AcalaAssetMetadata) {
await this.helper.executeExtrinsic(signer, 'api.tx.assetRegistry.registerForeignAsset', [destination, metadata], true);
@@ -2504,20 +2534,6 @@
async assetTypeId(location: any) {
return await this.helper.callRpc('api.query.assetManager.assetTypeId', [location]);
- }
-}
-
-class MoonbeamAssetsGroup extends HelperGroup<MoonbeamHelper> {
- async account(assetId: string, address: string) {
- const accountAsset = (
- await this.helper.callRpc('api.query.assets.account', [assetId, address])
- ).toJSON()! as any;
-
- if (accountAsset !== null) {
- return BigInt(accountAsset['balance']);
- } else {
- return null;
- }
}
}
@@ -2626,10 +2642,26 @@
}
}
+export class WestmintHelper extends XcmChainHelper {
+ balance: SubstrateBalanceGroup<WestmintHelper>;
+ xcm: XcmGroup<WestmintHelper>;
+ assets: AssetsGroup<WestmintHelper>;
+ xTokens: XTokensGroup<WestmintHelper>;
+
+ constructor(logger?: ILogger, options: {[key: string]: any} = {}) {
+ super(logger, options.helperBase ?? WestmintHelper);
+
+ this.balance = new SubstrateBalanceGroup(this);
+ this.xcm = new XcmGroup(this, 'polkadotXcm');
+ this.assets = new AssetsGroup(this);
+ this.xTokens = new XTokensGroup(this);
+ }
+}
+
export class MoonbeamHelper extends XcmChainHelper {
balance: EthereumBalanceGroup<MoonbeamHelper>;
assetManager: MoonbeamAssetManagerGroup;
- assets: MoonbeamAssetsGroup;
+ assets: AssetsGroup<MoonbeamHelper>;
xTokens: XTokensGroup<MoonbeamHelper>;
democracy: MoonbeamDemocracyGroup;
collective: {
@@ -2642,7 +2674,7 @@
this.balance = new EthereumBalanceGroup(this);
this.assetManager = new MoonbeamAssetManagerGroup(this);
- this.assets = new MoonbeamAssetsGroup(this);
+ this.assets = new AssetsGroup(this);
this.xTokens = new XTokensGroup(this);
this.democracy = new MoonbeamDemocracyGroup(this);
this.collective = {