difftreelog
test(util-playgrounds) modifications and additions of all stripes
in: master
5 files changed
tests/package.jsondiffbeforeafterboth1{2 "name": "unique-tests",3 "version": "1.0.0",4 "description": "Unique Chain Tests",5 "main": "",6 "devDependencies": {7 "@polkadot/ts": "0.4.22",8 "@polkadot/typegen": "9.2.2",9 "@types/chai": "^4.3.1",10 "@types/chai-as-promised": "^7.1.5",11 "@types/chai-like": "^1.1.1",12 "@types/mocha": "^9.1.1",13 "@types/node": "^17.0.35",14 "@typescript-eslint/eslint-plugin": "^5.26.0",15 "@typescript-eslint/parser": "^5.26.0",16 "chai": "^4.3.6",17 "eslint": "^8.16.0",18 "mocha": "^10.0.0",19 "ts-node": "^10.8.0",20 "typescript": "^4.7.2"21 },22 "mocha": {23 "timeout": 9999999,24 "require": "ts-node/register"25 },26 "scripts": {27 "lint": "eslint --ext .ts,.js src/",28 "fix": "eslint --ext .ts,.js src/ --fix",29 "test": "mocha --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",30 "testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",31 "testEthMarketplace": "mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",32 "testEthNesting": "mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",33 "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",34 "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",35 "loadTransfer": "ts-node src/transfer.nload.ts",36 "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",37 "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",38 "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",39 "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",40 "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",41 "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",42 "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",43 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",44 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",45 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",46 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",47 "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",48 "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",49 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",50 "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",51 "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",52 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",53 "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",54 "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",55 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",56 "testCreateMultipleItemsEx": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItemsEx.test.ts",57 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",58 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",59 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",60 "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts",61 "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",62 "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",63 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",64 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",65 "testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",66 "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",67 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",68 "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",69 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",70 "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",71 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",72 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",73 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",74 "testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts",75 "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",76 "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",77 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",78 "testXcmTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/xcmTransfer.test.ts",79 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",80 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",81 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",82 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",83 "testEthCreateNFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createNFTCollection.test.ts",84 "testEthCreateRFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createRFTCollection.test.ts",85 "testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",86 "testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",87 "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",88 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",89 "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",90 "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",91 "polkadot-types": "echo \"export default {}\" > src/interfaces/lookup.ts && yarn polkadot-types-fetch-metadata && yarn polkadot-types-from-defs && yarn polkadot-types-from-defs && yarn polkadot-types-from-chain"92 },93 "author": "",94 "license": "SEE LICENSE IN ../LICENSE",95 "homepage": "",96 "dependencies": {97 "@polkadot/api": "9.2.2",98 "@polkadot/api-contract": "9.2.2",99 "@polkadot/util-crypto": "10.1.1",100 "bignumber.js": "^9.0.2",101 "chai-as-promised": "^7.1.1",102 "chai-like": "^1.1.1",103 "find-process": "^1.4.7",104 "solc": "0.8.14-fixed",105 "web3": "^1.7.3"106 },107 "standard": {108 "globals": [109 "it",110 "assert",111 "beforeEach",112 "afterEach",113 "describe",114 "contract",115 "artifacts"116 ]117 },118 "resolutions": {119 "simple-get": "^4.0.1"120 }121}1{2 "name": "unique-tests",3 "version": "1.0.0",4 "description": "Unique Chain Tests",5 "main": "",6 "devDependencies": {7 "@polkadot/ts": "0.4.22",8 "@polkadot/typegen": "9.2.2",9 "@types/chai": "^4.3.1",10 "@types/chai-as-promised": "^7.1.5",11 "@types/chai-like": "^1.1.1",12 "@types/mocha": "^9.1.1",13 "@types/node": "^17.0.35",14 "@typescript-eslint/eslint-plugin": "^5.26.0",15 "@typescript-eslint/parser": "^5.26.0",16 "chai": "^4.3.6",17 "eslint": "^8.16.0",18 "mocha": "^10.0.0",19 "ts-node": "^10.8.0",20 "typescript": "^4.7.2"21 },22 "mocha": {23 "timeout": 9999999,24 "require": "ts-node/register"25 },26 "scripts": {27 "lint": "eslint --ext .ts,.js src/",28 "fix": "eslint --ext .ts,.js src/ --fix",29 "test": "mocha --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",30 "testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",31 "testEthMarketplace": "mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",32 "testEthNesting": "mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",33 "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",34 "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",35 "loadTransfer": "ts-node src/transfer.nload.ts",36 "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",37 "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",38 "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",39 "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",40 "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",41 "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",42 "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",43 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",44 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",45 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",46 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",47 "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",48 "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",49 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",50 "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",51 "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",52 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",53 "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",54 "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",55 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",56 "testCreateMultipleItemsEx": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItemsEx.test.ts",57 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",58 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",59 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",60 "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts",61 "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",62 "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",63 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",64 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",65 "testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",66 "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",67 "testSetPublicAccessMode": "mocha --timeout 9999999 -r ts-node/register ./**/setPublicAccessMode.test.ts",68 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",69 "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",70 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",71 "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",72 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",73 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",74 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",75 "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",76 "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",77 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",78 "testXcmTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/xcmTransfer.test.ts",79 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",80 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",81 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",82 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",83 "testEthCreateNFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createNFTCollection.test.ts",84 "testEthCreateRFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createRFTCollection.test.ts",85 "testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",86 "testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",87 "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",88 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",89 "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",90 "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",91 "polkadot-types": "echo \"export default {}\" > src/interfaces/lookup.ts && yarn polkadot-types-fetch-metadata && yarn polkadot-types-from-defs && yarn polkadot-types-from-defs && yarn polkadot-types-from-chain"92 },93 "author": "",94 "license": "SEE LICENSE IN ../LICENSE",95 "homepage": "",96 "dependencies": {97 "@polkadot/api": "9.2.2",98 "@polkadot/api-contract": "9.2.2",99 "@polkadot/util-crypto": "10.1.1",100 "bignumber.js": "^9.0.2",101 "chai-as-promised": "^7.1.1",102 "chai-like": "^1.1.1",103 "find-process": "^1.4.7",104 "solc": "0.8.14-fixed",105 "web3": "^1.7.3"106 },107 "standard": {108 "globals": [109 "it",110 "assert",111 "beforeEach",112 "afterEach",113 "describe",114 "contract",115 "artifacts"116 ]117 },118 "resolutions": {119 "simple-get": "^4.0.1"120 }121}tests/src/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/index.ts
+++ b/tests/src/util/playgrounds/index.ts
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import {IKeyringPair} from '@polkadot/types/types';
+import {Context} from 'mocha';
import config from '../../config';
import '../../interfaces/augment-api-events';
import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';
@@ -24,3 +25,39 @@
silentConsole.disable();
}
};
+
+export enum Pallets {
+ Inflation = 'inflation',
+ RmrkCore = 'rmrkcore',
+ RmrkEquip = 'rmrkequip',
+ ReFungible = 'refungible',
+ Fungible = 'fungible',
+ NFT = 'nonfungible',
+ Scheduler = 'scheduler',
+}
+
+export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {
+ const missingPallets = helper.fetchMissingPalletNames(requiredPallets);
+
+ if (missingPallets.length > 0) {
+ const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;
+ console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);
+ test.skip();
+ }
+}
+
+export async function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
+ (opts.only ? it.only :
+ opts.skip ? it.skip : it)(name, async function () {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ if (opts.requiredPallets) {
+ requirePalletsOrSkip(this, helper, opts.requiredPallets);
+ }
+
+ await cb({helper, privateKey});
+ });
+ });
+}
+itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {only: true});
+itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {skip: true});
+itSub.ifWithPallets = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itSub(name, cb, {requiredPallets: required});
tests/src/util/playgrounds/types.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/types.ts
+++ b/tests/src/util/playgrounds/types.ts
@@ -102,9 +102,9 @@
}
export interface ICollectionCreationOptions {
- name: string | number[];
- description: string | number[];
- tokenPrefix: string | number[];
+ name?: string | number[];
+ description?: string | number[];
+ tokenPrefix?: string | number[];
mode?: {
nft?: null;
refungible?: null;
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -118,14 +118,15 @@
*/
createAccounts = async (balances: bigint[], donor: IKeyringPair): Promise<IKeyringPair[]> => {
let nonce = await this.helper.chain.getNonce(donor.address);
+ const ss58Format = this.helper.chain.getChainProperties().ss58Format;
const tokenNominal = this.helper.balance.getOneTokenNominal();
const transactions = [];
const accounts: IKeyringPair[] = [];
for (const balance of balances) {
- const recepient = this.helper.util.fromSeed(mnemonicGenerate());
- accounts.push(recepient);
+ const recipient = this.helper.util.fromSeed(mnemonicGenerate(), ss58Format);
+ accounts.push(recipient);
if (balance !== 0n) {
- const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recepient.address}, balance * tokenNominal]);
+ const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recipient.address}, balance * tokenNominal]);
transactions.push(this.helper.signTransaction(donor, tx, 'account generation', {nonce}));
nonce++;
}
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -11,13 +11,12 @@
import {IKeyringPair} from '@polkadot/types/types';
import {IApiListeners, IChainEvent, IChainProperties, ICollectionCreationOptions, ICollectionLimits, ICollectionPermissions, ICrossAccountId, ICrossAccountIdLower, ILogger, INestingPermissions, IProperty, IToken, ITokenPropertyPermission, ITransactionResult, IUniqueHelperLog, TApiAllowedListeners, TEthereumAccount, TSigner, TSubstrateAccount, TUniqueNetworks} from './types';
-const crossAccountIdFromLower = (lowerAddress: ICrossAccountIdLower): ICrossAccountId => {
+export const crossAccountIdFromLower = (lowerAddress: ICrossAccountIdLower): ICrossAccountId => {
const address = {} as ICrossAccountId;
if(lowerAddress.substrate) address.Substrate = lowerAddress.substrate;
if(lowerAddress.ethereum) address.Ethereum = lowerAddress.ethereum;
return address;
};
-
const nesting = {
toChecksumAddress(address: string): string {
@@ -440,6 +439,16 @@
if(typeof signer === 'string') return signer;
return signer.address;
}
+
+ fetchAllPalletNames(): string[] {
+ if(this.api === null) throw Error('API not initialized');
+ return this.api.runtimeMetadata.asLatest.pallets.map(m => m.name.toString().toLowerCase());
+ }
+
+ fetchMissingPalletNames(requiredPallets: string[]): string[] {
+ const palletNames = this.fetchAllPalletNames();
+ return requiredPallets.filter(p => !palletNames.includes(p));
+ }
}
@@ -476,7 +485,9 @@
}
/**
- * Get information about the collection with additional data, including the number of tokens it contains, its administrators, the normalized address of the collection's owner, and decoded name and description.
+ * Get information about the collection with additional data,
+ * including the number of tokens it contains, its administrators,
+ * the normalized address of the collection's owner, and decoded name and description.
*
* @param collectionId ID of collection
* @example await getData(2)
@@ -504,42 +515,50 @@
collectionData[key] = this.helper.util.vec2str(humanCollection[key]);
}
- collectionData.tokensCount = (['RFT', 'NFT'].includes(humanCollection.mode)) ? await this.helper[humanCollection.mode.toLocaleLowerCase() as 'nft' | 'rft'].getLastTokenId(collectionId) : 0;
+ collectionData.tokensCount = (['RFT', 'NFT'].includes(humanCollection.mode))
+ ? await this.helper[humanCollection.mode.toLocaleLowerCase() as 'nft' | 'rft'].getLastTokenId(collectionId)
+ : 0;
collectionData.admins = await this.getAdmins(collectionId);
return collectionData;
}
/**
- * Get the normalized addresses of the collection's administrators.
+ * Get the addresses of the collection's administrators, optionally normalized.
*
* @param collectionId ID of collection
+ * @param normalize whether to normalize the addresses to the default ss58 format
* @example await getAdmins(1)
* @returns array of administrators
*/
- async getAdmins(collectionId: number): Promise<ICrossAccountId[]> {
- const normalized = [];
- for(const admin of (await this.helper.callRpc('api.rpc.unique.adminlist', [collectionId])).toHuman()) {
- if(admin.Substrate) normalized.push({Substrate: this.helper.address.normalizeSubstrate(admin.Substrate)});
- else normalized.push(admin);
- }
- return normalized;
+ async getAdmins(collectionId: number, normalize = false): Promise<ICrossAccountId[]> {
+ const admins = (await this.helper.callRpc('api.rpc.unique.adminlist', [collectionId])).toHuman();
+
+ return normalize
+ ? admins.map((address: any) => {
+ return address.Substrate
+ ? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}
+ : address;
+ })
+ : admins;
}
/**
- * Get the normalized addresses added to the collection allow-list.
+ * Get the addresses added to the collection allow-list, optionally normalized.
* @param collectionId ID of collection
+ * @param normalize whether to normalize the addresses to the default ss58 format
* @example await getAllowList(1)
* @returns array of allow-listed addresses
*/
- async getAllowList(collectionId: number): Promise<ICrossAccountId[]> {
- const normalized = [];
+ async getAllowList(collectionId: number, normalize = false): Promise<ICrossAccountId[]> {
const allowListed = (await this.helper.callRpc('api.rpc.unique.allowlist', [collectionId])).toHuman();
- for (const address of allowListed) {
- if (address.Substrate) normalized.push({Substrate: this.helper.address.normalizeSubstrate(address.Substrate)});
- else normalized.push(address);
- }
- return normalized;
+ return normalize
+ ? allowListed.map((address: any) => {
+ return address.Substrate
+ ? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}
+ : address;
+ })
+ : allowListed;
}
/**
@@ -572,7 +591,7 @@
}
/**
- * Sets the sponsor for the collection (Requires the Substrate address).
+ * Sets the sponsor for the collection (Requires the Substrate address). Needs confirmation by the sponsor.
*
* @param signer keyring of signer
* @param collectionId ID of collection
@@ -609,6 +628,24 @@
}
/**
+ * Removes the sponsor of a collection, regardless if it consented or not.
+ *
+ * @param signer keyring of signer
+ * @param collectionId ID of collection
+ * @example removeSponsor(aliceKeyring, 10)
+ * @returns ```true``` if extrinsic success, otherwise ```false```
+ */
+ async removeSponsor(signer: TSigner, collectionId: number): Promise<boolean> {
+ const result = await this.helper.executeExtrinsic(
+ signer,
+ 'api.tx.unique.removeCollectionSponsor', [collectionId],
+ true,
+ );
+
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorRemoved');
+ }
+
+ /**
* Sets the limits of the collection. At least one limit must be specified for a correct call.
*
* @param signer keyring of signer
@@ -2004,6 +2041,10 @@
return await this.helper.collection.confirmSponsorship(signer, this.collectionId);
}
+ async removeSponsor(signer: TSigner) {
+ return await this.helper.collection.removeSponsor(signer, this.collectionId);
+ }
+
async setLimits(signer: TSigner, limits: ICollectionLimits) {
return await this.helper.collection.setLimits(signer, this.collectionId, limits);
}
@@ -2016,8 +2057,8 @@
return await this.helper.collection.addAdmin(signer, this.collectionId, adminAddressObj);
}
- async enableAllowList(signer: TSigner, value = true/*: 'Normal' | 'AllowList' = 'AllowList'*/) {
- return await this.setPermissions(signer, value ? {access: 'AllowList', mintMode: true} : {access: 'Normal'});
+ async enableCertainPermissions(signer: TSigner, accessMode: 'AllowList' | 'Normal' | undefined = 'AllowList', mintMode: boolean | undefined = true) {
+ return await this.setPermissions(signer, {access: accessMode, mintMode: mintMode});
}
async addToAllowList(signer: TSigner, addressObj: ICrossAccountId) {