git.delta.rocks / unique-network / refs/commits / 378c38c72906

difftreelog

tests(util): altrefactorbstrate normalization

Fahrrader2022-09-23parent: #04cd15c.patch.diff
in: master

1 file changed

modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
596 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();
597597
598 return normalize598 return normalize
599 ? admins.map((address: any) => {599 ? admins.map((address: any) => this.helper.address.normalizeCrossAccountIfSubstrate(address))
600 return address.Substrate
601 ? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}
602 : address;
603 })
604 : admins;600 : admins;
605 }601 }
606602
614 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 normalize
617 ? allowListed.map((address: any) => {613 ? allowListed.map((address: any) => this.helper.address.normalizeCrossAccountIfSubstrate(address))
618 return address.Substrate
619 ? {Substrate: this.helper.address.normalizeSubstrate(address.Substrate)}
620 : address;
621 })
622 : allowListed;614 : allowListed;
623 }615 }
624616
1122 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;
13451337
1346 if (owner === null) return null;1338 if (owner === null) return null;
13471339
1348 owner = owner.toHuman();1340 return owner.toHuman();
1349
1350 return owner.Substrate ? {Substrate: this.helper.address.normalizeSubstrate(owner.Substrate)} : owner;
1351 }1341 }
13521342
1353 /**1343 /**
2071 return this.helper.util.normalizeSubstrateAddress(address, ss58Format);2061 return this.helper.util.normalizeSubstrateAddress(address, ss58Format);
2072 }2062 }
2063
2064 /**
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 changed
2067 * @param ss58Format format for address conversion, by default ```42```
2068 * @example normalizeCrossAccountIfSubstrate({Substrate: "unjKJQJrRd238pkUZZvzDQrfKuM39zBSnQ5zjAGAGcdRhaJTx"}) // returns 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
2069 * @returns untouched ethereum account or substrate account converted to normalized (i.e., starting with 5) or specified explicitly representation
2070 */
2071 normalizeCrossAccountIfSubstrate(account: ICrossAccountId, ss58Format = 42): ICrossAccountId {
2072 return account.Substrate
2073 ? {Substrate: this.normalizeSubstrate(account.Substrate, ss58Format)}
2074 : account;
2075 }
20732076
2074 /**2077 /**
2075 * Get address in the connected chain format2078 * Get address in the connected chain format