difftreelog
tests(util): altrefactorbstrate normalization
in: master
1 file changed
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth596 const admins = (await this.helper.callRpc('api.rpc.unique.adminlist', [collectionId])).toHuman();596 const admins = (await this.helper.callRpc('api.rpc.unique.adminlist', [collectionId])).toHuman();597597598 return normalize598 return normalize599 ? admins.map((address: any) => {599 ? admins.map((address: any) => this.helper.address.normalizeCrossAccountIfSubstrate(address))600 return address.Substrate601 ? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}602 : address;603 })604 : admins;600 : admins;605 }601 }606602614 async getAllowList(collectionId: number, normalize = false): Promise<ICrossAccountId[]> {610 async getAllowList(collectionId: number, normalize = false): Promise<ICrossAccountId[]> {615 const allowListed = (await this.helper.callRpc('api.rpc.unique.allowlist', [collectionId])).toHuman();611 const allowListed = (await this.helper.callRpc('api.rpc.unique.allowlist', [collectionId])).toHuman();616 return normalize612 return normalize617 ? allowListed.map((address: any) => {613 ? allowListed.map((address: any) => this.helper.address.normalizeCrossAccountIfSubstrate(address))618 return address.Substrate619 ? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}620 : address;621 })622 : allowListed;614 : allowListed;623 }615 }6246161122 if (tokenData === null || tokenData.owner === null) return null;1114 if (tokenData === null || tokenData.owner === null) return null;1123 const owner = {} as any;1115 const owner = {} as any;1124 for (const key of Object.keys(tokenData.owner)) {1116 for (const key of Object.keys(tokenData.owner)) {1125 owner[key.toLocaleLowerCase()] = key.toLocaleLowerCase() === 'substrate' ? this.helper.address.normalizeSubstrate(tokenData.owner[key]) : tokenData.owner[key];1117 owner[key.toLocaleLowerCase()] = this.helper.address.normalizeCrossAccountIfSubstrate(tokenData.owner[key]);1126 }1118 }1127 tokenData.normalizedOwner = crossAccountIdFromLower(owner);1119 tokenData.normalizedOwner = crossAccountIdFromLower(owner);1128 return tokenData;1120 return tokenData;134513371346 if (owner === null) return null;1338 if (owner === null) return null;134713391348 owner = owner.toHuman();1340 return owner.toHuman();13491350 return owner.Substrate ? {Substrate: this.helper.address.normalizeSubstrate(owner.Substrate)} : owner;1351 }1341 }135213421353 /**1343 /**2071 return this.helper.util.normalizeSubstrateAddress(address, ss58Format);2061 return this.helper.util.normalizeSubstrateAddress(address, ss58Format);2072 }2062 }20632064 /**2065 * Normalizes the address of an account ONLY if it's Substrate to the specified ss58 format, by default ```42```.2066 * @param account account of either Substrate type or Ethereum, but only Substrate will be changed2067 * @param ss58Format format for address conversion, by default ```42```2068 * @example normalizeCrossAccountIfSubstrate({Substrate: "unjKJQJrRd238pkUZZvzDQrfKuM39zBSnQ5zjAGAGcdRhaJTx"}) // returns 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY2069 * @returns untouched ethereum account or substrate account converted to normalized (i.e., starting with 5) or specified explicitly representation2070 */2071 normalizeCrossAccountIfSubstrate(account: ICrossAccountId, ss58Format = 42): ICrossAccountId {2072 return account.Substrate2073 ? {Substrate: this.normalizeSubstrate(account.Substrate, ss58Format)}2074 : account;2075 }207320762074 /**2077 /**2075 * Get address in the connected chain format2078 * Get address in the connected chain format