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

difftreelog

Test fix: use send instead of call

Max Andreev2022-11-30parent: #6adc689.patch.diff
in: master

1 file 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 {IEthCrossAccountId} from '../util/playgrounds/types';19import {usingEthPlaygrounds, itEth} from './util';20import {EthUniqueHelper} from './util/playgrounds/unique.dev';2122async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {23  const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));24  await call();25  await helper.wait.newBlocks(1);26  const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));2728  expect(after < before).to.be.true;2930  return before - after;31}3233describe('Add collection admins', () => {34  let donor: IKeyringPair;3536  before(async function() {37    await usingEthPlaygrounds(async (_helper, privateKey) => {38      donor = await privateKey({filename: __filename});39    });40  });4142  itEth('can add account admin by owner', async ({helper, privateKey}) => {43    // arrange44    const owner = await helper.eth.createAccountWithBalance(donor);45    const adminSub = await privateKey('//admin2');46    const adminEth = helper.eth.createAccount().toLowerCase();4748    const adminDeprecated = helper.eth.createAccount().toLowerCase();49    const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);50    const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);51        52    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');53    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);5455    // Soft-deprecated: can addCollectionAdmin 56    await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();57    // Can addCollectionAdminCross for substrate and ethereum address58    await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();59    await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();6061    // 1. Expect api.rpc.unique.adminlist returns admins:62    const adminListRpc = await helper.collection.getAdmins(collectionId);63    expect(adminListRpc).to.has.length(3);64    expect(adminListRpc).to.be.deep.contain.members([{Substrate: adminSub.address}, {Ethereum: adminEth}, {Ethereum: adminDeprecated}]);6566    // 2. Expect methods.collectionAdmins == api.rpc.unique.adminlist67    let adminListEth = await collectionEvm.methods.collectionAdmins().call();68    adminListEth = adminListEth.map((element: IEthCrossAccountId) => {69      return helper.address.convertCrossAccountFromEthCrossAccount(element);70    });71    expect(adminListRpc).to.be.like(adminListEth);72  });7374  itEth('cross account admin can mint', async ({helper}) => {75    // arrange: create collection and accounts76    const owner = await helper.eth.createAccountWithBalance(donor);77    const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', 'uri');78    const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();79    const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);80    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);81    82    // cannot mint while not admin83    await expect(collectionEvm.methods.mint(owner).call({from: adminEth})).to.be.rejectedWith('PublicMintingNotAllowed');84    85    // admin can mint token:86    await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();87    const result = await collectionEvm.methods.mint(owner).call({from: adminEth});8889    // TODO: Why fail90    expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);91  });9293  itEth('cannot add invalid cross account admin', async ({helper}) => {94    const owner = await helper.eth.createAccountWithBalance(donor);95    const [admin] = await helper.arrange.createAccounts([100n, 100n], donor);9697    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');98    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);99100    const adminCross = {101      eth: helper.address.substrateToEth(admin.address),102      sub: admin.addressRaw,103    };104    await expect(collectionEvm.methods.addCollectionAdminCross(adminCross).send()).to.be.rejected;105  });106107  itEth('can verify owner with methods.isOwnerOrAdmin[Cross]', async ({helper, privateKey}) => {108    const owner = await helper.eth.createAccountWithBalance(donor);109    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');110111    const adminDeprecated = helper.eth.createAccount();112    const admin1Cross = helper.ethCrossAccount.fromKeyringPair(await privateKey('admin'));113    const admin2Cross = helper.ethCrossAccount.fromAddress(helper.address.substrateToEth((await privateKey('admin3')).address));114    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);115  116    // Soft-deprecated:117    expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.false;118    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.false;119    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.false;120121    await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();122    await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();123    await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();124125    // Soft-deprecated: isOwnerOrAdmin returns true126    expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.true;127    // Expect isOwnerOrAdminCross return true128    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.true;129    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.true;130  });131132  // Soft-deprecated133  itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {134    const owner = await helper.eth.createAccountWithBalance(donor);135    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');136137    const admin = await helper.eth.createAccountWithBalance(donor);138    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);139    await collectionEvm.methods.addCollectionAdmin(admin).send();140141    const user = helper.eth.createAccount();142    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))143      .to.be.rejectedWith('NoPermission');144145    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);146    expect(adminList.length).to.be.eq(1);147    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())148      .to.be.eq(admin.toLocaleLowerCase());149  });150151  // Soft-deprecated152  itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {153    const owner = await helper.eth.createAccountWithBalance(donor);154    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');155156    const notAdmin = await helper.eth.createAccountWithBalance(donor);157    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);158159    const user = helper.eth.createAccount();160    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))161      .to.be.rejectedWith('NoPermission');162163    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);164    expect(adminList.length).to.be.eq(0);165  });166167  itEth('(!negative tests!) Add [cross] admin by ADMIN 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 [admin, notAdmin] = await helper.arrange.createAccounts([10n, 10n], donor);172    const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);173    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);174    await collectionEvm.methods.addCollectionAdminCross(adminCross).send();175176    const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);177    await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))178      .to.be.rejectedWith('NoPermission');179180    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);181    expect(adminList.length).to.be.eq(1);182    183    const admin0Cross = helper.ethCrossAccount.fromKeyringPair(adminList[0]);184    expect(admin0Cross.eth.toLocaleLowerCase())185      .to.be.eq(adminCross.eth.toLocaleLowerCase());186  });187188  itEth('(!negative tests!) Add [cross] admin by USER 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 notAdmin0 = await helper.eth.createAccountWithBalance(donor);193    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);194    const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);195    const notAdmin1Cross = helper.ethCrossAccount.fromKeyringPair(notAdmin1);196    await expect(collectionEvm.methods.addCollectionAdminCross(notAdmin1Cross).call({from: notAdmin0}))197      .to.be.rejectedWith('NoPermission');198199    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);200    expect(adminList.length).to.be.eq(0);201  });202});203204describe('Remove collection admins', () => {205  let donor: IKeyringPair;206207  before(async function() {208    await usingEthPlaygrounds(async (_helper, privateKey) => {209      donor = await privateKey({filename: __filename});210    });211  });212213  // Soft-deprecated214  itEth('Remove admin by owner', async ({helper}) => {215    const owner = await helper.eth.createAccountWithBalance(donor);216    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');217218    const newAdmin = helper.eth.createAccount();219    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);220    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();221222    {223      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);224      expect(adminList.length).to.be.eq(1);225      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())226        .to.be.eq(newAdmin.toLocaleLowerCase());227    }228229    await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();230    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);231    expect(adminList.length).to.be.eq(0);232  });233234  itEth('Remove [cross] admin by owner', async ({helper}) => {235    const owner = await helper.eth.createAccountWithBalance(donor);236    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');237238    const [newAdmin] = await helper.arrange.createAccounts([10n], donor);239    const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);240    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);241    await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();242    {243      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);244      expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())245        .to.be.eq(newAdmin.address.toLocaleLowerCase());246    }247248    await collectionEvm.methods.removeCollectionAdminCross(newAdminCross).send();249    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);250    expect(adminList.length).to.be.eq(0);251  });252253  // Soft-deprecated254  itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {255    const owner = await helper.eth.createAccountWithBalance(donor);256    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');257258    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);259260    const admin0 = await helper.eth.createAccountWithBalance(donor);261    await collectionEvm.methods.addCollectionAdmin(admin0).send();262    const admin1 = await helper.eth.createAccountWithBalance(donor);263    await collectionEvm.methods.addCollectionAdmin(admin1).send();264265    await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))266      .to.be.rejectedWith('NoPermission');267    {268      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);269      expect(adminList.length).to.be.eq(2);270      expect(adminList.toString().toLocaleLowerCase())271        .to.be.deep.contains(admin0.toLocaleLowerCase())272        .to.be.deep.contains(admin1.toLocaleLowerCase());273    }274  });275276  // Soft-deprecated277  itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {278    const owner = await helper.eth.createAccountWithBalance(donor);279    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');280281    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);282283    const admin = await helper.eth.createAccountWithBalance(donor);284    await collectionEvm.methods.addCollectionAdmin(admin).send();285    const notAdmin = helper.eth.createAccount();286287    await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))288      .to.be.rejectedWith('NoPermission');289    {290      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);291      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())292        .to.be.eq(admin.toLocaleLowerCase());293      expect(adminList.length).to.be.eq(1);294    }295  });296297  itEth('(!negative tests!) Remove [cross] admin by ADMIN is not allowed', async ({helper}) => {298    const owner = await helper.eth.createAccountWithBalance(donor);299    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');300301    const [admin1] = await helper.arrange.createAccounts([10n], donor);302    const admin1Cross = helper.ethCrossAccount.fromKeyringPair(admin1);303    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);304    await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();305    306    const [admin2] = await helper.arrange.createAccounts([10n], donor);307    const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);308    await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();309310    await expect(collectionEvm.methods.removeCollectionAdminCross(admin1Cross).call({from: admin2Cross.eth}))311      .to.be.rejectedWith('NoPermission');312313    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);314    expect(adminList.length).to.be.eq(2);315    expect(adminList.toString().toLocaleLowerCase())316      .to.be.deep.contains(admin1.address.toLocaleLowerCase())317      .to.be.deep.contains(admin2.address.toLocaleLowerCase());318  });319320  itEth('(!negative tests!) Remove [cross] admin by USER is not allowed', async ({helper}) => {321    const owner = await helper.eth.createAccountWithBalance(donor);322    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');323324    const [adminSub] = await helper.arrange.createAccounts([10n], donor);325    const adminSubCross = helper.ethCrossAccount.fromKeyringPair(adminSub);326    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);327    await collectionEvm.methods.addCollectionAdminCross(adminSubCross).send();328    const notAdminEth = await helper.eth.createAccountWithBalance(donor);329330    await expect(collectionEvm.methods.removeCollectionAdminCross(adminSubCross).call({from: notAdminEth}))331      .to.be.rejectedWith('NoPermission');332333    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);334    expect(adminList.length).to.be.eq(1);335    expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())336      .to.be.eq(adminSub.address.toLocaleLowerCase());337  });338});339340// Soft-deprecated341describe('Change owner tests', () => {342  let donor: IKeyringPair;343344  before(async function() {345    await usingEthPlaygrounds(async (_helper, privateKey) => {346      donor = await privateKey({filename: __filename});347    });348  });349350  itEth('Change owner', async ({helper}) => {351    const owner = await helper.eth.createAccountWithBalance(donor);352    const newOwner = await helper.eth.createAccountWithBalance(donor);353    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');354    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);355356    await collectionEvm.methods.changeCollectionOwner(newOwner).send();357358    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;359    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;360  });361362  itEth('change owner call fee', async ({helper}) => {363    const owner = await helper.eth.createAccountWithBalance(donor);364    const newOwner = await helper.eth.createAccountWithBalance(donor);365    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');366    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);367    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());368    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));369    expect(cost > 0);370  });371372  itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {373    const owner = await helper.eth.createAccountWithBalance(donor);374    const newOwner = await helper.eth.createAccountWithBalance(donor);375    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');376    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);377378    await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;379    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;380  });381});382383describe('Change substrate owner tests', () => {384  let donor: IKeyringPair;385386  before(async function() {387    await usingEthPlaygrounds(async (_helper, privateKey) => {388      donor = await privateKey({filename: __filename});389    });390  });391392  itEth('Change owner [cross]', async ({helper}) => {393    const owner = await helper.eth.createAccountWithBalance(donor);394    const [newOwner] = await helper.arrange.createAccounts([10n], donor);395    const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);396    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');397    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);398399    expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;400401    await collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send();402403    expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.true;404  });405406  itEth.skip('change owner call fee', async ({helper}) => {407    const owner = await helper.eth.createAccountWithBalance(donor);408    const [newOwner] = await helper.arrange.createAccounts([10n], donor);409    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');410    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);411412    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());413    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));414    expect(cost > 0);415  });416417  itEth('(!negative tests!) call setOwner by non owner [cross]', async ({helper}) => {418    const owner = await helper.eth.createAccountWithBalance(donor);419    const otherReceiver = await helper.eth.createAccountWithBalance(donor);420    const [newOwner] = await helper.arrange.createAccounts([10n], donor);421    const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);422    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');423    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);424425    await expect(collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send({from: otherReceiver})).to.be.rejected;426    expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;427  });428});
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 {IEthCrossAccountId} from '../util/playgrounds/types';19import {usingEthPlaygrounds, itEth} from './util';20import {EthUniqueHelper} from './util/playgrounds/unique.dev';2122async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {23  const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));24  await call();25  await helper.wait.newBlocks(1);26  const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));2728  expect(after < before).to.be.true;2930  return before - after;31}3233describe('Add collection admins', () => {34  let donor: IKeyringPair;3536  before(async function() {37    await usingEthPlaygrounds(async (_helper, privateKey) => {38      donor = await privateKey({filename: __filename});39    });40  });4142  itEth('can add account admin by owner', async ({helper, privateKey}) => {43    // arrange44    const owner = await helper.eth.createAccountWithBalance(donor);45    const adminSub = await privateKey('//admin2');46    const adminEth = helper.eth.createAccount().toLowerCase();4748    const adminDeprecated = helper.eth.createAccount().toLowerCase();49    const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);50    const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);51        52    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');53    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);5455    // Soft-deprecated: can addCollectionAdmin 56    await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();57    // Can addCollectionAdminCross for substrate and ethereum address58    await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();59    await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();6061    // 1. Expect api.rpc.unique.adminlist returns admins:62    const adminListRpc = await helper.collection.getAdmins(collectionId);63    expect(adminListRpc).to.has.length(3);64    expect(adminListRpc).to.be.deep.contain.members([{Substrate: adminSub.address}, {Ethereum: adminEth}, {Ethereum: adminDeprecated}]);6566    // 2. Expect methods.collectionAdmins == api.rpc.unique.adminlist67    let adminListEth = await collectionEvm.methods.collectionAdmins().call();68    adminListEth = adminListEth.map((element: IEthCrossAccountId) => {69      return helper.address.convertCrossAccountFromEthCrossAccount(element);70    });71    expect(adminListRpc).to.be.like(adminListEth);72  });7374  itEth('cross account admin can mint', async ({helper}) => {75    // arrange: create collection and accounts76    const owner = await helper.eth.createAccountWithBalance(donor);77    const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', 'uri');78    const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();79    const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);80    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);81    82    // cannot mint while not admin83    await expect(collectionEvm.methods.mint(owner).send({from: adminEth})).to.be.rejectedWith('PublicMintingNotAllowed');84    85    // admin can mint token:86    await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();87    await collectionEvm.methods.mint(owner).send({from: adminEth});8889    expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);90  });9192  itEth('cannot add invalid cross account admin', async ({helper}) => {93    const owner = await helper.eth.createAccountWithBalance(donor);94    const [admin] = await helper.arrange.createAccounts([100n, 100n], donor);9596    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');97    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);9899    const adminCross = {100      eth: helper.address.substrateToEth(admin.address),101      sub: admin.addressRaw,102    };103    await expect(collectionEvm.methods.addCollectionAdminCross(adminCross).send()).to.be.rejected;104  });105106  itEth('can verify owner with methods.isOwnerOrAdmin[Cross]', async ({helper, privateKey}) => {107    const owner = await helper.eth.createAccountWithBalance(donor);108    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');109110    const adminDeprecated = helper.eth.createAccount();111    const admin1Cross = helper.ethCrossAccount.fromKeyringPair(await privateKey('admin'));112    const admin2Cross = helper.ethCrossAccount.fromAddress(helper.address.substrateToEth((await privateKey('admin3')).address));113    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);114  115    // Soft-deprecated:116    expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.false;117    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.false;118    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.false;119120    await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();121    await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();122    await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();123124    // Soft-deprecated: isOwnerOrAdmin returns true125    expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.true;126    // Expect isOwnerOrAdminCross return true127    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.true;128    expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.true;129  });130131  // Soft-deprecated132  itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {133    const owner = await helper.eth.createAccountWithBalance(donor);134    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');135136    const admin = await helper.eth.createAccountWithBalance(donor);137    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);138    await collectionEvm.methods.addCollectionAdmin(admin).send();139140    const user = helper.eth.createAccount();141    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))142      .to.be.rejectedWith('NoPermission');143144    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);145    expect(adminList.length).to.be.eq(1);146    expect(adminList[0].asEthereum.toString().toLocaleLowerCase())147      .to.be.eq(admin.toLocaleLowerCase());148  });149150  // Soft-deprecated151  itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {152    const owner = await helper.eth.createAccountWithBalance(donor);153    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');154155    const notAdmin = await helper.eth.createAccountWithBalance(donor);156    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);157158    const user = helper.eth.createAccount();159    await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))160      .to.be.rejectedWith('NoPermission');161162    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);163    expect(adminList.length).to.be.eq(0);164  });165166  itEth('(!negative tests!) Add [cross] admin by ADMIN is not allowed', async ({helper}) => {167    const owner = await helper.eth.createAccountWithBalance(donor);168    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');169170    const [admin, notAdmin] = await helper.arrange.createAccounts([10n, 10n], donor);171    const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);172    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);173    await collectionEvm.methods.addCollectionAdminCross(adminCross).send();174175    const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);176    await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))177      .to.be.rejectedWith('NoPermission');178179    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);180    expect(adminList.length).to.be.eq(1);181    182    const admin0Cross = helper.ethCrossAccount.fromKeyringPair(adminList[0]);183    expect(admin0Cross.eth.toLocaleLowerCase())184      .to.be.eq(adminCross.eth.toLocaleLowerCase());185  });186187  itEth('(!negative tests!) Add [cross] admin by USER is not allowed', async ({helper}) => {188    const owner = await helper.eth.createAccountWithBalance(donor);189    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');190191    const notAdmin0 = await helper.eth.createAccountWithBalance(donor);192    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);193    const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);194    const notAdmin1Cross = helper.ethCrossAccount.fromKeyringPair(notAdmin1);195    await expect(collectionEvm.methods.addCollectionAdminCross(notAdmin1Cross).call({from: notAdmin0}))196      .to.be.rejectedWith('NoPermission');197198    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);199    expect(adminList.length).to.be.eq(0);200  });201});202203describe('Remove collection admins', () => {204  let donor: IKeyringPair;205206  before(async function() {207    await usingEthPlaygrounds(async (_helper, privateKey) => {208      donor = await privateKey({filename: __filename});209    });210  });211212  // Soft-deprecated213  itEth('Remove admin by owner', async ({helper}) => {214    const owner = await helper.eth.createAccountWithBalance(donor);215    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');216217    const newAdmin = helper.eth.createAccount();218    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);219    await collectionEvm.methods.addCollectionAdmin(newAdmin).send();220221    {222      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);223      expect(adminList.length).to.be.eq(1);224      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())225        .to.be.eq(newAdmin.toLocaleLowerCase());226    }227228    await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();229    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);230    expect(adminList.length).to.be.eq(0);231  });232233  itEth('Remove [cross] admin by owner', async ({helper}) => {234    const owner = await helper.eth.createAccountWithBalance(donor);235    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');236237    const [newAdmin] = await helper.arrange.createAccounts([10n], donor);238    const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);239    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);240    await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();241    {242      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);243      expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())244        .to.be.eq(newAdmin.address.toLocaleLowerCase());245    }246247    await collectionEvm.methods.removeCollectionAdminCross(newAdminCross).send();248    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);249    expect(adminList.length).to.be.eq(0);250  });251252  // Soft-deprecated253  itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {254    const owner = await helper.eth.createAccountWithBalance(donor);255    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');256257    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);258259    const admin0 = await helper.eth.createAccountWithBalance(donor);260    await collectionEvm.methods.addCollectionAdmin(admin0).send();261    const admin1 = await helper.eth.createAccountWithBalance(donor);262    await collectionEvm.methods.addCollectionAdmin(admin1).send();263264    await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))265      .to.be.rejectedWith('NoPermission');266    {267      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);268      expect(adminList.length).to.be.eq(2);269      expect(adminList.toString().toLocaleLowerCase())270        .to.be.deep.contains(admin0.toLocaleLowerCase())271        .to.be.deep.contains(admin1.toLocaleLowerCase());272    }273  });274275  // Soft-deprecated276  itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {277    const owner = await helper.eth.createAccountWithBalance(donor);278    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');279280    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);281282    const admin = await helper.eth.createAccountWithBalance(donor);283    await collectionEvm.methods.addCollectionAdmin(admin).send();284    const notAdmin = helper.eth.createAccount();285286    await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))287      .to.be.rejectedWith('NoPermission');288    {289      const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);290      expect(adminList[0].asEthereum.toString().toLocaleLowerCase())291        .to.be.eq(admin.toLocaleLowerCase());292      expect(adminList.length).to.be.eq(1);293    }294  });295296  itEth('(!negative tests!) Remove [cross] admin by ADMIN is not allowed', async ({helper}) => {297    const owner = await helper.eth.createAccountWithBalance(donor);298    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');299300    const [admin1] = await helper.arrange.createAccounts([10n], donor);301    const admin1Cross = helper.ethCrossAccount.fromKeyringPair(admin1);302    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);303    await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();304    305    const [admin2] = await helper.arrange.createAccounts([10n], donor);306    const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);307    await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();308309    await expect(collectionEvm.methods.removeCollectionAdminCross(admin1Cross).call({from: admin2Cross.eth}))310      .to.be.rejectedWith('NoPermission');311312    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);313    expect(adminList.length).to.be.eq(2);314    expect(adminList.toString().toLocaleLowerCase())315      .to.be.deep.contains(admin1.address.toLocaleLowerCase())316      .to.be.deep.contains(admin2.address.toLocaleLowerCase());317  });318319  itEth('(!negative tests!) Remove [cross] admin by USER is not allowed', async ({helper}) => {320    const owner = await helper.eth.createAccountWithBalance(donor);321    const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');322323    const [adminSub] = await helper.arrange.createAccounts([10n], donor);324    const adminSubCross = helper.ethCrossAccount.fromKeyringPair(adminSub);325    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);326    await collectionEvm.methods.addCollectionAdminCross(adminSubCross).send();327    const notAdminEth = await helper.eth.createAccountWithBalance(donor);328329    await expect(collectionEvm.methods.removeCollectionAdminCross(adminSubCross).call({from: notAdminEth}))330      .to.be.rejectedWith('NoPermission');331332    const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);333    expect(adminList.length).to.be.eq(1);334    expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())335      .to.be.eq(adminSub.address.toLocaleLowerCase());336  });337});338339// Soft-deprecated340describe('Change owner tests', () => {341  let donor: IKeyringPair;342343  before(async function() {344    await usingEthPlaygrounds(async (_helper, privateKey) => {345      donor = await privateKey({filename: __filename});346    });347  });348349  itEth('Change owner', async ({helper}) => {350    const owner = await helper.eth.createAccountWithBalance(donor);351    const newOwner = await helper.eth.createAccountWithBalance(donor);352    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');353    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);354355    await collectionEvm.methods.changeCollectionOwner(newOwner).send();356357    expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;358    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;359  });360361  itEth('change owner call fee', async ({helper}) => {362    const owner = await helper.eth.createAccountWithBalance(donor);363    const newOwner = await helper.eth.createAccountWithBalance(donor);364    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');365    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);366    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());367    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));368    expect(cost > 0);369  });370371  itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {372    const owner = await helper.eth.createAccountWithBalance(donor);373    const newOwner = await helper.eth.createAccountWithBalance(donor);374    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');375    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);376377    await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;378    expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;379  });380});381382describe('Change substrate owner tests', () => {383  let donor: IKeyringPair;384385  before(async function() {386    await usingEthPlaygrounds(async (_helper, privateKey) => {387      donor = await privateKey({filename: __filename});388    });389  });390391  itEth('Change owner [cross]', async ({helper}) => {392    const owner = await helper.eth.createAccountWithBalance(donor);393    const [newOwner] = await helper.arrange.createAccounts([10n], donor);394    const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);395    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');396    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);397398    expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;399400    await collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send();401402    expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.true;403  });404405  itEth.skip('change owner call fee', async ({helper}) => {406    const owner = await helper.eth.createAccountWithBalance(donor);407    const [newOwner] = await helper.arrange.createAccounts([10n], donor);408    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');409    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);410411    const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());412    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));413    expect(cost > 0);414  });415416  itEth('(!negative tests!) call setOwner by non owner [cross]', async ({helper}) => {417    const owner = await helper.eth.createAccountWithBalance(donor);418    const otherReceiver = await helper.eth.createAccountWithBalance(donor);419    const [newOwner] = await helper.arrange.createAccounts([10n], donor);420    const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);421    const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');422    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);423424    await expect(collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send({from: otherReceiver})).to.be.rejected;425    expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;426  });427});