difftreelog
Merge pull request #745 from UniqueNetwork/tests/eth-helpers
in: master
9 files changed
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth1// 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 [adminSub] = await helper.arrange.createAccounts([100n], donor);81 const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);82 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);83 84 // cannot mint while not admin85 await expect(collectionEvm.methods.mint(owner).send({from: adminEth})).to.be.rejected;86 await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);87 88 // admin (sub and eth) can mint token:89 await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();90 await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();91 await collectionEvm.methods.mint(owner).send({from: adminEth});92 await helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}});9394 expect(await helper.collection.getLastTokenId(collectionId)).to.eq(2);95 });9697 itEth('cannot add invalid cross account admin', async ({helper}) => {98 const owner = await helper.eth.createAccountWithBalance(donor);99 const [admin] = await helper.arrange.createAccounts([100n, 100n], donor);100101 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');102 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);103104 const adminCross = {105 eth: helper.address.substrateToEth(admin.address),106 sub: admin.addressRaw,107 };108 await expect(collectionEvm.methods.addCollectionAdminCross(adminCross).send()).to.be.rejected;109 });110111 itEth('can verify owner with methods.isOwnerOrAdmin[Cross]', async ({helper, privateKey}) => {112 const owner = await helper.eth.createAccountWithBalance(donor);113 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');114115 const adminDeprecated = helper.eth.createAccount();116 const admin1Cross = helper.ethCrossAccount.fromKeyringPair(await privateKey('admin'));117 const admin2Cross = helper.ethCrossAccount.fromAddress(helper.address.substrateToEth((await privateKey('admin3')).address));118 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);119 120 // Soft-deprecated:121 expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.false;122 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.false;123 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.false;124125 await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();126 await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();127 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();128129 // Soft-deprecated: isOwnerOrAdmin returns true130 expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.true;131 // Expect isOwnerOrAdminCross return true132 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.true;133 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.true;134 });135136 // Soft-deprecated137 itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {138 const owner = await helper.eth.createAccountWithBalance(donor);139 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');140141 const admin = await helper.eth.createAccountWithBalance(donor);142 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);143 await collectionEvm.methods.addCollectionAdmin(admin).send();144145 const user = helper.eth.createAccount();146 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))147 .to.be.rejectedWith('NoPermission');148149 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);150 expect(adminList.length).to.be.eq(1);151 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())152 .to.be.eq(admin.toLocaleLowerCase());153 });154155 // Soft-deprecated156 itEth('(!negative tests!) Add admin by USER 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 notAdmin = await helper.eth.createAccountWithBalance(donor);161 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);162163 const user = helper.eth.createAccount();164 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))165 .to.be.rejectedWith('NoPermission');166167 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);168 expect(adminList.length).to.be.eq(0);169 });170171 itEth('(!negative tests!) Add [cross] admin by ADMIN is not allowed', async ({helper}) => {172 const owner = await helper.eth.createAccountWithBalance(donor);173 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');174175 const [admin, notAdmin] = await helper.arrange.createAccounts([10n, 10n], donor);176 const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);177 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);178 await collectionEvm.methods.addCollectionAdminCross(adminCross).send();179180 const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);181 await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))182 .to.be.rejectedWith('NoPermission');183184 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);185 expect(adminList.length).to.be.eq(1);186 187 const admin0Cross = helper.ethCrossAccount.fromKeyringPair(adminList[0]);188 expect(admin0Cross.eth.toLocaleLowerCase())189 .to.be.eq(adminCross.eth.toLocaleLowerCase());190 });191192 itEth('(!negative tests!) Add [cross] admin by USER is not allowed', async ({helper}) => {193 const owner = await helper.eth.createAccountWithBalance(donor);194 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');195196 const notAdmin0 = await helper.eth.createAccountWithBalance(donor);197 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);198 const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);199 const notAdmin1Cross = helper.ethCrossAccount.fromKeyringPair(notAdmin1);200 await expect(collectionEvm.methods.addCollectionAdminCross(notAdmin1Cross).call({from: notAdmin0}))201 .to.be.rejectedWith('NoPermission');202203 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);204 expect(adminList.length).to.be.eq(0);205 });206});207208describe('Remove collection admins', () => {209 let donor: IKeyringPair;210211 before(async function() {212 await usingEthPlaygrounds(async (_helper, privateKey) => {213 donor = await privateKey({filename: __filename});214 });215 });216217 // Soft-deprecated218 itEth('Remove admin by owner', async ({helper}) => {219 const owner = await helper.eth.createAccountWithBalance(donor);220 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');221222 const newAdmin = helper.eth.createAccount();223 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);224 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();225226 {227 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);228 expect(adminList.length).to.be.eq(1);229 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())230 .to.be.eq(newAdmin.toLocaleLowerCase());231 }232233 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();234 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);235 expect(adminList.length).to.be.eq(0);236 });237238 itEth('Remove [cross] admin by owner', async ({helper}) => {239 const owner = await helper.eth.createAccountWithBalance(donor);240 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');241242 const [newAdmin] = await helper.arrange.createAccounts([10n], donor);243 const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);244 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);245 await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();246 {247 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);248 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())249 .to.be.eq(newAdmin.address.toLocaleLowerCase());250 }251252 await collectionEvm.methods.removeCollectionAdminCross(newAdminCross).send();253 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);254 expect(adminList.length).to.be.eq(0);255 });256257 // Soft-deprecated258 itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {259 const owner = await helper.eth.createAccountWithBalance(donor);260 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');261262 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);263264 const admin0 = await helper.eth.createAccountWithBalance(donor);265 await collectionEvm.methods.addCollectionAdmin(admin0).send();266 const admin1 = await helper.eth.createAccountWithBalance(donor);267 await collectionEvm.methods.addCollectionAdmin(admin1).send();268269 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))270 .to.be.rejectedWith('NoPermission');271 {272 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);273 expect(adminList.length).to.be.eq(2);274 expect(adminList.toString().toLocaleLowerCase())275 .to.be.deep.contains(admin0.toLocaleLowerCase())276 .to.be.deep.contains(admin1.toLocaleLowerCase());277 }278 });279280 // Soft-deprecated281 itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {282 const owner = await helper.eth.createAccountWithBalance(donor);283 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');284285 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);286287 const admin = await helper.eth.createAccountWithBalance(donor);288 await collectionEvm.methods.addCollectionAdmin(admin).send();289 const notAdmin = helper.eth.createAccount();290291 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))292 .to.be.rejectedWith('NoPermission');293 {294 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);295 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())296 .to.be.eq(admin.toLocaleLowerCase());297 expect(adminList.length).to.be.eq(1);298 }299 });300301 itEth('(!negative tests!) Remove [cross] admin by ADMIN is not allowed', async ({helper}) => {302 const owner = await helper.eth.createAccountWithBalance(donor);303 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');304305 const [admin1] = await helper.arrange.createAccounts([10n], donor);306 const admin1Cross = helper.ethCrossAccount.fromKeyringPair(admin1);307 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);308 await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();309 310 const [admin2] = await helper.arrange.createAccounts([10n], donor);311 const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);312 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();313314 await expect(collectionEvm.methods.removeCollectionAdminCross(admin1Cross).call({from: admin2Cross.eth}))315 .to.be.rejectedWith('NoPermission');316317 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);318 expect(adminList.length).to.be.eq(2);319 expect(adminList.toString().toLocaleLowerCase())320 .to.be.deep.contains(admin1.address.toLocaleLowerCase())321 .to.be.deep.contains(admin2.address.toLocaleLowerCase());322 });323324 itEth('(!negative tests!) Remove [cross] admin by USER is not allowed', async ({helper}) => {325 const owner = await helper.eth.createAccountWithBalance(donor);326 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');327328 const [adminSub] = await helper.arrange.createAccounts([10n], donor);329 const adminSubCross = helper.ethCrossAccount.fromKeyringPair(adminSub);330 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);331 await collectionEvm.methods.addCollectionAdminCross(adminSubCross).send();332 const notAdminEth = await helper.eth.createAccountWithBalance(donor);333334 await expect(collectionEvm.methods.removeCollectionAdminCross(adminSubCross).call({from: notAdminEth}))335 .to.be.rejectedWith('NoPermission');336337 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);338 expect(adminList.length).to.be.eq(1);339 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())340 .to.be.eq(adminSub.address.toLocaleLowerCase());341 });342});343344// Soft-deprecated345describe('Change owner tests', () => {346 let donor: IKeyringPair;347348 before(async function() {349 await usingEthPlaygrounds(async (_helper, privateKey) => {350 donor = await privateKey({filename: __filename});351 });352 });353354 itEth('Change owner', async ({helper}) => {355 const owner = await helper.eth.createAccountWithBalance(donor);356 const newOwner = await helper.eth.createAccountWithBalance(donor);357 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');358 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);359360 await collectionEvm.methods.changeCollectionOwner(newOwner).send();361362 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;363 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;364 });365366 itEth('change owner call fee', async ({helper}) => {367 const owner = await helper.eth.createAccountWithBalance(donor);368 const newOwner = await helper.eth.createAccountWithBalance(donor);369 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');370 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);371 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());372 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));373 expect(cost > 0);374 });375376 itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {377 const owner = await helper.eth.createAccountWithBalance(donor);378 const newOwner = await helper.eth.createAccountWithBalance(donor);379 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');380 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);381382 await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;383 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;384 });385});386387describe('Change substrate owner tests', () => {388 let donor: IKeyringPair;389390 before(async function() {391 await usingEthPlaygrounds(async (_helper, privateKey) => {392 donor = await privateKey({filename: __filename});393 });394 });395396 itEth('Change owner [cross]', async ({helper}) => {397 const owner = await helper.eth.createAccountWithBalance(donor);398 const [newOwner] = await helper.arrange.createAccounts([10n], donor);399 const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);400 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');401 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);402403 expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;404405 await collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send();406407 expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.true;408 });409410 itEth.skip('change owner call fee', async ({helper}) => {411 const owner = await helper.eth.createAccountWithBalance(donor);412 const [newOwner] = await helper.arrange.createAccounts([10n], donor);413 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');414 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);415416 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());417 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));418 expect(cost > 0);419 });420421 itEth('(!negative tests!) call setOwner by non owner [cross]', async ({helper}) => {422 const owner = await helper.eth.createAccountWithBalance(donor);423 const otherReceiver = await helper.eth.createAccountWithBalance(donor);424 const [newOwner] = await helper.arrange.createAccounts([10n], donor);425 const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);426 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');427 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);428429 await expect(collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send({from: otherReceiver})).to.be.rejected;430 expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;431 });432});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 [adminSub] = await helper.arrange.createAccounts([100n], donor);81 const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);82 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);83 84 // cannot mint while not admin85 await expect(collectionEvm.methods.mint(owner).send({from: adminEth})).to.be.rejected;86 await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);87 88 // admin (sub and eth) can mint token:89 await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();90 await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();91 await collectionEvm.methods.mint(owner).send({from: adminEth});92 await helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}});9394 expect(await helper.collection.getLastTokenId(collectionId)).to.eq(2);95 });9697 itEth('cannot add invalid cross account admin', async ({helper}) => {98 const owner = await helper.eth.createAccountWithBalance(donor);99 const [admin] = await helper.arrange.createAccounts([100n, 100n], donor);100101 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');102 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);103104 const adminCross = {105 eth: helper.address.substrateToEth(admin.address),106 sub: admin.addressRaw,107 };108 await expect(collectionEvm.methods.addCollectionAdminCross(adminCross).send()).to.be.rejected;109 });110111 itEth('can verify owner with methods.isOwnerOrAdmin[Cross]', async ({helper, privateKey}) => {112 const owner = await helper.eth.createAccountWithBalance(donor);113 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');114115 const adminDeprecated = helper.eth.createAccount();116 const admin1Cross = helper.ethCrossAccount.fromKeyringPair(await privateKey('admin'));117 const admin2Cross = helper.ethCrossAccount.fromAddress(helper.address.substrateToEth((await privateKey('admin3')).address));118 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);119 120 // Soft-deprecated:121 expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.false;122 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.false;123 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.false;124125 await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();126 await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();127 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();128129 // Soft-deprecated: isOwnerOrAdmin returns true130 expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.true;131 // Expect isOwnerOrAdminCross return true132 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.true;133 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.true;134 });135136 // Soft-deprecated137 itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {138 const owner = await helper.eth.createAccountWithBalance(donor);139 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');140141 const admin = await helper.eth.createAccountWithBalance(donor);142 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);143 await collectionEvm.methods.addCollectionAdmin(admin).send();144145 const user = helper.eth.createAccount();146 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))147 .to.be.rejectedWith('NoPermission');148149 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);150 expect(adminList.length).to.be.eq(1);151 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())152 .to.be.eq(admin.toLocaleLowerCase());153 });154155 // Soft-deprecated156 itEth('(!negative tests!) Add admin by USER 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 notAdmin = await helper.eth.createAccountWithBalance(donor);161 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);162163 const user = helper.eth.createAccount();164 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))165 .to.be.rejectedWith('NoPermission');166167 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);168 expect(adminList.length).to.be.eq(0);169 });170171 itEth('(!negative tests!) Add [cross] admin by ADMIN is not allowed', async ({helper}) => {172 const owner = await helper.eth.createAccountWithBalance(donor);173 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');174175 const [admin, notAdmin] = await helper.arrange.createAccounts([10n, 10n], donor);176 const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);177 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);178 await collectionEvm.methods.addCollectionAdminCross(adminCross).send();179180 const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);181 await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))182 .to.be.rejectedWith('NoPermission');183184 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);185 expect(adminList.length).to.be.eq(1);186 187 const admin0Cross = helper.ethCrossAccount.fromKeyringPair(adminList[0]);188 expect(admin0Cross.eth.toLocaleLowerCase())189 .to.be.eq(adminCross.eth.toLocaleLowerCase());190 });191192 itEth('(!negative tests!) Add [cross] admin by USER is not allowed', async ({helper}) => {193 const owner = await helper.eth.createAccountWithBalance(donor);194 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');195196 const notAdmin0 = await helper.eth.createAccountWithBalance(donor);197 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);198 const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);199 const notAdmin1Cross = helper.ethCrossAccount.fromKeyringPair(notAdmin1);200 await expect(collectionEvm.methods.addCollectionAdminCross(notAdmin1Cross).call({from: notAdmin0}))201 .to.be.rejectedWith('NoPermission');202203 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);204 expect(adminList.length).to.be.eq(0);205 });206});207208describe('Remove collection admins', () => {209 let donor: IKeyringPair;210211 before(async function() {212 await usingEthPlaygrounds(async (_helper, privateKey) => {213 donor = await privateKey({filename: __filename});214 });215 });216217 // Soft-deprecated218 itEth('Remove admin by owner', async ({helper}) => {219 const owner = await helper.eth.createAccountWithBalance(donor);220 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');221222 const newAdmin = helper.eth.createAccount();223 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);224 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();225226 {227 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);228 expect(adminList.length).to.be.eq(1);229 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())230 .to.be.eq(newAdmin.toLocaleLowerCase());231 }232233 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();234 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);235 expect(adminList.length).to.be.eq(0);236 });237238 itEth('Remove [cross] admin by owner', async ({helper}) => {239 const owner = await helper.eth.createAccountWithBalance(donor);240 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');241242 const [adminSub] = await helper.arrange.createAccounts([10n], donor);243 const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();244 const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);245 const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);246247 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);248 await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();249 await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();250251 {252 const adminList = await helper.collection.getAdmins(collectionId);253 expect(adminList).to.deep.include({Substrate: adminSub.address});254 expect(adminList).to.deep.include({Ethereum: adminEth});255 }256257 await collectionEvm.methods.removeCollectionAdminCross(adminCrossSub).send();258 await collectionEvm.methods.removeCollectionAdminCross(adminCrossEth).send();259 const adminList = await helper.collection.getAdmins(collectionId);260 expect(adminList.length).to.be.eq(0);261262 // Non admin cannot mint:263 await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Substrate: adminSub.address}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);264 await expect(collectionEvm.methods.mint(adminEth).send({from: adminEth})).to.be.rejected;265 });266267 // Soft-deprecated268 itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {269 const owner = await helper.eth.createAccountWithBalance(donor);270 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');271272 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);273274 const admin0 = await helper.eth.createAccountWithBalance(donor);275 await collectionEvm.methods.addCollectionAdmin(admin0).send();276 const admin1 = await helper.eth.createAccountWithBalance(donor);277 await collectionEvm.methods.addCollectionAdmin(admin1).send();278279 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))280 .to.be.rejectedWith('NoPermission');281 {282 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);283 expect(adminList.length).to.be.eq(2);284 expect(adminList.toString().toLocaleLowerCase())285 .to.be.deep.contains(admin0.toLocaleLowerCase())286 .to.be.deep.contains(admin1.toLocaleLowerCase());287 }288 });289290 // Soft-deprecated291 itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {292 const owner = await helper.eth.createAccountWithBalance(donor);293 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');294295 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);296297 const admin = await helper.eth.createAccountWithBalance(donor);298 await collectionEvm.methods.addCollectionAdmin(admin).send();299 const notAdmin = helper.eth.createAccount();300301 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))302 .to.be.rejectedWith('NoPermission');303 {304 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);305 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())306 .to.be.eq(admin.toLocaleLowerCase());307 expect(adminList.length).to.be.eq(1);308 }309 });310311 itEth('(!negative tests!) Remove [cross] admin by ADMIN is not allowed', async ({helper}) => {312 const owner = await helper.eth.createAccountWithBalance(donor);313 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');314315 const [admin1] = await helper.arrange.createAccounts([10n], donor);316 const admin1Cross = helper.ethCrossAccount.fromKeyringPair(admin1);317 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);318 await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();319 320 const [admin2] = await helper.arrange.createAccounts([10n], donor);321 const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);322 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();323324 await expect(collectionEvm.methods.removeCollectionAdminCross(admin1Cross).call({from: admin2Cross.eth}))325 .to.be.rejectedWith('NoPermission');326327 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);328 expect(adminList.length).to.be.eq(2);329 expect(adminList.toString().toLocaleLowerCase())330 .to.be.deep.contains(admin1.address.toLocaleLowerCase())331 .to.be.deep.contains(admin2.address.toLocaleLowerCase());332 });333334 itEth('(!negative tests!) Remove [cross] admin by USER is not allowed', async ({helper}) => {335 const owner = await helper.eth.createAccountWithBalance(donor);336 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');337338 const [adminSub] = await helper.arrange.createAccounts([10n], donor);339 const adminSubCross = helper.ethCrossAccount.fromKeyringPair(adminSub);340 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);341 await collectionEvm.methods.addCollectionAdminCross(adminSubCross).send();342 const notAdminEth = await helper.eth.createAccountWithBalance(donor);343344 await expect(collectionEvm.methods.removeCollectionAdminCross(adminSubCross).call({from: notAdminEth}))345 .to.be.rejectedWith('NoPermission');346347 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);348 expect(adminList.length).to.be.eq(1);349 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())350 .to.be.eq(adminSub.address.toLocaleLowerCase());351 });352});353354// Soft-deprecated355describe('Change owner tests', () => {356 let donor: IKeyringPair;357358 before(async function() {359 await usingEthPlaygrounds(async (_helper, privateKey) => {360 donor = await privateKey({filename: __filename});361 });362 });363364 itEth('Change owner', async ({helper}) => {365 const owner = await helper.eth.createAccountWithBalance(donor);366 const newOwner = await helper.eth.createAccountWithBalance(donor);367 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');368 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);369370 await collectionEvm.methods.changeCollectionOwner(newOwner).send();371372 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;373 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;374 });375376 itEth('change owner call fee', async ({helper}) => {377 const owner = await helper.eth.createAccountWithBalance(donor);378 const newOwner = await helper.eth.createAccountWithBalance(donor);379 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');380 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);381 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());382 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));383 expect(cost > 0);384 });385386 itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {387 const owner = await helper.eth.createAccountWithBalance(donor);388 const newOwner = await helper.eth.createAccountWithBalance(donor);389 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');390 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);391392 await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;393 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;394 });395});396397describe('Change substrate owner tests', () => {398 let donor: IKeyringPair;399400 before(async function() {401 await usingEthPlaygrounds(async (_helper, privateKey) => {402 donor = await privateKey({filename: __filename});403 });404 });405406 itEth('Change owner [cross]', async ({helper}) => {407 const owner = await helper.eth.createAccountWithBalance(donor);408 const ownerEth = await helper.eth.createAccountWithBalance(donor);409 const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);410 const [ownerSub] = await helper.arrange.createAccounts([10n], donor);411 const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);412413 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');414 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);415416 expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.false;417418 // Can set ethereum owner:419 await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossEth).send({from: owner});420 expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossEth).call()).to.be.true;421 expect(await helper.collection.getData(collectionId))422 .to.have.property('normalizedOwner').that.is.eq(helper.address.ethToSubstrate(ownerEth));423 424 // Can set Substrate owner:425 await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossSub).send({from: ownerEth});426 expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.true;427 expect(await helper.collection.getData(collectionId))428 .to.have.property('normalizedOwner').that.is.eq(helper.address.normalizeSubstrate(ownerSub.address));429 });430431 itEth.skip('change owner call fee', async ({helper}) => {432 const owner = await helper.eth.createAccountWithBalance(donor);433 const [newOwner] = await helper.arrange.createAccounts([10n], donor);434 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');435 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);436437 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());438 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));439 expect(cost > 0);440 });441442 itEth('(!negative tests!) call setOwner by non owner [cross]', async ({helper}) => {443 const owner = await helper.eth.createAccountWithBalance(donor);444 const otherReceiver = await helper.eth.createAccountWithBalance(donor);445 const [newOwner] = await helper.arrange.createAccounts([10n], donor);446 const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);447 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');448 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);449450 await expect(collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send({from: otherReceiver})).to.be.rejected;451 expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;452 });453});tests/src/eth/createFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createFTCollection.test.ts
+++ b/tests/src/eth/createFTCollection.test.ts
@@ -144,7 +144,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Exister', DECIMALS, 'absolutely anything', 'WIWT');
+ const {collectionAddress, collectionId} = await helper.eth.createFungibleCollection(owner, 'Exister', DECIMALS, 'absolutely anything', 'WIWT');
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collectionHelper.methods
@@ -166,6 +166,7 @@
expect(await collectionHelper.methods
.isCollectionExist(collectionAddress)
.call()).to.be.false;
+ expect(await helper.collection.getData(collectionId)).to.be.null;
});
});
@@ -214,12 +215,15 @@
}
});
- itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
+ itEth('(!negative test!) cannot create collection if value !== 2', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- await expect(collectionHelper.methods
- .createFTCollection('Peasantry', DECIMALS, 'absolutely anything', 'TWIW')
- .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
+ const expects = [0n, 1n, 30n].map(async value => {
+ await expect(collectionHelper.methods
+ .createFTCollection('Peasantry', DECIMALS, 'absolutely anything', 'TWIW')
+ .call({value: Number(value * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
+ });
+ await Promise.all(expects);
});
// Soft-deprecated
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -308,7 +308,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
+ const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
@@ -331,5 +331,6 @@
expect(await collectionHelper.methods
.isCollectionExist(collectionAddress)
.call()).to.be.false;
+ expect(await helper.collection.getData(collectionId)).to.be.null;
});
});
\ No newline at end of file
tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -340,7 +340,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
+ const {collectionAddress, collectionId} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
@@ -349,6 +349,7 @@
expect(await collectionHelper.methods
.isCollectionExist(collectionAddress)
- .call()).to.be.false;
+ .call()).to.be.false;
+ expect(await helper.collection.getData(collectionId)).to.be.null;
});
});
tests/src/eth/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/destroyCollection.test.ts
+++ b/tests/src/eth/destroyCollection.test.ts
@@ -15,62 +15,48 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import {Pallets, requirePalletsOrSkip} from '../util';
+import {Pallets} from '../util';
import {expect, itEth, usingEthPlaygrounds} from './util';
-
-describe('Destroy Collection from EVM', () => {
+describe('Destroy Collection from EVM', function() {
let donor: IKeyringPair;
+ const testCases = [
+ {method: 'createRFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.ReFungible]},
+ {method: 'createNFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.NFT]},
+ {method: 'createFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF', 18], requiredPallets: [Pallets.Fungible]},
+ ];
before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible, Pallets.NFT]);
+ await usingEthPlaygrounds(async (_, privateKey) => {
donor = await privateKey({filename: __filename});
});
});
-
- itEth('(!negative test!) RFT', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const signer = await helper.eth.createAccountWithBalance(donor);
-
- const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);
-
- const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
- const collectionHelper = helper.ethNativeContract.collectionHelpers(signer);
-
- await expect(collectionHelper.methods
- .destroyCollection(collectionAddress)
- .send({from: signer})).to.be.rejected;
-
- await expect(collectionHelper.methods
- .destroyCollection(unexistedCollection)
- .send({from: signer})).to.be.rejected;
-
- expect(await collectionHelper.methods
- .isCollectionExist(unexistedCollection)
- .call()).to.be.false;
- });
-
- itEth('(!negative test!) NFT', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const signer = await helper.eth.createAccountWithBalance(donor);
-
- const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);
-
- const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
- const collectionHelper = helper.ethNativeContract.collectionHelpers(signer);
-
- await expect(collectionHelper.methods
- .destroyCollection(collectionAddress)
- .send({from: signer})).to.be.rejected;
-
- await expect(collectionHelper.methods
- .destroyCollection(unexistedCollection)
- .send({from: signer})).to.be.rejected;
-
- expect(await collectionHelper.methods
- .isCollectionExist(unexistedCollection)
- .call()).to.be.false;
- });
+ testCases.map((testCase) =>
+ itEth.ifWithPallets(`Cannot burn non-owned or non-existing collection ${testCase.method}`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const signer = await helper.eth.createAccountWithBalance(donor);
+
+ const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);
+
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(signer);
+ const {collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, ...testCase.params as [string, string, string, number?]);
+
+ // cannot burn collec
+ await expect(collectionHelpers.methods
+ .destroyCollection(collectionAddress)
+ .send({from: signer})).to.be.rejected;
+
+ await expect(collectionHelpers.methods
+ .destroyCollection(unexistedCollection)
+ .send({from: signer})).to.be.rejected;
+
+ expect(await collectionHelpers.methods
+ .isCollectionExist(unexistedCollection)
+ .call()).to.be.false;
+
+ expect(await collectionHelpers.methods
+ .isCollectionExist(collectionAddress)
+ .call()).to.be.true;
+ }));
});
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -232,56 +232,64 @@
});
itEth('Can perform transferCross()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = await helper.eth.createAccountWithBalance(donor);
- const to = helper.ethCrossAccount.fromAddress(receiver);
- const toSubstrate = helper.ethCrossAccount.fromKeyringPair(donor);
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(donor);
const collection = await helper.ft.mintCollection(alice);
- await collection.mint(alice, 200n, {Ethereum: owner});
+ await collection.mint(alice, 200n, {Ethereum: sender});
const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);
{
- const result = await contract.methods.transferCross(to, 50).send({from: owner});
-
+ // Can transferCross to ethereum address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossEth, 50).send({from: sender});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(owner);
- expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.from).to.be.equal(sender);
+ expect(event.returnValues.to).to.be.equal(receiverEth);
expect(event.returnValues.value).to.be.equal('50');
- }
-
- {
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(150);
- }
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(50);
+ // Sender's balance decreased:
+ const ownerBalance = await collectionEvm.methods.balanceOf(sender).call();
+ expect(+ownerBalance).to.equal(150);
+ // Receiver's balance increased:
+ const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+receiverBalance).to.equal(50);
}
{
- const result = await contract.methods.transferCross(toSubstrate, 50).send({from: owner});
-
+ // Can transferCross to substrate address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossSub, 50).send({from: sender});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(owner);
+ expect(event.returnValues.from).to.be.equal(sender);
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));
expect(event.returnValues.value).to.be.equal('50');
+ // Sender's balance decreased:
+ const senderBalance = await collection.getBalance({Ethereum: sender});
+ expect(senderBalance).to.equal(100n);
+ // Receiver's balance increased:
+ const balance = await collection.getBalance({Substrate: donor.address});
+ expect(balance).to.equal(50n);
}
+ });
+
+ itEth('Cannot transferCross() more than have', async ({helper}) => {
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const BALANCE = 200n;
+ const BALANCE_TO_TRANSFER = BALANCE + 100n;
- {
- const balance = await collection.getBalance({Ethereum: owner});
- expect(balance).to.equal(100n);
- }
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, BALANCE, {Ethereum: sender});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);
- {
- const balance = await collection.getBalance({Substrate: donor.address});
- expect(balance).to.equal(50n);
- }
-
+ await expect(collectionEvm.methods.transferCross(receiverCrossEth, BALANCE_TO_TRANSFER).send({from: sender})).to.be.rejected;
});
itEth('Can perform transfer()', async ({helper}) => {
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -251,31 +251,48 @@
itEth('Can perform burnFromCross()', async ({helper}) => {
const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ const ownerSub = bob;
+ const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);
+ const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);
+ const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);
- const owner = bob;
- const spender = await helper.eth.createAccountWithBalance(donor, 100n);
+ const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);
+ const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);
- const token = await collection.mintToken(minter, {Substrate: owner.address});
+ const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});
+ const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft');
- const address = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(address, 'nft');
+ // Approve tokens from substrate and ethereum:
+ await token1.approve(ownerSub, {Ethereum: burnerEth});
+ await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});
- {
- await token.approve(owner, {Ethereum: spender});
- const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);
- const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});
- const events = result.events.Transfer;
+ // can burnFromCross:
+ const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});
+ const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});
+ const events1 = result1.events.Transfer;
+ const events2 = result2.events.Transfer;
- expect(events).to.be.like({
- address,
+ // Check events for burnFromCross (substrate and ethereum):
+ [
+ [events1, token1, helper.address.substrateToEth(ownerSub.address)],
+ [events2, token2, ownerEth],
+ ].map(burnData => {
+ expect(burnData[0]).to.be.like({
+ address: collectionAddress,
event: 'Transfer',
returnValues: {
- from: helper.address.substrateToEth(owner.address),
+ from: burnData[2],
to: '0x0000000000000000000000000000000000000000',
- tokenId: token.tokenId.toString(),
+ tokenId: burnData[1].tokenId.toString(),
},
});
- }
+ });
+
+ expect(await token1.doesExist()).to.be.false;
+ expect(await token2.doesExist()).to.be.false;
});
itEth('Can perform approveCross()', async ({helper}) => {
@@ -326,6 +343,34 @@
expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});
});
+ itEth('Can reaffirm approved address', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor, 100n);
+ const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);
+ const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);
+ const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);
+ const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);
+ const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ const token1 = await collection.mintToken(minter, {Ethereum: owner});
+ const token2 = await collection.mintToken(minter, {Ethereum: owner});
+ const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');
+
+ // Can approve and reaffirm approved address:
+ await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});
+ await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});
+
+ // receiver1 cannot transferFrom:
+ await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;
+ // receiver2 can transferFrom:
+ await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});
+
+ // can set approved address to self address to remove approval:
+ await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});
+ await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});
+
+ // receiver1 cannot transfer token anymore:
+ await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;
+ });
+
itEth('Can perform transferFrom()', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const spender = await helper.eth.createAccountWithBalance(donor);
@@ -426,54 +471,50 @@
itEth('Can perform transferCross()', async ({helper}) => {
const collection = await helper.nft.mintCollection(minter, {});
const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = await helper.eth.createAccountWithBalance(donor);
- const to = helper.ethCrossAccount.fromAddress(receiver);
- const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});
const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
{
- const result = await contract.methods.transferCross(to, tokenId).send({from: owner});
-
+ // Can transferCross to ethereum address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal(owner);
- expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.to).to.be.equal(receiverEth);
expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
- }
-
- {
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(0);
+
+ // owner has balance = 0:
+ const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();
+ expect(+ownerBalance).to.equal(0);
+ // receiver owns token:
+ const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+receiverBalance).to.equal(1);
+ expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});
}
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(1);
- }
{
- const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});
-
-
+ // Can transferCross to substrate address:
+ const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});
+ // Check events:
const event = substrateResult.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(receiver);
+ expect(event.returnValues.from).to.be.equal(receiverEth);
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));
expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
- }
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(0);
- }
-
- {
- const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
- expect(balance).to.be.contain(tokenId);
+
+ // owner has balance = 0:
+ const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+ownerBalance).to.equal(0);
+ // receiver owns token:
+ const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
+ expect(receiverBalance).to.contain(tokenId);
}
});
});
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -363,56 +363,71 @@
});
itEth('Can perform transferCross()', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiver = await helper.eth.createAccountWithBalance(donor);
- const to = helper.ethCrossAccount.fromAddress(receiver);
- const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
+
const collection = await helper.rft.mintCollection(minter, {});
const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);
- const {tokenId} = await collection.mintToken(minter, 1n, {Ethereum: caller});
+ const token = await collection.mintToken(minter, 50n, {Ethereum: sender});
{
- const result = await contract.methods.transferCross(to, tokenId).send({from: caller});
-
+ // Can transferCross to ethereum address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossEth, token.tokenId).send({from: sender});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal(caller);
- expect(event.returnValues.to).to.equal(receiver);
- expect(event.returnValues.tokenId).to.equal(tokenId.toString());
- }
-
- {
- const balance = await contract.methods.balanceOf(caller).call();
- expect(+balance).to.equal(0);
- }
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(1);
+ expect(event.returnValues.from).to.equal(sender);
+ expect(event.returnValues.to).to.equal(receiverEth);
+ expect(event.returnValues.tokenId).to.equal(token.tokenId.toString());
+ // Sender's balance decreased:
+ const senderBalance = await collectionEvm.methods.balanceOf(sender).call();
+ expect(+senderBalance).to.equal(0);
+ expect(await token.getBalance({Ethereum: sender})).to.eq(0n);
+ // Receiver's balance increased:
+ const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+receiverBalance).to.equal(1);
+ expect(await token.getBalance({Ethereum: receiverEth})).to.eq(50n);
}
{
- const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});
-
-
+ // Can transferCross to substrate address:
+ const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, token.tokenId).send({from: receiverEth});
+ // Check events:
const event = substrateResult.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(receiver);
+ expect(event.returnValues.from).to.be.equal(receiverEth);
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));
- expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
+ expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);
+ // Sender's balance decreased:
+ const senderBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+senderBalance).to.equal(0);
+ expect(await token.getBalance({Ethereum: receiverEth})).to.eq(0n);
+ // Receiver's balance increased:
+ const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
+ expect(receiverBalance).to.contain(token.tokenId);
+ expect(await token.getBalance({Substrate: minter.address})).to.eq(50n);
}
+ });
+
+ itEth.skip('Cannot transferCross with invalid params', async ({helper}) => {
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const tokenOwner = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(0);
- }
+ const collection = await helper.rft.mintCollection(minter, {});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);
- {
- const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
- expect(balance).to.be.contain(tokenId);
- }
+ await collection.mintToken(minter, 50n, {Ethereum: sender});
+ const notSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});
+ // Cannot transferCross someone else's token:
+ await expect(collectionEvm.methods.transferCross(receiverCrossSub, notSendersToken.tokenId).send({from: sender})).to.be.rejected;
+ // FIXME: (transaction successful): Cannot transfer token if it does not exist:
+ await expect(collectionEvm.methods.transferCross(receiverCrossSub, 999999).send({from: sender})).to.be.rejected;
});
itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -186,11 +186,12 @@
return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);
}
- async createCollecion(functionName: string, signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
+ async createCollecion(functionName: 'createNFTCollection' | 'createRFTCollection' | 'createFTCollection', signer: string, name: string, description: string, tokenPrefix: string, decimals?: number): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
- const result = await collectionHelper.methods[functionName](name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
+ const functionParams = functionName === 'createFTCollection' ? [name, decimals, description, tokenPrefix] : [name, description, tokenPrefix];
+ const result = await collectionHelper.methods[functionName](...functionParams).send({value: Number(collectionCreationPrice)});
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
@@ -217,17 +218,8 @@
return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);
}
- async createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {
- const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
- const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
-
- const result = await collectionHelper.methods.createFTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
- const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
- const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
-
- const events = this.helper.eth.normalizeEvents(result.events);
-
- return {collectionId, collectionAddress, events};
+ createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {
+ return this.createCollecion('createFTCollection', signer, name, description, tokenPrefix, decimals);
}
async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {