git.delta.rocks / unique-network / refs/commits / 7e1e685463e3

difftreelog

tests(allow-list): refactor overabundance of allow-list tests

Fahrrader2022-09-19parent: #065efcf.patch.diff
in: master

8 files changed

modifiedtests/package.jsondiffbeforeafterboth
48 "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",48 "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",
49 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",49 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
50 "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",50 "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",
51 "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",
52 "testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",51 "testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",
53 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",52 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
54 "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",53 "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",
64 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",63 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
65 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",64 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",
66 "testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",65 "testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",
67 "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",66 "testSetPermissions": "mocha --timeout 9999999 -r ts-node/register ./**/setPermissions.test.ts",
68 "testSetPublicAccessMode": "mocha --timeout 9999999 -r ts-node/register ./**/setPublicAccessMode.test.ts",
69 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",67 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
70 "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",68 "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",
71 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",69 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
deletedtests/src/addToAllowList.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/allowLists.test.tsdiffbeforeafterboth
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';19import {ICollectionPermissions} from './util/playgrounds/types';
2120
22chai.use(chaiAsPromised);21describe('Integration Test ext. Add to Allow List', () => {
22 let alice: IKeyringPair;
23const expect = chai.expect;23 let bob: IKeyringPair;
24 let charlie: IKeyringPair;
2425
25let donor: IKeyringPair;
26
27let alice: IKeyringPair;
28let bob: IKeyringPair;
29let charlie: IKeyringPair;
30
31describe('Integration Test ext. Allow list tests', () => {
32
33 before(async () => {26 before(async () => {
34 await usingPlaygrounds(async (helper, privateKey) => {27 await usingPlaygrounds(async (helper, privateKey) => {
35 donor = privateKey('//Alice');28 const donor = privateKey('//Alice');
36 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);29 [alice, bob, charlie] = await helper.arrange.createAccounts([30n, 10n, 10n], donor);
37 });30 });
38 });31 });
3932
40 it('Owner can add address to allow list', async () => {33 describe('Positive', async () => {
41 await usingPlaygrounds(async (helper) => {34 itSub('Owner can add address to allow list', async ({helper}) => {
42 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});35 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
36 // allow list does not need to be enabled to add someone in advance
43 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});37 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
44 const allowList = await helper.nft.getAllowList(collectionId);38 const allowList = await helper.nft.getAllowList(collectionId);
45 expect(allowList).to.be.deep.contains({Substrate: bob.address});39 expect(allowList).to.deep.contain({Substrate: bob.address});
46 });40 });
47 });41
48
49 it('Admin can add address to allow list', async () => {42 itSub('Admin can add address to allow list', async ({helper}) => {
50 await usingPlaygrounds(async (helper) => {
51 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});43 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
52 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});44 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});
5345
46 // allow list does not need to be enabled to add someone in advance
54 await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});47 await helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
55 const allowList = await helper.nft.getAllowList(collectionId);48 const allowList = await helper.nft.getAllowList(collectionId);
56 expect(allowList).to.be.deep.contains({Substrate: charlie.address});49 expect(allowList).to.deep.contain({Substrate: charlie.address});
57 });50 });
58 });
5951
60 it('Non-privileged user cannot add address to allow list', async () => {52 itSub('If address is already added to allow list, nothing happens', async ({helper}) => {
61 await usingPlaygrounds(async (helper) => {
62 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});53 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
63 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});54 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
55 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
64 await expect(addToAllowListTx()).to.be.rejected;56 const allowList = await helper.nft.getAllowList(collectionId);
57 expect(allowList).to.deep.contain({Substrate: bob.address});
65 });58 });
66 });59 });
6760
68 it('Nobody can add address to allow list of non-existing collection', async () => {61 describe('Negative', async () => {
62 itSub('Nobody can add address to allow list of non-existing collection', async ({helper}) => {
69 const collectionId = (1<<32) - 1;63 const collectionId = (1<<32) - 1;
70 await usingPlaygrounds(async (helper) => {64 await expect(helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}))
71 const addToAllowListTx = async () => helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address});
72 await expect(addToAllowListTx()).to.be.rejected;65 .to.be.rejectedWith(/common\.CollectionNotFound/);
73 });66 });
74 });67
75
76 it('Nobody can add address to allow list of destroyed collection', async () => {68 itSub('Nobody can add address to allow list of destroyed collection', async ({helper}) => {
77 await usingPlaygrounds(async (helper) => {
78 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});69 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
79 await helper.collection.burn(alice, collectionId);70 await helper.collection.burn(alice, collectionId);
80 const addToAllowListTx = async () => helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});71 await expect(helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address}))
81 await expect(addToAllowListTx()).to.be.rejected;72 .to.be.rejectedWith(/common\.CollectionNotFound/);
82 });73 });
83 });
8474
85 it('If address is already added to allow list, nothing happens', async () => {75 itSub('Non-privileged user cannot add address to allow list', async ({helper}) => {
86 await usingPlaygrounds(async (helper) => {
87 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'});
88 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});77 await expect(helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}))
89 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
90 const allowList = await helper.nft.getAllowList(collectionId);78 .to.be.rejectedWith(/common\.NoPermission/);
91 expect(allowList).to.be.deep.contains({Substrate: bob.address});
92 });79 });
93 });80 });
81});
9482
95 it('Owner can remove address from allow list', async () => {83describe('Integration Test ext. Remove from Allow List', () => {
84 let alice: IKeyringPair;
85 let bob: IKeyringPair;
86 let charlie: IKeyringPair;
87
88 before(async () => {
96 await usingPlaygrounds(async (helper) => {89 await usingPlaygrounds(async (helper, privateKey) => {
90 const donor = privateKey('//Alice');
91 [alice, bob, charlie] = await helper.arrange.createAccounts([30n, 10n, 10n], donor);
92 });
93 });
94
95 describe('Positive', async () => {
96 itSub('Owner can remove address from allow list', async ({helper}) => {
97 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});97 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
98 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});98 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
9999
100 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});100 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
101101
102 const allowList = await helper.nft.getAllowList(collectionId);102 const allowList = await helper.nft.getAllowList(collectionId);
103103
104 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});104 expect(allowList).to.not.deep.contain({Substrate: bob.address});
105 });105 });
106 });
107106
108 it('Admin can remove address from allow list', async () => {107 itSub('Admin can remove address from allow list', async ({helper}) => {
109 await usingPlaygrounds(async (helper) => {
110 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});108 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
111 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});109 await helper.nft.addAdmin(alice, collectionId, {Substrate: charlie.address});
112 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});110 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
113 await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});111 await helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: bob.address});
114112
115 const allowList = await helper.nft.getAllowList(collectionId);113 const allowList = await helper.nft.getAllowList(collectionId);
114 expect(allowList).to.not.deep.contain({Substrate: bob.address});
115 });
116116
117 expect(allowList).to.be.not.deep.contains({Substrate: bob.address});117 itSub('If address is already removed from allow list, nothing happens', async ({helper}) => {
118 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
119 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
120 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
121 const allowListBefore = await helper.nft.getAllowList(collectionId);
122 expect(allowListBefore).to.not.deep.contain({Substrate: bob.address});
123
124 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
125
126 const allowListAfter = await helper.nft.getAllowList(collectionId);
127 expect(allowListAfter).to.not.deep.contain({Substrate: bob.address});
118 });128 });
119 });129 });
120130
121 it('Non-privileged user cannot remove address from allow list', async () => {131 describe('Negative', async () => {
122 await usingPlaygrounds(async (helper) => {132 itSub('Non-privileged user cannot remove address from allow list', async ({helper}) => {
123 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});133 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
124 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});134 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
125 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});135 await expect(helper.collection.removeFromAllowList(charlie, collectionId, {Substrate: charlie.address}))
126 await expect(removeTx()).to.be.rejected;136 .to.be.rejectedWith(/common\.NoPermission/);
127 const allowList = await helper.nft.getAllowList(collectionId);
128137
129 expect(allowList).to.be.deep.contains({Substrate: charlie.address});138 const allowList = await helper.nft.getAllowList(collectionId);
139 expect(allowList).to.deep.contain({Substrate: charlie.address});
130 });140 });
131 });141
132
133 it('Nobody can remove address from allow list of non-existing collection', async () => {142 itSub('Nobody can remove address from allow list of non-existing collection', async ({helper}) => {
134 const collectionId = (1<<32) - 1;143 const collectionId = (1<<32) - 1;
135 await usingPlaygrounds(async (helper) => {144 await expect(helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address}))
136 const removeTx = async () => helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address});
137 await expect(removeTx()).to.be.rejected;145 .to.be.rejectedWith(/common\.CollectionNotFound/);
138 });146 });
139 });147
140
141 it('Nobody can remove address from allow list of deleted collection', async () => {148 itSub('Nobody can remove address from allow list of deleted collection', async ({helper}) => {
142 await usingPlaygrounds(async (helper) => {
143 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});149 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
144 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});150 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
145 await helper.collection.burn(alice, collectionId);151 await helper.collection.burn(alice, collectionId);
146 const removeTx = async () => helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});152
147153 await expect(helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address}))
148 await expect(removeTx()).to.be.rejected;154 .to.be.rejectedWith(/common\.CollectionNotFound/);
149 });155 });
150 });156 });
157});
151158
152 it('If address is already removed from allow list, nothing happens', async () => {159describe('Integration Test ext. Transfer if included in Allow List', () => {
153 await usingPlaygrounds(async (helper) => {
154 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});160 let alice: IKeyringPair;
155 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});161 let bob: IKeyringPair;
156 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});
157 const allowListBefore = await helper.nft.getAllowList(collectionId);162 let charlie: IKeyringPair;
158 expect(allowListBefore).to.be.not.deep.contains({Substrate: bob.address});
159163
160 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: bob.address});164 before(async () => {
161165 await usingPlaygrounds(async (helper, privateKey) => {
162 const allowListAfter = await helper.nft.getAllowList(collectionId);166 const donor = privateKey('//Alice');
163 expect(allowListAfter).to.be.not.deep.contains({Substrate: bob.address});167 [alice, bob, charlie] = await helper.arrange.createAccounts([30n, 10n, 10n], donor);
164 });168 });
165 });169 });
166170
167 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 () => {171 describe('Positive', async () => {
168 await usingPlaygrounds(async (helper) => {172 itSub('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async ({helper}) => {
169 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});173 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
170 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});174 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
171 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});175 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
176 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
172 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});177 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
173
174 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});178 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
175 await expect(transferResult()).to.be.rejected;179 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
180 expect(owner.Substrate).to.be.equal(charlie.address);
176 });181 });
177 });182
178
179 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 () => {183 itSub('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async ({helper}) => {
180 await usingPlaygrounds(async (helper) => {
181 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});184 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
182 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});185 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
183 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});186 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
184 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});187 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
185 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});188 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
186 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});189 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
187 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});190
188191 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
189 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});192 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
190 await expect(transferResult()).to.be.rejected;193 expect(owner.Substrate).to.be.equal(charlie.address);
191 });194 });
192 });195
193
194 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 () => {196 itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async ({helper}) => {
195 await usingPlaygrounds(async (helper) => {
196 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});197 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
197 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});198 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
198 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});199 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
199 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});200 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
200
201 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});201 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
202
203 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
202 await expect(transferResult()).to.be.rejected;204 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
205 expect(owner.Substrate).to.be.equal(charlie.address);
203 });206 });
204 });207
205
206 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 () => {208 itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async ({helper}) => {
207 await usingPlaygrounds(async (helper) => {
208 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});209 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
209 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});210 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
210 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});211 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
211 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});212 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
212 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});213 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
213
214 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});214 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
215 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});215
216216 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
217 const transferResult = async () => helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});217 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
218 await expect(transferResult()).to.be.rejected;218 expect(owner.Substrate).to.be.equal(charlie.address);
219 });219 });
220 });220 });
221221
222 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 () => {222 describe('Negative', async () => {
223 await usingPlaygrounds(async (helper) => {223 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}) => {
224 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});224 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
225 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});225 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
226 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});226 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
227 const burnTx = async () => helper.nft.burnToken(bob, collectionId, tokenId);227 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
228
229 await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}))
228 await expect(burnTx()).to.be.rejected;230 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);
229 });231 });
230 });232
231
232 it('If Public Access mode is set to AllowList, token transfers can’t be Approved by a non-allowlisted address (see Approve method)', async () => {233 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}) => {
233 await usingPlaygrounds(async (helper) => {
234 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});234 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
235 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});235 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
236 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});236 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
237 const approveTx = async () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});237 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
238 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
239 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
238 await expect(approveTx()).to.be.rejected;240 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});
241
242 await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}))
243 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);
239 });244 });
240 });245
241
242 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transfer.', async () => {246 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}) => {
243 await usingPlaygrounds(async (helper) => {
244 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});247 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
245 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});248 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
246 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});249 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
247 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});250 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
248 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});251
249 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});252 await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}))
250 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);253 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);
251 expect(owner.Substrate).to.be.equal(charlie.address);
252 });254 });
253 });255
254
255 it('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async () => {256 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}) => {
256 await usingPlaygrounds(async (helper) => {
257 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});257 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
258 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});258 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
259 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});259 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
260 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});260 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});
261 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});261 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
262
262 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});263 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
263
264 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});264 await helper.collection.removeFromAllowList(alice, collectionId, {Substrate: alice.address});
265 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);265
266 await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address}))
266 expect(owner.Substrate).to.be.equal(charlie.address);267 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);
267 });268 });
268 });269
269
270 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async () => {270 itSub('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 ({helper}) => {
271 await usingPlaygrounds(async (helper) => {
272 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});271 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
273 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});272 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
274 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});273 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
275 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});274 await expect(helper.nft.burnToken(bob, collectionId, tokenId))
276 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
277
278 await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
279 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);275 .to.be.rejectedWith(/common\.NoPermission/);
280 expect(owner.Substrate).to.be.equal(charlie.address);
281 });276 });
282 });277
283
284 it('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async () => {278 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}) => {
285 await usingPlaygrounds(async (helper) => {
286 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});279 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
287 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});280 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
288 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});281 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList'});
289 await helper.nft.addToAllowList(alice, collectionId, {Substrate: alice.address});282 await expect(helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}))
290 await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
291 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
292
293 await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
294 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);283 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);
295 expect(owner.Substrate).to.be.equal(charlie.address);
296 });284 });
297 });285 });
286});
298287
299 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by owner', async () => {288describe('Integration Test ext. Mint if included in Allow List', () => {
300 await usingPlaygrounds(async (helper) => {
301 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});289 let alice: IKeyringPair;
302 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});290 let bob: IKeyringPair;
303 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
304 const token = await helper.nft.getToken(collectionId, tokenId);
305 expect(token).to.be.not.null;
306 });
307 });
308291
309 it('If Public Access mode is set to AllowList, and Mint Permission is set to false, tokens can be created by admin', async () => {292 before(async () => {
310 await usingPlaygrounds(async (helper) => {293 await usingPlaygrounds(async (helper, privateKey) => {
311 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});294 const donor = privateKey('//Alice');
312 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});295 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
313 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
314 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
315 const token = await helper.nft.getToken(collectionId, tokenId);
316 expect(token).to.be.not.null;
317 });296 });
318 });297 });
319298
320 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 () => {299 const permissionSet: ICollectionPermissions[] = [
321 await usingPlaygrounds(async (helper) => {300 {access: 'Normal', mintMode: false},
322 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});301 {access: 'Normal', mintMode: true},
323 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});302 {access: 'AllowList', mintMode: false},
324 await helper.collection.addToAllowList(alice, collectionId, {Substrate: bob.address});
325 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});303 {access: 'AllowList', mintMode: true},
326 await expect(mintTokenTx()).to.be.rejected;304 ];
327 });
328 });
329305
330 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 () => {306 const testPermissionSuite = async (permissions: ICollectionPermissions) => {
331 await usingPlaygrounds(async (helper) => {
332 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});307 const allowlistedMintingShouldFail = !permissions.mintMode!;
333 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: false});
334 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});
335 await expect(mintTokenTx()).to.be.rejected;
336 });
337 });
338308
339 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by owner', async () => {309 const appropriateRejectionMessage = permissions.mintMode! ? /common\.AddressNotInAllowlist/ : /common\.PublicMintingNotAllowed/;
340 await usingPlaygrounds(async (helper) => {
341 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
342 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});
343 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
344 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
345 expect(owner.Substrate).to.be.equal(alice.address);
346 });
347 });
348310
349 it('If Public Access mode is set to AllowList, and Mint Permission is set to true, tokens can be created by admin', async () => {311 const allowlistedMintingTest = () => itSub(
312 `With the condtions above, tokens can${allowlistedMintingShouldFail ? '\'t' : ''} be created by allow-listed addresses`,
350 await usingPlaygrounds(async (helper) => {313 async ({helper}) => {
351 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});314 const collection = await helper.nft.mintCollection(alice, {});
352 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});315 await collection.setPermissions(alice, permissions);
353 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});
354 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});316 await collection.addToAllowList(alice, {Substrate: bob.address});
355 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
356 expect(owner.Substrate).to.be.equal(bob.address);
357 });
358 });
359317
360 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 () => {318 if (allowlistedMintingShouldFail)
361 await usingPlaygrounds(async (helper) => {319 await expect(collection.mintToken(bob, {Substrate: bob.address})).to.be.rejectedWith(appropriateRejectionMessage);
362 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
363 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});320 else
364 const mintTokenTx = async () => helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});321 await expect(collection.mintToken(bob, {Substrate: bob.address})).to.not.be.rejected;
365 await expect(mintTokenTx()).to.be.rejected;
366 });322 },
367 });323 );
368324
325
369 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 () => {326 describe(`Public Access Mode = ${permissions.access}, Mint Mode = ${permissions.mintMode}`, async () => {
327 describe('Positive', async () => {
370 await usingPlaygrounds(async (helper) => {328 itSub('With the condtions above, tokens can be created by owner', async ({helper}) => {
371 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});329 const collection = await helper.nft.mintCollection(alice, {});
330 await collection.setPermissions(alice, permissions);
331 await expect(collection.mintToken(alice, {Substrate: alice.address})).to.not.be.rejected;
332 });
333
334 itSub('With the condtions above, tokens can be created by admin', async ({helper}) => {
372 await helper.nft.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true});335 const collection = await helper.nft.mintCollection(alice, {});
336 await collection.setPermissions(alice, permissions);
337 await collection.addAdmin(alice, {Substrate: bob.address});
373 await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});338 await expect(collection.mintToken(bob, {Substrate: bob.address})).to.not.be.rejected;
374 const {tokenId} = await helper.nft.mintToken(bob, {collectionId: collectionId, owner: bob.address});339 });
340
341 if (!allowlistedMintingShouldFail) allowlistedMintingTest();
342 });
343
344 describe('Negative', async () => {
345 itSub('With the condtions above, tokens can\'t be created by non-priviliged non-allow-listed address', async ({helper}) => {
346 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
375 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);347 await collection.setPermissions(alice, permissions);
376 expect(owner.Substrate).to.be.equal(bob.address);348 await expect(collection.mintToken(bob, {Substrate: bob.address}))
349 .to.be.rejectedWith(appropriateRejectionMessage);
350 });
351
352 if (allowlistedMintingShouldFail) allowlistedMintingTest();
353 });
377 });354 });
378 });355 };
356
357 for (const permissions of permissionSet) {
358 testPermissionSuite(permissions);
359 }
379});360});
380361
deletedtests/src/mintModes.test.tsdiffbeforeafterboth

no changes

deletedtests/src/removeFromAllowList.test.tsdiffbeforeafterboth

no changes

deletedtests/src/setMintPermission.test.tsdiffbeforeafterboth

no changes

addedtests/src/setPermissions.test.tsdiffbeforeafterboth

no changes

deletedtests/src/setPublicAccessMode.test.tsdiffbeforeafterboth

no changes