difftreelog
test(eth) fix linting errors and warnings
in: master
8 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 subToEth,28} from './util/helpers';2930describe('Add collection admins', () => {31 itWeb3('Add admin by owner', async ({api, web3, privateKeyWrapper}) => {32 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);33 const collectionHelper = evmCollectionHelpers(web3, owner);34 35 const result = await collectionHelper.methods36 .createNonfungibleCollection('A', 'B', 'C')37 .send();38 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);3940 const newAdmin = await createEthAccount(web3);41 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);42 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();43 const adminList = await api.rpc.unique.adminlist(collectionId);44 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())45 .to.be.eq(newAdmin.toLocaleLowerCase());46 });4748 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 = await 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 = await 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 itWeb3('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {126 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);127 const collectionHelper = evmCollectionHelpers(web3, owner);128 129 const result = await collectionHelper.methods130 .createNonfungibleCollection('A', 'B', 'C')131 .send();132 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);133134 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);135 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);136 await collectionEvm.methods.addCollectionAdmin(admin).send();137138 const notAdmin = privateKey('//Alice');139 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))140 .to.be.rejectedWith('NoPermission');141142 const adminList = await api.rpc.unique.adminlist(collectionId);143 expect(adminList.length).to.be.eq(1);144 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())145 .to.be.eq(admin.toLocaleLowerCase());146 });147 148 itWeb3('(!negative tests!) Add substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {149 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);150 const collectionHelper = evmCollectionHelpers(web3, owner);151 152 const result = await collectionHelper.methods153 .createNonfungibleCollection('A', 'B', 'C')154 .send();155 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);156157 const notAdmin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);158 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);159 const notAdmin1 = privateKey('//Alice');160 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))161 .to.be.rejectedWith('NoPermission');162163 const adminList = await api.rpc.unique.adminlist(collectionId);164 expect(adminList.length).to.be.eq(0);165 });166});167168describe('Remove collection admins', () => {169 itWeb3('Remove admin by owner', async ({api, web3, privateKeyWrapper}) => {170 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);171 const collectionHelper = evmCollectionHelpers(web3, owner);172 173 const result = await collectionHelper.methods174 .createNonfungibleCollection('A', 'B', 'C')175 .send();176 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);177178 const newAdmin = await createEthAccount(web3);179 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);180 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();181 {182 const adminList = await api.rpc.unique.adminlist(collectionId);183 expect(adminList.length).to.be.eq(1);184 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())185 .to.be.eq(newAdmin.toLocaleLowerCase());186 }187188 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();189 const adminList = await api.rpc.unique.adminlist(collectionId);190 expect(adminList.length).to.be.eq(0);191 });192193 itWeb3('Remove substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {194 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);195 const collectionHelper = evmCollectionHelpers(web3, owner);196 197 const result = await collectionHelper.methods198 .createNonfungibleCollection('A', 'B', 'C')199 .send();200 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);201202 const newAdmin = privateKeyWrapper('//Alice');203 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);204 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();205 {206 const adminList = await api.rpc.unique.adminlist(collectionId);207 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())208 .to.be.eq(newAdmin.address.toLocaleLowerCase());209 }210 211 await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();212 const adminList = await api.rpc.unique.adminlist(collectionId);213 expect(adminList.length).to.be.eq(0);214 });215216 itWeb3('(!negative tests!) Remove admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {217 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);218 const collectionHelper = evmCollectionHelpers(web3, owner);219 220 const result = await collectionHelper.methods221 .createNonfungibleCollection('A', 'B', 'C')222 .send();223 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);224225 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);226227 const admin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);228 await collectionEvm.methods.addCollectionAdmin(admin0).send();229 const admin1 = await createEthAccount(web3);230 await collectionEvm.methods.addCollectionAdmin(admin1).send();231232 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))233 .to.be.rejectedWith('NoPermission');234 {235 const adminList = await api.rpc.unique.adminlist(collectionId);236 expect(adminList.length).to.be.eq(2);237 expect(adminList.toString().toLocaleLowerCase())238 .to.be.deep.contains(admin0.toLocaleLowerCase())239 .to.be.deep.contains(admin1.toLocaleLowerCase());240 }241 });242243 itWeb3('(!negative tests!) Remove admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {244 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);245 const collectionHelper = evmCollectionHelpers(web3, owner);246 247 const result = await collectionHelper.methods248 .createNonfungibleCollection('A', 'B', 'C')249 .send();250 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);251252 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);253254 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);255 await collectionEvm.methods.addCollectionAdmin(admin).send();256 const notAdmin = await createEthAccount(web3);257258 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))259 .to.be.rejectedWith('NoPermission');260 {261 const adminList = await api.rpc.unique.adminlist(collectionId);262 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())263 .to.be.eq(admin.toLocaleLowerCase());264 expect(adminList.length).to.be.eq(1);265 }266 });267268 itWeb3('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {269 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);270 const collectionHelper = evmCollectionHelpers(web3, owner);271 272 const result = await collectionHelper.methods273 .createNonfungibleCollection('A', 'B', 'C')274 .send();275 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);276277 const adminSub = privateKeyWrapper('//Alice');278 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);279 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();280 const adminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);281 await collectionEvm.methods.addCollectionAdmin(adminEth).send();282283 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))284 .to.be.rejectedWith('NoPermission');285286 const adminList = await api.rpc.unique.adminlist(collectionId);287 expect(adminList.length).to.be.eq(2);288 expect(adminList.toString().toLocaleLowerCase())289 .to.be.deep.contains(adminSub.address.toLocaleLowerCase())290 .to.be.deep.contains(adminEth.toLocaleLowerCase());291 });292293 itWeb3('(!negative tests!) Remove substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {294 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);295 const collectionHelper = evmCollectionHelpers(web3, owner);296 297 const result = await collectionHelper.methods298 .createNonfungibleCollection('A', 'B', 'C')299 .send();300 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);301302 const adminSub = privateKeyWrapper('//Alice');303 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);304 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();305 const notAdminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);306307 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))308 .to.be.rejectedWith('NoPermission');309310 const adminList = await api.rpc.unique.adminlist(collectionId);311 expect(adminList.length).to.be.eq(1);312 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())313 .to.be.eq(adminSub.address.toLocaleLowerCase());314 });315});316317describe('Change owner tests', () => {318 itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {319 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);320 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);321 const collectionHelper = evmCollectionHelpers(web3, owner);322 const result = await collectionHelper.methods323 .createNonfungibleCollection('A', 'B', 'C')324 .send();325 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);326 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);327 328 await collectionEvm.methods.setOwner(newOwner).send();329 330 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;331 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;332 });333334 itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {335 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);336 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);337 const collectionHelper = evmCollectionHelpers(web3, owner);338 const result = await collectionHelper.methods339 .createNonfungibleCollection('A', 'B', 'C')340 .send();341 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);342 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);343344 const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwner(newOwner).send());345 expect(cost < BigInt(0.2 * Number(UNIQUE)));346 expect(cost > 0);347 });348349 itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {350 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);351 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);352 const collectionHelper = evmCollectionHelpers(web3, owner);353 const result = await collectionHelper.methods354 .createNonfungibleCollection('A', 'B', 'C')355 .send();356 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);357 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);358 359 await expect(collectionEvm.methods.setOwner(newOwner).send({from: newOwner})).to.be.rejected;360 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;361 });362});363364describe('Change substrate owner tests', () => {365 itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {366 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);367 const newOwner = privateKeyWrapper('//Alice');368 const collectionHelper = evmCollectionHelpers(web3, owner);369 const result = await collectionHelper.methods370 .createNonfungibleCollection('A', 'B', 'C')371 .send();372 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);373 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);374 375 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.true;376 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;377 378 await collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send();379 380 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;381 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;382 });383384 itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {385 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);386 const newOwner = privateKeyWrapper('//Alice');387 const collectionHelper = evmCollectionHelpers(web3, owner);388 const result = await collectionHelper.methods389 .createNonfungibleCollection('A', 'B', 'C')390 .send();391 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);392 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);393394 const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());395 expect(cost < BigInt(0.2 * Number(UNIQUE)));396 expect(cost > 0);397 });398399 itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {400 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);401 const otherReceiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);402 const newOwner = privateKeyWrapper('//Alice');403 const collectionHelper = evmCollectionHelpers(web3, owner);404 const result = await collectionHelper.methods405 .createNonfungibleCollection('A', 'B', 'C')406 .send();407 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);408 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);409 410 await expect(collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;411 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;412 });413});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);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 itWeb3('Add substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {48 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);49 const collectionHelper = evmCollectionHelpers(web3, owner);50 51 const result = await collectionHelper.methods52 .createNonfungibleCollection('A', 'B', 'C')53 .send();54 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);5556 const newAdmin = privateKeyWrapper('//Alice');57 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);58 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();5960 const adminList = await api.rpc.unique.adminlist(collectionId);61 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())62 .to.be.eq(newAdmin.address.toLocaleLowerCase());63 });64 65 itWeb3('Verify owner or admin', async ({api, web3, privateKeyWrapper}) => {66 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);67 const collectionHelper = evmCollectionHelpers(web3, owner);68 69 const result = await collectionHelper.methods70 .createNonfungibleCollection('A', 'B', 'C')71 .send();72 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);7374 const newAdmin = createEthAccount(web3);75 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);76 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;77 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();78 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;79 });8081 itWeb3('(!negative tests!) Add admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {82 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);83 const collectionHelper = evmCollectionHelpers(web3, owner);84 85 const result = await collectionHelper.methods86 .createNonfungibleCollection('A', 'B', 'C')87 .send();88 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);8990 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);91 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);92 await collectionEvm.methods.addCollectionAdmin(admin).send();93 94 const user = createEthAccount(web3);95 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))96 .to.be.rejectedWith('NoPermission');9798 const adminList = await api.rpc.unique.adminlist(collectionId);99 expect(adminList.length).to.be.eq(1);100 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())101 .to.be.eq(admin.toLocaleLowerCase());102 });103104 itWeb3('(!negative tests!) Add admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {105 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);106 const collectionHelper = evmCollectionHelpers(web3, owner);107 108 const result = await collectionHelper.methods109 .createNonfungibleCollection('A', 'B', 'C')110 .send();111 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);112113 const notAdmin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);114 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);115 116 const user = createEthAccount(web3);117 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))118 .to.be.rejectedWith('NoPermission');119120 const adminList = await api.rpc.unique.adminlist(collectionId);121 expect(adminList.length).to.be.eq(0);122 });123124 itWeb3('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {125 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);126 const collectionHelper = evmCollectionHelpers(web3, owner);127 128 const result = await collectionHelper.methods129 .createNonfungibleCollection('A', 'B', 'C')130 .send();131 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);132133 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);134 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);135 await collectionEvm.methods.addCollectionAdmin(admin).send();136137 const notAdmin = privateKey('//Alice');138 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))139 .to.be.rejectedWith('NoPermission');140141 const adminList = await api.rpc.unique.adminlist(collectionId);142 expect(adminList.length).to.be.eq(1);143 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())144 .to.be.eq(admin.toLocaleLowerCase());145 });146 147 itWeb3('(!negative tests!) Add substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {148 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);149 const collectionHelper = evmCollectionHelpers(web3, owner);150 151 const result = await collectionHelper.methods152 .createNonfungibleCollection('A', 'B', 'C')153 .send();154 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);155156 const notAdmin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);157 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);158 const notAdmin1 = privateKey('//Alice');159 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))160 .to.be.rejectedWith('NoPermission');161162 const adminList = await api.rpc.unique.adminlist(collectionId);163 expect(adminList.length).to.be.eq(0);164 });165});166167describe('Remove collection admins', () => {168 itWeb3('Remove admin by owner', async ({api, web3, privateKeyWrapper}) => {169 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);170 const collectionHelper = evmCollectionHelpers(web3, owner);171 172 const result = await collectionHelper.methods173 .createNonfungibleCollection('A', 'B', 'C')174 .send();175 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);176177 const newAdmin = createEthAccount(web3);178 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);179 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();180 {181 const adminList = await api.rpc.unique.adminlist(collectionId);182 expect(adminList.length).to.be.eq(1);183 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())184 .to.be.eq(newAdmin.toLocaleLowerCase());185 }186187 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();188 const adminList = await api.rpc.unique.adminlist(collectionId);189 expect(adminList.length).to.be.eq(0);190 });191192 itWeb3('Remove substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {193 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);194 const collectionHelper = evmCollectionHelpers(web3, owner);195 196 const result = await collectionHelper.methods197 .createNonfungibleCollection('A', 'B', 'C')198 .send();199 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);200201 const newAdmin = privateKeyWrapper('//Alice');202 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);203 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();204 {205 const adminList = await api.rpc.unique.adminlist(collectionId);206 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())207 .to.be.eq(newAdmin.address.toLocaleLowerCase());208 }209 210 await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();211 const adminList = await api.rpc.unique.adminlist(collectionId);212 expect(adminList.length).to.be.eq(0);213 });214215 itWeb3('(!negative tests!) Remove admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {216 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);217 const collectionHelper = evmCollectionHelpers(web3, owner);218 219 const result = await collectionHelper.methods220 .createNonfungibleCollection('A', 'B', 'C')221 .send();222 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);223224 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);225226 const admin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);227 await collectionEvm.methods.addCollectionAdmin(admin0).send();228 const admin1 = createEthAccount(web3);229 await collectionEvm.methods.addCollectionAdmin(admin1).send();230231 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))232 .to.be.rejectedWith('NoPermission');233 {234 const adminList = await api.rpc.unique.adminlist(collectionId);235 expect(adminList.length).to.be.eq(2);236 expect(adminList.toString().toLocaleLowerCase())237 .to.be.deep.contains(admin0.toLocaleLowerCase())238 .to.be.deep.contains(admin1.toLocaleLowerCase());239 }240 });241242 itWeb3('(!negative tests!) Remove admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {243 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);244 const collectionHelper = evmCollectionHelpers(web3, owner);245 246 const result = await collectionHelper.methods247 .createNonfungibleCollection('A', 'B', 'C')248 .send();249 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);250251 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);252253 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);254 await collectionEvm.methods.addCollectionAdmin(admin).send();255 const notAdmin = createEthAccount(web3);256257 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))258 .to.be.rejectedWith('NoPermission');259 {260 const adminList = await api.rpc.unique.adminlist(collectionId);261 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())262 .to.be.eq(admin.toLocaleLowerCase());263 expect(adminList.length).to.be.eq(1);264 }265 });266267 itWeb3('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {268 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);269 const collectionHelper = evmCollectionHelpers(web3, owner);270 271 const result = await collectionHelper.methods272 .createNonfungibleCollection('A', 'B', 'C')273 .send();274 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);275276 const adminSub = privateKeyWrapper('//Alice');277 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);278 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();279 const adminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);280 await collectionEvm.methods.addCollectionAdmin(adminEth).send();281282 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))283 .to.be.rejectedWith('NoPermission');284285 const adminList = await api.rpc.unique.adminlist(collectionId);286 expect(adminList.length).to.be.eq(2);287 expect(adminList.toString().toLocaleLowerCase())288 .to.be.deep.contains(adminSub.address.toLocaleLowerCase())289 .to.be.deep.contains(adminEth.toLocaleLowerCase());290 });291292 itWeb3('(!negative tests!) Remove substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {293 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);294 const collectionHelper = evmCollectionHelpers(web3, owner);295 296 const result = await collectionHelper.methods297 .createNonfungibleCollection('A', 'B', 'C')298 .send();299 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);300301 const adminSub = privateKeyWrapper('//Alice');302 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);303 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();304 const notAdminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);305306 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))307 .to.be.rejectedWith('NoPermission');308309 const adminList = await api.rpc.unique.adminlist(collectionId);310 expect(adminList.length).to.be.eq(1);311 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())312 .to.be.eq(adminSub.address.toLocaleLowerCase());313 });314});315316describe('Change owner tests', () => {317 itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {318 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);319 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);320 const collectionHelper = evmCollectionHelpers(web3, owner);321 const result = await collectionHelper.methods322 .createNonfungibleCollection('A', 'B', 'C')323 .send();324 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);325 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);326 327 await collectionEvm.methods.setOwner(newOwner).send();328 329 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;330 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;331 });332333 itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {334 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);335 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);336 const collectionHelper = evmCollectionHelpers(web3, owner);337 const result = await collectionHelper.methods338 .createNonfungibleCollection('A', 'B', 'C')339 .send();340 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);341 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);342343 const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwner(newOwner).send());344 expect(cost < BigInt(0.2 * Number(UNIQUE)));345 expect(cost > 0);346 });347348 itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {349 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);350 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);351 const collectionHelper = evmCollectionHelpers(web3, owner);352 const result = await collectionHelper.methods353 .createNonfungibleCollection('A', 'B', 'C')354 .send();355 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);356 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);357 358 await expect(collectionEvm.methods.setOwner(newOwner).send({from: newOwner})).to.be.rejected;359 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;360 });361});362363describe('Change substrate owner tests', () => {364 itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {365 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);366 const newOwner = privateKeyWrapper('//Alice');367 const collectionHelper = evmCollectionHelpers(web3, owner);368 const result = await collectionHelper.methods369 .createNonfungibleCollection('A', 'B', 'C')370 .send();371 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);372 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);373 374 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.true;375 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;376 377 await collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send();378 379 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;380 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;381 });382383 itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {384 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);385 const newOwner = privateKeyWrapper('//Alice');386 const collectionHelper = evmCollectionHelpers(web3, owner);387 const result = await collectionHelper.methods388 .createNonfungibleCollection('A', 'B', 'C')389 .send();390 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);391 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);392393 const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());394 expect(cost < BigInt(0.2 * Number(UNIQUE)));395 expect(cost > 0);396 });397398 itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {399 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);400 const otherReceiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);401 const newOwner = privateKeyWrapper('//Alice');402 const collectionHelper = evmCollectionHelpers(web3, owner);403 const result = await collectionHelper.methods404 .createNonfungibleCollection('A', 'B', 'C')405 .send();406 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);407 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);408 409 await expect(collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;410 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;411 });412});tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -1,5 +1,5 @@
import {addToAllowListExpectSuccess, bigIntToSub, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, enablePublicMintingExpectSuccess, getDetailedCollectionInfo, setCollectionSponsorExpectSuccess} from '../util/helpers';
-import {itWeb3, createEthAccount, collectionIdToAddress, GAS_ARGS, normalizeEvents, createEthAccountWithBalance, evmCollectionHelpers, getCollectionAddressFromResult, evmCollection, ethBalanceViaSub, subToEth} 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';
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -181,7 +181,7 @@
});
itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {
- const owner = await createEthAccount(web3);
+ const owner = createEthAccount(web3);
const helper = evmCollectionHelpers(web3, owner);
const collectionName = 'A';
const description = 'A';
@@ -194,7 +194,7 @@
itWeb3('(!negative test!) Check owner', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notOwner = await createEthAccount(web3);
+ const notOwner = createEthAccount(web3);
const collectionHelpers = evmCollectionHelpers(web3, owner);
const result = await collectionHelpers.methods.createNonfungibleCollection('A', 'A', 'A').send();
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -189,7 +189,7 @@
});
itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {
- const owner = await createEthAccount(web3);
+ const owner = createEthAccount(web3);
const helper = evmCollectionHelpers(web3, owner);
const collectionName = 'A';
const description = 'A';
@@ -202,7 +202,7 @@
itWeb3('(!negative test!) Check owner', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notOwner = await createEthAccount(web3);
+ const notOwner = createEthAccount(web3);
const collectionHelpers = evmCollectionHelpers(web3, owner);
const result = await collectionHelpers.methods.createRefungibleCollection('A', 'A', 'A').send();
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
tests/src/eth/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/eth/nesting/nest.test.ts
+++ b/tests/src/eth/nesting/nest.test.ts
@@ -1,7 +1,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
-import {itEth, EthUniqueHelper, usingEthPlaygrounds, expect} from '../util/playgrounds'
+import {itEth, EthUniqueHelper, usingEthPlaygrounds, expect} from '../util/playgrounds';
const createNestingCollection = async (
helper: EthUniqueHelper,
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE, requirePallets, Pallets} from '../util/helpers';
-import {collectionIdFromAddress, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createNonfungibleCollection, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createRefungibleCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
tests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/index.ts
+++ b/tests/src/eth/util/playgrounds/index.ts
@@ -33,7 +33,7 @@
await helper.disconnectWeb3();
silentConsole.disable();
}
-}
+};
export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {
let i: any = it;
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
@@ -38,18 +38,18 @@
class ContractGroup extends EthGroupBase {
async findImports(imports?: ContractImports[]){
if(!imports) return function(path: string) {
- return {error: 'File not found'};
+ return {error: `File not found: ${path}`};
};
const knownImports = {} as any;
- for(let imp of imports) {
+ for(const imp of imports) {
knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();
}
return function(path: string) {
- if(knownImports.hasOwnProperty(path)) return {contents: knownImports[path]};
- return {error: 'File not found'};
- }
+ if(knownImports.hasOwnPropertyDescriptor(path)) return {contents: knownImports[path]};
+ return {error: `File not found: ${path}`};
+ };
}
async compile(name: string, src: string, imports?: ContractImports[]): Promise<CompiledContract> {
@@ -85,7 +85,7 @@
const contract = new web3.eth.Contract(abi, undefined, {
data: object,
from: signer,
- gas: this.helper.eth.DEFAULT_GAS
+ gas: this.helper.eth.DEFAULT_GAS,
});
return await contract.deploy({data: object}).send({from: signer});
}
@@ -108,7 +108,7 @@
const abi = {
'nft': nonFungibleAbi,
'rft': refungibleAbi,
- 'ft': fungibleAbi
+ 'ft': fungibleAbi,
}[mode];
const web3 = this.helper.getWeb3();
return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});
@@ -154,7 +154,7 @@
await this.helper.executeExtrinsic(
signer,
'api.tx.evm.call', [this.helper.address.substrateToEth(signer.address), contractAddress, abi, value, gasLimit, gasPrice, null, null, []],
- true, `Unable to perform evm.call`
+ true, 'Unable to perform evm.call',
);
}