git.delta.rocks / unique-network / refs/commits / 3d71464e6bed

difftreelog

fix allowLists code style

rkv2022-09-14parent: #6804826.patch.diff
in: master

1 file changed

modifiedtests/src/allowLists.test.tsdiffbeforeafterboth
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
2// This file is part of Unique Network.2// This file is part of Unique Network.
33
4// Unique Network is free software: you can redistribute it and/or modify4// Unique Network is free software: you can redistribute itSub and/or modify
5// it under the terms of the GNU General Public License as published by5// itSub under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.7// (at your option) any later version.
88
9// Unique Network is distributed in the hope that it will be useful,9// Unique Network is distributed in the hope that itSub will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.12// GNU General Public License for more details.
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import chai from 'chai';18import {usingPlaygrounds, expect, itSub} from './util/playgrounds';
19import chaiAsPromised from 'chai-as-promised';
20import {usingPlaygrounds} from './util/playgrounds';
2119
22chai.use(chaiAsPromised);
23const expect = chai.expect;
24
25let donor: IKeyringPair;
26
27before(async () => {
28 await usingPlaygrounds(async (_, privateKey) => {
29 donor = privateKey('//Alice');
30 });
31});
32
33let alice: IKeyringPair;
34let bob: IKeyringPair;
35let charlie: IKeyringPair;
36
37describe('Integration Test ext. Allow list tests', () => {20describe('Integration Test ext. Allow list tests', () => {
21 let alice: IKeyringPair;
22 let bob: IKeyringPair;
23 let charlie: IKeyringPair;
3824
39 before(async () => {25 before(async () => {
40 await usingPlaygrounds(async (helper) => {26 await usingPlaygrounds(async (helper, privateKey) => {
27 const donor = privateKey('//Alice');
41 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);28 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
42 });29 });
43 });30 });
4431
45 it('Owner can add address to allow list', async () => {32 itSub('Owner can add address to allow list', async ({helper}) => {
46 await usingPlaygrounds(async (helper) => {
47 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});33 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
48 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});34 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
49 const allowList = await helper.nft.getAllowList(collectionId);35 const allowList = await helper.nft.getAllowList(collectionId);
50 expect(allowList).to.be.deep.contains({Substrate: bob.address});36 expect(allowList).to.be.deep.contains({Substrate: bob.address});
51 });
52 });37 });
5338
54 it('Admin can add address to allow list', async () => {39 itSub('Admin can add address to allow list', async ({helper}) => {
55 await usingPlaygrounds(async (helper) => {
56 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});40 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
57 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});41 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});
5842
59 await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});43 await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
60 const allowList = await helper.nft.getAllowList(collectionId);44 const allowList = await helper.nft.getAllowList(collectionId);
61 expect(allowList).to.be.deep.contains({Substrate: charlie.address});45 expect(allowList).to.be.deep.contains({Substrate: charlie.address});
62 });
63 });46 });
6447
65 it('Non-privileged user cannot add address to allow list', async () => {48 itSub('Non-privileged user cannot add address to allow list', async ({helper}) => {
66 await usingPlaygrounds(async (helper) => {
67 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});49 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});50 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
69 await expect(addToAllowListTx()).to.be.rejected;51 await expect(addToAllowListTx()).to.be.rejectedWith(/common\.NoPermission/);
70 });
71 });52 });
7253
73 it('Nobody can add address to allow list of non-existing collection', async () => {54 itSub('Nobody can add address to allow list of non-existing collection', async ({helper}) => {
74 const collectionId = (1<<32) - 1;55 const collectionId = (1<<32) - 1;
75 await usingPlaygrounds(async (helper) => {56 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
76 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
77 await expect(addToAllowListTx()).to.be.rejected;57 await expect(addToAllowListTx()).to.be.rejectedWith(/common\.CollectionNotFound/);
78 });
79 });58 });
8059
81 it('Nobody can add address to allow list of destroyed collection', async () => {60 itSub('Nobody can add address to allow list of destroyed collection', async ({helper}) => {
82 await usingPlaygrounds(async (helper) => {
83 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});61 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
84 await helper.collection.burn(alice, collectionId);62 await helper.collection.burn(alice, collectionId);
85 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});63 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
86 await expect(addToAllowListTx()).to.be.rejected;64 await expect(addToAllowListTx()).to.be.rejectedWith(/common\.CollectionNotFound/);
87 });
88 });65 });
8966
90 it('If address is already added to allow list, nothing happens', async () => {67 itSub('If address is already added to allow list, nothing happens', async ({helper}) => {
91 await usingPlaygrounds(async (helper) => {
92 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});68 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
93 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});69 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
94 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});70 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
95 const allowList = await helper.nft.getAllowList(collectionId);71 const allowList = await helper.nft.getAllowList(collectionId);
96 expect(allowList).to.be.deep.contains({Substrate: bob.address});72 expect(allowList).to.be.deep.contains({Substrate: bob.address});
97 });
98 });73 });
9974
100 it('Owner can remove address from allow list', async () => {75 itSub('Owner can remove address from allow list', async ({helper}) => {
101 await usingPlaygrounds(async (helper) => {
102 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});76 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
103 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});77 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
10478
105 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});79 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
10680
107 const allowList = await helper.nft.getAllowList(collectionId);81 const allowList = await helper.nft.getAllowList(collectionId);
10882
109 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});83 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});
110 });
111 });84 });
11285
113 it('Admin can remove address from allow list', async () => {86 itSub('Admin can remove address from allow list', async ({helper}) => {
114 await usingPlaygrounds(async (helper) => {
115 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});87 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
116 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});88 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});
117 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});89 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
118 await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});90 await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});
11991
120 const allowList = await helper.nft.getAllowList(collectionId);92 const allowList = await helper.nft.getAllowList(collectionId);
12193
122 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});94 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});
123 });
124 });95 });
12596
126 it('Non-privileged user cannot remove address from allow list', async () => {97 itSub('Non-privileged user cannot remove address from allow list', async ({helper}) => {
127 await usingPlaygrounds(async (helper) => {
128 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});98 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
129 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});99 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
130 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});100 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});
131 await expect(removeTx()).to.be.rejected;101 await expect(removeTx()).to.be.rejectedWith(/common\.NoPermission/);
132 const allowList = await helper.nft.getAllowList(collectionId);102 const allowList = await helper.nft.getAllowList(collectionId);
133103
134 expect(allowList).to.be.deep.contains({Substrate: charlie.address});104 expect(allowList).to.be.deep.contains({Substrate: charlie.address});
135 });
136 });105 });
137106
138 it('Nobody can remove address from allow list of non-existing collection', async () => {107 itSub('Nobody can remove address from allow list of non-existing collection', async ({helper}) => {
139 const collectionId = (1<<32) - 1;108 const collectionId = (1<<32) - 1;
140 await usingPlaygrounds(async (helper) => {109 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});
141 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});
142 await expect(removeTx()).to.be.rejected;110 await expect(removeTx()).to.be.rejectedWith(/common\.CollectionNotFound/);
143 });
144 });111 });
145112
146 it('Nobody can remove address from allow list of deleted collection', async () => {113 itSub('Nobody can remove address from allow list of deleted collection', async ({helper}) => {
147 await usingPlaygrounds(async (helper) => {
148 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});114 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
149 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});115 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
150 await helper.collection.burn(alice, collectionId);116 await helper.collection.burn(alice, collectionId);
151 const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});117 const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
152118
153 await expect(removeTx()).to.be.rejected;119 await expect(removeTx()).to.be.rejectedWith(/common\.CollectionNotFound/);
154 });
155 });120 });
156121
157 it('If address is already removed from allow list, nothing happens', async () => {122 itSub('If address is already removed from allow list, nothing happens', async ({helper}) => {
158 await usingPlaygrounds(async (helper) => {
159 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});123 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
160 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});124 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
161 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});125 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
162 const allowListBefore = await helper.nft.getAllowList(collectionId);126 const allowListBefore = await helper.nft.getAllowList(collectionId);
163 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});127 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});
164128
165 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});129 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
166130
167 const allowListAfter = await helper.nft.getAllowList(collectionId);131 const allowListAfter = await helper.nft.getAllowList(collectionId);
168 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});132 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});
169 });
170 });133 });
171134
172 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 () => {135 itSub('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test1', async ({helper}) => {
173 await usingPlaygrounds(async (helper) => {
174 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});136 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});137 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
176 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});138 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
177 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});139 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
178140
179 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});141 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
180 await expect(transferResult()).to.be.rejected;142 await expect(transferResult()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);
181 });
182 });143 });
183144
184 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 () => {145 itSub('If Public Access mode is set to AllowList, tokens can’t be transferred from a non-allowlisted address with transfer or transferFrom. Test2', async ({helper}) => {
185 await usingPlaygrounds(async (helper) => {
186 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});146 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});147 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
188 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});148 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
189 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});149 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
190 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});150 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
191 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});151 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
192 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});152 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});
193153
194 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});154 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
195 await expect(transferResult()).to.be.rejected;155 await expect(transferResult()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);
196 });
197 });156 });
198157
199 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 () => {158 itSub('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test1', async ({helper}) => {
200 await usingPlaygrounds(async (helper) => {
201 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});159 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});160 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
203 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});161 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
204 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});162 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
205163
206 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});164 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
207 await expect(transferResult()).to.be.rejected;165 await expect(transferResult()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);
208 });
209 });166 });
210167
211 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 () => {168 itSub('If Public Access mode is set to AllowList, tokens can’t be transferred to a non-allowlisted address with transfer or transferFrom. Test2', async ({helper}) => {
212 await usingPlaygrounds(async (helper) => {
213 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});169 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});170 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
215 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});171 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
216 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});172 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
217 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});173 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
218174
219 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});175 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
220 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});176 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});
221177
222 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});178 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
223 await expect(transferResult()).to.be.rejected;179 await expect(transferResult()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);
224 });
225 });180 });
226181
227 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 () => {182 itSub('If Public Access mode is set to AllowList, tokens can’t be destroyed by a non-allowlisted address (even if itSub owned them before enabling AllowList mode)', async ({helper}) => {
228 await usingPlaygrounds(async (helper) => {
229 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});183 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});184 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
231 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});185 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
232 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);186 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);
233 await expect(burnTx()).to.be.rejected;187 await expect(burnTx()).to.be.rejectedWith(/common\.NoPermission/);
234 });
235 });188 });
236189
237 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {190 itSub('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async ({helper}) => {
238 await usingPlaygrounds(async (helper) => {
239 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});191 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});192 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
241 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});193 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
242 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});194 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
243 await expect(approveTx()).to.be.rejected;195 await expect(approveTx()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);
244 });
245 });196 });
246197
247 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {198 itSub('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async ({helper}) => {
248 await usingPlaygrounds(async (helper) => {
249 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});199 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});200 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
251 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});201 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
252 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});202 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
253 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});203 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
254 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});204 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
255 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);205 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
256 expect(owner.Substrate).to.be.equal(charlie.address);206 expect(owner.Substrate).to.be.equal(charlie.address);
257 });
258 });207 });
259208
260 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async () => {209 itSub('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async ({helper}) => {
261 await usingPlaygrounds(async (helper) => {
262 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});210 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});211 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
264 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});212 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
265 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});213 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
266 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});214 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
267 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});215 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
268216
269 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});217 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
270 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);218 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
271 expect(owner.Substrate).to.be.equal(charlie.address);219 expect(owner.Substrate).to.be.equal(charlie.address);
272 });
273 });220 });
274221
275 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {222 itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async ({helper}) => {
276 await usingPlaygrounds(async (helper) => {
277 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});223 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});224 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
279 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});225 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
280 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});226 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
281 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});227 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
282228
283 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});229 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
284 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);230 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
285 expect(owner.Substrate).to.be.equal(charlie.address);231 expect(owner.Substrate).to.be.equal(charlie.address);
286 });
287 });232 });
288233
289 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {234 itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async ({helper}) => {
290 await usingPlaygrounds(async (helper) => {
291 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});235 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});236 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
293 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});237 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
294 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});238 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
295 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});239 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
296 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});240 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
297241
298 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});242 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
299 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);243 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
300 expect(owner.Substrate).to.be.equal(charlie.address);244 expect(owner.Substrate).to.be.equal(charlie.address);
301 });
302 });245 });
303246
304 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {247 itSub('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async ({helper}) => {
305 await usingPlaygrounds(async (helper) => {
306 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});248 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
307 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});249 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
308 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});250 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
309 const token = await helper.nft.getToken(collectionId, tokenId);251 const token = await helper.nft.getToken(collectionId, tokenId);
310 expect(token).to.be.not.null;252 expect(token).to.be.not.null;
311 });
312 });253 });
313254
314 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {255 itSub('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async ({helper}) => {
315 await usingPlaygrounds(async (helper) => {
316 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});256 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
317 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});257 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
318 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});258 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
319 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});259 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
320 const token = await helper.nft.getToken(collectionId, tokenId);260 const token = await helper.nft.getToken(collectionId, tokenId);
321 expect(token).to.be.not.null;261 expect(token).to.be.not.null;
322 });
323 });262 });
324263
325 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 () => {264 itSub('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 ({helper}) => {
326 await usingPlaygrounds(async (helper) => {
327 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});265 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
328 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});266 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
329 await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});267 await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});
330 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});268 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
331 await expect(mintTokenTx()).to.be.rejected;269 await expect(mintTokenTx()).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);
332 });
333 });270 });
334271
335 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 () => {272 itSub('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 ({helper}) => {
336 await usingPlaygrounds(async (helper) => {
337 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});273 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
338 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});274 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
339 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});275 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
340 await expect(mintTokenTx()).to.be.rejected;276 await expect(mintTokenTx()).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);
341 });
342 });277 });
343278
344 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {279 itSub('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async ({helper}) => {
345 await usingPlaygrounds(async (helper) => {
346 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});280 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
347 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});281 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
348 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});282 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
349 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);283 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
350 expect(owner.Substrate).to.be.equal(alice.address);284 expect(owner.Substrate).to.be.equal(alice.address);
351 });
352 });285 });
353286
354 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {287 itSub('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async ({helper}) => {
355 await usingPlaygrounds(async (helper) => {
356 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});288 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
357 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});289 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
358 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});290 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});
359 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});291 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
360 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);292 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
361 expect(owner.Substrate).to.be.equal(bob.address);293 expect(owner.Substrate).to.be.equal(bob.address);
362 });
363 });294 });
364295
365 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 () => {296 itSub('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 ({helper}) => {
366 await usingPlaygrounds(async (helper) => {
367 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});297 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
368 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});298 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
369 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});299 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
370 await expect(mintTokenTx()).to.be.rejected;300 await expect(mintTokenTx()).to.be.rejectedWith(/common\.AddressNotInAllowlist/);
371 });
372 });301 });
373302
374 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 () => {303 itSub('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 ({helper}) => {
375 await usingPlaygrounds(async (helper) => {
376 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});304 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
377 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});305 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
378 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});306 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
379 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});307 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
380 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);308 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
381 expect(owner.Substrate).to.be.equal(bob.address);309 expect(owner.Substrate).to.be.equal(bob.address);
382 });
383 });310 });
384});311});
385312