git.delta.rocks / unique-network / refs/commits / 8b9e255fd2b8

difftreelog

feat Add `collection_admins` method to eth collection.

Trubnikov Sergey2022-09-16parent: #2ffba98.patch.diff
in: master

2 files changed

modifiedtests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth
before · tests/src/eth/collectionAdmin.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.3// Unique Network is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// Unique Network is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the11// GNU General Public License for more details.1213// You should have received a copy of the GNU General Public License14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1516import {IKeyringPair} from '@polkadot/types/types';17import {usingEthPlaygrounds, itEth, expect, EthUniqueHelper} from './util';1819async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {20  const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));21  await call();22  await helper.wait.newBlocks(1);23  const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));2425  expect(after < before).to.be.true;2627  return before - after;28}2930describe('Add collection admins', () => {31  let donor: IKeyringPair;3233  before(async function() {34    await usingEthPlaygrounds(async (_helper, privateKey) => {35      donor = await privateKey({filename: __filename});36    });37  });3839  itEth('Add admin by owner', async ({helper}) => {40    const owner = await helper.eth.createAccountWithBalance(donor);41    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');42    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);4344    const newAdmin = helper.eth.createAccount();4546    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();47    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);48    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())49      .to.be.eq(newAdmin.toLocaleLowerCase());50  });5152  itEth('Add cross account admin by owner', async ({helper, privateKey}) => {53    const owner = await helper.eth.createAccountWithBalance(donor);54        55    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');56    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);57    58    const newAdmin = await privateKey('//Bob');59    const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);60    await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();6162    const adminList = await helper.collection.getAdmins(collectionId);63    expect(adminList).to.be.like([{Substrate: newAdmin.address}]);64  });6566  // itEth('Check adminlist', async ({helper, privateKey}) => {67  //   const owner = await helper.eth.createAccountWithBalance(donor);68        69  //   const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');70  //   const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);7172  //   const admin1 = helper.eth.createAccount();73  //   const admin2 = await privateKey('admin');74  //   await collectionEvm.methods.addCollectionAdmin(admin1).send();75  //   await collectionEvm.methods.addCollectionAdminCross(helper.ethCrossAccount.fromKeyringPair(admin2)).send();7677  //   const adminListRpc = await helper.collection.getAdmins(collectionId);78  //   let adminListEth = await collectionEvm.methods.collectionAdmins().call();79  //   adminListEth = adminListEth.map((element: IEthCrossAccountId) => {80  //     return helper.address.convertCrossAccountFromEthCrossAcoount(element);81  //   });82  //   expect(adminListRpc).to.be.like(adminListEth);83  // });8485  itEth('Verify owner or admin', async ({helper}) => {86    const owner = await helper.eth.createAccountWithBalance(donor);87    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');8889    const newAdmin = helper.eth.createAccount();90    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);91  92    expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;93    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();94    expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;95  });9697  // itEth.skip('Check adminlist', async ({helper, privateKey}) => {98  //   const owner = await helper.eth.createAccountWithBalance(donor);99        100  //   const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');101  //   const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);102103  //   const admin1 = helper.eth.createAccount();104  //   const admin2 = await privateKey('admin');105  //   await collectionEvm.methods.addCollectionAdmin(admin1).send();106  //   await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();107108  //   const adminListRpc = await helper.collection.getAdmins(collectionId);109  //   let adminListEth = await collectionEvm.methods.collectionAdmins().call();110  //   adminListEth = adminListEth.map((element: IEthCrossAccountId) => {111  //     return helper.address.convertCrossAccountFromEthCrossAcoount(element);112  //   });113  //   expect(adminListRpc).to.be.like(adminListEth);114  // });115    116  itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {117    const owner = await helper.eth.createAccountWithBalance(donor);118    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');119120    const admin = await helper.eth.createAccountWithBalance(donor);121    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);122    await collectionEvm.methods.addCollectionAdmin(admin).send();123124    const user = helper.eth.createAccount();125    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))126      .to.be.rejectedWith('NoPermission');127128    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);129    expect(adminList.length).to.be.eq(1);130    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())131      .to.be.eq(admin.toLocaleLowerCase());132  });133134  itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {135    const owner = await helper.eth.createAccountWithBalance(donor);136    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');137138    const notAdmin = await helper.eth.createAccountWithBalance(donor);139    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);140141    const user = helper.eth.createAccount();142    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))143      .to.be.rejectedWith('NoPermission');144145    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);146    expect(adminList.length).to.be.eq(0);147  });148149  itEth.skip('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({helper}) => {150    const owner = await helper.eth.createAccountWithBalance(donor);151    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');152153    const admin = await helper.eth.createAccountWithBalance(donor);154    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);155    await collectionEvm.methods.addCollectionAdmin(admin).send();156157    const [notAdmin] = await helper.arrange.createAccounts([10n], donor);158    await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))159      .to.be.rejectedWith('NoPermission');160161    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);162    expect(adminList.length).to.be.eq(1);163    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())164      .to.be.eq(admin.toLocaleLowerCase());165  });166167  itEth.skip('(!negative tests!) Add substrate admin by USER is not allowed', async ({helper}) => {168    const owner = await helper.eth.createAccountWithBalance(donor);169    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');170171    const notAdmin0 = await helper.eth.createAccountWithBalance(donor);172    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);173    const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);174    await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))175      .to.be.rejectedWith('NoPermission');176177    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);178    expect(adminList.length).to.be.eq(0);179  });180});181182describe('Remove collection admins', () => {183  let donor: IKeyringPair;184185  before(async function() {186    await usingEthPlaygrounds(async (_helper, privateKey) => {187      donor = await privateKey({filename: __filename});188    });189  });190191  itEth('Remove admin by owner', async ({helper}) => {192    const owner = await helper.eth.createAccountWithBalance(donor);193    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');194195    const newAdmin = helper.eth.createAccount();196    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);197    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();198199    {200      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);201      expect(adminList.length).to.be.eq(1);202      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())203        .to.be.eq(newAdmin.toLocaleLowerCase());204    }205206    await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();207    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);208    expect(adminList.length).to.be.eq(0);209  });210211  itEth.skip('Remove substrate admin by owner', async ({helper}) => {212    const owner = await helper.eth.createAccountWithBalance(donor);213    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');214215    const [newAdmin] = await helper.arrange.createAccounts([10n], donor);216    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);217    await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();218    {219      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);220      expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())221        .to.be.eq(newAdmin.address.toLocaleLowerCase());222    }223224    await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();225    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);226    expect(adminList.length).to.be.eq(0);227  });228229  itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {230    const owner = await helper.eth.createAccountWithBalance(donor);231    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');232233    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);234235    const admin0 = await helper.eth.createAccountWithBalance(donor);236    await collectionEvm.methods.addCollectionAdmin(admin0).send();237    const admin1 = await helper.eth.createAccountWithBalance(donor);238    await collectionEvm.methods.addCollectionAdmin(admin1).send();239240    await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))241      .to.be.rejectedWith('NoPermission');242    {243      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);244      expect(adminList.length).to.be.eq(2);245      expect(adminList.toString().toLocaleLowerCase())246        .to.be.deep.contains(admin0.toLocaleLowerCase())247        .to.be.deep.contains(admin1.toLocaleLowerCase());248    }249  });250251  itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {252    const owner = await helper.eth.createAccountWithBalance(donor);253    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');254255    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);256257    const admin = await helper.eth.createAccountWithBalance(donor);258    await collectionEvm.methods.addCollectionAdmin(admin).send();259    const notAdmin = helper.eth.createAccount();260261    await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))262      .to.be.rejectedWith('NoPermission');263    {264      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);265      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())266        .to.be.eq(admin.toLocaleLowerCase());267      expect(adminList.length).to.be.eq(1);268    }269  });270271  itEth.skip('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({helper}) => {272    const owner = await helper.eth.createAccountWithBalance(donor);273    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');274275    const [adminSub] = await helper.arrange.createAccounts([10n], donor);276    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);277    await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();278    const adminEth = await helper.eth.createAccountWithBalance(donor);279    await collectionEvm.methods.addCollectionAdmin(adminEth).send();280281    await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))282      .to.be.rejectedWith('NoPermission');283284    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);285    expect(adminList.length).to.be.eq(2);286    expect(adminList.toString().toLocaleLowerCase())287      .to.be.deep.contains(adminSub.address.toLocaleLowerCase())288      .to.be.deep.contains(adminEth.toLocaleLowerCase());289  });290291  itEth.skip('(!negative tests!) Remove substrate admin by USER is not allowed', async ({helper}) => {292    const owner = await helper.eth.createAccountWithBalance(donor);293    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');294295    const [adminSub] = await helper.arrange.createAccounts([10n], donor);296    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);297    await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();298    const notAdminEth = await helper.eth.createAccountWithBalance(donor);299300    await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))301      .to.be.rejectedWith('NoPermission');302303    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);304    expect(adminList.length).to.be.eq(1);305    expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())306      .to.be.eq(adminSub.address.toLocaleLowerCase());307  });308});309310describe('Change owner tests', () => {311  let donor: IKeyringPair;312313  before(async function() {314    await usingEthPlaygrounds(async (_helper, privateKey) => {315      donor = await privateKey({filename: __filename});316    });317  });318319  itEth('Change owner', async ({helper}) => {320    const owner = await helper.eth.createAccountWithBalance(donor);321    const newOwner = await helper.eth.createAccountWithBalance(donor);322    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');323    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);324325    await collectionEvm.methods.changeCollectionOwner(newOwner).send();326327    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;328    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;329  });330331  itEth('change owner call fee', async ({helper}) => {332    const owner = await helper.eth.createAccountWithBalance(donor);333    const newOwner = await helper.eth.createAccountWithBalance(donor);334    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');335    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);336    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());337    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));338    expect(cost > 0);339  });340341  itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {342    const owner = await helper.eth.createAccountWithBalance(donor);343    const newOwner = await helper.eth.createAccountWithBalance(donor);344    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');345    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);346347    await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;348    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;349  });350});351352describe('Change substrate owner tests', () => {353  let donor: IKeyringPair;354355  before(async function() {356    await usingEthPlaygrounds(async (_helper, privateKey) => {357      donor = await privateKey({filename: __filename});358    });359  });360361  itEth.skip('Change owner', async ({helper}) => {362    const owner = await helper.eth.createAccountWithBalance(donor);363    const [newOwner] = await helper.arrange.createAccounts([10n], donor);364    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');365    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);366367    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.true;368    expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;369370    await collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send();371372    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;373    expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;374  });375376  itEth.skip('change owner call fee', async ({helper}) => {377    const owner = await helper.eth.createAccountWithBalance(donor);378    const [newOwner] = await helper.arrange.createAccounts([10n], donor);379    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');380    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);381382    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());383    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));384    expect(cost > 0);385  });386387  itEth.skip('(!negative tests!) call setOwner by non owner', async ({helper}) => {388    const owner = await helper.eth.createAccountWithBalance(donor);389    const otherReceiver = await helper.eth.createAccountWithBalance(donor);390    const [newOwner] = await helper.arrange.createAccounts([10n], donor);391    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');392    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);393394    await expect(collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;395    expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;396  });397});
after · tests/src/eth/collectionAdmin.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.3// Unique Network is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// Unique Network is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the11// GNU General Public License for more details.1213// You should have received a copy of the GNU General Public License14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1516import {IKeyringPair} from '@polkadot/types/types';17import {IEthCrossAccountId} from '../util/playgrounds/types';18import {usingEthPlaygrounds, itEth, expect, EthUniqueHelper} from './util/playgrounds';1920async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {21  const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));22  await call();23  await helper.wait.newBlocks(1);24  const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));2526  expect(after < before).to.be.true;2728  return before - after;29}3031describe('Add collection admins', () => {32  let donor: IKeyringPair;3334  before(async function() {35    await usingEthPlaygrounds(async (_helper, privateKey) => {36      donor = await privateKey({filename: __filename});37    });38  });3940  itEth('Add admin by owner', async ({helper}) => {41    const owner = await helper.eth.createAccountWithBalance(donor);42    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');43    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);4445    const newAdmin = helper.eth.createAccount();4647    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();48    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);49    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())50      .to.be.eq(newAdmin.toLocaleLowerCase());51  });5253  itEth('Add cross account admin by owner', async ({helper, privateKey}) => {54    const owner = await helper.eth.createAccountWithBalance(donor);55        56    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');57    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);58    59    const newAdmin = await privateKey('//Bob');60    const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);61    await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();6263    const adminList = await helper.collection.getAdmins(collectionId);64    expect(adminList).to.be.like([{Substrate: newAdmin.address}]);65  });6667  // 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);7273  //   const admin1 = helper.eth.createAccount();74  //   const admin2 = await privateKey('admin');75  //   await collectionEvm.methods.addCollectionAdmin(admin1).send();76  //   await collectionEvm.methods.addCollectionAdminCross(helper.ethCrossAccount.fromKeyringPair(admin2)).send();7778  //   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  // });8586  itEth('Verify owner or admin', async ({helper}) => {87    const owner = await helper.eth.createAccountWithBalance(donor);88    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');8990    const newAdmin = helper.eth.createAccount();91    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);92  93    expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;94    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();95    expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;96  });97  98  itEth('Check adminlist', async ({helper, privateKey}) => {99    const owner = await helper.eth.createAccountWithBalance(donor);100        101    const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');102    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);103104    const admin1 = helper.eth.createAccount();105    const admin2 = privateKey('admin');106    await collectionEvm.methods.addCollectionAdmin(admin1).send();107    await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();108109    const adminListRpc = await helper.collection.getAdmins(collectionId);110    let adminListEth = await collectionEvm.methods.collectionAdmins().call();111    adminListEth = adminListEth.map((element: IEthCrossAccountId) => {112      return helper.address.convertCrossAccountFromEthCrossAcoount(element);113    });114    expect(adminListRpc).to.be.like(adminListEth);115  });  116    117  itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {118    const owner = await helper.eth.createAccountWithBalance(donor);119    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');120121    const admin = await helper.eth.createAccountWithBalance(donor);122    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);123    await collectionEvm.methods.addCollectionAdmin(admin).send();124125    const user = helper.eth.createAccount();126    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))127      .to.be.rejectedWith('NoPermission');128129    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);130    expect(adminList.length).to.be.eq(1);131    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())132      .to.be.eq(admin.toLocaleLowerCase());133  });134135  itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {136    const owner = await helper.eth.createAccountWithBalance(donor);137    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');138139    const notAdmin = await helper.eth.createAccountWithBalance(donor);140    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);141142    const user = helper.eth.createAccount();143    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))144      .to.be.rejectedWith('NoPermission');145146    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);147    expect(adminList.length).to.be.eq(0);148  });149150  itEth.skip('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({helper}) => {151    const owner = await helper.eth.createAccountWithBalance(donor);152    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');153154    const admin = await helper.eth.createAccountWithBalance(donor);155    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);156    await collectionEvm.methods.addCollectionAdmin(admin).send();157158    const [notAdmin] = await helper.arrange.createAccounts([10n], donor);159    await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))160      .to.be.rejectedWith('NoPermission');161162    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);163    expect(adminList.length).to.be.eq(1);164    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())165      .to.be.eq(admin.toLocaleLowerCase());166  });167168  itEth.skip('(!negative tests!) Add substrate admin by USER is not allowed', async ({helper}) => {169    const owner = await helper.eth.createAccountWithBalance(donor);170    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');171172    const notAdmin0 = await helper.eth.createAccountWithBalance(donor);173    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);174    const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);175    await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))176      .to.be.rejectedWith('NoPermission');177178    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);179    expect(adminList.length).to.be.eq(0);180  });181});182183describe('Remove collection admins', () => {184  let donor: IKeyringPair;185186  before(async function() {187    await usingEthPlaygrounds(async (_helper, privateKey) => {188      donor = await privateKey({filename: __filename});189    });190  });191192  itEth('Remove admin by owner', async ({helper}) => {193    const owner = await helper.eth.createAccountWithBalance(donor);194    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');195196    const newAdmin = helper.eth.createAccount();197    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);198    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();199200    {201      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);202      expect(adminList.length).to.be.eq(1);203      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())204        .to.be.eq(newAdmin.toLocaleLowerCase());205    }206207    await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();208    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);209    expect(adminList.length).to.be.eq(0);210  });211212  itEth.skip('Remove substrate admin by owner', async ({helper}) => {213    const owner = await helper.eth.createAccountWithBalance(donor);214    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');215216    const [newAdmin] = await helper.arrange.createAccounts([10n], donor);217    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);218    await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();219    {220      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);221      expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())222        .to.be.eq(newAdmin.address.toLocaleLowerCase());223    }224225    await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();226    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);227    expect(adminList.length).to.be.eq(0);228  });229230  itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {231    const owner = await helper.eth.createAccountWithBalance(donor);232    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');233234    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);235236    const admin0 = await helper.eth.createAccountWithBalance(donor);237    await collectionEvm.methods.addCollectionAdmin(admin0).send();238    const admin1 = await helper.eth.createAccountWithBalance(donor);239    await collectionEvm.methods.addCollectionAdmin(admin1).send();240241    await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))242      .to.be.rejectedWith('NoPermission');243    {244      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);245      expect(adminList.length).to.be.eq(2);246      expect(adminList.toString().toLocaleLowerCase())247        .to.be.deep.contains(admin0.toLocaleLowerCase())248        .to.be.deep.contains(admin1.toLocaleLowerCase());249    }250  });251252  itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {253    const owner = await helper.eth.createAccountWithBalance(donor);254    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');255256    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);257258    const admin = await helper.eth.createAccountWithBalance(donor);259    await collectionEvm.methods.addCollectionAdmin(admin).send();260    const notAdmin = helper.eth.createAccount();261262    await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))263      .to.be.rejectedWith('NoPermission');264    {265      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);266      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())267        .to.be.eq(admin.toLocaleLowerCase());268      expect(adminList.length).to.be.eq(1);269    }270  });271272  itEth.skip('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({helper}) => {273    const owner = await helper.eth.createAccountWithBalance(donor);274    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');275276    const [adminSub] = await helper.arrange.createAccounts([10n], donor);277    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);278    await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();279    const adminEth = await helper.eth.createAccountWithBalance(donor);280    await collectionEvm.methods.addCollectionAdmin(adminEth).send();281282    await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))283      .to.be.rejectedWith('NoPermission');284285    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);286    expect(adminList.length).to.be.eq(2);287    expect(adminList.toString().toLocaleLowerCase())288      .to.be.deep.contains(adminSub.address.toLocaleLowerCase())289      .to.be.deep.contains(adminEth.toLocaleLowerCase());290  });291292  itEth.skip('(!negative tests!) Remove substrate admin by USER is not allowed', async ({helper}) => {293    const owner = await helper.eth.createAccountWithBalance(donor);294    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');295296    const [adminSub] = await helper.arrange.createAccounts([10n], donor);297    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);298    await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();299    const notAdminEth = await helper.eth.createAccountWithBalance(donor);300301    await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))302      .to.be.rejectedWith('NoPermission');303304    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);305    expect(adminList.length).to.be.eq(1);306    expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())307      .to.be.eq(adminSub.address.toLocaleLowerCase());308  });309});310311describe('Change owner tests', () => {312  let donor: IKeyringPair;313314  before(async function() {315    await usingEthPlaygrounds(async (_helper, privateKey) => {316      donor = await privateKey({filename: __filename});317    });318  });319320  itEth('Change owner', async ({helper}) => {321    const owner = await helper.eth.createAccountWithBalance(donor);322    const newOwner = await helper.eth.createAccountWithBalance(donor);323    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');324    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);325326    await collectionEvm.methods.changeCollectionOwner(newOwner).send();327328    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;329    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;330  });331332  itEth('change owner call fee', async ({helper}) => {333    const owner = await helper.eth.createAccountWithBalance(donor);334    const newOwner = await helper.eth.createAccountWithBalance(donor);335    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');336    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);337    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());338    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));339    expect(cost > 0);340  });341342  itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {343    const owner = await helper.eth.createAccountWithBalance(donor);344    const newOwner = await helper.eth.createAccountWithBalance(donor);345    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');346    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);347348    await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;349    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;350  });351});352353describe('Change substrate owner tests', () => {354  let donor: IKeyringPair;355356  before(async function() {357    await usingEthPlaygrounds(async (_helper, privateKey) => {358      donor = await privateKey({filename: __filename});359    });360  });361362  itEth.skip('Change owner', async ({helper}) => {363    const owner = await helper.eth.createAccountWithBalance(donor);364    const [newOwner] = await helper.arrange.createAccounts([10n], donor);365    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');366    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);367368    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.true;369    expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;370371    await collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send();372373    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;374    expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;375  });376377  itEth.skip('change owner call fee', async ({helper}) => {378    const owner = await helper.eth.createAccountWithBalance(donor);379    const [newOwner] = await helper.arrange.createAccounts([10n], donor);380    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');381    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);382383    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());384    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));385    expect(cost > 0);386  });387388  itEth.skip('(!negative tests!) call setOwner by non owner', async ({helper}) => {389    const owner = await helper.eth.createAccountWithBalance(donor);390    const otherReceiver = await helper.eth.createAccountWithBalance(donor);391    const [newOwner] = await helper.arrange.createAccounts([10n], donor);392    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');393    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);394395    await expect(collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;396    expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;397  });398});
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -7,8 +7,10 @@
 
 import {ApiPromise, WsProvider, Keyring} from '@polkadot/api';
 import {ApiInterfaceEvents, SignerOptions} from '@polkadot/api/types';
-import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm} from '@polkadot/util-crypto';
+import {encodeAddress, decodeAddress, keccakAsHex, evmToAddress, addressToEvm, base58Encode, blake2AsU8a} from '@polkadot/util-crypto';
 import {IKeyringPair} from '@polkadot/types/types';
+import {hexToU8a} from '@polkadot/util/hex';
+import {u8aConcat} from '@polkadot/util/u8a';
 import {
   IApiListeners,
   IBlock,
@@ -2368,6 +2370,73 @@
     return CrossAccountId.translateSubToEth(subAddress);
   }
 
+  /**
+   * Encode key to substrate address
+   * @param key key for encoding address
+   * @param ss58Format prefix for encoding to the address of the corresponding network
+   * @returns encoded substrate address
+   */
+  encodeSubstrateAddress (key: Uint8Array | string | bigint, ss58Format = 42): string {
+    const u8a :Uint8Array = typeof key === 'string'
+      ? hexToU8a(key)
+      : typeof key === 'bigint'
+        ? hexToU8a(key.toString(16))
+        : key;
+  
+    if (ss58Format < 0 || ss58Format > 16383 || [46, 47].includes(ss58Format)) {
+      throw new Error(`ss58Format is not valid, received ${typeof ss58Format} "${ss58Format}"`);
+    }
+  
+    const allowedDecodedLengths = [1, 2, 4, 8, 32, 33];
+    if (!allowedDecodedLengths.includes(u8a.length)) {
+      throw new Error(`key length is not valid, received ${u8a.length}, valid values are ${allowedDecodedLengths.join(', ')}`);
+    }
+  
+    const u8aPrefix = ss58Format < 64
+      ? new Uint8Array([ss58Format])
+      : new Uint8Array([
+        ((ss58Format & 0xfc) >> 2) | 0x40,
+        (ss58Format >> 8) | ((ss58Format & 0x03) << 6),
+      ]);
+
+    const input = u8aConcat(u8aPrefix, u8a);
+  
+    return base58Encode(u8aConcat(
+      input,
+      blake2AsU8a(input).subarray(0, [32, 33].includes(u8a.length) ? 2 : 1),
+    ));
+  }
+
+  /**
+   * Restore substrate address from bigint representation
+   * @param number decimal representation of substrate address
+   * @returns substrate address
+   */
+  restoreCrossAccountFromBigInt(number: bigint): TSubstrateAccount {
+    if (this.helper.api === null) {
+      throw 'Not connected';
+    }
+    const res = this.helper.api.registry.createType('AccountId', '0x' + number.toString(16).padStart(64, '0')).toJSON();
+    if (res === undefined || res === null) {
+      throw 'Restore address error';
+    }
+    return res.toString();
+  }
+
+  /**
+   * Convert etherium cross account id to substrate cross account id
+   * @param ethCrossAccount etherium cross account
+   * @returns substrate cross account id
+   */
+  convertCrossAccountFromEthCrossAcoount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId {
+    if (ethCrossAccount.field_1 === '0') {
+      return {Ethereum: ethCrossAccount.field_0.toLocaleLowerCase()};
+    }
+    
+    const ss58 = this.restoreCrossAccountFromBigInt(BigInt(ethCrossAccount.field_1));
+    return {Substrate: ss58};
+  }
+
   paraSiblingSovereignAccount(paraid: number) {
     // We are getting a *sibling* parachain sovereign account,
     // so we need a sibling prefix: encoded(b"sibl") == 0x7369626c