git.delta.rocks / unique-network / refs/commits / ddd521cfaa4d

difftreelog

Add call-methods checks

Max Andreev2022-12-22parent: #7d30844.patch.diff
in: master

6 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 {expect} from 'chai';18import {Pallets} from '../util';19import {IEthCrossAccountId} from '../util/playgrounds/types';20import {usingEthPlaygrounds, itEth} from './util';21import {EthUniqueHelper} from './util/playgrounds/unique.dev';2223async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {24  const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));25  await call();26  await helper.wait.newBlocks(1);27  const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));2829  expect(after < before).to.be.true;3031  return before - after;32}3334describe('Add collection admins', () => {35  let donor: IKeyringPair;3637  before(async function() {38    await usingEthPlaygrounds(async (_helper, privateKey) => {39      donor = await privateKey({filename: __filename});40    });41  });4243  [44    {mode: 'nft' as const, requiredPallets: []},45    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},46    {mode: 'ft' as const, requiredPallets: []},47  ].map(testCase => {48    itEth.ifWithPallets(`can add account admin by owner for ${testCase.mode}`, testCase.requiredPallets, async ({helper, privateKey}) => {49      // arrange50      const owner = await helper.eth.createAccountWithBalance(donor);51      const adminSub = await privateKey('//admin2');52      const adminEth = helper.eth.createAccount().toLowerCase();53  54      const adminDeprecated = helper.eth.createAccount().toLowerCase();55      const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);56      const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);57      58      const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');59      const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner, true);6061      // Check isOwnerOrAdminCross returns false:62      expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossSub).call()).to.be.false;63      expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossEth).call()).to.be.false;64      expect(await collectionEvm.methods.isOwnerOrAdminCross(helper.ethCrossAccount.fromAddress(adminDeprecated)).call()).to.be.false;65      66      // Soft-deprecated: can addCollectionAdmin 67      await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();68      // Can addCollectionAdminCross for substrate and ethereum address69      await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();70      await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();71  72      // 1. Expect api.rpc.unique.adminlist returns admins:73      const adminListRpc = await helper.collection.getAdmins(collectionId);74      expect(adminListRpc).to.has.length(3);75      expect(adminListRpc).to.be.deep.contain.members([{Substrate: adminSub.address}, {Ethereum: adminEth}, {Ethereum: adminDeprecated}]);76  77      // 2. Expect methods.collectionAdmins == api.rpc.unique.adminlist78      let adminListEth = await collectionEvm.methods.collectionAdmins().call();79      adminListEth = adminListEth.map((element: IEthCrossAccountId) => {80        return helper.address.convertCrossAccountFromEthCrossAccount(element);81      });82      expect(adminListRpc).to.be.like(adminListEth);8384      // 3. check isOwnerOrAdminCross returns true:85      expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossSub).call()).to.be.true;86      expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossEth).call()).to.be.true;87      expect(await collectionEvm.methods.isOwnerOrAdminCross(helper.ethCrossAccount.fromAddress(adminDeprecated)).call()).to.be.true;88    });89  });9091  itEth('cross account admin can mint', async ({helper}) => {92    // arrange: create collection and accounts93    const owner = await helper.eth.createAccountWithBalance(donor);94    const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', 'uri');95    const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();96    const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);97    const [adminSub] = await helper.arrange.createAccounts([100n], donor);98    const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);99    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);100    101    // cannot mint while not admin102    await expect(collectionEvm.methods.mint(owner).send({from: adminEth})).to.be.rejected;103    await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);104    105    // admin (sub and eth) can mint token:106    await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();107    await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();108    await collectionEvm.methods.mint(owner).send({from: adminEth});109    await helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}});110111    expect(await helper.collection.getLastTokenId(collectionId)).to.eq(2);112  });113114  itEth('cannot add invalid cross account admin', async ({helper}) => {115    const owner = await helper.eth.createAccountWithBalance(donor);116    const [admin] = await helper.arrange.createAccounts([100n, 100n], donor);117118    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');119    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);120121    const adminCross = {122      eth: helper.address.substrateToEth(admin.address),123      sub: admin.addressRaw,124    };125    await expect(collectionEvm.methods.addCollectionAdminCross(adminCross).send()).to.be.rejected;126  });127128  itEth('can verify owner with methods.isOwnerOrAdmin[Cross]', async ({helper, privateKey}) => {129    const owner = await helper.eth.createAccountWithBalance(donor);130    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');131132    const adminDeprecated = helper.eth.createAccount();133    const admin1Cross = helper.ethCrossAccount.fromKeyringPair(await privateKey('admin'));134    const admin2Cross = helper.ethCrossAccount.fromAddress(helper.address.substrateToEth((await privateKey('admin3')).address));135    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);136  137    // Soft-deprecated:138    expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.false;139    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.false;140    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.false;141142    await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();143    await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();144    await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();145146    // Soft-deprecated: isOwnerOrAdmin returns true147    expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.true;148    // Expect isOwnerOrAdminCross return true149    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.true;150    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.true;151  });152153  // Soft-deprecated154  itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {155    const owner = await helper.eth.createAccountWithBalance(donor);156    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');157158    const admin = await helper.eth.createAccountWithBalance(donor);159    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);160    await collectionEvm.methods.addCollectionAdmin(admin).send();161162    const user = helper.eth.createAccount();163    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))164      .to.be.rejectedWith('NoPermission');165166    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);167    expect(adminList.length).to.be.eq(1);168    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())169      .to.be.eq(admin.toLocaleLowerCase());170  });171172  // Soft-deprecated173  itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {174    const owner = await helper.eth.createAccountWithBalance(donor);175    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');176177    const notAdmin = await helper.eth.createAccountWithBalance(donor);178    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);179180    const user = helper.eth.createAccount();181    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))182      .to.be.rejectedWith('NoPermission');183184    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);185    expect(adminList.length).to.be.eq(0);186  });187188  itEth('(!negative tests!) Add [cross] admin by ADMIN is not allowed', async ({helper}) => {189    const owner = await helper.eth.createAccountWithBalance(donor);190    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');191192    const [admin, notAdmin] = await helper.arrange.createAccounts([10n, 10n], donor);193    const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);194    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);195    await collectionEvm.methods.addCollectionAdminCross(adminCross).send();196197    const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);198    await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))199      .to.be.rejectedWith('NoPermission');200201    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);202    expect(adminList.length).to.be.eq(1);203    204    const admin0Cross = helper.ethCrossAccount.fromKeyringPair(adminList[0]);205    expect(admin0Cross.eth.toLocaleLowerCase())206      .to.be.eq(adminCross.eth.toLocaleLowerCase());207  });208209  itEth('(!negative tests!) Add [cross] admin by USER is not allowed', async ({helper}) => {210    const owner = await helper.eth.createAccountWithBalance(donor);211    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');212213    const notAdmin0 = await helper.eth.createAccountWithBalance(donor);214    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);215    const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);216    const notAdmin1Cross = helper.ethCrossAccount.fromKeyringPair(notAdmin1);217    await expect(collectionEvm.methods.addCollectionAdminCross(notAdmin1Cross).call({from: notAdmin0}))218      .to.be.rejectedWith('NoPermission');219220    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);221    expect(adminList.length).to.be.eq(0);222  });223});224225describe('Remove collection admins', () => {226  let donor: IKeyringPair;227228  before(async function() {229    await usingEthPlaygrounds(async (_helper, privateKey) => {230      donor = await privateKey({filename: __filename});231    });232  });233234  // Soft-deprecated235  itEth('Remove admin by owner', async ({helper}) => {236    const owner = await helper.eth.createAccountWithBalance(donor);237    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');238239    const newAdmin = helper.eth.createAccount();240    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);241    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();242243    {244      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);245      expect(adminList.length).to.be.eq(1);246      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())247        .to.be.eq(newAdmin.toLocaleLowerCase());248    }249250    await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();251    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);252    expect(adminList.length).to.be.eq(0);253  });254255  itEth('Remove [cross] admin by owner', async ({helper}) => {256    const owner = await helper.eth.createAccountWithBalance(donor);257    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');258259    const [adminSub] = await helper.arrange.createAccounts([10n], donor);260    const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();261    const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);262    const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);263264    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);265    await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();266    await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();267268    {269      const adminList = await helper.collection.getAdmins(collectionId);270      expect(adminList).to.deep.include({Substrate: adminSub.address});271      expect(adminList).to.deep.include({Ethereum: adminEth});272    }273274    await collectionEvm.methods.removeCollectionAdminCross(adminCrossSub).send();275    await collectionEvm.methods.removeCollectionAdminCross(adminCrossEth).send();276    const adminList = await helper.collection.getAdmins(collectionId);277    expect(adminList.length).to.be.eq(0);278279    // Non admin cannot mint:280    await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Substrate: adminSub.address}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);281    await expect(collectionEvm.methods.mint(adminEth).send({from: adminEth})).to.be.rejected;282  });283284  // Soft-deprecated285  itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {286    const owner = await helper.eth.createAccountWithBalance(donor);287    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');288289    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);290291    const admin0 = await helper.eth.createAccountWithBalance(donor);292    await collectionEvm.methods.addCollectionAdmin(admin0).send();293    const admin1 = await helper.eth.createAccountWithBalance(donor);294    await collectionEvm.methods.addCollectionAdmin(admin1).send();295296    await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))297      .to.be.rejectedWith('NoPermission');298    {299      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);300      expect(adminList.length).to.be.eq(2);301      expect(adminList.toString().toLocaleLowerCase())302        .to.be.deep.contains(admin0.toLocaleLowerCase())303        .to.be.deep.contains(admin1.toLocaleLowerCase());304    }305  });306307  // Soft-deprecated308  itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {309    const owner = await helper.eth.createAccountWithBalance(donor);310    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');311312    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);313314    const admin = await helper.eth.createAccountWithBalance(donor);315    await collectionEvm.methods.addCollectionAdmin(admin).send();316    const notAdmin = helper.eth.createAccount();317318    await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))319      .to.be.rejectedWith('NoPermission');320    {321      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);322      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())323        .to.be.eq(admin.toLocaleLowerCase());324      expect(adminList.length).to.be.eq(1);325    }326  });327328  itEth('(!negative tests!) Remove [cross] admin by ADMIN is not allowed', async ({helper}) => {329    const owner = await helper.eth.createAccountWithBalance(donor);330    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');331332    const [admin1] = await helper.arrange.createAccounts([10n], donor);333    const admin1Cross = helper.ethCrossAccount.fromKeyringPair(admin1);334    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);335    await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();336    337    const [admin2] = await helper.arrange.createAccounts([10n], donor);338    const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);339    await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();340341    await expect(collectionEvm.methods.removeCollectionAdminCross(admin1Cross).call({from: admin2Cross.eth}))342      .to.be.rejectedWith('NoPermission');343344    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);345    expect(adminList.length).to.be.eq(2);346    expect(adminList.toString().toLocaleLowerCase())347      .to.be.deep.contains(admin1.address.toLocaleLowerCase())348      .to.be.deep.contains(admin2.address.toLocaleLowerCase());349  });350351  itEth('(!negative tests!) Remove [cross] admin by USER is not allowed', async ({helper}) => {352    const owner = await helper.eth.createAccountWithBalance(donor);353    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');354355    const [adminSub] = await helper.arrange.createAccounts([10n], donor);356    const adminSubCross = helper.ethCrossAccount.fromKeyringPair(adminSub);357    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);358    await collectionEvm.methods.addCollectionAdminCross(adminSubCross).send();359    const notAdminEth = await helper.eth.createAccountWithBalance(donor);360361    await expect(collectionEvm.methods.removeCollectionAdminCross(adminSubCross).call({from: notAdminEth}))362      .to.be.rejectedWith('NoPermission');363364    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);365    expect(adminList.length).to.be.eq(1);366    expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())367      .to.be.eq(adminSub.address.toLocaleLowerCase());368  });369});370371// Soft-deprecated372describe('Change owner tests', () => {373  let donor: IKeyringPair;374375  before(async function() {376    await usingEthPlaygrounds(async (_helper, privateKey) => {377      donor = await privateKey({filename: __filename});378    });379  });380381  itEth('Change owner', async ({helper}) => {382    const owner = await helper.eth.createAccountWithBalance(donor);383    const newOwner = await helper.eth.createAccountWithBalance(donor);384    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');385    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);386387    await collectionEvm.methods.changeCollectionOwner(newOwner).send();388389    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;390    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;391  });392393  itEth('change owner call fee', async ({helper}) => {394    const owner = await helper.eth.createAccountWithBalance(donor);395    const newOwner = await helper.eth.createAccountWithBalance(donor);396    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');397    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);398    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());399    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));400    expect(cost > 0);401  });402403  itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {404    const owner = await helper.eth.createAccountWithBalance(donor);405    const newOwner = await helper.eth.createAccountWithBalance(donor);406    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');407    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);408409    await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;410    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;411  });412});413414describe('Change substrate owner tests', () => {415  let donor: IKeyringPair;416417  before(async function() {418    await usingEthPlaygrounds(async (_helper, privateKey) => {419      donor = await privateKey({filename: __filename});420    });421  });422423  itEth('Change owner [cross]', async ({helper}) => {424    const owner = await helper.eth.createAccountWithBalance(donor);425    const ownerEth = await helper.eth.createAccountWithBalance(donor);426    const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);427    const [ownerSub] = await helper.arrange.createAccounts([10n], donor);428    const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);429430    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');431    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);432433    expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.false;434435    // Can set ethereum owner:436    await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossEth).send({from: owner});437    expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossEth).call()).to.be.true;438    expect(await helper.collection.getData(collectionId))439      .to.have.property('normalizedOwner').that.is.eq(helper.address.ethToSubstrate(ownerEth));440    441    // Can set Substrate owner:442    await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossSub).send({from: ownerEth});443    expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.true;444    expect(await helper.collection.getData(collectionId))445      .to.have.property('normalizedOwner').that.is.eq(helper.address.normalizeSubstrate(ownerSub.address));446  });447448  itEth.skip('change owner call fee', async ({helper}) => {449    const owner = await helper.eth.createAccountWithBalance(donor);450    const [newOwner] = await helper.arrange.createAccounts([10n], donor);451    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');452    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);453454    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());455    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));456    expect(cost > 0);457  });458459  itEth('(!negative tests!) call setOwner by non owner [cross]', async ({helper}) => {460    const owner = await helper.eth.createAccountWithBalance(donor);461    const otherReceiver = await helper.eth.createAccountWithBalance(donor);462    const [newOwner] = await helper.arrange.createAccounts([10n], donor);463    const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);464    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');465    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);466467    await expect(collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send({from: otherReceiver})).to.be.rejected;468    expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;469  });470});
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 {expect} from 'chai';18import {Pallets} from '../util';19import {IEthCrossAccountId} from '../util/playgrounds/types';20import {usingEthPlaygrounds, itEth} from './util';21import {EthUniqueHelper} from './util/playgrounds/unique.dev';2223async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {24  const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));25  await call();26  await helper.wait.newBlocks(1);27  const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));2829  expect(after < before).to.be.true;3031  return before - after;32}3334describe('Add collection admins', () => {35  let donor: IKeyringPair;3637  before(async function() {38    await usingEthPlaygrounds(async (_helper, privateKey) => {39      donor = await privateKey({filename: __filename});40    });41  });4243  [44    {mode: 'nft' as const, requiredPallets: []},45    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},46    {mode: 'ft' as const, requiredPallets: []},47  ].map(testCase => {48    itEth.ifWithPallets(`can add account admin by owner for ${testCase.mode}`, testCase.requiredPallets, async ({helper, privateKey}) => {49      // arrange50      const owner = await helper.eth.createAccountWithBalance(donor);51      const adminSub = await privateKey('//admin2');52      const adminEth = helper.eth.createAccount().toLowerCase();53  54      const adminDeprecated = helper.eth.createAccount().toLowerCase();55      const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);56      const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);57      58      const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');59      const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner, true);6061      // Check isOwnerOrAdminCross returns false:62      expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossSub).call()).to.be.false;63      expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossEth).call()).to.be.false;64      expect(await collectionEvm.methods.isOwnerOrAdminCross(helper.ethCrossAccount.fromAddress(adminDeprecated)).call()).to.be.false;65      expect(await collectionEvm.methods.collectionAdmins().call()).to.be.like([]);6667      68      // Soft-deprecated: can addCollectionAdmin 69      await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();70      // Can addCollectionAdminCross for substrate and ethereum address71      await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();72      await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();73  74      // 1. Expect api.rpc.unique.adminlist returns admins:75      const adminListRpc = await helper.collection.getAdmins(collectionId);76      expect(adminListRpc).to.has.length(3);77      expect(adminListRpc).to.be.deep.contain.members([{Substrate: adminSub.address}, {Ethereum: adminEth}, {Ethereum: adminDeprecated}]);78  79      // 2. Expect methods.collectionAdmins == api.rpc.unique.adminlist80      let adminListEth = await collectionEvm.methods.collectionAdmins().call();81      adminListEth = adminListEth.map((element: IEthCrossAccountId) => {82        return helper.address.convertCrossAccountFromEthCrossAccount(element);83      });84      expect(adminListRpc).to.be.like(adminListEth);8586      // 3. check isOwnerOrAdminCross returns true:87      expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossSub).call()).to.be.true;88      expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossEth).call()).to.be.true;89      expect(await collectionEvm.methods.isOwnerOrAdminCross(helper.ethCrossAccount.fromAddress(adminDeprecated)).call()).to.be.true;90    });91  });9293  itEth('cross account admin can mint', async ({helper}) => {94    // arrange: create collection and accounts95    const owner = await helper.eth.createAccountWithBalance(donor);96    const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', 'uri');97    const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();98    const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);99    const [adminSub] = await helper.arrange.createAccounts([100n], donor);100    const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);101    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);102    103    // cannot mint while not admin104    await expect(collectionEvm.methods.mint(owner).send({from: adminEth})).to.be.rejected;105    await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);106    107    // admin (sub and eth) can mint token:108    await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();109    await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();110    await collectionEvm.methods.mint(owner).send({from: adminEth});111    await helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}});112113    expect(await helper.collection.getLastTokenId(collectionId)).to.eq(2);114  });115116  itEth('cannot add invalid cross account admin', async ({helper}) => {117    const owner = await helper.eth.createAccountWithBalance(donor);118    const [admin] = await helper.arrange.createAccounts([100n, 100n], donor);119120    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');121    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);122123    const adminCross = {124      eth: helper.address.substrateToEth(admin.address),125      sub: admin.addressRaw,126    };127    await expect(collectionEvm.methods.addCollectionAdminCross(adminCross).send()).to.be.rejected;128  });129130  itEth('can verify owner with methods.isOwnerOrAdmin[Cross]', async ({helper, privateKey}) => {131    const owner = await helper.eth.createAccountWithBalance(donor);132    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');133134    const adminDeprecated = helper.eth.createAccount();135    const admin1Cross = helper.ethCrossAccount.fromKeyringPair(await privateKey('admin'));136    const admin2Cross = helper.ethCrossAccount.fromAddress(helper.address.substrateToEth((await privateKey('admin3')).address));137    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);138  139    // Soft-deprecated:140    expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.false;141    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.false;142    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.false;143144    await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();145    await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();146    await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();147148    // Soft-deprecated: isOwnerOrAdmin returns true149    expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.true;150    // Expect isOwnerOrAdminCross return true151    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.true;152    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.true;153  });154155  // Soft-deprecated156  itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {157    const owner = await helper.eth.createAccountWithBalance(donor);158    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');159160    const admin = await helper.eth.createAccountWithBalance(donor);161    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);162    await collectionEvm.methods.addCollectionAdmin(admin).send();163164    const user = helper.eth.createAccount();165    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))166      .to.be.rejectedWith('NoPermission');167168    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);169    expect(adminList.length).to.be.eq(1);170    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())171      .to.be.eq(admin.toLocaleLowerCase());172  });173174  // Soft-deprecated175  itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {176    const owner = await helper.eth.createAccountWithBalance(donor);177    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');178179    const notAdmin = await helper.eth.createAccountWithBalance(donor);180    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);181182    const user = helper.eth.createAccount();183    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))184      .to.be.rejectedWith('NoPermission');185186    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);187    expect(adminList.length).to.be.eq(0);188  });189190  itEth('(!negative tests!) Add [cross] admin by ADMIN is not allowed', async ({helper}) => {191    const owner = await helper.eth.createAccountWithBalance(donor);192    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');193194    const [admin, notAdmin] = await helper.arrange.createAccounts([10n, 10n], donor);195    const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);196    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);197    await collectionEvm.methods.addCollectionAdminCross(adminCross).send();198199    const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);200    await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))201      .to.be.rejectedWith('NoPermission');202203    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);204    expect(adminList.length).to.be.eq(1);205    206    const admin0Cross = helper.ethCrossAccount.fromKeyringPair(adminList[0]);207    expect(admin0Cross.eth.toLocaleLowerCase())208      .to.be.eq(adminCross.eth.toLocaleLowerCase());209  });210211  itEth('(!negative tests!) Add [cross] admin by USER is not allowed', async ({helper}) => {212    const owner = await helper.eth.createAccountWithBalance(donor);213    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');214215    const notAdmin0 = await helper.eth.createAccountWithBalance(donor);216    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);217    const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);218    const notAdmin1Cross = helper.ethCrossAccount.fromKeyringPair(notAdmin1);219    await expect(collectionEvm.methods.addCollectionAdminCross(notAdmin1Cross).call({from: notAdmin0}))220      .to.be.rejectedWith('NoPermission');221222    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);223    expect(adminList.length).to.be.eq(0);224  });225});226227describe('Remove collection admins', () => {228  let donor: IKeyringPair;229230  before(async function() {231    await usingEthPlaygrounds(async (_helper, privateKey) => {232      donor = await privateKey({filename: __filename});233    });234  });235236  // Soft-deprecated237  itEth('Remove admin by owner', async ({helper}) => {238    const owner = await helper.eth.createAccountWithBalance(donor);239    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');240241    const newAdmin = helper.eth.createAccount();242    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);243    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();244245    {246      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);247      expect(adminList.length).to.be.eq(1);248      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())249        .to.be.eq(newAdmin.toLocaleLowerCase());250    }251252    await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();253    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);254    expect(adminList.length).to.be.eq(0);255  });256257  itEth('Remove [cross] admin by owner', async ({helper}) => {258    const owner = await helper.eth.createAccountWithBalance(donor);259    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');260261    const [adminSub] = await helper.arrange.createAccounts([10n], donor);262    const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();263    const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);264    const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);265266    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);267    await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();268    await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();269270    {271      const adminList = await helper.collection.getAdmins(collectionId);272      expect(adminList).to.deep.include({Substrate: adminSub.address});273      expect(adminList).to.deep.include({Ethereum: adminEth});274    }275276    await collectionEvm.methods.removeCollectionAdminCross(adminCrossSub).send();277    await collectionEvm.methods.removeCollectionAdminCross(adminCrossEth).send();278    const adminList = await helper.collection.getAdmins(collectionId);279    expect(adminList.length).to.be.eq(0);280281    // Non admin cannot mint:282    await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Substrate: adminSub.address}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);283    await expect(collectionEvm.methods.mint(adminEth).send({from: adminEth})).to.be.rejected;284  });285286  // Soft-deprecated287  itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {288    const owner = await helper.eth.createAccountWithBalance(donor);289    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');290291    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);292293    const admin0 = await helper.eth.createAccountWithBalance(donor);294    await collectionEvm.methods.addCollectionAdmin(admin0).send();295    const admin1 = await helper.eth.createAccountWithBalance(donor);296    await collectionEvm.methods.addCollectionAdmin(admin1).send();297298    await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))299      .to.be.rejectedWith('NoPermission');300    {301      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);302      expect(adminList.length).to.be.eq(2);303      expect(adminList.toString().toLocaleLowerCase())304        .to.be.deep.contains(admin0.toLocaleLowerCase())305        .to.be.deep.contains(admin1.toLocaleLowerCase());306    }307  });308309  // Soft-deprecated310  itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {311    const owner = await helper.eth.createAccountWithBalance(donor);312    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');313314    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);315316    const admin = await helper.eth.createAccountWithBalance(donor);317    await collectionEvm.methods.addCollectionAdmin(admin).send();318    const notAdmin = helper.eth.createAccount();319320    await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))321      .to.be.rejectedWith('NoPermission');322    {323      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);324      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())325        .to.be.eq(admin.toLocaleLowerCase());326      expect(adminList.length).to.be.eq(1);327    }328  });329330  itEth('(!negative tests!) Remove [cross] admin by ADMIN is not allowed', async ({helper}) => {331    const owner = await helper.eth.createAccountWithBalance(donor);332    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');333334    const [admin1] = await helper.arrange.createAccounts([10n], donor);335    const admin1Cross = helper.ethCrossAccount.fromKeyringPair(admin1);336    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);337    await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();338    339    const [admin2] = await helper.arrange.createAccounts([10n], donor);340    const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);341    await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();342343    await expect(collectionEvm.methods.removeCollectionAdminCross(admin1Cross).call({from: admin2Cross.eth}))344      .to.be.rejectedWith('NoPermission');345346    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);347    expect(adminList.length).to.be.eq(2);348    expect(adminList.toString().toLocaleLowerCase())349      .to.be.deep.contains(admin1.address.toLocaleLowerCase())350      .to.be.deep.contains(admin2.address.toLocaleLowerCase());351  });352353  itEth('(!negative tests!) Remove [cross] admin by USER is not allowed', async ({helper}) => {354    const owner = await helper.eth.createAccountWithBalance(donor);355    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');356357    const [adminSub] = await helper.arrange.createAccounts([10n], donor);358    const adminSubCross = helper.ethCrossAccount.fromKeyringPair(adminSub);359    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);360    await collectionEvm.methods.addCollectionAdminCross(adminSubCross).send();361    const notAdminEth = await helper.eth.createAccountWithBalance(donor);362363    await expect(collectionEvm.methods.removeCollectionAdminCross(adminSubCross).call({from: notAdminEth}))364      .to.be.rejectedWith('NoPermission');365366    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);367    expect(adminList.length).to.be.eq(1);368    expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())369      .to.be.eq(adminSub.address.toLocaleLowerCase());370  });371});372373// Soft-deprecated374describe('Change owner tests', () => {375  let donor: IKeyringPair;376377  before(async function() {378    await usingEthPlaygrounds(async (_helper, privateKey) => {379      donor = await privateKey({filename: __filename});380    });381  });382383  itEth('Change owner', async ({helper}) => {384    const owner = await helper.eth.createAccountWithBalance(donor);385    const newOwner = await helper.eth.createAccountWithBalance(donor);386    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');387    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);388389    await collectionEvm.methods.changeCollectionOwner(newOwner).send();390391    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;392    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;393  });394395  itEth('change owner call fee', async ({helper}) => {396    const owner = await helper.eth.createAccountWithBalance(donor);397    const newOwner = await helper.eth.createAccountWithBalance(donor);398    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');399    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);400    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());401    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));402    expect(cost > 0);403  });404405  itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {406    const owner = await helper.eth.createAccountWithBalance(donor);407    const newOwner = await helper.eth.createAccountWithBalance(donor);408    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');409    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);410411    await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;412    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;413  });414});415416describe('Change substrate owner tests', () => {417  let donor: IKeyringPair;418419  before(async function() {420    await usingEthPlaygrounds(async (_helper, privateKey) => {421      donor = await privateKey({filename: __filename});422    });423  });424425  itEth('Change owner [cross]', async ({helper}) => {426    const owner = await helper.eth.createAccountWithBalance(donor);427    const ownerEth = await helper.eth.createAccountWithBalance(donor);428    const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);429    const [ownerSub] = await helper.arrange.createAccounts([10n], donor);430    const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);431432    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');433    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);434435    expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.false;436437    // Can set ethereum owner:438    await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossEth).send({from: owner});439    expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossEth).call()).to.be.true;440    expect(await helper.collection.getData(collectionId))441      .to.have.property('normalizedOwner').that.is.eq(helper.address.ethToSubstrate(ownerEth));442    443    // Can set Substrate owner:444    await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossSub).send({from: ownerEth});445    expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.true;446    expect(await helper.collection.getData(collectionId))447      .to.have.property('normalizedOwner').that.is.eq(helper.address.normalizeSubstrate(ownerSub.address));448  });449450  itEth.skip('change owner call fee', async ({helper}) => {451    const owner = await helper.eth.createAccountWithBalance(donor);452    const [newOwner] = await helper.arrange.createAccounts([10n], donor);453    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');454    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);455456    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());457    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));458    expect(cost > 0);459  });460461  itEth('(!negative tests!) call setOwner by non owner [cross]', async ({helper}) => {462    const owner = await helper.eth.createAccountWithBalance(donor);463    const otherReceiver = await helper.eth.createAccountWithBalance(donor);464    const [newOwner] = await helper.arrange.createAccounts([10n], donor);465    const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);466    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');467    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);468469    await expect(collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send({from: otherReceiver})).to.be.rejected;470    expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;471  });472});
modifiedtests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -101,11 +101,13 @@
       expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;
   
       await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
+      let sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});
+      expect(helper.address.restoreCrossAccountFromBigInt(BigInt(sponsorTuple.sub))).to.be.eq(helper.address.ethToSubstrate(sponsor));
       expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
   
       await collectionEvm.methods.removeCollectionSponsor().send({from: owner});
   
-      const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});
+      sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});
       expect(sponsorTuple.eth).to.be.eq('0x0000000000000000000000000000000000000000');
     }));
 
modifiedtests/src/eth/createFTCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createFTCollection.test.ts
+++ b/tests/src/eth/createFTCollection.test.ts
@@ -18,7 +18,7 @@
 import {evmToAddress} from '@polkadot/util-crypto';
 import {Pallets, requirePalletsOrSkip} from '../util';
 import {expect, itEth, usingEthPlaygrounds} from './util';
-import { CollectionLimits } from './util/playgrounds/types';
+import {CollectionLimits} from './util/playgrounds/types';
 
 const DECIMALS = 18;
 
@@ -32,6 +32,7 @@
     });
   });
   
+  // TODO move sponsorship tests to another file:
   // Soft-deprecated
   itEth('[eth] Set sponsorship', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
@@ -91,6 +92,11 @@
     expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)
       .methods.isCollectionExist(collectionAddress).call())
       .to.be.true;
+    
+    // check collectionOwner:
+    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
+    const collectionOwner = await collectionEvm.methods.collectionOwner().call();
+    expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner));
   });
   
   itEth('destroyCollection', async ({helper}) => {
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -132,6 +132,11 @@
     expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)
       .methods.isCollectionExist(collectionAddress).call())
       .to.be.true;
+
+    // check collectionOwner:
+    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
+    const collectionOwner = await collectionEvm.methods.collectionOwner().call();
+    expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner));
   });
 });
 
modifiedtests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -88,27 +88,6 @@
     ]);
   });
   
-  // this test will occasionally fail when in async environment.
-  itEth.skip('Check collection address exist', async ({helper}) => {
-    const owner = await helper.eth.createAccountWithBalance(donor);
-
-    const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;
-    const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);
-    const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
-
-    expect(await collectionHelpers.methods
-      .isCollectionExist(expectedCollectionAddress)
-      .call()).to.be.false;
-
-    await collectionHelpers.methods
-      .createRFTCollection('A', 'A', 'A')
-      .send({value: Number(2n * helper.balance.getOneTokenNominal())});
-    
-    expect(await collectionHelpers.methods
-      .isCollectionExist(expectedCollectionAddress)
-      .call()).to.be.true;
-  });
-  
   // Soft-deprecated
   itEth('[eth] Set sponsorship', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
@@ -164,6 +143,11 @@
     expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)
       .methods.isCollectionExist(collectionAddress).call())
       .to.be.true;
+
+    // check collectionOwner:
+    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);
+    const collectionOwner = await collectionEvm.methods.collectionOwner().call();
+    expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner));
   });
 });
 
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -167,7 +167,6 @@
     expect(event.returnValues.to).to.be.equal(receiver);
 
     expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
-    console.log(await contract.methods.crossOwnerOf(tokenId).call());
     expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
     // TODO: this wont work right now, need release 919000 first
     // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
@@ -200,8 +199,7 @@
             },
           };
         });
-    
-    
+
       const collection = await helper.nft.mintCollection(minter, {
         tokenPrefix: 'ethp',
         tokenPropertyPermissions: permissions,