difftreelog
Merge pull request #744 from UniqueNetwork/tests/eth-helpers
in: master
Tests/eth helpers
5 files changed
tests/src/eth/allowlist.test.tsdiffbeforeafterboth--- a/tests/src/eth/allowlist.test.ts
+++ b/tests/src/eth/allowlist.test.ts
@@ -92,21 +92,47 @@
});
itEth('Collection allowlist can be added and removed by [cross] address', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const user = donor;
+ const owner = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();
+ const [userSub] = await helper.arrange.createAccounts([10n], donor);
+ const userEth = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
- const userCross = helper.ethCrossAccount.fromKeyringPair(user);
+ const userCrossSub = helper.ethCrossAccount.fromKeyringPair(userSub);
+ const userCrossEth = helper.ethCrossAccount.fromAddress(userEth);
+ const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);
+
+ // Can addToCollectionAllowListCross:
+ expect(await helper.collection.allowed(collectionId, {Substrate: userSub.address})).to.be.false;
+ await collectionEvm.methods.addToCollectionAllowListCross(userCrossSub).send({from: owner});
+ await collectionEvm.methods.addToCollectionAllowListCross(userCrossEth).send({from: owner});
+ await collectionEvm.methods.addToCollectionAllowListCross(ownerCrossEth).send({from: owner});
+ expect(await helper.collection.allowed(collectionId, {Substrate: userSub.address})).to.be.true;
+ expect(await helper.collection.allowed(collectionId, {Ethereum: userEth})).to.be.true;
+ expect(await collectionEvm.methods.allowlistedCross(userCrossSub).call({from: owner})).to.be.true;
+ expect(await collectionEvm.methods.allowlistedCross(userCrossEth).call({from: owner})).to.be.true;
+
+ await collectionEvm.methods.mint(userEth).send(); // token #1
+ await collectionEvm.methods.mint(userEth).send(); // token #2
+ await collectionEvm.methods.setCollectionAccess(1).send();
- expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
- await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});
- expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;
- expect(await collectionEvm.methods.allowlistedCross(userCross).call({from: owner})).to.be.true;
+ // allowlisted account can transfer and transferCross:
+ await collectionEvm.methods.transfer(owner, 1).send({from: userEth});
+ await collectionEvm.methods.transferCross(userCrossSub, 2).send({from: userEth});
+ expect(await helper.nft.getTokenOwner(collectionId, 1)).to.deep.eq({Ethereum: owner});
+ expect(await helper.nft.getTokenOwner(collectionId, 2)).to.deep.eq({Substrate: userSub.address});
- await collectionEvm.methods.removeFromCollectionAllowListCross(userCross).send({from: owner});
- expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
- expect(await collectionEvm.methods.allowlistedCross(userCross).call({from: owner})).to.be.false;
+ // can removeFromCollectionAllowListCross:
+ await collectionEvm.methods.removeFromCollectionAllowListCross(userCrossSub).send({from: owner});
+ await collectionEvm.methods.removeFromCollectionAllowListCross(userCrossEth).send({from: owner});
+ expect(await helper.collection.allowed(collectionId, {Substrate: userSub.address})).to.be.false;
+ expect(await helper.collection.allowed(collectionId, {Ethereum: userEth})).to.be.false;
+ expect(await collectionEvm.methods.allowlistedCross(userCrossSub).call({from: owner})).to.be.false;
+ expect(await collectionEvm.methods.allowlistedCross(userCrossEth).call({from: owner})).to.be.false;
+
+ // cannot transfer anymore
+ await collectionEvm.methods.mint(userEth).send();
+ await expect(collectionEvm.methods.transfer(owner, 2).send({from: userEth})).to.be.rejectedWith(/Transaction has been reverted/);
});
// Soft-deprecated
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 // Soft-deprecated43 itEth('Add admin by owner', async ({helper}) => {44 const owner = await helper.eth.createAccountWithBalance(donor);45 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');46 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);4748 const newAdmin = helper.eth.createAccount();4950 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();51 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);52 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())53 .to.be.eq(newAdmin.toLocaleLowerCase());54 });5556 itEth('Add cross account admin by owner', async ({helper, privateKey}) => {57 const owner = await helper.eth.createAccountWithBalance(donor);58 59 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');60 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);61 62 const newAdmin = await privateKey('//Bob');63 const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);64 await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();6566 const adminList = await helper.collection.getAdmins(collectionId);67 expect(adminList).to.be.like([{Substrate: newAdmin.address}]);68 });6970 itEth('Check adminlist', async ({helper, privateKey}) => {71 const owner = await helper.eth.createAccountWithBalance(donor);72 73 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');74 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);7576 const admin1 = helper.eth.createAccount();77 const admin2 = await privateKey('admin');78 const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);79 80 // Soft-deprecated81 await collectionEvm.methods.addCollectionAdmin(admin1).send();82 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();8384 const adminListRpc = await helper.collection.getAdmins(collectionId);85 let adminListEth = await collectionEvm.methods.collectionAdmins().call();86 adminListEth = adminListEth.map((element: IEthCrossAccountId) => {87 return helper.address.convertCrossAccountFromEthCrossAcoount(element);88 });89 expect(adminListRpc).to.be.like(adminListEth);90 });9192 // Soft-deprecated93 itEth('Verify owner or admin', async ({helper}) => {94 const owner = await helper.eth.createAccountWithBalance(donor);95 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');9697 const newAdmin = helper.eth.createAccount();98 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);99 100 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;101 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();102 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;103 });104105 itEth('Verify owner or admin cross', async ({helper, privateKey}) => {106 const owner = await helper.eth.createAccountWithBalance(donor);107 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');108109 const newAdmin = await privateKey('admin');110 const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);111 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);112 113 expect(await collectionEvm.methods.isOwnerOrAdminCross(newAdminCross).call()).to.be.false;114 await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();115 expect(await collectionEvm.methods.isOwnerOrAdminCross(newAdminCross).call()).to.be.true;116 });117118 // Soft-deprecated119 itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {120 const owner = await helper.eth.createAccountWithBalance(donor);121 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');122123 const admin = await helper.eth.createAccountWithBalance(donor);124 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);125 await collectionEvm.methods.addCollectionAdmin(admin).send();126127 const user = helper.eth.createAccount();128 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))129 .to.be.rejectedWith('NoPermission');130131 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);132 expect(adminList.length).to.be.eq(1);133 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())134 .to.be.eq(admin.toLocaleLowerCase());135 });136137 // Soft-deprecated138 itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {139 const owner = await helper.eth.createAccountWithBalance(donor);140 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');141142 const notAdmin = await helper.eth.createAccountWithBalance(donor);143 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);144145 const user = helper.eth.createAccount();146 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))147 .to.be.rejectedWith('NoPermission');148149 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);150 expect(adminList.length).to.be.eq(0);151 });152153 itEth('(!negative tests!) Add [cross] admin by ADMIN is not allowed', async ({helper}) => {154 const owner = await helper.eth.createAccountWithBalance(donor);155 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');156157 const [admin] = await helper.arrange.createAccounts([10n], donor);158 const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);159 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);160 await collectionEvm.methods.addCollectionAdminCross(adminCross).send();161162 const [notAdmin] = await helper.arrange.createAccounts([10n], donor);163 const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);164 await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))165 .to.be.rejectedWith('NoPermission');166167 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);168 expect(adminList.length).to.be.eq(1);169 170 const admin0Cross = helper.ethCrossAccount.fromKeyringPair(adminList[0]);171 expect(admin0Cross.eth.toLocaleLowerCase())172 .to.be.eq(adminCross.eth.toLocaleLowerCase());173 });174175 itEth('(!negative tests!) Add [cross] admin by USER is not allowed', async ({helper}) => {176 const owner = await helper.eth.createAccountWithBalance(donor);177 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');178179 const notAdmin0 = await helper.eth.createAccountWithBalance(donor);180 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);181 const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);182 const notAdmin1Cross = helper.ethCrossAccount.fromKeyringPair(notAdmin1);183 await expect(collectionEvm.methods.addCollectionAdminCross(notAdmin1Cross).call({from: notAdmin0}))184 .to.be.rejectedWith('NoPermission');185186 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);187 expect(adminList.length).to.be.eq(0);188 });189});190191describe('Remove collection admins', () => {192 let donor: IKeyringPair;193194 before(async function() {195 await usingEthPlaygrounds(async (_helper, privateKey) => {196 donor = await privateKey({filename: __filename});197 });198 });199200 // Soft-deprecated201 itEth('Remove admin by owner', async ({helper}) => {202 const owner = await helper.eth.createAccountWithBalance(donor);203 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');204205 const newAdmin = helper.eth.createAccount();206 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);207 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();208209 {210 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);211 expect(adminList.length).to.be.eq(1);212 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())213 .to.be.eq(newAdmin.toLocaleLowerCase());214 }215216 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();217 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);218 expect(adminList.length).to.be.eq(0);219 });220221 itEth('Remove [cross] admin by owner', async ({helper}) => {222 const owner = await helper.eth.createAccountWithBalance(donor);223 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');224225 const [newAdmin] = await helper.arrange.createAccounts([10n], donor);226 const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);227 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);228 await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();229 {230 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);231 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())232 .to.be.eq(newAdmin.address.toLocaleLowerCase());233 }234235 await collectionEvm.methods.removeCollectionAdminCross(newAdminCross).send();236 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);237 expect(adminList.length).to.be.eq(0);238 });239240 // Soft-deprecated241 itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {242 const owner = await helper.eth.createAccountWithBalance(donor);243 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');244245 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);246247 const admin0 = await helper.eth.createAccountWithBalance(donor);248 await collectionEvm.methods.addCollectionAdmin(admin0).send();249 const admin1 = await helper.eth.createAccountWithBalance(donor);250 await collectionEvm.methods.addCollectionAdmin(admin1).send();251252 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))253 .to.be.rejectedWith('NoPermission');254 {255 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);256 expect(adminList.length).to.be.eq(2);257 expect(adminList.toString().toLocaleLowerCase())258 .to.be.deep.contains(admin0.toLocaleLowerCase())259 .to.be.deep.contains(admin1.toLocaleLowerCase());260 }261 });262263 // Soft-deprecated264 itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {265 const owner = await helper.eth.createAccountWithBalance(donor);266 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');267268 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);269270 const admin = await helper.eth.createAccountWithBalance(donor);271 await collectionEvm.methods.addCollectionAdmin(admin).send();272 const notAdmin = helper.eth.createAccount();273274 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))275 .to.be.rejectedWith('NoPermission');276 {277 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);278 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())279 .to.be.eq(admin.toLocaleLowerCase());280 expect(adminList.length).to.be.eq(1);281 }282 });283284 itEth('(!negative tests!) Remove [cross] admin by ADMIN is not allowed', async ({helper}) => {285 const owner = await helper.eth.createAccountWithBalance(donor);286 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');287288 const [admin1] = await helper.arrange.createAccounts([10n], donor);289 const admin1Cross = helper.ethCrossAccount.fromKeyringPair(admin1);290 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);291 await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();292 293 const [admin2] = await helper.arrange.createAccounts([10n], donor);294 const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);295 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();296297 await expect(collectionEvm.methods.removeCollectionAdminCross(admin1Cross).call({from: admin2Cross.eth}))298 .to.be.rejectedWith('NoPermission');299300 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);301 expect(adminList.length).to.be.eq(2);302 expect(adminList.toString().toLocaleLowerCase())303 .to.be.deep.contains(admin1.address.toLocaleLowerCase())304 .to.be.deep.contains(admin2.address.toLocaleLowerCase());305 });306307 itEth('(!negative tests!) Remove [cross] admin by USER is not allowed', async ({helper}) => {308 const owner = await helper.eth.createAccountWithBalance(donor);309 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');310311 const [adminSub] = await helper.arrange.createAccounts([10n], donor);312 const adminSubCross = helper.ethCrossAccount.fromKeyringPair(adminSub);313 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);314 await collectionEvm.methods.addCollectionAdminCross(adminSubCross).send();315 const notAdminEth = await helper.eth.createAccountWithBalance(donor);316317 await expect(collectionEvm.methods.removeCollectionAdminCross(adminSubCross).call({from: notAdminEth}))318 .to.be.rejectedWith('NoPermission');319320 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);321 expect(adminList.length).to.be.eq(1);322 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())323 .to.be.eq(adminSub.address.toLocaleLowerCase());324 });325});326327// Soft-deprecated328describe('Change owner tests', () => {329 let donor: IKeyringPair;330331 before(async function() {332 await usingEthPlaygrounds(async (_helper, privateKey) => {333 donor = await privateKey({filename: __filename});334 });335 });336337 itEth('Change owner', async ({helper}) => {338 const owner = await helper.eth.createAccountWithBalance(donor);339 const newOwner = await helper.eth.createAccountWithBalance(donor);340 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');341 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);342343 await collectionEvm.methods.changeCollectionOwner(newOwner).send();344345 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;346 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;347 });348349 itEth('change owner call fee', 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);354 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());355 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));356 expect(cost > 0);357 });358359 itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {360 const owner = await helper.eth.createAccountWithBalance(donor);361 const newOwner = await helper.eth.createAccountWithBalance(donor);362 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');363 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);364365 await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;366 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;367 });368});369370describe('Change substrate owner tests', () => {371 let donor: IKeyringPair;372373 before(async function() {374 await usingEthPlaygrounds(async (_helper, privateKey) => {375 donor = await privateKey({filename: __filename});376 });377 });378379 itEth('Change owner [cross]', async ({helper}) => {380 const owner = await helper.eth.createAccountWithBalance(donor);381 const [newOwner] = await helper.arrange.createAccounts([10n], donor);382 const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);383 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');384 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);385386 expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;387388 await collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send();389390 expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.true;391 });392393 itEth.skip('change owner call fee', async ({helper}) => {394 const owner = await helper.eth.createAccountWithBalance(donor);395 const [newOwner] = await helper.arrange.createAccounts([10n], donor);396 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');397 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);398399 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());400 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));401 expect(cost > 0);402 });403404 itEth('(!negative tests!) call setOwner by non owner [cross]', async ({helper}) => {405 const owner = await helper.eth.createAccountWithBalance(donor);406 const otherReceiver = await helper.eth.createAccountWithBalance(donor);407 const [newOwner] = await helper.arrange.createAccounts([10n], donor);408 const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);409 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');410 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);411412 await expect(collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send({from: otherReceiver})).to.be.rejected;413 expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;414 });415});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 [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});tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -314,7 +314,7 @@
}
});
- itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {
+ itEth('Can perform transferFromCross()', async ({helper}) => {
const sender = await helper.eth.createAccountWithBalance(donor, 100n);
const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);
@@ -508,7 +508,7 @@
expect(event.returnValues.value).to.be.equal('51');
});
- itEth('Events emitted for transferFromCross()', async ({helper, privateKey}) => {
+ itEth('Events emitted for transferFromCross()', async ({helper}) => {
const sender = await helper.eth.createAccountWithBalance(donor, 100n);
const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -17,7 +17,6 @@
import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
-import exp from 'constants';
describe('NFT: Information getting', () => {
@@ -280,30 +279,51 @@
});
itEth('Can perform approveCross()', async ({helper}) => {
+ // arrange: create accounts
+ const owner = await helper.eth.createAccountWithBalance(donor, 100n);
+ const ownerCross = helper.ethCrossAccount.fromAddress(owner);
+ const receiverSub = charlie;
+ const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+
+ // arrange: create collection and tokens:
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 owner = await helper.eth.createAccountWithBalance(donor, 100n);
- const receiver = charlie;
+ const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');
- const token = await collection.mintToken(minter, {Ethereum: owner});
-
- const address = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(address, 'nft');
+ // Can approveCross substrate and ethereum address:
+ const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});
+ const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});
+ const eventSub = resultSub.events.Approval;
+ const eventEth = resultEth.events.Approval;
+ expect(eventSub).to.be.like({
+ address: helper.ethAddress.fromCollectionId(collection.collectionId),
+ event: 'Approval',
+ returnValues: {
+ owner,
+ approved: helper.address.substrateToEth(receiverSub.address),
+ tokenId: token1.tokenId.toString(),
+ },
+ });
+ expect(eventEth).to.be.like({
+ address: helper.ethAddress.fromCollectionId(collection.collectionId),
+ event: 'Approval',
+ returnValues: {
+ owner,
+ approved: receiverEth,
+ tokenId: token2.tokenId.toString(),
+ },
+ });
- {
- const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);
- const result = await contract.methods.approveCross(recieverCross, token.tokenId).send({from: owner});
- const event = result.events.Approval;
- expect(event).to.be.like({
- address: helper.ethAddress.fromCollectionId(collection.collectionId),
- event: 'Approval',
- returnValues: {
- owner,
- approved: helper.address.substrateToEth(receiver.address),
- tokenId: token.tokenId.toString(),
- },
- });
- }
+ // Substrate address can transferFrom approved tokens:
+ await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});
+ expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});
+ // Ethereum address can transferFromCross approved tokens:
+ await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});
+ expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});
});
itEth('Can perform transferFrom()', async ({helper}) => {
@@ -340,13 +360,11 @@
}
});
- itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {
- const minter = await privateKey('//Alice');
+ itEth('Can perform transferFromCross()', async ({helper}) => {
const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});
- const owner = await privateKey('//Bob');
+ const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);
const spender = await helper.eth.createAccountWithBalance(donor);
- const receiver = await privateKey('//Charlie');
const token = await collection.mintToken(minter, {Substrate: owner.address});
@@ -501,7 +519,7 @@
expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
- itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {
+ itEth('Can perform transferFromCross()', async ({helper}) => {
const collectionMinter = alice;
const owner = bob;
const receiver = charlie;
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2429,7 +2429,7 @@
* @param ethCrossAccount etherium cross account
* @returns substrate cross account id
*/
- convertCrossAccountFromEthCrossAcoount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId {
+ convertCrossAccountFromEthCrossAccount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId {
if (ethCrossAccount.sub === '0') {
return {Ethereum: ethCrossAccount.eth.toLocaleLowerCase()};
}