difftreelog
test(util) addtional docs + minor refactoring
in: master
1 file changed
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth967 return (await this.helper.callRpc('api.rpc.unique.accountTokens', [collectionId, addressObj])).toJSON();967 return (await this.helper.callRpc('api.rpc.unique.accountTokens', [collectionId, addressObj])).toJSON();968 }968 }969969970 /**970 /**971 * Get token data971 * Get token data972 * 972 * 973 * @param collectionId ID of collection973 * @param collectionId ID of collection974 * @param tokenId ID of token974 * @param tokenId ID of token975 * @param blockHashAt 975 * @param propertyKeys optionally filter the token properties to only these keys976 * @param propertyKeys976 * @param blockHashAt optionally query the data at some block with this hash977 * @example getToken(10, 5);977 * @example getToken(10, 5);978 * @returns human readable token data 978 * @returns human readable token data 979 */979 */980 async getToken(collectionId: number, tokenId: number, blockHashAt?: string, propertyKeys?: string[]): Promise<{980 async getToken(collectionId: number, tokenId: number, propertyKeys: string[] = [], blockHashAt?: string): Promise<{981 properties: IProperty[];981 properties: IProperty[];982 owner: ICrossAccountId;982 owner: ICrossAccountId;983 normalizedOwner: ICrossAccountId;983 normalizedOwner: ICrossAccountId;987 tokenData = await this.helper.callRpc('api.rpc.unique.tokenData', [collectionId, tokenId]);987 tokenData = await this.helper.callRpc('api.rpc.unique.tokenData', [collectionId, tokenId]);988 }988 }989 else {989 else {990 if(typeof propertyKeys === 'undefined') {990 if(propertyKeys.length == 0) {991 const collection = (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();991 const collection = (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();992 if(!collection) return null;992 if(!collection) return null;993 propertyKeys = collection.tokenPropertyPermissions.map((x: ITokenPropertyPermission) => x.key);993 propertyKeys = collection.tokenPropertyPermissions.map((x: ITokenPropertyPermission) => x.key);1025 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet');1025 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet');1026 }1026 }102710271028 /**1028 /**1029 * Set token properties1029 * Set token properties1030 * 1030 * 1031 * @param signer keyring of signer1031 * @param signer keyring of signer1032 * @param collectionId ID of collection1032 * @param collectionId ID of collection1033 * @param tokenId ID of token1033 * @param tokenId ID of token1034 * @param properties 1034 * @param properties key-value pairs of metadata which to add to a token. Keys must be permitted in the collection1035 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])1035 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])1036 * @returns ```true``` if extrinsic success, otherwise ```false```1036 * @returns ```true``` if extrinsic success, otherwise ```false```1037 */1037 */1038 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[]): Promise<boolean> {1038 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[]): Promise<boolean> {1039 const result = await this.helper.executeExtrinsic(1039 const result = await this.helper.executeExtrinsic(1040 signer,1040 signer,1119 return new UniqueNFTToken(tokenId, this.getCollectionObject(collectionId));1119 return new UniqueNFTToken(tokenId, this.getCollectionObject(collectionId));1120 }1120 }112111211122 /**1122 /**1123 * Get token's owner1123 * Get token's owner1124 * @param collectionId ID of collection1124 * @param collectionId ID of collection1125 * @param tokenId ID of token1125 * @param tokenId ID of token1126 * @param blockHashAt 1126 * @param blockHashAt optionally query the data at the block with this hash1127 * @example getTokenOwner(10, 5);1127 * @example getTokenOwner(10, 5);1128 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}1128 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}1129 */1129 */1130 async getTokenOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId> {1130 async getTokenOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId> {1131 let owner;1131 let owner;1132 if (typeof blockHashAt === 'undefined') {1132 if (typeof blockHashAt === 'undefined') {1201 return owner.Substrate ? {Substrate: this.helper.address.normalizeSubstrate(owner.Substrate)} : owner;1201 return owner.Substrate ? {Substrate: this.helper.address.normalizeSubstrate(owner.Substrate)} : owner;1202 }1202 }120312031204 /**1204 /**1205 * Get tokens nested in the provided token1205 * Get tokens nested in the provided token1206 * @param collectionId ID of collection1206 * @param collectionId ID of collection1207 * @param tokenId ID of token1207 * @param tokenId ID of token1208 * @param blockHashAt 1208 * @param blockHashAt optionally query the data at the block with this hash1209 * @example getTokenChildren(10, 5);1209 * @example getTokenChildren(10, 5);1210 * @returns tokens whose depth of nesting is <= 5 1210 * @returns tokens whose depth of nesting is <= 5 1211 */1211 */1212 async getTokenChildren(collectionId: number, tokenId: number, blockHashAt?: string): Promise<IToken[]> {1212 async getTokenChildren(collectionId: number, tokenId: number, blockHashAt?: string): Promise<IToken[]> {1213 let children;1213 let children;1214 if(typeof blockHashAt === 'undefined') {1214 if(typeof blockHashAt === 'undefined') {1695 return (await this.helper.callRpc('api.rpc.unique.balance', [collectionId, addressObj, 0])).toBigInt();1695 return (await this.helper.callRpc('api.rpc.unique.balance', [collectionId, addressObj, 0])).toBigInt();1696 }1696 }169716971698 /**1698 /**1699 * Transfer tokens to address1699 * Transfer tokens to address1700 * @param signer keyring of signer1700 * @param signer keyring of signer1701 * @param collectionId ID of collection1701 * @param collectionId ID of collection1702 * @param toAddressObj address recepient1702 * @param toAddressObj address recipient1703 * @param amount amount of tokens to be sent1703 * @param amount amount of tokens to be sent1704 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1704 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1705 * @returns ```true``` if extrinsic success, otherwise ```false``` 1705 * @returns ```true``` if extrinsic success, otherwise ```false``` 1706 */1706 */1707 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {1707 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {1708 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);1708 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);1709 }1709 }1862 return (await this.helper.callRpc('api.rpc.eth.getBalance', [address])).toBigInt();1862 return (await this.helper.callRpc('api.rpc.eth.getBalance', [address])).toBigInt();1863 }1863 }186418641865 /**1865 /**1866 * Transfer tokens to substrate address1866 * Transfer tokens to substrate address1867 * @param signer keyring of signer1867 * @param signer keyring of signer1868 * @param address substrate address of a recepient1868 * @param address substrate address of a recipient1869 * @param amount amount of tokens to be transfered1869 * @param amount amount of tokens to be transfered1870 * @example transferToSubstrate(aliceKeyring, "5GrwvaEF5zXb26Fz...", 100_000_000_000n);1870 * @example transferToSubstrate(aliceKeyring, "5GrwvaEF5zXb26Fz...", 100_000_000_000n);1871 * @returns ```true``` if extrinsic success, otherwise ```false```1871 * @returns ```true``` if extrinsic success, otherwise ```false```1872 */1872 */1873 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {1873 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {1874 const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true/*, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`*/);1874 const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true/*, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`*/);187518752070 }2070 }207120712072 async getToken(tokenId: number, blockHashAt?: string) {2072 async getToken(tokenId: number, blockHashAt?: string) {2073 return await this.helper.nft.getToken(this.collectionId, tokenId, blockHashAt);2073 return await this.helper.nft.getToken(this.collectionId, tokenId, [], blockHashAt);2074 }2074 }207520752076 async getTokenOwner(tokenId: number, blockHashAt?: string) {2076 async getTokenOwner(tokenId: number, blockHashAt?: string) {