From 85f3ef2e0166f1917e5827c58e1cf434c55f94e8 Mon Sep 17 00:00:00 2001 From: Max Andreev Date: Wed, 24 Aug 2022 13:06:53 +0000 Subject: [PATCH] move types and interfaces to types.ts --- --- /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 --- a/tests/src/util/playgrounds/unique.dev.ts +++ b/tests/src/util/playgrounds/unique.dev.ts @@ -3,9 +3,9 @@ import {mnemonicGenerate} from '@polkadot/util-crypto'; import {UniqueHelper} from './unique'; -import {IKeyringPair} from '@polkadot/types/types'; import {ApiPromise, WsProvider} from '@polkadot/api'; import * as defs from '../../interfaces/definitions'; +import { TSigner } from './types'; export class DevUniqueHelper extends UniqueHelper { @@ -69,7 +69,7 @@ * @returns array of newly created accounts * @example const [acc1, acc2, acc3] = await createAccounts([0n, 10n, 20n], donor); */ - creteAccounts = async (balances: bigint[], donor: IKeyringPair): Promise => { + creteAccounts = async (balances: bigint[], donor: TSigner): Promise => { let nonce = await this.helper.chain.getNonce(donor.address); const tokenNominal = this.helper.balance.getOneTokenNominal(); const transactions = []; --- 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 = { -- gitstuff