12345678910111213141516import {expect} from 'chai';17import privateKey from '../substrate/privateKey';18import {19 createEthAccount,20 createEthAccountWithBalance, 21 evmCollection, 22 evmCollectionHelpers, 23 getCollectionAddressFromResult, 24 itWeb3,25} from './util/helpers';2627describe('Add collection admins', () => {28 itWeb3('Add admin by owner', async ({api, web3, privateKeyWrapper}) => {29 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);30 const collectionHelper = evmCollectionHelpers(web3, owner);31 32 const result = await collectionHelper.methods33 .createNonfungibleCollection('A', 'B', 'C')34 .send();35 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);3637 const newAdmin = await createEthAccount(web3);38 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);39 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();40 const adminList = await api.rpc.unique.adminlist(collectionId);41 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())42 .to.be.eq(newAdmin.toLocaleLowerCase());43 });4445 itWeb3('Add substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {46 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);47 const collectionHelper = evmCollectionHelpers(web3, owner);48 49 const result = await collectionHelper.methods50 .createNonfungibleCollection('A', 'B', 'C')51 .send();52 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);5354 const newAdmin = privateKeyWrapper('//Alice');55 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);56 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();5758 const adminList = await api.rpc.unique.adminlist(collectionId);59 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())60 .to.be.eq(newAdmin.address.toLocaleLowerCase());61 });62 63 itWeb3('Verify owner or admin', async ({api, web3, privateKeyWrapper}) => {64 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);65 const collectionHelper = evmCollectionHelpers(web3, owner);66 67 const result = await collectionHelper.methods68 .createNonfungibleCollection('A', 'B', 'C')69 .send();70 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);7172 const newAdmin = createEthAccount(web3);73 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);74 expect(await collectionEvm.methods.verifyOwnerOrAdmin(newAdmin).call()).to.be.false;75 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();76 expect(await collectionEvm.methods.verifyOwnerOrAdmin(newAdmin).call()).to.be.true;77 });7879 itWeb3('(!negative tests!) Add admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {80 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);81 const collectionHelper = evmCollectionHelpers(web3, owner);82 83 const result = await collectionHelper.methods84 .createNonfungibleCollection('A', 'B', 'C')85 .send();86 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);8788 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);89 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);90 await collectionEvm.methods.addCollectionAdmin(admin).send();91 92 const user = await createEthAccount(web3);93 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))94 .to.be.rejectedWith('NoPermission');9596 const adminList = await api.rpc.unique.adminlist(collectionId);97 expect(adminList.length).to.be.eq(1);98 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())99 .to.be.eq(admin.toLocaleLowerCase());100 });101102 itWeb3('(!negative tests!) Add admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {103 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);104 const collectionHelper = evmCollectionHelpers(web3, owner);105 106 const result = await collectionHelper.methods107 .createNonfungibleCollection('A', 'B', 'C')108 .send();109 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);110111 const notAdmin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);112 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);113 114 const user = await createEthAccount(web3);115 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))116 .to.be.rejectedWith('NoPermission');117118 const adminList = await api.rpc.unique.adminlist(collectionId);119 expect(adminList.length).to.be.eq(0);120 });121122 itWeb3('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {123 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);124 const collectionHelper = evmCollectionHelpers(web3, owner);125 126 const result = await collectionHelper.methods127 .createNonfungibleCollection('A', 'B', 'C')128 .send();129 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);130131 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);132 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);133 await collectionEvm.methods.addCollectionAdmin(admin).send();134135 const notAdmin = privateKey('//Alice');136 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))137 .to.be.rejectedWith('NoPermission');138139 const adminList = await api.rpc.unique.adminlist(collectionId);140 expect(adminList.length).to.be.eq(1);141 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())142 .to.be.eq(admin.toLocaleLowerCase());143 });144 145 itWeb3('(!negative tests!) Add substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {146 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);147 const collectionHelper = evmCollectionHelpers(web3, owner);148 149 const result = await collectionHelper.methods150 .createNonfungibleCollection('A', 'B', 'C')151 .send();152 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);153154 const notAdmin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);155 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);156 const notAdmin1 = privateKey('//Alice');157 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))158 .to.be.rejectedWith('NoPermission');159160 const adminList = await api.rpc.unique.adminlist(collectionId);161 expect(adminList.length).to.be.eq(0);162 });163});164165describe('Remove collection admins', () => {166 itWeb3('Remove admin by owner', async ({api, web3, privateKeyWrapper}) => {167 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);168 const collectionHelper = evmCollectionHelpers(web3, owner);169 170 const result = await collectionHelper.methods171 .createNonfungibleCollection('A', 'B', 'C')172 .send();173 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);174175 const newAdmin = await createEthAccount(web3);176 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);177 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();178 {179 const adminList = await api.rpc.unique.adminlist(collectionId);180 expect(adminList.length).to.be.eq(1);181 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())182 .to.be.eq(newAdmin.toLocaleLowerCase());183 }184185 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();186 const adminList = await api.rpc.unique.adminlist(collectionId);187 expect(adminList.length).to.be.eq(0);188 });189190 itWeb3('Remove substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {191 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);192 const collectionHelper = evmCollectionHelpers(web3, owner);193 194 const result = await collectionHelper.methods195 .createNonfungibleCollection('A', 'B', 'C')196 .send();197 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);198199 const newAdmin = privateKeyWrapper('//Alice');200 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);201 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();202 {203 const adminList = await api.rpc.unique.adminlist(collectionId);204 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())205 .to.be.eq(newAdmin.address.toLocaleLowerCase());206 }207 208 await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();209 const adminList = await api.rpc.unique.adminlist(collectionId);210 expect(adminList.length).to.be.eq(0);211 });212213 itWeb3('(!negative tests!) Remove admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {214 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);215 const collectionHelper = evmCollectionHelpers(web3, owner);216 217 const result = await collectionHelper.methods218 .createNonfungibleCollection('A', 'B', 'C')219 .send();220 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);221222 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);223224 const admin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);225 await collectionEvm.methods.addCollectionAdmin(admin0).send();226 const admin1 = await createEthAccount(web3);227 await collectionEvm.methods.addCollectionAdmin(admin1).send();228229 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))230 .to.be.rejectedWith('NoPermission');231 {232 const adminList = await api.rpc.unique.adminlist(collectionId);233 expect(adminList.length).to.be.eq(2);234 expect(adminList.toString().toLocaleLowerCase())235 .to.be.deep.contains(admin0.toLocaleLowerCase())236 .to.be.deep.contains(admin1.toLocaleLowerCase());237 }238 });239240 itWeb3('(!negative tests!) Remove admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {241 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);242 const collectionHelper = evmCollectionHelpers(web3, owner);243 244 const result = await collectionHelper.methods245 .createNonfungibleCollection('A', 'B', 'C')246 .send();247 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);248249 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);250251 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);252 await collectionEvm.methods.addCollectionAdmin(admin).send();253 const notAdmin = await createEthAccount(web3);254255 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))256 .to.be.rejectedWith('NoPermission');257 {258 const adminList = await api.rpc.unique.adminlist(collectionId);259 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())260 .to.be.eq(admin.toLocaleLowerCase());261 expect(adminList.length).to.be.eq(1);262 }263 });264265 itWeb3('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {266 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);267 const collectionHelper = evmCollectionHelpers(web3, owner);268 269 const result = await collectionHelper.methods270 .createNonfungibleCollection('A', 'B', 'C')271 .send();272 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);273274 const adminSub = privateKeyWrapper('//Alice');275 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);276 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();277 const adminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);278 await collectionEvm.methods.addCollectionAdmin(adminEth).send();279280 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))281 .to.be.rejectedWith('NoPermission');282283 const adminList = await api.rpc.unique.adminlist(collectionId);284 expect(adminList.length).to.be.eq(2);285 expect(adminList.toString().toLocaleLowerCase())286 .to.be.deep.contains(adminSub.address.toLocaleLowerCase())287 .to.be.deep.contains(adminEth.toLocaleLowerCase());288 });289290 itWeb3('(!negative tests!) Remove substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {291 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);292 const collectionHelper = evmCollectionHelpers(web3, owner);293 294 const result = await collectionHelper.methods295 .createNonfungibleCollection('A', 'B', 'C')296 .send();297 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);298299 const adminSub = privateKeyWrapper('//Alice');300 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);301 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();302 const notAdminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);303304 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))305 .to.be.rejectedWith('NoPermission');306307 const adminList = await api.rpc.unique.adminlist(collectionId);308 expect(adminList.length).to.be.eq(1);309 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())310 .to.be.eq(adminSub.address.toLocaleLowerCase());311 });312});