difftreelog
Fix tests for quartz and unique: remove global before
in: master
2 files changed
tests/src/adminTransferAndBurn.test.tsdiffbeforeafterboth--- a/tests/src/adminTransferAndBurn.test.ts
+++ b/tests/src/adminTransferAndBurn.test.ts
@@ -24,19 +24,14 @@
let donor: IKeyringPair;
-before(async () => {
- await usingPlaygrounds(async (_, privateKey) => {
- donor = privateKey('//Alice');
- });
-});
-
describe('Integration Test: ownerCanTransfer allows admins to use only transferFrom/burnFrom:', () => {
let alice: IKeyringPair;
let bob: IKeyringPair;
let charlie: IKeyringPair;
before(async () => {
- await usingPlaygrounds(async (helper) => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
[alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
});
});
tests/src/allowLists.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let donor: IKeyringPair;2627before(async () => {28 await usingPlaygrounds(async (_, privateKey) => {29 donor = privateKey('//Alice');30 });31});3233let alice: IKeyringPair;34let bob: IKeyringPair;35let charlie: IKeyringPair;3637describe('Integration Test ext. Allow list tests', () => {3839 before(async () => {40 await usingPlaygrounds(async (helper) => {41 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);42 });43 });4445 it('Owner can add address to allow list', async () => {46 await usingPlaygrounds(async (helper) => {47 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});48 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});49 const allowList = await helper.nft.getAllowList(collectionId);50 expect(allowList).to.be.deep.contains({Substrate: bob.address});51 });52 });5354 it('Admin can add address to allow list', async () => {55 await usingPlaygrounds(async (helper) => {56 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});57 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});5859 await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});60 const allowList = await helper.nft.getAllowList(collectionId);61 expect(allowList).to.be.deep.contains({Substrate: charlie.address});62 });63 });6465 it('Non-privileged user cannot add address to allow list', async () => {66 await usingPlaygrounds(async (helper) => {67 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});68 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});69 await expect(addToAllowListTx()).to.be.rejected;70 });71 });7273 it('Nobody can add address to allow list of non-existing collection', async () => {74 const collectionId = (1<<32) - 1;75 await usingPlaygrounds(async (helper) => {76 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});77 await expect(addToAllowListTx()).to.be.rejected;78 });79 });8081 it('Nobody can add address to allow list of destroyed collection', async () => {82 await usingPlaygrounds(async (helper) => {83 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});84 await helper.collection.burn(alice, collectionId);85 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});86 await expect(addToAllowListTx()).to.be.rejected;87 });88 });8990 it('If address is already added to allow list, nothing happens', async () => {91 await usingPlaygrounds(async (helper) => {92 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});93 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});94 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});95 const allowList = await helper.nft.getAllowList(collectionId);96 expect(allowList).to.be.deep.contains({Substrate: bob.address});97 });98 });99100 it('Owner can remove address from allow list', async () => {101 await usingPlaygrounds(async (helper) => {102 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});103 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});104105 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});106107 const allowList = await helper.nft.getAllowList(collectionId);108109 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});110 });111 });112113 it('Admin can remove address from allow list', async () => {114 await usingPlaygrounds(async (helper) => {115 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});116 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});117 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});118 await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});119120 const allowList = await helper.nft.getAllowList(collectionId);121122 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});123 });124 });125126 it('Non-privileged user cannot remove address from allow list', async () => {127 await usingPlaygrounds(async (helper) => {128 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});129 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});130 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});131 await expect(removeTx()).to.be.rejected;132 const allowList = await helper.nft.getAllowList(collectionId);133134 expect(allowList).to.be.deep.contains({Substrate: charlie.address});135 });136 });137138 it('Nobody can remove address from allow list of non-existing collection', async () => {139 const collectionId = (1<<32) - 1;140 await usingPlaygrounds(async (helper) => {141 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});142 await expect(removeTx()).to.be.rejected;143 });144 });145146 it('Nobody can remove address from allow list of deleted collection', async () => {147 await usingPlaygrounds(async (helper) => {148 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});149 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});150 await helper.collection.burn(alice, collectionId);151 const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});152153 await expect(removeTx()).to.be.rejected;154 });155 });156157 it('If address is already removed from allow list, nothing happens', async () => {158 await usingPlaygrounds(async (helper) => {159 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});160 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});161 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});162 const allowListBefore = await helper.nft.getAllowList(collectionId);163 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});164165 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});166167 const allowListAfter = await helper.nft.getAllowList(collectionId);168 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});169 });170 });171172 it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test1', async () => {173 await usingPlaygrounds(async (helper) => {174 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});175 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});176 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});177 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});178179 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});180 await expect(transferResult()).to.be.rejected;181 });182 });183184 it('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test2', async () => {185 await usingPlaygrounds(async (helper) => {186 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});187 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});188 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});189 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});190 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});191 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});192 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});193194 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});195 await expect(transferResult()).to.be.rejected;196 });197 });198199 it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test1', async () => {200 await usingPlaygrounds(async (helper) => {201 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});202 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});203 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});204 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});205206 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});207 await expect(transferResult()).to.be.rejected;208 });209 });210211 it('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test2', async () => {212 await usingPlaygrounds(async (helper) => {213 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});214 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});215 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});216 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});217 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});218219 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});220 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});221222 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});223 await expect(transferResult()).to.be.rejected;224 });225 });226227 it('If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if it owned them before enabling AllowList mode)', async () => {228 await usingPlaygrounds(async (helper) => {229 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});230 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});231 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});232 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);233 await expect(burnTx()).to.be.rejected;234 });235 });236237 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {238 await usingPlaygrounds(async (helper) => {239 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});240 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});241 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});242 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});243 await expect(approveTx()).to.be.rejected;244 });245 });246247 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {248 await usingPlaygrounds(async (helper) => {249 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});250 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});251 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});252 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});253 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});254 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});255 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);256 expect(owner.Substrate).to.be.equal(charlie.address);257 });258 });259260 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async () => {261 await usingPlaygrounds(async (helper) => {262 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});263 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});264 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});265 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});266 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});267 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});268269 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});270 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);271 expect(owner.Substrate).to.be.equal(charlie.address);272 });273 });274275 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {276 await usingPlaygrounds(async (helper) => {277 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});278 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});279 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});280 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});281 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});282283 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});284 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);285 expect(owner.Substrate).to.be.equal(charlie.address);286 });287 });288289 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {290 await usingPlaygrounds(async (helper) => {291 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});292 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});293 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});294 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});295 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});296 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});297298 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});299 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);300 expect(owner.Substrate).to.be.equal(charlie.address);301 });302 });303304 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {305 await usingPlaygrounds(async (helper) => {306 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});307 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});308 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});309 const token = await helper.nft.getToken(collectionId, tokenId);310 expect(token).to.be.not.null;311 });312 });313314 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {315 await usingPlaygrounds(async (helper) => {316 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});317 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});318 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});319 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});320 const token = await helper.nft.getToken(collectionId, tokenId);321 expect(token).to.be.not.null;322 });323 });324325 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and allow-listed address', async () => {326 await usingPlaygrounds(async (helper) => {327 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});328 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});329 await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});330 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});331 await expect(mintTokenTx()).to.be.rejected;332 });333 });334335 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens cannot be created by non-privileged and non-allow listed address', async () => {336 await usingPlaygrounds(async (helper) => {337 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});338 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});339 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});340 await expect(mintTokenTx()).to.be.rejected;341 });342 });343344 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {345 await usingPlaygrounds(async (helper) => {346 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});347 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});348 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});349 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);350 expect(owner.Substrate).to.be.equal(alice.address);351 });352 });353354 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {355 await usingPlaygrounds(async (helper) => {356 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});357 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});358 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});359 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});360 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);361 expect(owner.Substrate).to.be.equal(bob.address);362 });363 });364365 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens cannot be created by non-privileged and non-allow listed address', async () => {366 await usingPlaygrounds(async (helper) => {367 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});368 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});369 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});370 await expect(mintTokenTx()).to.be.rejected;371 });372 });373374 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by non-privileged and allow listed address', async () => {375 await usingPlaygrounds(async (helper) => {376 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});377 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});378 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});379 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});380 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);381 expect(owner.Substrate).to.be.equal(bob.address);382 });383 });384});