git.delta.rocks / unique-network / refs/commits / b1123c37498f

difftreelog

allowLists migrated

rkv2022-09-07parent: #0335e51.patch.diff
in: master

1 file changed

modifiedtests/src/allowLists.test.tsdiffbeforeafterboth
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import chai from 'chai';18import chai from 'chai';
19import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';
20import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';20import { usingPlaygrounds } from './util/playgrounds';
21import {
22 addToAllowListExpectSuccess,
23 createCollectionExpectSuccess,
24 createItemExpectSuccess,
25 destroyCollectionExpectSuccess,
26 enableAllowListExpectSuccess,
27 normalizeAccountId,
28 addCollectionAdminExpectSuccess,
29 addToAllowListExpectFail,
30 removeFromAllowListExpectSuccess,
31 removeFromAllowListExpectFailure,
32 addToAllowListAgainExpectSuccess,
33 transferExpectFailure,
34 approveExpectSuccess,
35 approveExpectFail,
36 transferExpectSuccess,
37 transferFromExpectSuccess,
38 setMintPermissionExpectSuccess,
39 createItemExpectFailure,
40} from './util/helpers';
4121
42chai.use(chaiAsPromised);22chai.use(chaiAsPromised);
43const expect = chai.expect;23const expect = chai.expect;
4424
25let donor: IKeyringPair;
26
27before(async () => {
28 await usingPlaygrounds(async (_, privateKeyWrapper) => {
29 donor = privateKeyWrapper('//Alice');
30 });
31});
32
45let alice: IKeyringPair;33let alice: IKeyringPair;
46let bob: IKeyringPair;34let bob: IKeyringPair;
47let charlie: IKeyringPair;35let charlie: IKeyringPair;
4836
49describe('Integration Test ext. Allow list tests', () => {37describe('Integration Test ext. Allow list tests', () => {
5038
51 before(async () => {39 before(async () => {
52 await usingApi(async (api, privateKeyWrapper) => {40 await usingPlaygrounds(async (helper) => {
53 alice = privateKeyWrapper('//Alice');41 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
54 bob = privateKeyWrapper('//Bob');
55 charlie = privateKeyWrapper('//Charlie');
56 });42 });
57 });43 });
5844
59 it('Owner can add address to allow list', async () => {45 it('Owner can add address to allow list', async () => {
60 const collectionId = await createCollectionExpectSuccess();46 await usingPlaygrounds(async (helper) => {
47 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
61 await addToAllowListExpectSuccess(alice, collectionId, bob.address);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 });
62 });52 });
6353
64 it('Admin can add address to allow list', async () => {54 it('Admin can add address to allow list', async () => {
65 const collectionId = await createCollectionExpectSuccess();55 await usingPlaygrounds(async (helper) => {
56 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
66 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);57 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});
58
67 await addToAllowListExpectSuccess(bob, collectionId, charlie.address);59 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 });
68 });63 });
6964
70 it('Non-privileged user cannot add address to allow list', async () => {65 it('Non-privileged user cannot add address to allow list', async () => {
71 const collectionId = await createCollectionExpectSuccess();66 await usingPlaygrounds(async (helper) => {
67 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
72 await addToAllowListExpectFail(bob, collectionId, charlie.address);68 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
69 expect(addToAllowListTx()).to.be.rejected;
70 });
73 });71 });
7472
75 it('Nobody can add address to allow list of non-existing collection', async () => {73 it('Nobody can add address to allow list of non-existing collection', async () => {
76 const collectionId = (1<<32) - 1;74 const collectionId = (1<<32) - 1;
77 await addToAllowListExpectFail(alice, collectionId, bob.address);75 await usingPlaygrounds(async (helper) => {
76 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
77 expect(addToAllowListTx()).to.be.rejected;
78 });
78 });79 });
7980
80 it('Nobody can add address to allow list of destroyed collection', async () => {81 it('Nobody can add address to allow list of destroyed collection', async () => {
81 const collectionId = await createCollectionExpectSuccess();82 await usingPlaygrounds(async (helper) => {
83 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
82 await destroyCollectionExpectSuccess(collectionId, '//Alice');84 await helper.collection.burn(alice, collectionId);
83 await addToAllowListExpectFail(alice, collectionId, bob.address);85 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
86 expect(addToAllowListTx()).to.be.rejected;
87 });
84 });88 });
8589
86 it('If address is already added to allow list, nothing happens', async () => {90 it('If address is already added to allow list, nothing happens', async () => {
87 const collectionId = await createCollectionExpectSuccess();91 await usingPlaygrounds(async (helper) => {
92 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
88 await addToAllowListExpectSuccess(alice, collectionId, bob.address);93 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
89 await addToAllowListAgainExpectSuccess(alice, collectionId, 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 });
90 });98 });
9199
92 it('Owner can remove address from allow list', async () => {100 it('Owner can remove address from allow list', async () => {
93 const collectionId = await createCollectionExpectSuccess();101 await usingPlaygrounds(async (helper) => {
102 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
94 await addToAllowListExpectSuccess(alice, collectionId, bob.address);103 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
104
95 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob));105 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
106 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);
107
108 const allowList = await helper.nft.getAllowList(collectionId);
109
110 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});
111 });
96 });112 });
97113
98 it('Admin can remove address from allow list', async () => {114 it('Admin can remove address from allow list', async () => {
99 const collectionId = await createCollectionExpectSuccess();115 await usingPlaygrounds(async (helper) => {
116 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
100 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);117 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});
101 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);118 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
102 await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie));119 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
120 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(charlie);
121
122 const allowList = await helper.nft.getAllowList(collectionId);
123
124 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});
125 });
103 });126 });
104127
105 it('Non-privileged user cannot remove address from allow list', async () => {128 it('Non-privileged user cannot remove address from allow list', async () => {
106 const collectionId = await createCollectionExpectSuccess();129 await usingPlaygrounds(async (helper) => {
130 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
107 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);131 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
108 await removeFromAllowListExpectFailure(bob, collectionId, normalizeAccountId(charlie));132 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
133 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: charlie.address}).signAndSend(bob);
134
135 const allowList = await helper.nft.getAllowList(collectionId);
136
137 expect(allowList).to.be.deep.contains({Substrate: charlie.address});
138 });
109 });139 });
110140
111 it('Nobody can remove address from allow list of non-existing collection', async () => {141 it('Nobody can remove address from allow list of non-existing collection', async () => {
112 const collectionId = (1<<32) - 1;142 const collectionId = (1<<32) - 1;
113 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));143 await usingPlaygrounds(async (helper) => {
144 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
145 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: charlie.address}).signAndSend(bob);
146
147 const allowList = await helper.nft.getAllowList(collectionId);
148
149 expect(allowList).to.be.not.deep.contains({Substrate: charlie.address});
150 });
114 });151 });
115152
116 it('Nobody can remove address from allow list of deleted collection', async () => {153 it('Nobody can remove address from allow list of deleted collection', async () => {
117 const collectionId = await createCollectionExpectSuccess();154 await usingPlaygrounds(async (helper) => {
155 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
118 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);156 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
119 await destroyCollectionExpectSuccess(collectionId, '//Alice');157 await helper.collection.burn(alice, collectionId);
158
159 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
120 await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(charlie));160 const removeTx = async () => helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);
161
162 expect(removeTx()).to.be.rejected;
163 });
121 });164 });
122165
123 it('If address is already removed from allow list, nothing happens', async () => {166 it('If address is already removed from allow list, nothing happens', async () => {
124 const collectionId = await createCollectionExpectSuccess();167 await usingPlaygrounds(async (helper) => {
168 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
125 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);169 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
170
126 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));171 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
172 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);
173 const allowListBefore = await helper.nft.getAllowList(collectionId);
174 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});
175
127 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(charlie));176 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: bob.address}).signAndSend(alice);
177
178 const allowListAfter = await helper.nft.getAllowList(collectionId);
179 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});
180 });
128 });181 });
129182
130 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 () => {183 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 () => {
131 const collectionId = await createCollectionExpectSuccess();184 await usingPlaygrounds(async (helper) => {
185 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
132 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);186 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
133 await enableAllowListExpectSuccess(alice, collectionId);187 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
134 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);188 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
135189
136 await transferExpectFailure(190 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
137 collectionId,
138 itemId,
139 alice,
140 charlie,
141 1,191 expect(transferResult()).to.be.rejected;
142 );192 });
143 });193 });
144194
145 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 () => {195 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 () => {
146 const collectionId = await createCollectionExpectSuccess();196 await usingPlaygrounds(async (helper) => {
147 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);197 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
148 await enableAllowListExpectSuccess(alice, collectionId);198 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
149 await addToAllowListExpectSuccess(alice, collectionId, alice.address);199 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
150 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);200 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
151 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);201 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
152 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));202 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
153203
154 await transferExpectFailure(204 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
155 collectionId,205 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: alice.address}).signAndSend(alice);
206
156 itemId,207 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
157 alice,
158 charlie,
159 1,208 expect(transferResult()).to.be.rejected;
160 );209 });
161 });210 });
162211
163 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 () => {212 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 () => {
164 const collectionId = await createCollectionExpectSuccess();213 await usingPlaygrounds(async (helper) => {
214 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
165 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);215 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
166 await enableAllowListExpectSuccess(alice, collectionId);216 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
167 await addToAllowListExpectSuccess(alice, collectionId, alice.address);217 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
168218
169 await transferExpectFailure(219 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
170 collectionId,
171 itemId,
172 alice,
173 charlie,
174 1,220 expect(transferResult()).to.be.rejected;
175 );221 });
176 });222 });
177223
178 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 () => {224 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 () => {
179 const collectionId = await createCollectionExpectSuccess();225 await usingPlaygrounds(async (helper) => {
180 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);226 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
181 await enableAllowListExpectSuccess(alice, collectionId);227 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
182 await addToAllowListExpectSuccess(alice, collectionId, alice.address);
183 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);228 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
184 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);229 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
185 await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(alice));230 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
186231
187 await transferExpectFailure(232 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
233
188 collectionId,234 //FIXME: removeFromAllowList doesn't not implemented in unique helpers yet. Change to helper later.
189 itemId,235 await helper.api?.tx.unique.removeFromAllowList(collectionId, {Substrate: alice.address}).signAndSend(alice);
236
190 alice,237 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
191 charlie,
192 1,238 expect(transferResult()).to.be.rejected;
193 );239 });
194 });240 });
195241
196 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 () => {242 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 () => {
197 const collectionId = await createCollectionExpectSuccess();243 await usingPlaygrounds(async (helper) => {
198 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);244 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
199 await enableAllowListExpectSuccess(alice, collectionId);245 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
200
201 await usingApi(async (api) => {
202 const tx = api.tx.unique.burnItem(collectionId, itemId, /*normalizeAccountId(Alice.address),*/ 11);246 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
203 const badTransaction = async function () {247 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);
204 await submitTransactionExpectFailAsync(alice, tx);
205 };248 expect(burnTx()).to.be.rejected;
206 await expect(badTransaction()).to.be.rejected;
207 });249 });
208 });250 });
209251
210 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {252 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {
211 const collectionId = await createCollectionExpectSuccess();253 await usingPlaygrounds(async (helper) => {
254 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
212 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);255 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
213 await enableAllowListExpectSuccess(alice, collectionId);256 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
214 await approveExpectFail(collectionId, itemId, alice, bob);257 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
258 await expect(approveTx()).to.be.rejected;
259 });
215 });260 });
216261
217 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {262 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {
218 const collectionId = await createCollectionExpectSuccess();263 await usingPlaygrounds(async (helper) => {
264 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
219 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);265 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
220 await enableAllowListExpectSuccess(alice, collectionId);266 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
221 await addToAllowListExpectSuccess(alice, collectionId, alice.address);267 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
222 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);268 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
223 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');269 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
270 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
271 expect(owner.Substrate).to.be.equal(charlie.address);
272 });
224 });273 });
225274
226 it('If Public Access mode is set to AllowList, tokens can be transferred to a alowlisted address with transferFrom.', async () => {275 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async () => {
227 const collectionId = await createCollectionExpectSuccess();276 await usingPlaygrounds(async (helper) => {
277 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
228 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);278 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
229 await enableAllowListExpectSuccess(alice, collectionId);279 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
230 await addToAllowListExpectSuccess(alice, collectionId, alice.address);280 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
231 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);281 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
232 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);282 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
283
233 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');284 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
285 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
286 expect(owner.Substrate).to.be.equal(charlie.address);
287 });
234 });288 });
235289
236 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {290 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {
237 const collectionId = await createCollectionExpectSuccess();291 await usingPlaygrounds(async (helper) => {
292 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
238 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);293 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
239 await enableAllowListExpectSuccess(alice, collectionId);294 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
240 await addToAllowListExpectSuccess(alice, collectionId, alice.address);295 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
241 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);296 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
297
242 await transferExpectSuccess(collectionId, itemId, alice, charlie, 1, 'NFT');298 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
299 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
300 expect(owner.Substrate).to.be.equal(charlie.address);
301 });
243 });302 });
244303
245 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {304 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {
246 const collectionId = await createCollectionExpectSuccess();305 await usingPlaygrounds(async (helper) => {
306 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
247 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);307 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
248 await enableAllowListExpectSuccess(alice, collectionId);308 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
249 await addToAllowListExpectSuccess(alice, collectionId, alice.address);309 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
250 await addToAllowListExpectSuccess(alice, collectionId, charlie.address);310 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
251 await approveExpectSuccess(collectionId, itemId, alice, charlie.address);311 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
312
252 await transferFromExpectSuccess(collectionId, itemId, alice, alice, charlie, 1, 'NFT');313 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
314 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
315 expect(owner.Substrate).to.be.equal(charlie.address);
316 });
253 });317 });
254318
255 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {319 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {
256 const collectionId = await createCollectionExpectSuccess();320 await usingPlaygrounds(async (helper) => {
321 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
257 await enableAllowListExpectSuccess(alice, collectionId);322 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
258 await setMintPermissionExpectSuccess(alice, collectionId, false);323 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
259 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);324 const token = await helper.nft.getToken(collectionId, tokenId);
325 expect(token).to.be.not.null;
326 });
260 });327 });
261328
262 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {329 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {
263 const collectionId = await createCollectionExpectSuccess();330 await usingPlaygrounds(async (helper) => {
331 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
264 await enableAllowListExpectSuccess(alice, collectionId);332 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
265 await setMintPermissionExpectSuccess(alice, collectionId, false);333 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
266 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);334 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
267 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);335 const token = await helper.nft.getToken(collectionId, tokenId);
336 expect(token).to.be.not.null;
337 });
268 });338 });
269339
270 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 () => {340 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 () => {
271 const collectionId = await createCollectionExpectSuccess();341 await usingPlaygrounds(async (helper) => {
272 await enableAllowListExpectSuccess(alice, collectionId);342 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
273 await setMintPermissionExpectSuccess(alice, collectionId, false);343 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
274 await addToAllowListExpectSuccess(alice, collectionId, bob.address);344 await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});
275 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);345 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
346 await expect(mintTokenTx()).to.be.rejected;
347 });
276 });348 });
277349
278 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 () => {350 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 () => {
279 const collectionId = await createCollectionExpectSuccess();351 await usingPlaygrounds(async (helper) => {
280 await enableAllowListExpectSuccess(alice, collectionId);352 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
281 await setMintPermissionExpectSuccess(alice, collectionId, false);353 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
282 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);354 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
355 await expect(mintTokenTx()).to.be.rejected;
356 });
283 });357 });
284358
285 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {359 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {
286 const collectionId = await createCollectionExpectSuccess();360 await usingPlaygrounds(async (helper) => {
361 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
287 await enableAllowListExpectSuccess(alice, collectionId);362 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
288 await setMintPermissionExpectSuccess(alice, collectionId, true);363 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
289 await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);364 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
365 expect(owner.Substrate).to.be.equal(alice.address);
366 });
290 });367 });
291368
292 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {369 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {
293 const collectionId = await createCollectionExpectSuccess();370 await usingPlaygrounds(async (helper) => {
371 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
294 await enableAllowListExpectSuccess(alice, collectionId);372 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
295 await setMintPermissionExpectSuccess(alice, collectionId, true);373 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});
296 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);374 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
297 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);375 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
376 expect(owner.Substrate).to.be.equal(bob.address);
377 });
298 });378 });
299379
300 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 () => {380 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 () => {
301 const collectionId = await createCollectionExpectSuccess();381 await usingPlaygrounds(async (helper) => {
302 await enableAllowListExpectSuccess(alice, collectionId);382 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
303 await setMintPermissionExpectSuccess(alice, collectionId, true);383 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
304 await createItemExpectFailure(bob, collectionId, 'NFT', bob.address);384 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
385 await expect(mintTokenTx()).to.be.rejected;
386 });
305 });387 });
306388
307 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 () => {389 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 () => {
308 const collectionId = await createCollectionExpectSuccess();390 await usingPlaygrounds(async (helper) => {
391 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
309 await enableAllowListExpectSuccess(alice, collectionId);392 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
310 await setMintPermissionExpectSuccess(alice, collectionId, true);393 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
311 await addToAllowListExpectSuccess(alice, collectionId, bob.address);394 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
312 await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);395 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
396 expect(owner.Substrate).to.be.equal(bob.address);
397 });
313 });398 });
314});399});
315400