difftreelog
Merge pull request #799 from UniqueNetwork/tests/eth-helpers
in: master
14 files changed
.envdiffbeforeafterboth--- a/.env
+++ b/.env
@@ -3,21 +3,21 @@
POLKADOT_MAINNET_BRANCH=release-v0.9.30
STATEMINT_BUILD_BRANCH=release-parachains-v9320
-ACALA_BUILD_BRANCH=2.10.1
+ACALA_BUILD_BRANCH=2.11.0
MOONBEAM_BUILD_BRANCH=runtime-1901
-UNIQUE_MAINNET_BRANCH=v930033
+UNIQUE_MAINNET_BRANCH=release-v930033
UNIQUE_REPLICA_FROM=wss://eu-ws.unique.network:443
-KUSAMA_MAINNET_BRANCH=release-v0.9.34
-STATEMINE_BUILD_BRANCH=release-parachains-v9320
-KARURA_BUILD_BRANCH=release-karura-2.10.0
-MOONRIVER_BUILD_BRANCH=runtime-1901
-QUARTZ_MAINNET_BRANCH=v930033
+KUSAMA_MAINNET_BRANCH=release-v0.9.35
+STATEMINE_BUILD_BRANCH=release-parachains-v9330
+KARURA_BUILD_BRANCH=release-karura-2.11.0
+MOONRIVER_BUILD_BRANCH=runtime-2000
+QUARTZ_MAINNET_BRANCH=release-v930034
QUARTZ_REPLICA_FROM=wss://eu-ws-quartz.unique.network:443
UNQWND_MAINNET_BRANCH=release-v0.9.30
WESTMINT_BUILD_BRANCH=parachains-v9330
-OPAL_MAINNET_BRANCH=v930032
+OPAL_MAINNET_BRANCH=release-v930034
OPAL_REPLICA_FROM=wss://eu-ws-opal.unique.network:443
POLKADOT_LAUNCH_BRANCH=unique-network
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -8,11 +8,13 @@
"@types/chai": "^4.3.3",
"@types/chai-as-promised": "^7.1.5",
"@types/chai-like": "^1.1.1",
+ "@types/chai-subset": "^1.3.3",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.2",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"chai": "^4.3.6",
+ "chai-subset": "^1.6.0",
"eslint": "^8.25.0",
"eslint-plugin-mocha": "^10.1.0",
"mocha": "^10.1.0",
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 [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/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -26,27 +26,36 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
donor = await privateKey({filename: __filename});
- [alice] = await _helper.arrange.createAccounts([20n], donor);
+ [alice] = await _helper.arrange.createAccounts([50n], donor);
});
});
// Soft-deprecated: setCollectionProperty
[
- {method: 'setCollectionProperties', methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]},
- {method: 'setCollectionProperty', methodParams: ['testKey', Buffer.from('testValue')], expectedProps: [{key: 'testKey', value: 'testValue'}]},
+ {method: 'setCollectionProperties', mode: 'nft' as const, methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]},
+ {method: 'setCollectionProperties', mode: 'rft' as const, methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]},
+ {method: 'setCollectionProperties', mode: 'ft' as const, methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]},
+ {method: 'setCollectionProperty', mode: 'nft' as const, methodParams: ['testKey', Buffer.from('testValue')], expectedProps: [{key: 'testKey', value: 'testValue'}]},
].map(testCase =>
- itEth(`Collection properties can be set: ${testCase.method}`, async({helper}) => {
+ itEth.ifWithPallets(`Collection properties can be set: ${testCase.method}() for ${testCase.mode}`, testCase.mode === 'rft' ? [Pallets.ReFungible] : [], async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});
+ const collection = await helper[testCase.mode].mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});
await collection.addAdmin(alice, {Ethereum: caller});
-
+
const address = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(address, 'nft', caller, testCase.method === 'setCollectionProperty');
+ const collectionEvm = helper.ethNativeContract.collection(address, 'nft', caller, testCase.method === 'setCollectionProperty');
- await contract.methods[testCase.method](...testCase.methodParams).send({from: caller});
+ // collectionProperties returns an empty array if no properties:
+ expect(await collectionEvm.methods.collectionProperties([]).call()).to.be.like([]);
+ expect(await collectionEvm.methods.collectionProperties(['NonExistingKey']).call()).to.be.like([]);
+
+ await collectionEvm.methods[testCase.method](...testCase.methodParams).send({from: caller});
const raw = (await collection.getData())?.raw;
expect(raw.properties).to.deep.equal(testCase.expectedProps);
+
+ // collectionProperties returns properties:
+ expect(await collectionEvm.methods.collectionProperties([]).call()).to.be.like(testCase.expectedProps.map(prop => helper.ethProperty.property(prop.key, prop.value)));
}));
itEth('Cannot set invalid properties', async({helper}) => {
@@ -68,16 +77,18 @@
// Soft-deprecated: deleteCollectionProperty
[
- {method: 'deleteCollectionProperties', methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},
- {method: 'deleteCollectionProperty', methodParams: ['testKey1'], expectedProps: [{key: 'testKey2', value: 'testValue2'}, {key: 'testKey3', value: 'testValue3'}]},
+ {method: 'deleteCollectionProperties', mode: 'nft' as const, methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},
+ {method: 'deleteCollectionProperties', mode: 'rft' as const, methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},
+ {method: 'deleteCollectionProperties', mode: 'ft' as const, methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},
+ {method: 'deleteCollectionProperty', mode: 'nft' as const, methodParams: ['testKey1'], expectedProps: [{key: 'testKey2', value: 'testValue2'}, {key: 'testKey3', value: 'testValue3'}]},
].map(testCase =>
- itEth(`Collection properties can be deleted: ${testCase.method}()`, async({helper}) => {
+ itEth.ifWithPallets(`Collection properties can be deleted: ${testCase.method}() for ${testCase.mode}`, testCase.mode === 'rft' ? [Pallets.ReFungible] : [], async({helper}) => {
const properties = [
{key: 'testKey1', value: 'testValue1'},
{key: 'testKey2', value: 'testValue2'},
{key: 'testKey3', value: 'testValue3'}];
const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties});
+ const collection = await helper[testCase.mode].mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties});
await collection.addAdmin(alice, {Ethereum: caller});
@@ -92,7 +103,6 @@
expect(raw.properties).to.deep.equal(testCase.expectedProps);
}));
-
[
{method: 'deleteCollectionProperties', methodParams: [['testKey2']]},
{method: 'deleteCollectionProperty', methodParams: ['testKey2']},
@@ -207,82 +217,5 @@
await contract.methods.setProperties(tokenId2, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);
- }));
-});
-
-describe('EVM collection property', () => {
- let donor: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = await privateKey({filename: __filename});
- });
- });
-
- [
- {case: 'nft' as const},
- {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
- {case: 'ft' as const},
- ].map(testCase =>
- itEth.ifWithPallets(`can set/read properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
- const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
-
- const sender = await helper.eth.createAccountWithBalance(donor, 100n);
- await collection.addAdmin(donor, {Ethereum: sender});
-
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
-
- const keys = ['key0', 'key1'];
-
- const writeProperties = [
- helper.ethProperty.property(keys[0], 'value0'),
- helper.ethProperty.property(keys[1], 'value1'),
- ];
-
- await contract.methods.setCollectionProperties(writeProperties).send();
- const readProperties = await contract.methods.collectionProperties([keys[0], keys[1]]).call();
- expect(readProperties).to.be.like(writeProperties);
- }));
-
- [
- {case: 'nft' as const},
- {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
- {case: 'ft' as const},
- ].map(testCase =>
- itEth.ifWithPallets(`can delete properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
- const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
-
- const sender = await helper.eth.createAccountWithBalance(donor, 100n);
- await collection.addAdmin(donor, {Ethereum: sender});
-
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
-
- const keys = ['key0', 'key1', 'key2', 'key3'];
-
- {
- const writeProperties = [
- helper.ethProperty.property(keys[0], 'value0'),
- helper.ethProperty.property(keys[1], 'value1'),
- helper.ethProperty.property(keys[2], 'value2'),
- helper.ethProperty.property(keys[3], 'value3'),
- ];
-
- await contract.methods.setCollectionProperties(writeProperties).send();
- const readProperties = await contract.methods.collectionProperties([keys[0], keys[1], keys[2], keys[3]]).call();
- expect(readProperties).to.be.like(writeProperties);
- }
-
- {
- const expectProperties = [
- helper.ethProperty.property(keys[0], 'value0'),
- helper.ethProperty.property(keys[1], 'value1'),
- ];
-
- await contract.methods.deleteCollectionProperties([keys[2], keys[3]]).send();
- const readProperties = await contract.methods.collectionProperties([]).call();
- expect(readProperties).to.be.like(expectProperties);
- }
}));
});
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -22,29 +22,31 @@
describe('Sponsoring EVM contracts', () => {
let donor: IKeyringPair;
+ let nominal: bigint;
before(async () => {
- await usingPlaygrounds(async (_helper, privateKey) => {
+ await usingPlaygrounds(async (helper, privateKey) => {
donor = await privateKey({filename: __filename});
+ nominal = helper.balance.getOneTokenNominal();
});
});
- itEth('Self sponsored can be set by the address that deployed the contract', async ({helper}) => {
+ itEth('Self sponsoring can be set by the address that deployed the contract', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const flipper = await helper.eth.deployFlipper(owner);
const helpers = helper.ethNativeContract.contractHelpers(owner);
+ // 1. owner can set selfSponsoring:
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
- await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.not.rejected;
+ const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send({from: owner});
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
- });
- itEth('Set self sponsored events', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const flipper = await helper.eth.deployFlipper(owner);
- const helpers = helper.ethNativeContract.contractHelpers(owner);
-
- const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send();
+ // 1.1 Can get sponsor using methods.sponsor:
+ const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();
+ expect(actualSponsor.eth).to.eq(flipper.options.address);
+ expect(actualSponsor.sub).to.eq('0');
+
+ // 2. Events should be:
const ethEvents = helper.eth.helper.eth.normalizeEvents(result.events);
expect(ethEvents).to.be.deep.equal([
{
@@ -66,7 +68,7 @@
]);
});
- itEth('Self sponsored can not be set by the address that did not deployed the contract', async ({helper}) => {
+ itEth('Self sponsoring cannot be set by the address that did not deployed the contract', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const notOwner = await helper.eth.createAccountWithBalance(donor);
const helpers = helper.ethNativeContract.contractHelpers(owner);
@@ -83,7 +85,7 @@
const flipper = await helper.eth.deployFlipper(owner);
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
- await expect(helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner})).to.be.not.rejected;
+ await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
});
@@ -104,18 +106,12 @@
const helpers = helper.ethNativeContract.contractHelpers(owner);
const flipper = await helper.eth.deployFlipper(owner);
+ // 1. owner can set a sponsor:
expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;
- await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
- expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;
- });
-
- itEth('Set sponsor event', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const sponsor = await helper.eth.createAccountWithBalance(donor);
- const helpers = helper.ethNativeContract.contractHelpers(owner);
- const flipper = await helper.eth.deployFlipper(owner);
-
const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
+ expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;
+
+ // 2. Events should be:
const events = helper.eth.normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -129,7 +125,7 @@
]);
});
- itEth('Sponsor can not be set by the address that did not deployed the contract', async ({helper}) => {
+ itEth('Sponsor cannot be set by the address that did not deployed the contract', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const sponsor = await helper.eth.createAccountWithBalance(donor);
const notOwner = await helper.eth.createAccountWithBalance(donor);
@@ -148,19 +144,18 @@
const flipper = await helper.eth.deployFlipper(owner);
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
- await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
- await expect(helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor})).to.be.not.rejected;
+ await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
+
+ // 1. sponsor can confirm sponsorship:
+ const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
- });
- itEth('Confirm sponsorship event', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const sponsor = await helper.eth.createAccountWithBalance(donor);
- const helpers = helper.ethNativeContract.contractHelpers(owner);
- const flipper = await helper.eth.deployFlipper(owner);
+ // 1.1 Can get sponsor using methods.sponsor:
+ const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();
+ expect(actualSponsor.eth).to.eq(sponsor);
+ expect(actualSponsor.sub).to.eq('0');
- await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
- const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
+ // 2. Events should be:
const events = helper.eth.normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -196,34 +191,6 @@
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
- });
-
- itEth('Get self sponsored sponsor', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const helpers = helper.ethNativeContract.contractHelpers(owner);
- const flipper = await helper.eth.deployFlipper(owner);
-
- await helpers.methods.selfSponsoredEnable(flipper.options.address).send();
-
- const result = await helpers.methods.sponsor(flipper.options.address).call();
-
- expect(result[0]).to.be.eq(flipper.options.address);
- expect(result[1]).to.be.eq('0');
- });
-
- itEth('Get confirmed sponsor', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const sponsor = await helper.eth.createAccountWithBalance(donor);
- const helpers = helper.ethNativeContract.contractHelpers(owner);
- const flipper = await helper.eth.deployFlipper(owner);
-
- await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
- await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
-
- const result = await helpers.methods.sponsor(flipper.options.address).call();
-
- expect(result[0]).to.be.eq(sponsor);
- expect(result[1]).to.be.eq('0');
});
itEth('Sponsor can be removed by the address that deployed the contract', async ({helper}) => {
@@ -236,21 +203,11 @@
await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
-
- await helpers.methods.removeSponsor(flipper.options.address).send();
+ // 1. Can remove sponsor:
+ const result = await helpers.methods.removeSponsor(flipper.options.address).send();
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
- });
- itEth('Remove sponsor event', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const sponsor = await helper.eth.createAccountWithBalance(donor);
- const helpers = helper.ethNativeContract.contractHelpers(owner);
- const flipper = await helper.eth.deployFlipper(owner);
-
- await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
- await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
-
- const result = await helpers.methods.removeSponsor(flipper.options.address).send();
+ // 2. Events should be:
const events = helper.eth.normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -261,6 +218,11 @@
},
},
]);
+
+ // TODO: why call method reverts?
+ // const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();
+ // expect(actualSponsor.eth).to.eq(sponsor);
+ // expect(actualSponsor.sub).to.eq('0');
});
itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper}) => {
@@ -276,6 +238,7 @@
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
await expect(helpers.methods.removeSponsor(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');
+ await expect(helpers.methods.removeSponsor(flipper.options.address).send({from: notOwner})).to.be.rejected;
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
});
@@ -292,15 +255,15 @@
await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
- const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
- const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ const callerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
// Balance should be taken from sponsor instead of caller
- const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
- const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ const callerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));
expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);
});
@@ -331,82 +294,67 @@
expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);
});
- itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const sponsor = await helper.eth.createAccountWithBalance(donor);
- const caller = helper.eth.createAccount();
- const helpers = helper.ethNativeContract.contractHelpers(owner);
- const flipper = await helper.eth.deployFlipper(owner);
-
- await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
- await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
-
- await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
- await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
-
- await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
- await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
-
- const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
- expect(sponsorBalanceBefore).to.be.not.equal('0');
-
- await flipper.methods.flip().send({from: caller});
- expect(await flipper.methods.getValue().call()).to.be.true;
-
- // Balance should be taken from flipper instead of caller
- const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
- expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
+ [
+ {balance: 0n, label: '0'},
+ {balance: 10n, label: '10'},
+ ].map(testCase => {
+ itEth(`Allow-listed address that has ${testCase.label} UNQ can call a contract. Sponsor balance should decrease`, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const caller = helper.eth.createAccount();
+ await helper.eth.transferBalanceFromSubstrate(donor, caller, testCase.balance);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
+ await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
+ await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
+
+ await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
+ await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
+
+ await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
+ await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
+
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ expect(sponsorBalanceBefore > 0n).to.be.true;
+
+ await flipper.methods.flip().send({from: caller});
+ expect(await flipper.methods.getValue().call()).to.be.true;
+
+ // Balance should be taken from flipper instead of caller
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
+ // Caller's balance does not change:
+ const callerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));
+ expect(callerBalanceAfter).to.eq(testCase.balance * nominal);
+ });
});
- itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({helper}) => {
+ itEth('Non-allow-listed address can call a contract. Sponsor balance should not decrease', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const caller = await helper.eth.createAccount();
- const helpers = helper.ethNativeContract.contractHelpers(owner);
- const flipper = await helper.eth.deployFlipper(owner);
-
- await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
- await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
+ const caller = helper.eth.createAccount();
+ const contractHelpers = helper.ethNativeContract.contractHelpers(owner);
+ // Deploy flipper and send some tokens:
+ const flipper = await helper.eth.deployFlipper(owner);
await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);
-
+ expect(await flipper.methods.getValue().call()).to.be.false;
+ // flipper address has some tokens:
const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address);
- expect(originalFlipperBalance).to.be.not.equal('0');
+ expect(originalFlipperBalance > 0n).to.be.true;
+
+ // Set Allowlisted sponsoring mode. caller is not in allow list:
+ await contractHelpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
+ await contractHelpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
+ await contractHelpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
+ // 1. Caller has no UNQ and is not in allow list. So he cannot flip:
await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/Returned error: insufficient funds for gas \* price \+ value/);
expect(await flipper.methods.getValue().call()).to.be.false;
- // Balance should be taken from flipper instead of caller
- // FIXME the comment is wrong! What check should be here?
+ // Flipper's balance does not change:
const balanceAfter = await helper.balance.getEthereum(flipper.options.address);
expect(balanceAfter).to.be.equal(originalFlipperBalance);
- });
-
- itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const sponsor = await helper.eth.createAccountWithBalance(donor);
- const caller = await helper.eth.createAccountWithBalance(donor);
- const helpers = helper.ethNativeContract.contractHelpers(owner);
- const flipper = await helper.eth.deployFlipper(owner);
-
- await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
- await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
-
- await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
- await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
-
- await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
- await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
-
- const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
- const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
-
- await flipper.methods.flip().send({from: caller});
- expect(await flipper.methods.getValue().call()).to.be.true;
-
- const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
- const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
- expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
- expect(callerBalanceAfter).to.be.equal(callerBalanceBefore);
});
itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {
@@ -427,7 +375,7 @@
await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
const originalFlipperBalance = await helper.balance.getEthereum(sponsor);
- expect(originalFlipperBalance).to.be.not.equal('0');
+ expect(originalFlipperBalance > 0n).to.be.true;
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
tests/src/eth/events.test.tsdiffbeforeafterboth--- a/tests/src/eth/events.test.ts
+++ b/tests/src/eth/events.test.ts
@@ -40,7 +40,7 @@
const {collectionAddress, events: ethEvents} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
await helper.wait.newBlocks(1);
{
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionCreated',
args: {
@@ -49,21 +49,21 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionCreated'}]);
clearEvents(ethEvents, subEvents);
}
{
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});
await helper.wait.newBlocks(1);
- expect(result.events).to.be.like({
+ expect(result.events).to.containSubset({
CollectionDestroyed: {
returnValues: {
collectionId: collectionAddress,
},
},
});
- expect(subEvents).to.be.like([{method: 'CollectionDestroyed'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionDestroyed'}]);
}
unsubscribe();
}
@@ -71,7 +71,7 @@
async function testCollectionPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
@@ -82,7 +82,7 @@
{
await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -90,13 +90,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPropertySet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.deleteCollectionProperties(['A']).send({from:owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -104,7 +104,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPropertyDeleted'}]);
}
unsubscribe();
}
@@ -112,7 +112,7 @@
async function testPropertyPermissionSet(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -127,7 +127,7 @@
],
]).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -135,7 +135,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]);
+ expect(subEvents).to.containSubset([{method: 'PropertyPermissionSet'}]);
unsubscribe();
}
@@ -143,7 +143,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const user = helper.ethCrossAccount.createAccount();
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any[] = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -154,7 +154,7 @@
{
await collection.methods.addToCollectionAllowListCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -162,14 +162,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);
+ expect(subEvents).to.containSubset([{method: 'AllowListAddressAdded'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents.length).to.be.eq(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -177,7 +176,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);
+ expect(subEvents).to.containSubset([{method: 'AllowListAddressRemoved'}]);
}
unsubscribe();
}
@@ -186,7 +185,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const user = helper.ethCrossAccount.createAccount();
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -196,7 +195,7 @@
{
await collection.methods.addCollectionAdminCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -204,13 +203,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionAdminAdded'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeCollectionAdminCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -218,7 +217,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionAdminRemoved'}]);
}
unsubscribe();
}
@@ -226,7 +225,7 @@
async function testCollectionLimitSet(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -236,7 +235,7 @@
{
await collection.methods.setCollectionLimit(CollectionLimits.OwnerCanTransfer, true, 0).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -244,7 +243,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionLimitSet'}]);
}
unsubscribe();
}
@@ -253,7 +252,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const newOwner = helper.ethCrossAccount.createAccount();
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -263,7 +262,7 @@
{
await collection.methods.changeCollectionOwnerCross(newOwner).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -271,7 +270,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionOwnerChanged'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionOwnerChanged'}]);
}
unsubscribe();
}
@@ -279,7 +278,7 @@
async function testCollectionPermissionSet(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -289,7 +288,7 @@
{
await collection.methods.setCollectionMintMode(true).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -297,13 +296,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPermissionSet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.setCollectionAccess(1).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -311,7 +310,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPermissionSet'}]);
}
unsubscribe();
}
@@ -320,7 +319,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -332,21 +331,19 @@
{
await collection.methods.setCollectionSponsorCross(sponsor).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
- {
- event: 'CollectionChanged',
- returnValues: {
- collectionId: collectionAddress,
- },
+ expect(ethEvents).to.containSubset([{
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress,
},
- ]);
- expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);
+ }]);
+ expect(subEvents).to.containSubset([{method: 'CollectionSponsorSet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -354,13 +351,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);
+ expect(subEvents).to.containSubset([{method: 'SponsorshipConfirmed'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeCollectionSponsor().send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -368,7 +365,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionSponsorRemoved'}]);
}
unsubscribe();
}
@@ -376,7 +373,7 @@
async function testTokenPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collection.methods.mint(owner).send({from: owner});
const tokenId = result.events.Transfer.returnValues.tokenId;
@@ -397,7 +394,7 @@
{
await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'TokenChanged',
returnValues: {
@@ -405,13 +402,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);
+ expect(subEvents).to.containSubset([{method: 'TokenPropertySet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'TokenChanged',
returnValues: {
@@ -419,7 +416,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]);
+ expect(subEvents).to.containSubset([{method: 'TokenPropertyDeleted'}]);
}
unsubscribe();
}
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -79,23 +79,40 @@
expect(event.returnValues.value).to.equal('100');
});
+ [
+ 'substrate' as const,
+ 'ethereum' as const,
+ ].map(testCase => {
+ itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {
+ // 1. Create receiver depending on the test case:
+ const receiverEth = helper.eth.createAccount();
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverSub = owner;
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(owner);
+
+ const ethOwner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.addAdmin(alice, {Ethereum: ethOwner});
- itEth('Can perform mintCross()', async ({helper}) => {
- const receiverCross = helper.ethCrossAccount.fromKeyringPair(owner);
- const ethOwner = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.ft.mintCollection(alice);
- await collection.addAdmin(alice, {Ethereum: ethOwner});
-
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);
+
+ // 2. Mint tokens:
+ const result = await collectionEvm.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, 100).send();
+
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(receiverSub.address));
+ expect(event.returnValues.value).to.equal('100');
- const result = await contract.methods.mintCross(receiverCross, 100).send();
-
- const event = result.events.Transfer;
- expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.equal(helper.address.substrateToEth(owner.address));
- expect(event.returnValues.value).to.equal('100');
+ // 3. Get balance depending on the test case:
+ let balance;
+ if (testCase === 'ethereum') balance = await collection.getBalance({Ethereum: receiverEth});
+ else if (testCase === 'substrate') balance = await collection.getBalance({Substrate: receiverSub.address});
+ // 3.1 Check balance:
+ expect(balance).to.eq(100n);
+ });
});
itEth('Can perform mintBulk()', async ({helper}) => {
@@ -169,6 +186,68 @@
}
});
+ itEth('Can perform approveCross()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = helper.eth.createAccount();
+ const spenderSub = (await helper.arrange.createAccounts([1n], donor))[0];
+ const spenderCrossEth = helper.ethCrossAccount.fromAddress(spender);
+ const spenderCrossSub = helper.ethCrossAccount.fromKeyringPair(spenderSub);
+
+
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+
+ {
+ const result = await contract.methods.approveCross(spenderCrossEth, 100).send({from: owner});
+ const event = result.events.Approval;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(spender);
+ expect(event.returnValues.value).to.be.equal('100');
+ }
+
+ {
+ const allowance = await contract.methods.allowance(owner, spender).call();
+ expect(+allowance).to.equal(100);
+ }
+
+
+ {
+ const result = await contract.methods.approveCross(spenderCrossSub, 100).send({from: owner});
+ const event = result.events.Approval;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(spenderSub.address));
+ expect(event.returnValues.value).to.be.equal('100');
+ }
+
+ {
+ const allowance = await collection.getApprovedTokens({Ethereum: owner}, {Substrate: spenderSub.address});
+ expect(allowance).to.equal(100n);
+ }
+
+ {
+ //TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()
+ }
+ });
+
+ itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ await collection.mint(alice, 100n, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+
+ await expect(collectionEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');
+ });
+
+
itEth('Can perform burnFromCross()', async ({helper}) => {
const sender = await helper.eth.createAccountWithBalance(donor, 100n);
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -175,55 +175,82 @@
// expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
});
- itEth('Can perform mintCross()', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
- const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
- const permissions: ITokenPropertyPermission[] = properties
- .map(p => {
- return {
- key: p.key, permission: {
- tokenOwner: true,
- collectionAdmin: true,
- mutable: true,
- },
- };
- });
+ // TODO combine all minting tests in one place
+ [
+ 'substrate' as const,
+ 'ethereum' as const,
+ ].map(testCase => {
+ itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {
+ const collectionAdmin = await helper.eth.createAccountWithBalance(donor);
+
+ const receiverEth = helper.eth.createAccount();
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverSub = bob;
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);
+
+ // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
+ const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
+ const permissions: ITokenPropertyPermission[] = properties
+ .map(p => {
+ return {
+ key: p.key, permission: {
+ tokenOwner: false,
+ collectionAdmin: true,
+ mutable: false,
+ },
+ };
+ });
- const collection = await helper.nft.mintCollection(minter, {
- tokenPrefix: 'ethp',
- tokenPropertyPermissions: permissions,
- });
- await collection.addAdmin(minter, {Ethereum: caller});
+ const collection = await helper.nft.mintCollection(minter, {
+ tokenPrefix: 'ethp',
+ tokenPropertyPermissions: permissions,
+ });
+ await collection.addAdmin(minter, {Ethereum: collectionAdmin});
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller, true);
- let expectedTokenId = await contract.methods.nextTokenId().call();
- let result = await contract.methods.mintCross(receiverCross, []).send();
- let tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal(expectedTokenId);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);
+ let expectedTokenId = await contract.methods.nextTokenId().call();
+ let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();
+ let tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal(expectedTokenId);
- let event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+ let event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
- expectedTokenId = await contract.methods.nextTokenId().call();
- result = await contract.methods.mintCross(receiverCross, properties).send();
- event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+ expectedTokenId = await contract.methods.nextTokenId().call();
+ result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();
+ event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
- tokenId = result.events.Transfer.returnValues.tokenId;
+ tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal(expectedTokenId);
+ expect(tokenId).to.be.equal(expectedTokenId);
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
- .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
+ .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+
+ expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))
+ .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});
+ });
+ });
+
+ itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+
+ const collection = await helper.nft.mintCollection(minter);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft');
+
+ await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))
+ .to.be.rejectedWith('PublicMintingNotAllowed');
});
//TODO: CORE-302 add eth methods
@@ -375,6 +402,8 @@
},
});
}
+
+ expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;
});
itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {
@@ -455,6 +484,7 @@
expect(await token2.doesExist()).to.be.false;
});
+ // TODO combine all approve tests in one place
itEth('Can perform approveCross()', async ({helper}) => {
// arrange: create accounts
const owner = await helper.eth.createAccountWithBalance(donor, 100n);
@@ -503,6 +533,17 @@
expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});
});
+ itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');
+ const token = await collection.mintToken(minter, {Ethereum: owner});
+
+ await expect(collectionEvm.methods.approveCross(nonOwnerCross, token.tokenId).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');
+ });
+
itEth('Can reaffirm approved address', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor, 100n);
const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -137,48 +137,63 @@
expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
});
- itEth('Can perform mintCross()', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
- const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
- const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
- collectionAdmin: true,
- mutable: true}}; });
+ [
+ 'substrate' as const,
+ 'ethereum' as const,
+ ].map(testCase => {
+ itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {
+ const collectionAdmin = await helper.eth.createAccountWithBalance(donor);
+
+ const receiverEth = helper.eth.createAccount();
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverSub = bob;
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);
+
+ const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
+ const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {
+ tokenOwner: false,
+ collectionAdmin: true,
+ mutable: false}};
+ });
- const collection = await helper.rft.mintCollection(minter, {
- tokenPrefix: 'ethp',
- tokenPropertyPermissions: permissions,
- });
- await collection.addAdmin(minter, {Ethereum: caller});
+ const collection = await helper.rft.mintCollection(minter, {
+ tokenPrefix: 'ethp',
+ tokenPropertyPermissions: permissions,
+ });
+ await collection.addAdmin(minter, {Ethereum: collectionAdmin});
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller, true);
- let expectedTokenId = await contract.methods.nextTokenId().call();
- let result = await contract.methods.mintCross(receiverCross, []).send();
- let tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal(expectedTokenId);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', collectionAdmin, true);
+ let expectedTokenId = await contract.methods.nextTokenId().call();
+ let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();
+ let tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal(expectedTokenId);
- let event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+ let event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
- expectedTokenId = await contract.methods.nextTokenId().call();
- result = await contract.methods.mintCross(receiverCross, properties).send();
- event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+ expectedTokenId = await contract.methods.nextTokenId().call();
+ result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();
+ event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
- tokenId = result.events.Transfer.returnValues.tokenId;
+ tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal(expectedTokenId);
+ expect(tokenId).to.be.equal(expectedTokenId);
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
- .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
+ .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+
+ expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))
+ .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});
+ });
});
itEth.skip('Can perform mintBulk()', async ({helper}) => {
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -207,7 +207,20 @@
//TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()
}
});
-
+
+ itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ const token = await collection.mintToken(alice, 100n, {Ethereum: owner});
+
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);
+ const tokenEvm = helper.ethNativeContract.rftToken(tokenAddress, owner);
+
+ await expect(tokenEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');
+ });
+
[
'transferFrom',
'transferFromCross',
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/tokenProperties.test.ts
+++ b/tests/src/eth/tokenProperties.test.ts
@@ -37,7 +37,7 @@
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Set and get token property permissions`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Can set all possible token property permissions`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);
for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {
@@ -72,11 +72,11 @@
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Set and get multiple token property permissions as owner`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Can set multiple token property permissions as owner`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
await collection.methods.setTokenPropertyPermissions([
['testKey_0', [
@@ -128,19 +128,18 @@
[EthTokenPermissions.CollectionAdmin.toString(), false]],
],
]);
-
}));
[
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Set and get multiple token property permissions as admin`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Can set multiple token property permissions as admin`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);
const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
await collection.methods.addCollectionAdminCross(caller).send({from: owner});
await collection.methods.setTokenPropertyPermissions([
@@ -452,12 +451,12 @@
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Cant set token property permissions as non owner or admin`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Cannot set token property permissions as non owner or admin`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const caller = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
await expect(collection.methods.setTokenPropertyPermissions([
['testKey_0', [
@@ -472,11 +471,11 @@
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Cant set token property permissions with invalid character`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Cannot set token property permissions with invalid character`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
await expect(collection.methods.setTokenPropertyPermissions([
// "Space" is invalid character
@@ -487,7 +486,73 @@
],
]).call({from: owner})).to.be.rejectedWith('InvalidCharacterInPropertyKey');
}));
-
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ ].map(testCase =>
+ itEth.ifWithPallets(`[${testCase.mode}] Can reconfigure token property permissions to stricter ones`, testCase.requiredPallets, async({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ // 1. Owner sets strict property-permissions:
+ await collection.methods.setTokenPropertyPermissions([
+ ['testKey', [
+ [EthTokenPermissions.Mutable, true],
+ [EthTokenPermissions.TokenOwner, true],
+ [EthTokenPermissions.CollectionAdmin, true]],
+ ],
+ ]).send({from: owner});
+
+ // 2. Owner can set stricter property-permissions:
+ for(const values of [[true, true, false], [true, false, false], [false, false, false]]) {
+ await collection.methods.setTokenPropertyPermissions([
+ ['testKey', [
+ [EthTokenPermissions.Mutable, values[0]],
+ [EthTokenPermissions.TokenOwner, values[1]],
+ [EthTokenPermissions.CollectionAdmin, values[2]]],
+ ],
+ ]).send({from: owner});
+ }
+
+ expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([{
+ key: 'testKey',
+ permission: {mutable: false, collectionAdmin: false, tokenOwner: false},
+ }]);
+ }));
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ ].map(testCase =>
+ itEth.ifWithPallets(`[${testCase.mode}] Cannot reconfigure token property permissions to less strict ones`, testCase.requiredPallets, async({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ // 1. Owner sets strict property-permissions:
+ await collection.methods.setTokenPropertyPermissions([
+ ['testKey', [
+ [EthTokenPermissions.Mutable, false],
+ [EthTokenPermissions.TokenOwner, false],
+ [EthTokenPermissions.CollectionAdmin, false]],
+ ],
+ ]).send({from: owner});
+
+ // 2. Owner cannot set less strict property-permissions:
+ for(const values of [[true, false, false], [false, true, false], [false, false, true]]) {
+ await expect(collection.methods.setTokenPropertyPermissions([
+ ['testKey', [
+ [EthTokenPermissions.Mutable, values[0]],
+ [EthTokenPermissions.TokenOwner, values[1]],
+ [EthTokenPermissions.CollectionAdmin, values[2]]],
+ ],
+ ]).call({from: owner})).to.be.rejectedWith('NoPermission');
+ }
+ }));
});
tests/src/util/index.tsdiffbeforeafterboth--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -6,6 +6,7 @@
import {IKeyringPair} from '@polkadot/types/types/interfaces';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
+import chaiSubset from 'chai-subset';
import {Context} from 'mocha';
import config from '../config';
import {ChainHelperBase} from './playgrounds/unique';
@@ -13,6 +14,7 @@
import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper} from './playgrounds/unique.dev';
chai.use(chaiAsPromised);
+chai.use(chaiSubset);
export const expect = chai.expect;
const getTestHash = (filename: string) => {
tests/src/vesting.test.tsdiffbeforeafterboth--- a/tests/src/vesting.test.ts
+++ b/tests/src/vesting.test.ts
@@ -32,8 +32,12 @@
// arrange
const [sender, recepient] = await helper.arrange.createAccounts([1000n, 1n], donor);
const currentRelayBlock = await helper.chain.getRelayBlockNumber();
- const schedule1 = {start: currentRelayBlock + 4n, period: 4n, periodCount: 2n, perPeriod: 50n * nominal};
- const schedule2 = {start: currentRelayBlock + 8n, period: 8n, periodCount: 2n, perPeriod: 100n * nominal};
+ const SCHEDULE_1_PERIOD = 4n; // 6 blocks one period
+ const SCHEDULE_1_START = currentRelayBlock + 6n; // Block when 1 schedule starts
+ const SCHEDULE_2_PERIOD = 8n; // 12 blocks one period
+ const SCHEDULE_2_START = currentRelayBlock + 12n; // Block when 2 schedule starts
+ const schedule1 = {start: SCHEDULE_1_START, period: SCHEDULE_1_PERIOD, periodCount: 2n, perPeriod: 50n * nominal};
+ const schedule2 = {start: SCHEDULE_2_START, period: SCHEDULE_2_PERIOD, periodCount: 2n, perPeriod: 100n * nominal};
// act
await helper.balance.vestedTransfer(sender, recepient.address, schedule1);
@@ -59,20 +63,22 @@
expect(schedule[0]).to.deep.eq(schedule1);
expect(schedule[1]).to.deep.eq(schedule2);
- await helper.wait.forRelayBlockNumber(currentRelayBlock + 8n);
+ // Wait first part available:
+ await helper.wait.forRelayBlockNumber(SCHEDULE_1_START + SCHEDULE_1_PERIOD);
await helper.balance.claim(recepient);
- // check recepient balance after claim (50 tokens claimed):
+ // check recepient balance after claim (50 tokens claimed, 250 left):
balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);
expect(balanceRecepient.free / nominal).to.eq(300n);
expect(balanceRecepient.feeFrozen).to.eq(250n * nominal);
expect(balanceRecepient.miscFrozen).to.eq(250n * nominal);
expect(balanceRecepient.reserved).to.eq(0n);
- await helper.wait.forRelayBlockNumber(currentRelayBlock + 16n);
+ // Wait first schedule ends and first part od second schedule:
+ await helper.wait.forRelayBlockNumber(SCHEDULE_2_START + SCHEDULE_2_PERIOD);
await helper.balance.claim(recepient);
- // check recepient balance after second claim (150 tokens claimed):
+ // check recepient balance after second claim (150 tokens claimed, 100 left):
balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);
expect(balanceRecepient.free / nominal).to.eq(300n);
expect(balanceRecepient.feeFrozen).to.eq(100n * nominal);
@@ -84,10 +90,11 @@
expect(schedule).to.has.length(1);
expect(schedule[0]).to.deep.eq(schedule2);
- await helper.wait.forRelayBlockNumber(currentRelayBlock + 24n);
+ // Wait 2 schedule ends:
+ await helper.wait.forRelayBlockNumber(SCHEDULE_2_START + SCHEDULE_2_PERIOD * 2n);
await helper.balance.claim(recepient);
- // check recepient balance after second claim (100 tokens claimed):
+ // check recepient balance after second claim (100 tokens claimed, 0 left):
balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);
expect(balanceRecepient.free / nominal).to.eq(300n);
expect(balanceRecepient.feeFrozen).to.eq(0n);
tests/yarn.lockdiffbeforeafterboth--- a/tests/yarn.lock
+++ b/tests/yarn.lock
@@ -979,6 +979,13 @@
dependencies:
"@types/chai" "*"
+"@types/chai-subset@^1.3.3":
+ version "1.3.3"
+ resolved "https://registry.yarnpkg.com/@types/chai-subset/-/chai-subset-1.3.3.tgz#97893814e92abd2c534de422cb377e0e0bdaac94"
+ integrity sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==
+ dependencies:
+ "@types/chai" "*"
+
"@types/chai@*", "@types/chai@^4.3.3":
version "4.3.4"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
@@ -1569,6 +1576,11 @@
resolved "https://registry.yarnpkg.com/chai-like/-/chai-like-1.1.1.tgz#8c558a414c34514e814d497c772547ceb7958f64"
integrity sha512-VKa9z/SnhXhkT1zIjtPACFWSoWsqVoaz1Vg+ecrKo5DCKVlgL30F/pEyEvXPBOVwCgLZcWUleCM/C1okaKdTTA==
+chai-subset@^1.6.0:
+ version "1.6.0"
+ resolved "https://registry.yarnpkg.com/chai-subset/-/chai-subset-1.6.0.tgz#a5d0ca14e329a79596ed70058b6646bd6988cfe9"
+ integrity sha512-K3d+KmqdS5XKW5DWPd5sgNffL3uxdDe+6GdnJh3AYPhwnBGRY5urfvfcbRtWIvvpz+KxkL9FeBB6MZewLUNwug==
+
chai@^4.3.6:
version "4.3.7"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.7.tgz#ec63f6df01829088e8bf55fca839bcd464a8ec51"