git.delta.rocks / unique-network / refs/commits / 6d40fa6f157c

difftreelog

fix after rebase

Trubnikov Sergey2022-10-24parent: #36fc5ab.patch.diff
in: master

3 files changed

modifiedtests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth
64 expect(adminList).to.be.like([{Substrate: newAdmin.address}]);64 expect(adminList).to.be.like([{Substrate: newAdmin.address}]);
65 });65 });
66
67 itEth('Check adminlist', async ({helper, privateKey}) => {
68 const owner = await helper.eth.createAccountWithBalance(donor);
69
70 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
71 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
72
73 const admin1 = helper.eth.createAccount();
74 const admin2 = await privateKey('admin');
75 await collectionEvm.methods.addCollectionAdmin(admin1).send();
76 await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();
77
78 const adminListRpc = await helper.collection.getAdmins(collectionId);
79 let adminListEth = await collectionEvm.methods.collectionAdmins().call();
80 adminListEth = adminListEth.map((element: IEthCrossAccountId) => {
81 return helper.address.convertCrossAccountFromEthCrossAcoount(element);
82 });
83 expect(adminListRpc).to.be.like(adminListEth);
84 });
6685
67 itEth('Verify owner or admin', async ({helper}) => {86 itEth('Verify owner or admin', async ({helper}) => {
68 const owner = await helper.eth.createAccountWithBalance(donor);87 const owner = await helper.eth.createAccountWithBalance(donor);
modifiedtests/src/eth/collectionProperties.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper, EthUniqueHelper} from './util';
18import {Pallets} from '../util';18import {Pallets} from '../util';
19import {IProperty, ITokenPropertyPermission, TCollectionMode} from '../util/playgrounds/types';19import {IProperty, ITokenPropertyPermission, TCollectionMode} from '../util/playgrounds/types';
20import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';
21import {TCollectionMode} from '../util/playgrounds/types';
2122
22describe('EVM collection properties', () => {23describe('EVM collection properties', () => {
23 let donor: IKeyringPair;24 let donor: IKeyringPair;
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
2342 return siblingPrefix + encodedParaId + suffix;2342 return siblingPrefix + encodedParaId + suffix;
2343 }2343 }
2344
2345 /**
2346 * Encode key to substrate address
2347 * @param key key for encoding address
2348 * @param ss58Format prefix for encoding to the address of the corresponding network
2349 * @returns encoded substrate address
2350 */
2351 encodeSubstrateAddress (key: Uint8Array | string | bigint, ss58Format = 42): string {
2352 const u8a :Uint8Array = typeof key === 'string'
2353 ? hexToU8a(key)
2354 : typeof key === 'bigint'
2355 ? hexToU8a(key.toString(16))
2356 : key;
2357
2358 if (ss58Format < 0 || ss58Format > 16383 || [46, 47].includes(ss58Format)) {
2359 throw new Error(`ss58Format is not valid, received ${typeof ss58Format} "${ss58Format}"`);
2360 }
2361
2362 const allowedDecodedLengths = [1, 2, 4, 8, 32, 33];
2363 if (!allowedDecodedLengths.includes(u8a.length)) {
2364 throw new Error(`key length is not valid, received ${u8a.length}, valid values are ${allowedDecodedLengths.join(', ')}`);
2365 }
2366
2367 const u8aPrefix = ss58Format < 64
2368 ? new Uint8Array([ss58Format])
2369 : new Uint8Array([
2370 ((ss58Format & 0xfc) >> 2) | 0x40,
2371 (ss58Format >> 8) | ((ss58Format & 0x03) << 6),
2372 ]);
2373
2374 const input = u8aConcat(u8aPrefix, u8a);
2375
2376 return base58Encode(u8aConcat(
2377 input,
2378 blake2AsU8a(input).subarray(0, [32, 33].includes(u8a.length) ? 2 : 1),
2379 ));
2380 }
2381
2382 /**
2383 * Restore substrate address from bigint representation
2384 * @param number decimal representation of substrate address
2385 * @returns substrate address
2386 */
2387 restoreCrossAccountFromBigInt(number: bigint): TSubstrateAccount {
2388 if (this.helper.api === null) {
2389 throw 'Not connected';
2390 }
2391 const res = this.helper.api.registry.createType('AccountId', '0x' + number.toString(16).padStart(64, '0')).toJSON();
2392 if (res === undefined || res === null) {
2393 throw 'Restore address error';
2394 }
2395 return res.toString();
2396 }
2397
2398 /**
2399 * Convert etherium cross account id to substrate cross account id
2400 * @param ethCrossAccount etherium cross account
2401 * @returns substrate cross account id
2402 */
2403 convertCrossAccountFromEthCrossAcoount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId {
2404 if (ethCrossAccount.field_1 === '0') {
2405 return {Ethereum: ethCrossAccount.field_0.toLocaleLowerCase()};
2406 }
2407
2408 const ss58 = this.restoreCrossAccountFromBigInt(BigInt(ethCrossAccount.field_1));
2409 return {Substrate: ss58};
2410 }
2411}2344}
24122345
2413class StakingGroup extends HelperGroup<UniqueHelper> {2346class StakingGroup extends HelperGroup<UniqueHelper> {