git.delta.rocks / unique-network / refs/commits / 85f3ef2e0166

difftreelog

move types and interfaces to types.ts

Max Andreev2022-08-24parent: #a36e310.patch.diff
in: master

3 files changed

addedtests/src/util/playgrounds/types.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/util/playgrounds/types.ts
@@ -0,0 +1,130 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+import {IKeyringPair} from '@polkadot/types/types';
+
+export interface IChainEvent {
+  data: any;
+  method: string;
+  section: string;
+}
+
+export interface ITransactionResult {
+    status: 'Fail' | 'Success';
+    result: {
+        events: {
+          event: IChainEvent
+        }[];
+    },
+    moduleError?: string;
+}
+
+export interface ILogger {
+  log: (msg: any, level?: string) => void;
+  level: {
+    ERROR: 'ERROR';
+    WARNING: 'WARNING';
+    INFO: 'INFO';
+    [key: string]: string;
+  }
+}
+
+export interface IUniqueHelperLog {
+  executedAt: number;
+  executionTime: number;
+  type: 'extrinsic' | 'rpc';
+  status: 'Fail' | 'Success';
+  call: string;
+  params: any[];
+  moduleError?: string;
+  events?: any;
+}
+
+export interface IApiListeners {
+  connected?: (...args: any[]) => any;
+  disconnected?: (...args: any[]) => any;
+  error?: (...args: any[]) => any;
+  ready?: (...args: any[]) => any; 
+  decorated?: (...args: any[]) => any;
+}
+
+export interface ICrossAccountId {
+  Substrate?: TSubstrateAccount;
+  Ethereum?: TEthereumAccount;
+}
+
+export interface ICrossAccountIdLower {
+  substrate?: TSubstrateAccount;
+  ethereum?: TEthereumAccount;
+}
+
+export interface ICollectionLimits {
+  accountTokenOwnershipLimit?: number | null;
+  sponsoredDataSize?: number | null;
+  sponsoredDataRateLimit?: {blocks: number} | {sponsoringDisabled: null} | null;
+  tokenLimit?: number | null;
+  sponsorTransferTimeout?: number | null;
+  sponsorApproveTimeout?: number | null;
+  ownerCanTransfer?: boolean | null;
+  ownerCanDestroy?: boolean | null;
+  transfersEnabled?: boolean | null;
+}
+
+export interface INestingPermissions {
+  tokenOwner?: boolean;
+  collectionAdmin?: boolean;
+  restricted?: number[] | null;
+}
+
+export interface ICollectionPermissions {
+  access?: 'Normal' | 'AllowList';
+  mintMode?: boolean;
+  nesting?: INestingPermissions;
+}
+
+export interface IProperty {
+  key: string;
+  value: string;
+}
+
+export interface ITokenPropertyPermission {
+  key: string;
+  permission: {
+    mutable: boolean;
+    tokenOwner: boolean;
+    collectionAdmin: boolean;
+  }
+}
+
+export interface IToken {
+  collectionId: number;
+  tokenId: number;
+}
+
+export interface ICollectionCreationOptions {
+  name: string | number[];
+  description: string | number[];
+  tokenPrefix: string | number[];
+  mode?: {
+    nft?: null;
+    refungible?: null;
+    fungible?: number;
+  }
+  permissions?: ICollectionPermissions;
+  properties?: IProperty[];
+  tokenPropertyPermissions?: ITokenPropertyPermission[];
+  limits?: ICollectionLimits;
+  pendingSponsor?: TSubstrateAccount;
+}
+
+export interface IChainProperties {
+  ss58Format: number;
+  tokenDecimals: number[];
+  tokenSymbol: string[]
+}
+
+export type TSubstrateAccount = string;
+export type TEthereumAccount = string;
+export type TApiAllowedListeners = 'connected' | 'disconnected' | 'error' | 'ready' | 'decorated';
+export type TUniqueNetworks = 'opal' | 'quartz' | 'unique';
+export type TSigner = IKeyringPair; // | 'string'
\ No newline at end of file
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
before · tests/src/util/playgrounds/unique.dev.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {mnemonicGenerate} from '@polkadot/util-crypto';5import {UniqueHelper} from './unique';6import {IKeyringPair} from '@polkadot/types/types';7import {ApiPromise, WsProvider} from '@polkadot/api';8import * as defs from '../../interfaces/definitions';91011export class DevUniqueHelper extends UniqueHelper {12  /**13   * Arrange methods for tests14   */15  arrange: ArrangeGroup;1617  constructor(logger: { log: (msg: any, level: any) => void, level: any }) {18    super(logger);19    this.arrange = new ArrangeGroup(this);20  }2122  async connect(wsEndpoint: string, listeners?: any): Promise<void> {23    const wsProvider = new WsProvider(wsEndpoint);24    this.api = new ApiPromise({25      provider: wsProvider,26      signedExtensions: {27        ContractHelpers: {28          extrinsic: {},29          payload: {},30        },31        FakeTransactionFinalizer: {32          extrinsic: {},33          payload: {},34        },35      },36      rpc: {37        unique: defs.unique.rpc,38        rmrk: defs.rmrk.rpc,39        eth: {40          feeHistory: {41            description: 'Dummy',42            params: [],43            type: 'u8',44          },45          maxPriorityFeePerGas: {46            description: 'Dummy',47            params: [],48            type: 'u8',49          },50        },51      },52    });53    await this.api.isReadyOrError;54    this.network = await UniqueHelper.detectNetwork(this.api);55  }56}5758class ArrangeGroup {59  helper: UniqueHelper;6061  constructor(helper: UniqueHelper) {62    this.helper = helper;63  }6465  /**66   * Generates accounts with the specified UNQ token balance 67   * @param balances balances for generated accounts. Each balance will be multiplied by the token nominal.68   * @param donor donor account for balances69   * @returns array of newly created accounts70   * @example const [acc1, acc2, acc3] = await createAccounts([0n, 10n, 20n], donor); 71   */72  creteAccounts = async (balances: bigint[], donor: IKeyringPair): Promise<IKeyringPair[]> => {73    let nonce = await this.helper.chain.getNonce(donor.address);74    const tokenNominal = this.helper.balance.getOneTokenNominal();75    const transactions = [];76    const accounts = [];77    for (const balance of balances) {78      const recepient = this.helper.util.fromSeed(mnemonicGenerate());79      accounts.push(recepient);80      if (balance !== 0n) {81        const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recepient.address}, balance * tokenNominal]);82        transactions.push(this.helper.signTransaction(donor, tx, 'account generation', {nonce}));83        nonce++;84      }85    }8687    await Promise.all(transactions);88    return accounts;89  };90}
after · tests/src/util/playgrounds/unique.dev.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {mnemonicGenerate} from '@polkadot/util-crypto';5import {UniqueHelper} from './unique';6import {ApiPromise, WsProvider} from '@polkadot/api';7import * as defs from '../../interfaces/definitions';8import { TSigner } from './types';91011export class DevUniqueHelper extends UniqueHelper {12  /**13   * Arrange methods for tests14   */15  arrange: ArrangeGroup;1617  constructor(logger: { log: (msg: any, level: any) => void, level: any }) {18    super(logger);19    this.arrange = new ArrangeGroup(this);20  }2122  async connect(wsEndpoint: string, listeners?: any): Promise<void> {23    const wsProvider = new WsProvider(wsEndpoint);24    this.api = new ApiPromise({25      provider: wsProvider,26      signedExtensions: {27        ContractHelpers: {28          extrinsic: {},29          payload: {},30        },31        FakeTransactionFinalizer: {32          extrinsic: {},33          payload: {},34        },35      },36      rpc: {37        unique: defs.unique.rpc,38        rmrk: defs.rmrk.rpc,39        eth: {40          feeHistory: {41            description: 'Dummy',42            params: [],43            type: 'u8',44          },45          maxPriorityFeePerGas: {46            description: 'Dummy',47            params: [],48            type: 'u8',49          },50        },51      },52    });53    await this.api.isReadyOrError;54    this.network = await UniqueHelper.detectNetwork(this.api);55  }56}5758class ArrangeGroup {59  helper: UniqueHelper;6061  constructor(helper: UniqueHelper) {62    this.helper = helper;63  }6465  /**66   * Generates accounts with the specified UNQ token balance 67   * @param balances balances for generated accounts. Each balance will be multiplied by the token nominal.68   * @param donor donor account for balances69   * @returns array of newly created accounts70   * @example const [acc1, acc2, acc3] = await createAccounts([0n, 10n, 20n], donor); 71   */72  creteAccounts = async (balances: bigint[], donor: TSigner): Promise<TSigner[]> => {73    let nonce = await this.helper.chain.getNonce(donor.address);74    const tokenNominal = this.helper.balance.getOneTokenNominal();75    const transactions = [];76    const accounts = [];77    for (const balance of balances) {78      const recepient = this.helper.util.fromSeed(mnemonicGenerate());79      accounts.push(recepient);80      if (balance !== 0n) {81        const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recepient.address}, balance * tokenNominal]);82        transactions.push(this.helper.signTransaction(donor, tx, 'account generation', {nonce}));83        nonce++;84      }85    }8687    await Promise.all(transactions);88    return accounts;89  };90}
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -9,6 +9,7 @@
 import {ApiInterfaceEvents} from '@polkadot/api/types';
 import {IKeyringPair} from '@polkadot/types/types';
 import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm} from '@polkadot/util-crypto';
+import { ICrossAccountIdLower, ICrossAccountId, TUniqueNetworks, IApiListeners, TApiAllowedListeners, TSigner, TSubstrateAccount, ICollectionLimits, ICollectionPermissions, INestingPermissions, IProperty, ITokenPropertyPermission, ICollectionCreationOptions, IToken, IChainProperties, TEthereumAccount } from './types';
 
 
 const crossAccountIdFromLower = (lowerAddress: ICrossAccountIdLower): ICrossAccountId => {
@@ -80,96 +81,7 @@
   params: any[];
   moduleError?: string;
   events?: any;
-}
-
-interface IApiListeners {
-  connected?: (...args: any[]) => any;
-  disconnected?: (...args: any[]) => any;
-  error?: (...args: any[]) => any;
-  ready?: (...args: any[]) => any; 
-  decorated?: (...args: any[]) => any;
-}
-
-interface ICrossAccountId {
-  Substrate?: TSubstrateAccount;
-  Ethereum?: TEthereumAccount;
-}
-
-interface ICrossAccountIdLower {
-  substrate?: TSubstrateAccount;
-  ethereum?: TEthereumAccount;
-}
-
-interface ICollectionLimits {
-  accountTokenOwnershipLimit?: number | null;
-  sponsoredDataSize?: number | null;
-  sponsoredDataRateLimit?: {blocks: number} | {sponsoringDisabled: null} | null;
-  tokenLimit?: number | null;
-  sponsorTransferTimeout?: number | null;
-  sponsorApproveTimeout?: number | null;
-  ownerCanTransfer?: boolean | null;
-  ownerCanDestroy?: boolean | null;
-  transfersEnabled?: boolean | null;
-}
-
-interface INestingPermissions {
-  tokenOwner?: boolean;
-  collectionAdmin?: boolean;
-  restricted?: number[] | null;
-}
-
-interface ICollectionPermissions {
-  access?: 'Normal' | 'AllowList';
-  mintMode?: boolean;
-  nesting?: INestingPermissions;
-}
-
-interface IProperty {
-  key: string;
-  value: string;
-}
-
-interface ITokenPropertyPermission {
-  key: string;
-  permission: {
-    mutable: boolean;
-    tokenOwner: boolean;
-    collectionAdmin: boolean;
-  }
 }
-
-interface IToken {
-  collectionId: number;
-  tokenId: number;
-}
-
-interface ICollectionCreationOptions {
-  name: string | number[];
-  description: string | number[];
-  tokenPrefix: string | number[];
-  mode?: {
-    nft?: null;
-    refungible?: null;
-    fungible?: number;
-  }
-  permissions?: ICollectionPermissions;
-  properties?: IProperty[];
-  tokenPropertyPermissions?: ITokenPropertyPermission[];
-  limits?: ICollectionLimits;
-  pendingSponsor?: TSubstrateAccount;
-}
-
-interface IChainProperties {
-  ss58Format: number;
-  tokenDecimals: number[];
-  tokenSymbol: string[]
-}
-
-type TSubstrateAccount = string;
-type TEthereumAccount = string;
-type TApiAllowedListeners = 'connected' | 'disconnected' | 'error' | 'ready' | 'decorated';
-type TUniqueNetworks = 'opal' | 'quartz' | 'unique';
-type TSigner = IKeyringPair; // | 'string'
 
 class UniqueUtil {
   static transactionStatus = {