difftreelog
chore fix tests
in: master
12 files changed
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.3// Unique Network is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// Unique Network is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.1213// You should have received a copy of the GNU General Public License14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1516import {expect} from 'chai';17import privateKey from '../substrate/privateKey';18import {UNIQUE} from '../util/helpers';19import {20 createEthAccount,21 createEthAccountWithBalance, 22 evmCollection, 23 evmCollectionHelpers, 24 getCollectionAddressFromResult, 25 itWeb3,26 recordEthFee,27} from './util/helpers';2829describe('Add collection admins', () => {30 itWeb3('Add admin by owner', async ({api, web3, privateKeyWrapper}) => {31 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);32 const collectionHelper = evmCollectionHelpers(web3, owner);33 34 const result = await collectionHelper.methods35 .createNonfungibleCollection('A', 'B', 'C')36 .send();37 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);3839 const newAdmin = createEthAccount(web3);40 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);41 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();42 const adminList = await api.rpc.unique.adminlist(collectionId);43 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())44 .to.be.eq(newAdmin.toLocaleLowerCase());45 });4647 // TODO: Temprorary off. Need refactor48 // itWeb3('Add substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {49 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);50 // const collectionHelper = evmCollectionHelpers(web3, owner);51 52 // const result = await collectionHelper.methods53 // .createNonfungibleCollection('A', 'B', 'C')54 // .send();55 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);5657 // const newAdmin = privateKeyWrapper('//Alice');58 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);59 // await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();6061 // const adminList = await api.rpc.unique.adminlist(collectionId);62 // expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())63 // .to.be.eq(newAdmin.address.toLocaleLowerCase());64 // });65 66 itWeb3('Verify owner or admin', async ({api, web3, privateKeyWrapper}) => {67 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);68 const collectionHelper = evmCollectionHelpers(web3, owner);69 70 const result = await collectionHelper.methods71 .createNonfungibleCollection('A', 'B', 'C')72 .send();73 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);7475 const newAdmin = createEthAccount(web3);76 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);77 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;78 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();79 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;80 });8182 itWeb3('(!negative tests!) Add admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {83 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);84 const collectionHelper = evmCollectionHelpers(web3, owner);85 86 const result = await collectionHelper.methods87 .createNonfungibleCollection('A', 'B', 'C')88 .send();89 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);9091 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);92 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);93 await collectionEvm.methods.addCollectionAdmin(admin).send();94 95 const user = createEthAccount(web3);96 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))97 .to.be.rejectedWith('NoPermission');9899 const adminList = await api.rpc.unique.adminlist(collectionId);100 expect(adminList.length).to.be.eq(1);101 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())102 .to.be.eq(admin.toLocaleLowerCase());103 });104105 itWeb3('(!negative tests!) Add admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {106 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);107 const collectionHelper = evmCollectionHelpers(web3, owner);108 109 const result = await collectionHelper.methods110 .createNonfungibleCollection('A', 'B', 'C')111 .send();112 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);113114 const notAdmin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);115 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);116 117 const user = createEthAccount(web3);118 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))119 .to.be.rejectedWith('NoPermission');120121 const adminList = await api.rpc.unique.adminlist(collectionId);122 expect(adminList.length).to.be.eq(0);123 });124125 // TODO: Temprorary off. Need refactor126 // itWeb3('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {127 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);128 // const collectionHelper = evmCollectionHelpers(web3, owner);129 130 // const result = await collectionHelper.methods131 // .createNonfungibleCollection('A', 'B', 'C')132 // .send();133 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);134135 // const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);136 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);137 // await collectionEvm.methods.addCollectionAdmin(admin).send();138139 // const notAdmin = privateKey('//Alice');140 // await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))141 // .to.be.rejectedWith('NoPermission');142143 // const adminList = await api.rpc.unique.adminlist(collectionId);144 // expect(adminList.length).to.be.eq(1);145 // expect(adminList[0].asEthereum.toString().toLocaleLowerCase())146 // .to.be.eq(admin.toLocaleLowerCase());147 // });148 149 // TODO: Temprorary off. Need refactor150 // itWeb3('(!negative tests!) Add substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {151 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);152 // const collectionHelper = evmCollectionHelpers(web3, owner);153 154 // const result = await collectionHelper.methods155 // .createNonfungibleCollection('A', 'B', 'C')156 // .send();157 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);158159 // const notAdmin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);160 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);161 // const notAdmin1 = privateKey('//Alice');162 // await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))163 // .to.be.rejectedWith('NoPermission');164165 // const adminList = await api.rpc.unique.adminlist(collectionId);166 // expect(adminList.length).to.be.eq(0);167 // });168});169170describe('Remove collection admins', () => {171 itWeb3('Remove admin by owner', async ({api, web3, privateKeyWrapper}) => {172 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);173 const collectionHelper = evmCollectionHelpers(web3, owner);174 175 const result = await collectionHelper.methods176 .createNonfungibleCollection('A', 'B', 'C')177 .send();178 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);179180 const newAdmin = createEthAccount(web3);181 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);182 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();183 {184 const adminList = await api.rpc.unique.adminlist(collectionId);185 expect(adminList.length).to.be.eq(1);186 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())187 .to.be.eq(newAdmin.toLocaleLowerCase());188 }189190 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();191 const adminList = await api.rpc.unique.adminlist(collectionId);192 expect(adminList.length).to.be.eq(0);193 });194195 // TODO: Temprorary off. Need refactor196 // itWeb3('Remove substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {197 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);198 // const collectionHelper = evmCollectionHelpers(web3, owner);199 200 // const result = await collectionHelper.methods201 // .createNonfungibleCollection('A', 'B', 'C')202 // .send();203 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);204205 // const newAdmin = privateKeyWrapper('//Alice');206 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);207 // await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();208 // {209 // const adminList = await api.rpc.unique.adminlist(collectionId);210 // expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())211 // .to.be.eq(newAdmin.address.toLocaleLowerCase());212 // }213 214 // await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();215 // const adminList = await api.rpc.unique.adminlist(collectionId);216 // expect(adminList.length).to.be.eq(0);217 // });218219 itWeb3('(!negative tests!) Remove admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {220 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);221 const collectionHelper = evmCollectionHelpers(web3, owner);222 223 const result = await collectionHelper.methods224 .createNonfungibleCollection('A', 'B', 'C')225 .send();226 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);227228 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);229230 const admin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);231 await collectionEvm.methods.addCollectionAdmin(admin0).send();232 const admin1 = createEthAccount(web3);233 await collectionEvm.methods.addCollectionAdmin(admin1).send();234235 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))236 .to.be.rejectedWith('NoPermission');237 {238 const adminList = await api.rpc.unique.adminlist(collectionId);239 expect(adminList.length).to.be.eq(2);240 expect(adminList.toString().toLocaleLowerCase())241 .to.be.deep.contains(admin0.toLocaleLowerCase())242 .to.be.deep.contains(admin1.toLocaleLowerCase());243 }244 });245246 itWeb3('(!negative tests!) Remove admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {247 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);248 const collectionHelper = evmCollectionHelpers(web3, owner);249 250 const result = await collectionHelper.methods251 .createNonfungibleCollection('A', 'B', 'C')252 .send();253 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);254255 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);256257 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);258 await collectionEvm.methods.addCollectionAdmin(admin).send();259 const notAdmin = createEthAccount(web3);260261 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))262 .to.be.rejectedWith('NoPermission');263 {264 const adminList = await api.rpc.unique.adminlist(collectionId);265 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())266 .to.be.eq(admin.toLocaleLowerCase());267 expect(adminList.length).to.be.eq(1);268 }269 });270271 // TODO: Temprorary off. Need refactor272 // itWeb3('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {273 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);274 // const collectionHelper = evmCollectionHelpers(web3, owner);275 276 // const result = await collectionHelper.methods277 // .createNonfungibleCollection('A', 'B', 'C')278 // .send();279 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);280281 // const adminSub = privateKeyWrapper('//Alice');282 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);283 // await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();284 // const adminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);285 // await collectionEvm.methods.addCollectionAdmin(adminEth).send();286287 // await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))288 // .to.be.rejectedWith('NoPermission');289290 // const adminList = await api.rpc.unique.adminlist(collectionId);291 // expect(adminList.length).to.be.eq(2);292 // expect(adminList.toString().toLocaleLowerCase())293 // .to.be.deep.contains(adminSub.address.toLocaleLowerCase())294 // .to.be.deep.contains(adminEth.toLocaleLowerCase());295 // });296297 // TODO: Temprorary off. Need refactor298 // itWeb3('(!negative tests!) Remove substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {299 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);300 // const collectionHelper = evmCollectionHelpers(web3, owner);301 302 // const result = await collectionHelper.methods303 // .createNonfungibleCollection('A', 'B', 'C')304 // .send();305 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);306307 // const adminSub = privateKeyWrapper('//Alice');308 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);309 // await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();310 // const notAdminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);311312 // await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))313 // .to.be.rejectedWith('NoPermission');314315 // const adminList = await api.rpc.unique.adminlist(collectionId);316 // expect(adminList.length).to.be.eq(1);317 // expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())318 // .to.be.eq(adminSub.address.toLocaleLowerCase());319 // });320});321322describe('Change owner tests', () => {323 itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {324 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);325 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);326 const collectionHelper = evmCollectionHelpers(web3, owner);327 const result = await collectionHelper.methods328 .createNonfungibleCollection('A', 'B', 'C')329 .send();330 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);331 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);332 333 await collectionEvm.methods.setOwner(newOwner).send();334 335 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;336 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;337 });338339 itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {340 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);341 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);342 const collectionHelper = evmCollectionHelpers(web3, owner);343 const result = await collectionHelper.methods344 .createNonfungibleCollection('A', 'B', 'C')345 .send();346 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);347 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);348349 const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwner(newOwner).send());350 expect(cost < BigInt(0.2 * Number(UNIQUE)));351 expect(cost > 0);352 });353354 itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {355 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);356 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);357 const collectionHelper = evmCollectionHelpers(web3, owner);358 const result = await collectionHelper.methods359 .createNonfungibleCollection('A', 'B', 'C')360 .send();361 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);362 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);363 364 await expect(collectionEvm.methods.setOwner(newOwner).send({from: newOwner})).to.be.rejected;365 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;366 });367});368369describe('Change substrate owner tests', () => {370 // TODO: Temprorary off. Need refactor371 // itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {372 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);373 // const newOwner = privateKeyWrapper('//Alice');374 // const collectionHelper = evmCollectionHelpers(web3, owner);375 // const result = await collectionHelper.methods376 // .createNonfungibleCollection('A', 'B', 'C')377 // .send();378 // const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);379 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);380 381 // expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.true;382 // expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;383 384 // await collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send();385 386 // expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;387 // expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;388 // });389390 // TODO: Temprorary off. Need refactor391 // itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {392 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);393 // const newOwner = privateKeyWrapper('//Alice');394 // const collectionHelper = evmCollectionHelpers(web3, owner);395 // const result = await collectionHelper.methods396 // .createNonfungibleCollection('A', 'B', 'C')397 // .send();398 // const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);399 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);400401 // const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());402 // expect(cost < BigInt(0.2 * Number(UNIQUE)));403 // expect(cost > 0);404 // });405406 // TODO: Temprorary off. Need refactor407 // itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {408 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);409 // const otherReceiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);410 // const newOwner = privateKeyWrapper('//Alice');411 // const collectionHelper = evmCollectionHelpers(web3, owner);412 // const result = await collectionHelper.methods413 // .createNonfungibleCollection('A', 'B', 'C')414 // .send();415 // const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);416 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);417 418 // await expect(collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;419 // expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;420 // });421});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.3// Unique Network is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// Unique Network is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.1213// You should have received a copy of the GNU General Public License14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1516import {expect} from 'chai';17import privateKey from '../substrate/privateKey';18import {UNIQUE} from '../util/helpers';19import {20 createEthAccount,21 createEthAccountWithBalance, 22 evmCollection, 23 evmCollectionHelpers, 24 getCollectionAddressFromResult, 25 itWeb3,26 recordEthFee,27} from './util/helpers';2829describe('Add collection admins', () => {30 itWeb3('Add admin by owner', async ({api, web3, privateKeyWrapper}) => {31 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);32 const collectionHelper = evmCollectionHelpers(web3, owner);3334 const result = await collectionHelper.methods35 .createNonfungibleCollection('A', 'B', 'C')36 .send({value: Number(2n * UNIQUE)});37 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);3839 const newAdmin = createEthAccount(web3);40 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);41 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();42 const adminList = await api.rpc.unique.adminlist(collectionId);43 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())44 .to.be.eq(newAdmin.toLocaleLowerCase());45 });4647 // TODO: Temprorary off. Need refactor48 // itWeb3('Add substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {49 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);50 // const collectionHelper = evmCollectionHelpers(web3, owner);51 52 // const result = await collectionHelper.methods53 // .createNonfungibleCollection('A', 'B', 'C')54 // .send();55 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);5657 // const newAdmin = privateKeyWrapper('//Alice');58 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);59 // await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();6061 // const adminList = await api.rpc.unique.adminlist(collectionId);62 // expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())63 // .to.be.eq(newAdmin.address.toLocaleLowerCase());64 // });65 66 itWeb3('Verify owner or admin', async ({api, web3, privateKeyWrapper}) => {67 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);68 const collectionHelper = evmCollectionHelpers(web3, owner);69 70 const result = await collectionHelper.methods71 .createNonfungibleCollection('A', 'B', 'C')72 .send({value: Number(2n * UNIQUE)});73 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);7475 const newAdmin = createEthAccount(web3);76 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);77 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;78 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();79 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;80 });8182 itWeb3('(!negative tests!) Add admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {83 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);84 const collectionHelper = evmCollectionHelpers(web3, owner);85 86 const result = await collectionHelper.methods87 .createNonfungibleCollection('A', 'B', 'C')88 .send({value: Number(2n * UNIQUE)});89 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);9091 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);92 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);93 await collectionEvm.methods.addCollectionAdmin(admin).send();94 95 const user = createEthAccount(web3);96 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))97 .to.be.rejectedWith('NoPermission');9899 const adminList = await api.rpc.unique.adminlist(collectionId);100 expect(adminList.length).to.be.eq(1);101 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())102 .to.be.eq(admin.toLocaleLowerCase());103 });104105 itWeb3('(!negative tests!) Add admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {106 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);107 const collectionHelper = evmCollectionHelpers(web3, owner);108 109 const result = await collectionHelper.methods110 .createNonfungibleCollection('A', 'B', 'C')111 .send({value: Number(2n * UNIQUE)});112 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);113114 const notAdmin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);115 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);116 117 const user = createEthAccount(web3);118 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))119 .to.be.rejectedWith('NoPermission');120121 const adminList = await api.rpc.unique.adminlist(collectionId);122 expect(adminList.length).to.be.eq(0);123 });124125 // TODO: Temprorary off. Need refactor126 // itWeb3('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {127 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);128 // const collectionHelper = evmCollectionHelpers(web3, owner);129 130 // const result = await collectionHelper.methods131 // .createNonfungibleCollection('A', 'B', 'C')132 // .send();133 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);134135 // const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);136 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);137 // await collectionEvm.methods.addCollectionAdmin(admin).send();138139 // const notAdmin = privateKey('//Alice');140 // await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))141 // .to.be.rejectedWith('NoPermission');142143 // const adminList = await api.rpc.unique.adminlist(collectionId);144 // expect(adminList.length).to.be.eq(1);145 // expect(adminList[0].asEthereum.toString().toLocaleLowerCase())146 // .to.be.eq(admin.toLocaleLowerCase());147 // });148 149 // TODO: Temprorary off. Need refactor150 // itWeb3('(!negative tests!) Add substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {151 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);152 // const collectionHelper = evmCollectionHelpers(web3, owner);153 154 // const result = await collectionHelper.methods155 // .createNonfungibleCollection('A', 'B', 'C')156 // .send();157 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);158159 // const notAdmin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);160 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);161 // const notAdmin1 = privateKey('//Alice');162 // await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))163 // .to.be.rejectedWith('NoPermission');164165 // const adminList = await api.rpc.unique.adminlist(collectionId);166 // expect(adminList.length).to.be.eq(0);167 // });168});169170describe('Remove collection admins', () => {171 itWeb3('Remove admin by owner', async ({api, web3, privateKeyWrapper}) => {172 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);173 const collectionHelper = evmCollectionHelpers(web3, owner);174 175 const result = await collectionHelper.methods176 .createNonfungibleCollection('A', 'B', 'C')177 .send({value: Number(2n * UNIQUE)});178 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);179180 const newAdmin = createEthAccount(web3);181 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);182 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();183 {184 const adminList = await api.rpc.unique.adminlist(collectionId);185 expect(adminList.length).to.be.eq(1);186 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())187 .to.be.eq(newAdmin.toLocaleLowerCase());188 }189190 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();191 const adminList = await api.rpc.unique.adminlist(collectionId);192 expect(adminList.length).to.be.eq(0);193 });194195 // TODO: Temprorary off. Need refactor196 // itWeb3('Remove substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {197 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);198 // const collectionHelper = evmCollectionHelpers(web3, owner);199 200 // const result = await collectionHelper.methods201 // .createNonfungibleCollection('A', 'B', 'C')202 // .send();203 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);204205 // const newAdmin = privateKeyWrapper('//Alice');206 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);207 // await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();208 // {209 // const adminList = await api.rpc.unique.adminlist(collectionId);210 // expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())211 // .to.be.eq(newAdmin.address.toLocaleLowerCase());212 // }213 214 // await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();215 // const adminList = await api.rpc.unique.adminlist(collectionId);216 // expect(adminList.length).to.be.eq(0);217 // });218219 itWeb3('(!negative tests!) Remove admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {220 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);221 const collectionHelper = evmCollectionHelpers(web3, owner);222 223 const result = await collectionHelper.methods224 .createNonfungibleCollection('A', 'B', 'C')225 .send({value: Number(2n * UNIQUE)});226 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);227228 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);229230 const admin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);231 await collectionEvm.methods.addCollectionAdmin(admin0).send();232 const admin1 = createEthAccount(web3);233 await collectionEvm.methods.addCollectionAdmin(admin1).send();234235 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))236 .to.be.rejectedWith('NoPermission');237 {238 const adminList = await api.rpc.unique.adminlist(collectionId);239 expect(adminList.length).to.be.eq(2);240 expect(adminList.toString().toLocaleLowerCase())241 .to.be.deep.contains(admin0.toLocaleLowerCase())242 .to.be.deep.contains(admin1.toLocaleLowerCase());243 }244 });245246 itWeb3('(!negative tests!) Remove admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {247 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);248 const collectionHelper = evmCollectionHelpers(web3, owner);249 250 const result = await collectionHelper.methods251 .createNonfungibleCollection('A', 'B', 'C')252 .send({value: Number(2n * UNIQUE)});253 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);254255 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);256257 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);258 await collectionEvm.methods.addCollectionAdmin(admin).send();259 const notAdmin = createEthAccount(web3);260261 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))262 .to.be.rejectedWith('NoPermission');263 {264 const adminList = await api.rpc.unique.adminlist(collectionId);265 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())266 .to.be.eq(admin.toLocaleLowerCase());267 expect(adminList.length).to.be.eq(1);268 }269 });270271 // TODO: Temprorary off. Need refactor272 // itWeb3('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {273 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);274 // const collectionHelper = evmCollectionHelpers(web3, owner);275 276 // const result = await collectionHelper.methods277 // .createNonfungibleCollection('A', 'B', 'C')278 // .send();279 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);280281 // const adminSub = privateKeyWrapper('//Alice');282 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);283 // await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();284 // const adminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);285 // await collectionEvm.methods.addCollectionAdmin(adminEth).send();286287 // await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))288 // .to.be.rejectedWith('NoPermission');289290 // const adminList = await api.rpc.unique.adminlist(collectionId);291 // expect(adminList.length).to.be.eq(2);292 // expect(adminList.toString().toLocaleLowerCase())293 // .to.be.deep.contains(adminSub.address.toLocaleLowerCase())294 // .to.be.deep.contains(adminEth.toLocaleLowerCase());295 // });296297 // TODO: Temprorary off. Need refactor298 // itWeb3('(!negative tests!) Remove substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {299 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);300 // const collectionHelper = evmCollectionHelpers(web3, owner);301 302 // const result = await collectionHelper.methods303 // .createNonfungibleCollection('A', 'B', 'C')304 // .send();305 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);306307 // const adminSub = privateKeyWrapper('//Alice');308 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);309 // await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();310 // const notAdminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);311312 // await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))313 // .to.be.rejectedWith('NoPermission');314315 // const adminList = await api.rpc.unique.adminlist(collectionId);316 // expect(adminList.length).to.be.eq(1);317 // expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())318 // .to.be.eq(adminSub.address.toLocaleLowerCase());319 // });320});321322describe('Change owner tests', () => {323 itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {324 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);325 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);326 const collectionHelper = evmCollectionHelpers(web3, owner);327 const result = await collectionHelper.methods328 .createNonfungibleCollection('A', 'B', 'C')329 .send({value: Number(2n * UNIQUE)});330 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);331 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);332 333 await collectionEvm.methods.setOwner(newOwner).send();334 335 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;336 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;337 });338339 itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {340 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);341 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);342 const collectionHelper = evmCollectionHelpers(web3, owner);343 const result = await collectionHelper.methods344 .createNonfungibleCollection('A', 'B', 'C')345 .send({value: Number(2n * UNIQUE)});346 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);347 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);348349 const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwner(newOwner).send());350 expect(cost < BigInt(0.2 * Number(UNIQUE)));351 expect(cost > 0);352 });353354 itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {355 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);356 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);357 const collectionHelper = evmCollectionHelpers(web3, owner);358 const result = await collectionHelper.methods359 .createNonfungibleCollection('A', 'B', 'C')360 .send({value: Number(2n * UNIQUE)});361 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);362 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);363 364 await expect(collectionEvm.methods.setOwner(newOwner).send({from: newOwner})).to.be.rejected;365 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;366 });367});368369describe('Change substrate owner tests', () => {370 // TODO: Temprorary off. Need refactor371 // itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {372 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);373 // const newOwner = privateKeyWrapper('//Alice');374 // const collectionHelper = evmCollectionHelpers(web3, owner);375 // const result = await collectionHelper.methods376 // .createNonfungibleCollection('A', 'B', 'C')377 // .send();378 // const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);379 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);380 381 // expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.true;382 // expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;383 384 // await collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send();385 386 // expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;387 // expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;388 // });389390 // TODO: Temprorary off. Need refactor391 // itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {392 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);393 // const newOwner = privateKeyWrapper('//Alice');394 // const collectionHelper = evmCollectionHelpers(web3, owner);395 // const result = await collectionHelper.methods396 // .createNonfungibleCollection('A', 'B', 'C')397 // .send();398 // const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);399 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);400401 // const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());402 // expect(cost < BigInt(0.2 * Number(UNIQUE)));403 // expect(cost > 0);404 // });405406 // TODO: Temprorary off. Need refactor407 // itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {408 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);409 // const otherReceiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);410 // const newOwner = privateKeyWrapper('//Alice');411 // const collectionHelper = evmCollectionHelpers(web3, owner);412 // const result = await collectionHelper.methods413 // .createNonfungibleCollection('A', 'B', 'C')414 // .send();415 // const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);416 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);417 418 // await expect(collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;419 // expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;420 // });421});tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -1,10 +1,8 @@
-import {addToAllowListExpectSuccess, bigIntToSub, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, enablePublicMintingExpectSuccess, getDetailedCollectionInfo, setCollectionSponsorExpectSuccess} from '../util/helpers';
+import {addToAllowListExpectSuccess, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, enablePublicMintingExpectSuccess, getDetailedCollectionInfo, setCollectionSponsorExpectSuccess, UNIQUE} from '../util/helpers';
import {itWeb3, createEthAccount, collectionIdToAddress, GAS_ARGS, normalizeEvents, createEthAccountWithBalance, evmCollectionHelpers, getCollectionAddressFromResult, evmCollection, ethBalanceViaSub} from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
import {expect} from 'chai';
import {evmToAddress} from '@polkadot/util-crypto';
-import {submitTransactionAsync} from '../substrate/substrate-api';
-import getBalance from '../substrate/get-balance';
describe('evm collection sponsoring', () => {
itWeb3('sponsors mint transactions', async ({web3, privateKeyWrapper}) => {
@@ -64,7 +62,7 @@
itWeb3('Remove sponsor', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionHelpers = evmCollectionHelpers(web3, owner);
- let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * UNIQUE)});
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -85,7 +83,7 @@
itWeb3('Sponsoring collection from evm address via access list', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionHelpers = evmCollectionHelpers(web3, owner);
- let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -210,7 +208,7 @@
itWeb3('Check that transaction via EVM spend money from sponsor address', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionHelpers = evmCollectionHelpers(web3, owner);
- let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -17,6 +17,7 @@
import {evmToAddress} from '@polkadot/util-crypto';
import {IKeyringPair} from '@polkadot/types/types';
import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {UNIQUE} from '../util/helpers';
describe('Create NFT collection from EVM', () => {
let donor: IKeyringPair;
@@ -64,7 +65,7 @@
await collectionHelpers.methods
.createNonfungibleCollection('A', 'A', 'A')
- .send();
+ .send({value: Number(2n * UNIQUE)});
expect(await collectionHelpers.methods
.isCollectionExist(expectedCollectionAddress)
@@ -164,7 +165,7 @@
await expect(collectionHelper.methods
.createNonfungibleCollection(collectionName, description, tokenPrefix)
- .call()).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
+ .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
}
{
@@ -174,7 +175,7 @@
const tokenPrefix = 'A';
await expect(collectionHelper.methods
.createNonfungibleCollection(collectionName, description, tokenPrefix)
- .call()).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
+ .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
}
{
const MAX_TOKEN_PREFIX_LENGTH = 16;
@@ -183,16 +184,16 @@
const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
await expect(collectionHelper.methods
.createNonfungibleCollection(collectionName, description, tokenPrefix)
- .call()).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
+ .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
}
});
itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
- const owner = helper.eth.createAccount();
+ const owner = await helper.eth.createAccountWithBalance(donor);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
.createNonfungibleCollection('Peasantry', 'absolutely anything', 'CVE')
- .call()).to.be.rejectedWith('NotSufficientFounds');
+ .call({value: Number(1n * UNIQUE)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
});
itEth('(!negative test!) Check owner', async ({helper}) => {
tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -18,6 +18,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';
import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {UNIQUE} from '../util/helpers';
describe('Create RFT collection from EVM', () => {
let donor: IKeyringPair;
@@ -65,7 +66,7 @@
await collectionHelpers.methods
.createRFTCollection('A', 'A', 'A')
- .send();
+ .send({value: Number(2n * UNIQUE)});
expect(await collectionHelpers.methods
.isCollectionExist(expectedCollectionAddress)
@@ -166,7 +167,7 @@
await expect(collectionHelper.methods
.createRFTCollection(collectionName, description, tokenPrefix)
- .call()).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
+ .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
}
{
const MAX_DESCRIPTION_LENGTH = 256;
@@ -175,7 +176,7 @@
const tokenPrefix = 'A';
await expect(collectionHelper.methods
.createRFTCollection(collectionName, description, tokenPrefix)
- .call()).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
+ .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
}
{
const MAX_TOKEN_PREFIX_LENGTH = 16;
@@ -184,16 +185,16 @@
const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
await expect(collectionHelper.methods
.createRFTCollection(collectionName, description, tokenPrefix)
- .call()).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
+ .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
}
});
itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
- const owner = helper.eth.createAccount();
+ const owner = await helper.eth.createAccountWithBalance(donor);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
.createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')
- .call()).to.be.rejectedWith('NotSufficientFounds');
+ .call({value: Number(1n * UNIQUE)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
});
itEth('(!negative test!) Check owner', async ({helper}) => {
tests/src/eth/fractionalizer/Fractionalizer.soldiffbeforeafterboth--- a/tests/src/eth/fractionalizer/Fractionalizer.sol
+++ b/tests/src/eth/fractionalizer/Fractionalizer.sol
@@ -81,10 +81,10 @@
string calldata _name,
string calldata _description,
string calldata _tokenPrefix
- ) external onlyOwner {
+ ) external payable onlyOwner {
require(rftCollection == address(0), "RFT collection is already set");
address collectionHelpers = 0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F;
- rftCollection = CollectionHelpers(collectionHelpers).createRFTCollection(_name, _description, _tokenPrefix);
+ rftCollection = CollectionHelpers(collectionHelpers).createRFTCollection{value: msg.value}(_name, _description, _tokenPrefix);
emit RFTCollectionSet(rftCollection);
}
tests/src/eth/fractionalizer/fractionalizer.test.tsdiffbeforeafterboth--- a/tests/src/eth/fractionalizer/fractionalizer.test.ts
+++ b/tests/src/eth/fractionalizer/fractionalizer.test.ts
@@ -93,7 +93,7 @@
const fractionalizer = await deployFractionalizer(web3, owner);
const amount = 10n * UNIQUE;
await web3.eth.sendTransaction({from: owner, to: fractionalizer.options.address, value: `${amount}`, ...GAS_ARGS});
- const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send();
+ const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({value: Number(2n * UNIQUE)});
const rftCollectionAddress = result.events.RFTCollectionSet.returnValues._collection;
return {fractionalizer, rftCollectionAddress};
}
@@ -141,9 +141,9 @@
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const fractionalizer = await deployFractionalizer(web3, owner);
const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);
- await submitTransactionAsync(alice, tx);
+ await executeTransaction(api, alice, tx);
- const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});
+ const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner, value: Number(2n * UNIQUE)});
expect(result.events).to.be.like({
RFTCollectionSet: {},
});
@@ -295,7 +295,7 @@
const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);
await submitTransactionAsync(alice, tx);
- const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});
+ const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner, value: Number(2n * UNIQUE)});
const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;
await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -17,6 +17,7 @@
import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util/playgrounds';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
+import {UNIQUE} from '../util/helpers';
describe('NFT: Information getting', () => {
let donor: IKeyringPair;
@@ -83,7 +84,7 @@
const receiver = helper.eth.createAccount();
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send();
+ let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * UNIQUE)});
const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
tests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth--- a/tests/src/eth/proxy/nonFungibleProxy.test.ts
+++ b/tests/src/eth/proxy/nonFungibleProxy.test.ts
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import {createCollectionExpectSuccess, createItemExpectSuccess} from '../../util/helpers';
+import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../../util/helpers';
import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents} from '../util/helpers';
import nonFungibleAbi from '../nonFungibleAbi.json';
import {expect} from 'chai';
@@ -93,7 +93,7 @@
const collectionHelper = evmCollectionHelpers(web3, owner);
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'A', 'A')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const receiver = createEthAccount(web3);
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -18,6 +18,7 @@
import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
+import {UNIQUE} from '../util/helpers';
describe('Refungible token: Information getting', () => {
let donor: IKeyringPair;
@@ -80,7 +81,7 @@
const receiver = helper.eth.createAccount();
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send();
+ let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * UNIQUE)});
const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -145,7 +145,7 @@
const collectionHelper = evmCollectionHelpers(web3, owner);
const result = await collectionHelper.methods
.createRFTCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
return await getCollectionAddressFromResult(api, result);
}
@@ -154,7 +154,7 @@
const collectionHelper = evmCollectionHelpers(web3, owner);
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
return await getCollectionAddressFromResult(api, result);
}
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -170,9 +170,10 @@
}
async createNonfungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {
+ const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
-
- const result = await collectionHelper.methods.createNonfungibleCollection(name, description, tokenPrefix).send();
+
+ const result = await collectionHelper.methods.createNonfungibleCollection(name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
@@ -181,9 +182,10 @@
}
async createRefungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {
+ const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
-
- const result = await collectionHelper.methods.createRFTCollection(name, description, tokenPrefix).send();
+
+ const result = await collectionHelper.methods.createRFTCollection(name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2034,6 +2034,9 @@
class BalanceGroup extends HelperGroup {
+ getCollectionCreationPrice(): bigint {
+ return 2n * this.helper.balance.getOneTokenNominal();
+ }
/**
* Representation of the native token in the smallest unit - one OPAL (OPL), QUARTZ (QTZ), or UNIQUE (UNQ).
* @example getOneTokenNominal()