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

difftreelog

CORE-160. Collection admin integration tests

str-mv2021-07-29parent: #cd2e9c1.patch.diff
in: master

23 files changed

modifiedtests/src/addToWhiteList.test.tsdiffbeforeafterboth
16 enablePublicMintingExpectSuccess,16 enablePublicMintingExpectSuccess,
17 enableWhiteListExpectSuccess,17 enableWhiteListExpectSuccess,
18 normalizeAccountId,18 normalizeAccountId,
19 addCollectionAdminExpectSuccess,
19} from './util/helpers';20} from './util/helpers';
2021
21chai.use(chaiAsPromised);22chai.use(chaiAsPromised);
22const expect = chai.expect;23const expect = chai.expect;
2324
24let Alice: IKeyringPair;25let Alice: IKeyringPair;
25let Bob: IKeyringPair;26let Bob: IKeyringPair;
27let Charlie: IKeyringPair;
2628
27describe('Integration Test ext. addToWhiteList()', () => {29describe('Integration Test ext. addToWhiteList()', () => {
2830
8688
87});89});
8890
91describe('Integration Test ext. addToWhiteList() with collection admin permissions:', () => {
92
93 before(async () => {
94 await usingApi(async () => {
95 Alice = privateKey('//Alice');
96 Bob = privateKey('//Bob');
97 Charlie = privateKey('//Charlie');
98 });
99 });
100
101 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
102 const collectionId = await createCollectionExpectSuccess();
103 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
104 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);
105 });
106
107 it('Whitelisted minting: list restrictions', async () => {
108 const collectionId = await createCollectionExpectSuccess();
109 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
110 await addToWhiteListExpectSuccess(Bob, collectionId, Charlie.address);
111
112 // allowed only for collection owner
113 await enableWhiteListExpectSuccess(Alice, collectionId);
114 await enablePublicMintingExpectSuccess(Alice, collectionId);
115
116 await createItemExpectSuccess(Charlie, collectionId, 'NFT', Charlie.address);
117 });
118});
modifiedtests/src/approve.test.tsdiffbeforeafterboth
16 destroyCollectionExpectSuccess,16 destroyCollectionExpectSuccess,
17 setCollectionLimitsExpectSuccess,17 setCollectionLimitsExpectSuccess,
18 transferExpectSuccess,18 transferExpectSuccess,
19 addCollectionAdminExpectSuccess,
19} from './util/helpers';20} from './util/helpers';
2021
21chai.use(chaiAsPromised);22chai.use(chaiAsPromised);
178 });179 });
179});180});
181
182describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {
183 let Alice: IKeyringPair;
184 let Bob: IKeyringPair;
185 let Charlie: IKeyringPair;
186
187 before(async () => {
188 await usingApi(async () => {
189 Alice = privateKey('//Alice');
190 Bob = privateKey('//Bob');
191 Charlie = privateKey('//Charlie');
192 });
193 });
194
195 it('can be called by collection admin on non-owned item', async () => {
196 const collectionId = await createCollectionExpectSuccess();
197 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);
198
199 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
200 await approveExpectSuccess(collectionId, itemId, Bob, Charlie);
201 });
202});
180203
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
12 getGenericResult,12 getGenericResult,
13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,
14 normalizeAccountId,14 normalizeAccountId,
15 addCollectionAdminExpectSuccess,
15} from './util/helpers';16} from './util/helpers';
1617
17import chai from 'chai';18import chai from 'chai';
136136
137});137});
138
139describe('integration test: ext. burnItem() with admin permissions:', () => {
140 before(async () => {
141 await usingApi(async () => {
142 const keyring = new Keyring({ type: 'sr25519' });
143 alice = keyring.addFromUri('//Alice');
144 bob = keyring.addFromUri('//Bob');
145 });
146 });
147
148 it('Burn item in NFT collection', async () => {
149 const createMode = 'NFT';
150 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
151 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
152 await addCollectionAdminExpectSuccess(alice, collectionId, bob);
153
154 await usingApi(async (api) => {
155 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
156 const events = await submitTransactionAsync(bob, tx);
157 const result = getGenericResult(events);
158 // Get the item
159 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
160 // What to expect
161 // tslint:disable-next-line:no-unused-expression
162 expect(result.success).to.be.true;
163 // tslint:disable-next-line:no-unused-expression
164 expect(item).to.be.null;
165 });
166 });
167});
138168
139describe('Negative integration test: ext. burnItem():', () => {169describe('Negative integration test: ext. burnItem():', () => {
140 before(async () => {170 before(async () => {
modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';
8import privateKey from './substrate/privateKey';8import privateKey from './substrate/privateKey';
9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';9import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
10import { createCollectionExpectSuccess } from './util/helpers';10import { createCollectionExpectSuccess, addCollectionAdminExpectSuccess } from './util/helpers';
1111
12chai.use(chaiAsPromised);12chai.use(chaiAsPromised);
13const expect = chai.expect;13const expect = chai.expect;
49 });49 });
50 });50 });
51
52 it('Collection admin can\'t change owner.', async () => {
53 await usingApi(async api => {
54 const collectionId = await createCollectionExpectSuccess();
55 const alice = privateKey('//Alice');
56 const bob = privateKey('//Bob');
57
58 await addCollectionAdminExpectSuccess(alice, collectionId, bob);
59
60 const changeOwnerTx = api.tx.nft.changeCollectionOwner(collectionId, bob.address);
61 await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
62
63 const collectionAfterOwnerChange: any = (await api.query.nft.collectionById(collectionId)).toJSON();
64 expect(collectionAfterOwnerChange.Owner).to.be.deep.eq(alice.address);
65
66 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
67 await createCollectionExpectSuccess();
68 });
69 });
70
51 it('Can\'t change owner of a non-existing collection.', async () => {71 it('Can\'t change owner of a non-existing collection.', async () => {
52 await usingApi(async api => {72 await usingApi(async api => {
modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
19 enablePublicMintingExpectSuccess,19 enablePublicMintingExpectSuccess,
20 addToWhiteListExpectSuccess,20 addToWhiteListExpectSuccess,
21 normalizeAccountId,21 normalizeAccountId,
22 addCollectionAdminExpectSuccess,
22} from './util/helpers';23} from './util/helpers';
23import { Keyring } from '@polkadot/api';24import { Keyring } from '@polkadot/api';
24import { IKeyringPair } from '@polkadot/types/types';25import { IKeyringPair } from '@polkadot/types/types';
365 await confirmSponsorshipExpectFailure(collectionId, '//Alice');366 await confirmSponsorshipExpectFailure(collectionId, '//Alice');
366 });367 });
368
369 it('(!negative test!) Confirm sponsorship by collection admin', async () => {
370 const collectionId = await createCollectionExpectSuccess();
371 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
372 await addCollectionAdminExpectSuccess(alice, collectionId, charlie);
373 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');
374 });
367375
368 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {376 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {
369 const collectionId = await createCollectionExpectSuccess();377 const collectionId = await createCollectionExpectSuccess();
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
4//4//
55
6import { default as usingApi } from './substrate/substrate-api';6import { default as usingApi } from './substrate/substrate-api';
7import chai from 'chai';
7import { Keyring } from '@polkadot/api';8import { Keyring } from '@polkadot/api';
8import { IKeyringPair } from '@polkadot/types/types';9import { IKeyringPair } from '@polkadot/types/types';
9import { 10import {
10 createCollectionExpectSuccess, 11 createCollectionExpectSuccess,
11 createItemExpectSuccess,12 createItemExpectSuccess,
13 addCollectionAdminExpectSuccess,
12} from './util/helpers';14} from './util/helpers';
1315
16const expect = chai.expect;
14let alice: IKeyringPair;17let alice: IKeyringPair;
18let bob: IKeyringPair;
1519
16describe('integration test: ext. createItem():', () => {20describe('integration test: ext. createItem():', () => {
17 before(async () => {21 before(async () => {
18 await usingApi(async () => {22 await usingApi(async () => {
19 const keyring = new Keyring({ type: 'sr25519' });23 const keyring = new Keyring({ type: 'sr25519' });
20 alice = keyring.addFromUri('//Alice');24 alice = keyring.addFromUri('//Alice');
25 bob = keyring.addFromUri('//Bob');
21 });26 });
22 });27 });
2328
36 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});41 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
37 await createItemExpectSuccess(alice, newCollectionID, createMode);42 await createItemExpectSuccess(alice, newCollectionID, createMode);
38 });43 });
44 it('Create new item in NFT collection with collection admin permissions', async () => {
45 const createMode = 'NFT';
46 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
47 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);
48 await createItemExpectSuccess(bob, newCollectionID, createMode);
49 });
50 it('Create new item in Fungible collection with collection admin permissions', async () => {
51 const createMode = 'Fungible';
52 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
53 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);
54 await createItemExpectSuccess(bob, newCollectionID, createMode);
55 });
56 it('Create new item in ReFungible collection with collection admin permissions', async () => {
57 const createMode = 'ReFungible';
58 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
59 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob);
60 await createItemExpectSuccess(bob, newCollectionID, createMode);
61 });
39});62});
63
64describe('Negative integration test: ext. createItem():', () => {
65 before(async () => {
66 await usingApi(async () => {
67 const keyring = new Keyring({ type: 'sr25519' });
68 alice = keyring.addFromUri('//Alice');
69 bob = keyring.addFromUri('//Bob');
70 });
71 });
72
73 it('Regular user cannot create new item in NFT collection', async () => {
74 const createMode = 'NFT';
75 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
76 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;
77 });
78 it('Regular user cannot create new item in Fungible collection', async () => {
79 const createMode = 'Fungible';
80 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
81 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;
82 });
83 it('Regular user cannot create new item in ReFungible collection', async () => {
84 const createMode = 'ReFungible';
85 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
86 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;
87 });
88});
4089
modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.
4//4//
5import { ApiPromise } from '@polkadot/api';5import { ApiPromise } from '@polkadot/api';
6import { IKeyringPair } from '@polkadot/types/types';
6import BN from 'bn.js';7import BN from 'bn.js';
7import chai from 'chai';8import chai from 'chai';
8import chaiAsPromised from 'chai-as-promised';9import chaiAsPromised from 'chai-as-promised';
12 createCollectionExpectSuccess,13 createCollectionExpectSuccess,
13 destroyCollectionExpectSuccess,14 destroyCollectionExpectSuccess,
14 getGenericResult,15 getGenericResult,
16 IFungibleTokenDataType,
15 IReFungibleTokenDataType,17 IReFungibleTokenDataType,
16 normalizeAccountId,18 normalizeAccountId,
17 setCollectionLimitsExpectSuccess,19 setCollectionLimitsExpectSuccess,
20 addCollectionAdminExpectSuccess,
18} from './util/helpers';21} from './util/helpers';
1922
20chai.use(chaiAsPromised);23chai.use(chaiAsPromised);
57 });60 });
58 });61 });
5962
63 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {
64 await usingApi(async (api: ApiPromise) => {
65 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
66 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
67 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
68 const Alice = privateKey('//Alice');
69 const args = [
70 {fungible: { value: 1 }},
71 {fungible: { value: 2 }},
72 {fungible: { value: 3 }},
73 ];
74 const createMultipleItemsTx = api.tx.nft
75 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
76 await submitTransactionAsync(Alice, createMultipleItemsTx);
77 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Alice.address) as any).toJSON() as unknown as IFungibleTokenDataType;
78
79 expect(token1Data.Value).to.be.equal(6); // 1 + 2 + 3
80 });
81 });
82
60 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {83 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {
61 await usingApi(async (api: ApiPromise) => {84 await usingApi(async (api: ApiPromise) => {
62 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});85 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
116 });139 });
117});140});
118141
142describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {
143
144 let Alice: IKeyringPair;
145 let Bob: IKeyringPair;
146
147 before(async () => {
148 await usingApi(async () => {
149 Alice = privateKey('//Alice');
150 Bob = privateKey('//Bob');
151 });
152 });
153
154 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {
155 await usingApi(async (api: ApiPromise) => {
156 const collectionId = await createCollectionExpectSuccess();
157 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
158 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
159 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
160 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
161 const createMultipleItemsTx = api.tx.nft
162 .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);
163 await submitTransactionAsync(Bob, createMultipleItemsTx);
164 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
165 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
166 const token1Data = (await api.query.nft.nftItemList(collectionId, 1)).toJSON() as unknown as ITokenDataType;
167 const token2Data = (await api.query.nft.nftItemList(collectionId, 2)).toJSON() as unknown as ITokenDataType;
168 const token3Data = (await api.query.nft.nftItemList(collectionId, 3)).toJSON() as unknown as ITokenDataType;
169
170 expect(token1Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
171 expect(token2Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
172 expect(token3Data.Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
173
174 expect(token1Data.ConstData.toString()).to.be.equal('0x31');
175 expect(token2Data.ConstData.toString()).to.be.equal('0x32');
176 expect(token3Data.ConstData.toString()).to.be.equal('0x33');
177
178 expect(token1Data.VariableData.toString()).to.be.equal('0x31');
179 expect(token2Data.VariableData.toString()).to.be.equal('0x32');
180 expect(token3Data.VariableData.toString()).to.be.equal('0x33');
181 });
182 });
183
184 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {
185 await usingApi(async (api: ApiPromise) => {
186 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
187 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
188 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
189 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
190 const args = [
191 {fungible: { value: 1 }},
192 {fungible: { value: 2 }},
193 {fungible: { value: 3 }},
194 ];
195 const createMultipleItemsTx = api.tx.nft
196 .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);
197 await submitTransactionAsync(Bob, createMultipleItemsTx);
198 const token1Data = (await api.query.nft.fungibleItemList(collectionId, Bob.address) as any).toJSON() as unknown as IFungibleTokenDataType;
199
200 expect(token1Data.Value).to.be.equal(6); // 1 + 2 + 3
201 });
202 });
203
204 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {
205 await usingApi(async (api: ApiPromise) => {
206 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
207 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
208 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
209 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
210 const args = [
211 {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
212 {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
213 {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
214 ];
215 const createMultipleItemsTx = api.tx.nft
216 .createMultipleItems(collectionId, normalizeAccountId(Bob.address), args);
217 await submitTransactionAsync(Bob, createMultipleItemsTx);
218 const itemsListIndexAfter = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
219 expect(itemsListIndexAfter.toNumber()).to.be.equal(3);
220 const token1Data = (await api.query.nft.reFungibleItemList(collectionId, 1) as any).toJSON() as unknown as IReFungibleTokenDataType;
221 const token2Data = (await api.query.nft.reFungibleItemList(collectionId, 2) as any).toJSON() as unknown as IReFungibleTokenDataType;
222 const token3Data = (await api.query.nft.reFungibleItemList(collectionId, 3) as any).toJSON() as unknown as IReFungibleTokenDataType;
223
224 expect(token1Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
225 expect(token1Data.Owner[0].Fraction).to.be.equal(1);
226
227 expect(token2Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
228 expect(token2Data.Owner[0].Fraction).to.be.equal(1);
229
230 expect(token3Data.Owner[0].Owner).to.be.deep.equal(normalizeAccountId(Bob.address));
231 expect(token3Data.Owner[0].Fraction).to.be.equal(1);
232
233 expect(token1Data.ConstData.toString()).to.be.equal('0x31');
234 expect(token2Data.ConstData.toString()).to.be.equal('0x32');
235 expect(token3Data.ConstData.toString()).to.be.equal('0x33');
236
237 expect(token1Data.VariableData.toString()).to.be.equal('0x31');
238 expect(token2Data.VariableData.toString()).to.be.equal('0x32');
239 expect(token3Data.VariableData.toString()).to.be.equal('0x33');
240 });
241 });
242});
243
119describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {244describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
245
246 let Alice: IKeyringPair;
247 let Bob: IKeyringPair;
248
249 before(async () => {
250 await usingApi(async () => {
251 Alice = privateKey('//Alice');
252 Bob = privateKey('//Bob');
253 });
254 });
255
256 it('Regular user cannot create items in active NFT collection', async () => {
257 await usingApi(async (api: ApiPromise) => {
258 const collectionId = await createCollectionExpectSuccess();
259 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
260 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
261 const args = [{ nft: ['0x31', '0x31'] }, { nft: ['0x32', '0x32'] }, { nft: ['0x33', '0x33'] }];
262 const createMultipleItemsTx = api.tx.nft
263 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
264 await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;
265 });
266 });
267
268 it('Regular user cannot create items in active Fungible collection', async () => {
269 await usingApi(async (api: ApiPromise) => {
270 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
271 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
272 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
273 const args = [
274 {fungible: { value: 1 }},
275 {fungible: { value: 2 }},
276 {fungible: { value: 3 }},
277 ];
278 const createMultipleItemsTx = api.tx.nft
279 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
280 await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;
281 });
282 });
283
284 it('Regular user cannot create items in active ReFungible collection', async () => {
285 await usingApi(async (api: ApiPromise) => {
286 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
287 const itemsListIndexBefore = await api.query.nft.itemListIndex(collectionId) as unknown as BN;
288 expect(itemsListIndexBefore.toNumber()).to.be.equal(0);
289 const args = [
290 {refungible: {const_data: [0x31], variable_data: [0x31], pieces: 1}},
291 {refungible: {const_data: [0x32], variable_data: [0x32], pieces: 1}},
292 {refungible: {const_data: [0x33], variable_data: [0x33], pieces: 1}},
293 ];
294 const createMultipleItemsTx = api.tx.nft
295 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
296 await expect(submitTransactionAsync(Bob, createMultipleItemsTx)).to.be.rejected;
297 });
298 });
299
120 it('Create token with not existing type', async () => {300 it('Create token with not existing type', async () => {
121 await usingApi(async (api: ApiPromise) => {301 await usingApi(async (api: ApiPromise) => {
122 const collectionId = await createCollectionExpectSuccess();302 const collectionId = await createCollectionExpectSuccess();
123 const Alice = privateKey('//Alice');
124 try {303 try {
125 const args = [{ invalid: null }, { invalid: null }, { invalid: null }];304 const args = [{ invalid: null }, { invalid: null }, { invalid: null }];
126 const createMultipleItemsTx = await api.tx.nft305 const createMultipleItemsTx = await api.tx.nft
136 it('Create token in not existing collection', async () => {315 it('Create token in not existing collection', async () => {
137 await usingApi(async (api: ApiPromise) => {316 await usingApi(async (api: ApiPromise) => {
138 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;317 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
139 const Alice = privateKey('//Alice');
140 const createMultipleItemsTx = api.tx.nft318 const createMultipleItemsTx = api.tx.nft
141 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'NFT', 'NFT']);319 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'NFT', 'NFT']);
142 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;320 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
174 it('Create tokens with different types', async () => {352 it('Create tokens with different types', async () => {
175 await usingApi(async (api: ApiPromise) => {353 await usingApi(async (api: ApiPromise) => {
176 const collectionId = await createCollectionExpectSuccess();354 const collectionId = await createCollectionExpectSuccess();
177 const Alice = privateKey('//Alice');
178 const createMultipleItemsTx = api.tx.nft355 const createMultipleItemsTx = api.tx.nft
179 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'Fungible', 'ReFungible']);356 .createMultipleItems(collectionId, normalizeAccountId(Alice.address), ['NFT', 'Fungible', 'ReFungible']);
180 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;357 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
186 it('Create tokens with different data limits <> maximum data limit', async () => {363 it('Create tokens with different data limits <> maximum data limit', async () => {
187 await usingApi(async (api: ApiPromise) => {364 await usingApi(async (api: ApiPromise) => {
188 const collectionId = await createCollectionExpectSuccess();365 const collectionId = await createCollectionExpectSuccess();
189 const Alice = privateKey('//Alice');
190 const args = [366 const args = [
191 { nft: ['A', 'A'] },367 { nft: ['A', 'A'] },
192 { nft: ['B', 'B'.repeat(2049)] },368 { nft: ['B', 'B'.repeat(2049)] },
200376
201 it('Fails when minting tokens exceeds collectionLimits amount', async () => {377 it('Fails when minting tokens exceeds collectionLimits amount', async () => {
202 await usingApi(async (api) => {378 await usingApi(async (api) => {
203 const alice = privateKey('//Alice');
204379
205 const collectionId = await createCollectionExpectSuccess();380 const collectionId = await createCollectionExpectSuccess();
206 await setCollectionLimitsExpectSuccess(alice, collectionId, {381 await setCollectionLimitsExpectSuccess(Alice, collectionId, {
207 TokenLimit: 1,382 TokenLimit: 1,
208 });383 });
209 const args = [384 const args = [
210 { nft: ['A', 'A'] },385 { nft: ['A', 'A'] },
211 { nft: ['B', 'B'] },386 { nft: ['B', 'B'] },
212 ];387 ];
213 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);388 const createMultipleItemsTx = api.tx.nft.createMultipleItems(collectionId, normalizeAccountId(Alice.address), args);
214 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;389 await expect(submitTransactionExpectFailAsync(Alice, createMultipleItemsTx)).to.be.rejected;
215 });390 });
216 });391 });
217});392});
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
11import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, destroyCollectionExpectFailure, setCollectionLimitsExpectSuccess } from './util/helpers';11import { createCollectionExpectSuccess,
12 destroyCollectionExpectSuccess,
13 destroyCollectionExpectFailure,
14 setCollectionLimitsExpectSuccess,
15 addCollectionAdminExpectSuccess,
16} from './util/helpers';
1217
13chai.use(chaiAsPromised);18chai.use(chaiAsPromised);
2934
30describe('(!negative test!) integration test: ext. destroyCollection():', () => {35describe('(!negative test!) integration test: ext. destroyCollection():', () => {
31 let alice: IKeyringPair;36 let alice: IKeyringPair;
37 let bob: IKeyringPair;
3238
33 before(async () => {39 before(async () => {
34 await usingApi(async () => {40 await usingApi(async () => {
35 alice = privateKey('//Alice');41 alice = privateKey('//Alice');
42 bob = privateKey('//Bob');
36 });43 });
37 });44 });
3845
53 await destroyCollectionExpectFailure(collectionId, '//Bob');60 await destroyCollectionExpectFailure(collectionId, '//Bob');
54 await destroyCollectionExpectSuccess(collectionId, '//Alice');61 await destroyCollectionExpectSuccess(collectionId, '//Alice');
55 });62 });
63 it('(!negative test!) Destroy a collection using collection admin account', async () => {
64 const collectionId = await createCollectionExpectSuccess();
65 await addCollectionAdminExpectSuccess(alice, collectionId, bob);
66 await destroyCollectionExpectFailure(collectionId, '//Bob');
67 });
56 it('fails when OwnerCanDestroy == false', async () => {68 it('fails when OwnerCanDestroy == false', async () => {
57 const collectionId = await createCollectionExpectSuccess();69 const collectionId = await createCollectionExpectSuccess();
58 await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanDestroy: false });70 await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanDestroy: false });
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
84 });84 });
85 });85 });
86
87 it('Regular user Can\'t remove collection admin', async () => {
88 await usingApi(async (api: ApiPromise) => {
89 const collectionId = await createCollectionExpectSuccess();
90 const Alice = privateKey('//Alice');
91 const Bob = privateKey('//Bob');
92 const Charlie = privateKey('//Charlie');
93
94 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
95 await submitTransactionAsync(Alice, addAdminTx);
96
97 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
98 await expect(submitTransactionExpectFailAsync(Charlie, changeOwnerTx)).to.be.rejected;
99
100 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
101 await createCollectionExpectSuccess();
102 });
103 });
86});104});
87105
modifiedtests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth
17 removeCollectionSponsorExpectSuccess,17 removeCollectionSponsorExpectSuccess,
18 removeCollectionSponsorExpectFailure,18 removeCollectionSponsorExpectFailure,
19 normalizeAccountId,19 normalizeAccountId,
20 addCollectionAdminExpectSuccess,
20} from './util/helpers';21} from './util/helpers';
21import { Keyring } from '@polkadot/api';22import { Keyring } from '@polkadot/api';
22import { IKeyringPair } from '@polkadot/types/types';23import { IKeyringPair } from '@polkadot/types/types';
104 await removeCollectionSponsorExpectFailure(collectionId);105 await removeCollectionSponsorExpectFailure(collectionId);
105 });106 });
107
108 it('(!negative test!) Remove sponsor for a collection with collection admin permissions', async () => {
109 const collectionId = await createCollectionExpectSuccess();
110 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
111 await addCollectionAdminExpectSuccess(alice, collectionId, bob);
112 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');
113 });
106114
107 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {115 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {
108 const collectionId = await createCollectionExpectSuccess();116 const collectionId = await createCollectionExpectSuccess();
modifiedtests/src/removeFromWhiteList.test.tsdiffbeforeafterboth
17 removeFromWhiteListExpectFailure,17 removeFromWhiteListExpectFailure,
18 disableWhiteListExpectSuccess,18 disableWhiteListExpectSuccess,
19 normalizeAccountId,19 normalizeAccountId,
20 addCollectionAdminExpectSuccess,
20} from './util/helpers';21} from './util/helpers';
21import { IKeyringPair } from '@polkadot/types/types';22import { IKeyringPair } from '@polkadot/types/types';
22import privateKey from './substrate/privateKey';23import privateKey from './substrate/privateKey';
89 });90 });
90});91});
9192
93describe('Integration Test removeFromWhiteList with collection admin permissions', () => {
94 let alice: IKeyringPair;
95 let bob: IKeyringPair;
96 let charlie: IKeyringPair;
97
98 before(async () => {
99 await usingApi(async () => {
100 alice = privateKey('//Alice');
101 bob = privateKey('//Bob');
102 charlie = privateKey('//Charlie');
103 });
104 });
105
106 it('ensure address is not in whitelist after removal', async () => {
107 await usingApi(async () => {
108 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
109 await enableWhiteListExpectSuccess(alice, collectionId);
110 await addCollectionAdminExpectSuccess(alice, collectionId, bob);
111 await addToWhiteListExpectSuccess(alice, collectionId, charlie.address);
112 await removeFromWhiteListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));
113 expect(await isWhitelisted(collectionId, charlie.address)).to.be.false;
114 });
115 });
116
117 it('Collection admin allowed to remove from whitelist with unset whitelist status', async () => {
118 await usingApi(async () => {
119 const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
120 await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
121 await addCollectionAdminExpectSuccess(alice, collectionWithoutWhitelistId, bob);
122 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);
123 await disableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
124 await removeFromWhiteListExpectSuccess(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
125 });
126 });
127});
addedtests/src/setChainLimits.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
16 getDetailedCollectionInfo,16 getDetailedCollectionInfo,
17 setCollectionLimitsExpectFailure,17 setCollectionLimitsExpectFailure,
18 setCollectionLimitsExpectSuccess,18 setCollectionLimitsExpectSuccess,
19 addCollectionAdminExpectSuccess,
19} from './util/helpers';20} from './util/helpers';
2021
21chai.use(chaiAsPromised);22chai.use(chaiAsPromised);
150 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;151 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
151 });152 });
152 });153 });
154 it('execute setCollectionLimits from admin collection', async () => {
155 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);
156 await usingApi(async (api: ApiPromise) => {
157 tx = api.tx.nft.setCollectionLimits(
158 collectionIdForTesting,
159 {
160 accountTokenOwnershipLimit,
161 sponsoredDataSize,
162 sponsoredMintSize,
163 tokenLimit,
164 },
165 );
166 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
167 });
168 });
153 it('execute setCollectionLimits with incorrect limits', async () => {169 it('execute setCollectionLimits with incorrect limits', async () => {
154 await usingApi(async (api: ApiPromise) => {170 await usingApi(async (api: ApiPromise) => {
155 tx = api.tx.nft.setCollectionLimits(171 tx = api.tx.nft.setCollectionLimits(
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
9import { createCollectionExpectSuccess, setCollectionSponsorExpectSuccess, destroyCollectionExpectSuccess, setCollectionSponsorExpectFailure } from './util/helpers';9import { createCollectionExpectSuccess,
10 setCollectionSponsorExpectSuccess,
11 destroyCollectionExpectSuccess,
12 setCollectionSponsorExpectFailure,
13 addCollectionAdminExpectSuccess,
14} from './util/helpers';
10import { Keyring } from '@polkadot/api';15import { Keyring } from '@polkadot/api';
11import { IKeyringPair } from '@polkadot/types/types';16import { IKeyringPair } from '@polkadot/types/types';
1217
13chai.use(chaiAsPromised);18chai.use(chaiAsPromised);
1419
20let alice: IKeyringPair;
15let bob: IKeyringPair;21let bob: IKeyringPair;
22let charlie: IKeyringPair;
1623
17describe('integration test: ext. setCollectionSponsor():', () => {24describe('integration test: ext. setCollectionSponsor():', () => {
1825
19 before(async () => {26 before(async () => {
20 await usingApi(async () => {27 await usingApi(async () => {
21 const keyring = new Keyring({ type: 'sr25519' });28 const keyring = new Keyring({ type: 'sr25519' });
29 alice = keyring.addFromUri('//Alice');
22 bob = keyring.addFromUri('//Bob');30 bob = keyring.addFromUri('//Bob');
23 });31 });
24 });32 });
55 before(async () => {63 before(async () => {
56 await usingApi(async () => {64 await usingApi(async () => {
57 const keyring = new Keyring({ type: 'sr25519' });65 const keyring = new Keyring({ type: 'sr25519' });
66 alice = keyring.addFromUri('//Alice');
58 bob = keyring.addFromUri('//Bob');67 bob = keyring.addFromUri('//Bob');
68 charlie = keyring.addFromUri('//Charlie');
59 });69 });
60 });70 });
6171
77 await destroyCollectionExpectSuccess(collectionId);87 await destroyCollectionExpectSuccess(collectionId);
78 await setCollectionSponsorExpectFailure(collectionId, bob.address);88 await setCollectionSponsorExpectFailure(collectionId, bob.address);
79 });89 });
90 it('(!negative test!) Collection admin add sponsor', async () => {
91 const collectionId = await createCollectionExpectSuccess();
92 await addCollectionAdminExpectSuccess(alice, collectionId, bob);
93 await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Bob');
94 });
80});95});
8196
modifiedtests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth
11import {11import {
12 createCollectionExpectSuccess,12 createCollectionExpectSuccess,
13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,
14 addCollectionAdminExpectSuccess,
14} from './util/helpers';15} from './util/helpers';
1516
16chai.use(chaiAsPromised);17chai.use(chaiAsPromised);
43 });44 });
44 });45 });
46
47 it('Collection admin can set the scheme', async () => {
48 await usingApi(async (api) => {
49 const collectionId = await createCollectionExpectSuccess();
50 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
51 expect(collection.Owner).to.be.eq(Alice.address);
52 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
53 const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);
54 await submitTransactionAsync(Bob, setShema);
55 });
56 });
4557
46 it('Checking collection data using the ConstOnChainSchema parameter', async () => {58 it('Checking collection data using the ConstOnChainSchema parameter', async () => {
47 await usingApi(async (api) => {59 await usingApi(async (api) => {
modifiedtests/src/setMintPermission.test.tsdiffbeforeafterboth
16 findNotExistingCollection,16 findNotExistingCollection,
17 setMintPermissionExpectFailure,17 setMintPermissionExpectFailure,
18 setMintPermissionExpectSuccess,18 setMintPermissionExpectSuccess,
19 addCollectionAdminExpectSuccess,
19} from './util/helpers';20} from './util/helpers';
2021
21describe('Integration Test setMintPermission', () => {22describe('Integration Test setMintPermission', () => {
91 await setMintPermissionExpectFailure(bob, collectionId, true);92 await setMintPermissionExpectFailure(bob, collectionId, true);
92 });93 });
94
95 it('Collection admin fails on set', async () => {
96 await usingApi(async () => {
97 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
98 await addCollectionAdminExpectSuccess(alice, collectionId, bob);
99 await setMintPermissionExpectFailure(bob, collectionId, true);
100 });
101 });
93102
94 it('ensure non-white-listed non-privileged address can\'t mint tokens', async () => {103 it('ensure non-white-listed non-privileged address can\'t mint tokens', async () => {
95 await usingApi(async () => {104 await usingApi(async () => {
modifiedtests/src/setOffchainSchema.test.tsdiffbeforeafterboth
15 queryCollectionExpectSuccess,15 queryCollectionExpectSuccess,
16 setOffchainSchemaExpectFailure,16 setOffchainSchemaExpectFailure,
17 setOffchainSchemaExpectSuccess,17 setOffchainSchemaExpectSuccess,
18 addCollectionAdminExpectSuccess,
18} from './util/helpers';19} from './util/helpers';
1920
20chai.use(chaiAsPromised);21chai.use(chaiAsPromised);
2425
25describe('Integration Test setOffchainSchema', () => {26describe('Integration Test setOffchainSchema', () => {
26 let alice: IKeyringPair;27 let alice: IKeyringPair;
28 let bob: IKeyringPair;
2729
28 before(async () => {30 before(async () => {
29 await usingApi(async () => {31 await usingApi(async () => {
30 alice = privateKey('//Alice');32 alice = privateKey('//Alice');
33 bob = privateKey('//Bob');
31 });34 });
32 });35 });
3336
39 expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));42 expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
40 });43 });
44
45 it('execute setOffchainSchema (collection admin), verify data was set', async () => {
46 const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
47 await addCollectionAdminExpectSuccess(alice, collectionId, bob);
48 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);
49 const collection = await queryCollectionExpectSuccess(collectionId);
50
51 expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
52 });
41});53});
4254
43describe('Negative Integration Test setOffchainSchema', () => {55describe('Negative Integration Test setOffchainSchema', () => {
modifiedtests/src/setPublicAccessMode.test.tsdiffbeforeafterboth
18 enablePublicMintingExpectSuccess,18 enablePublicMintingExpectSuccess,
19 enableWhiteListExpectSuccess,19 enableWhiteListExpectSuccess,
20 normalizeAccountId,20 normalizeAccountId,
21 addCollectionAdminExpectSuccess,
21} from './util/helpers';22} from './util/helpers';
2223
23chai.use(chaiAsPromised);24chai.use(chaiAsPromised);
93 });94 });
94});95});
96
97describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {
98 before(async () => {
99 await usingApi(async () => {
100 Alice = privateKey('//Alice');
101 Bob = privateKey('//Bob');
102 });
103 });
104 it('Set the collection that has been deleted', async () => {
105 await usingApi(async (api: ApiPromise) => {
106 // tslint:disable-next-line: no-bitwise
107 const collectionId = await createCollectionExpectSuccess();
108 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
109 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
110 await expect(submitTransactionExpectFailAsync(Bob, tx)).to.be.rejected;
111 });
112 });
113});
95114
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
16 getCreatedCollectionCount,16 getCreatedCollectionCount,
17 getCreateItemResult,17 getCreateItemResult,
18 getDetailedCollectionInfo,18 getDetailedCollectionInfo,
19 addCollectionAdminExpectSuccess,
19} from './util/helpers';20} from './util/helpers';
2021
21chai.use(chaiAsPromised);22chai.use(chaiAsPromised);
22const expect = chai.expect;23const expect = chai.expect;
2324
24let alice: IKeyringPair;25let alice: IKeyringPair;
26let bob: IKeyringPair;
25let collectionIdForTesting: number;27let collectionIdForTesting: number;
2628
27/*29/*
44 });46 });
45});47});
48
49describe('setSchemaVersion positive', () => {
50 let tx;
51 before(async () => {
52 await usingApi(async () => {
53 const keyring = new Keyring({ type: 'sr25519' });
54 alice = keyring.addFromUri('//Alice');
55 });
56 });
57 it('execute setSchemaVersion with image url and unique ', async () => {
58 await usingApi(async (api: ApiPromise) => {
59 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
60 const events = await submitTransactionAsync(alice, tx);
61 const result = getCreateItemResult(events);
62 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
63 // tslint:disable-next-line:no-unused-expression
64 expect(result.success).to.be.true;
65 // tslint:disable-next-line:no-unused-expression
66 expect(collectionInfo).to.be.exist;
67 // tslint:disable-next-line:no-unused-expression
68 expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');
69 });
70 });
71});
4672
47describe('setSchemaVersion positive', () => {73describe('Collection admin setSchemaVersion positive', () => {
48 let tx;74 let tx;
49 before(async () => {75 before(async () => {
50 await usingApi(async () => {76 await usingApi(async () => {
51 const keyring = new Keyring({ type: 'sr25519' });77 const keyring = new Keyring({ type: 'sr25519' });
52 alice = keyring.addFromUri('//Alice');78 alice = keyring.addFromUri('//Alice');
79 bob = keyring.addFromUri('//Bob');
80 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);
53 });81 });
54 });82 });
55 it('execute setSchemaVersion with image url and unique ', async () => {83 it('execute setSchemaVersion with image url and unique ', async () => {
56 await usingApi(async (api: ApiPromise) => {84 await usingApi(async (api: ApiPromise) => {
57 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');85 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
58 const events = await submitTransactionAsync(alice, tx);86 const events = await submitTransactionAsync(bob, tx);
59 const result = getCreateItemResult(events);87 const result = getCreateItemResult(events);
60 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;88 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
61 // tslint:disable-next-line:no-unused-expression89 // tslint:disable-next-line:no-unused-expression
70 it('validate schema version with just entered data', async () => {98 it('validate schema version with just entered data', async () => {
71 await usingApi(async (api: ApiPromise) => {99 await usingApi(async (api: ApiPromise) => {
72 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');100 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
73 const events = await submitTransactionAsync(alice, tx);101 const events = await submitTransactionAsync(bob, tx);
74 const result = getCreateItemResult(events);102 const result = getCreateItemResult(events);
75 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;103 const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;
76 // tslint:disable-next-line:no-unused-expression104 // tslint:disable-next-line:no-unused-expression
modifiedtests/src/setVariableMetaData.test.tsdiffbeforeafterboth
16 findNotExistingCollection,16 findNotExistingCollection,
17 setVariableMetaDataExpectFailure,17 setVariableMetaDataExpectFailure,
18 setVariableMetaDataExpectSuccess,18 setVariableMetaDataExpectSuccess,
19 addCollectionAdminExpectSuccess,
19} from './util/helpers';20} from './util/helpers';
2021
21chai.use(chaiAsPromised);22chai.use(chaiAsPromised);
48 });49 });
49});50});
51
52describe('Integration Test collection admin setVariableMetaData', () => {
53 const data = [1, 2, 254, 255];
54
55 let alice: IKeyringPair;
56 let bob: IKeyringPair;
57 let collectionId: number;
58 let tokenId: number;
59 before(async () => {
60 await usingApi(async () => {
61 alice = privateKey('//Alice');
62 bob = privateKey('//Bob');
63 collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });
64 tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
65 await addCollectionAdminExpectSuccess(alice, collectionId, bob);
66 });
67 });
68
69 it('execute setVariableMetaData', async () => {
70 await setVariableMetaDataExpectSuccess(bob, collectionId, tokenId, data);
71 });
72
73 it('verify data was set', async () => {
74 await usingApi(async api => {
75 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap();
76
77 expect(Array.from(item.VariableData)).to.deep.equal(Array.from(data));
78 });
79 });
80});
5081
51describe('Negative Integration Test setVariableMetaData', () => {82describe('Negative Integration Test setVariableMetaData', () => {
52 const data = [1];83 const data = [1];
modifiedtests/src/setVariableOnChainSchema.test.tsdiffbeforeafterboth
11import {11import {
12 createCollectionExpectSuccess,12 createCollectionExpectSuccess,
13 destroyCollectionExpectSuccess,13 destroyCollectionExpectSuccess,
14 addCollectionAdminExpectSuccess,
14} from './util/helpers';15} from './util/helpers';
1516
16chai.use(chaiAsPromised);17chai.use(chaiAsPromised);
55 });56 });
56});57});
58
59describe('Integration Test ext. collection admin setVariableOnChainSchema()', () => {
60
61 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
62 await usingApi(async (api) => {
63 const collectionId = await createCollectionExpectSuccess();
64 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
65 expect(collection.Owner).to.be.eq(Alice.address);
66 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
67 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
68 await submitTransactionAsync(Bob, setSchema);
69 });
70 });
71
72 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {
73 await usingApi(async (api) => {
74 const collectionId = await createCollectionExpectSuccess();
75 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);
76 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);
77 await submitTransactionAsync(Bob, setSchema);
78 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
79 expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);
80
81 });
82 });
83});
5784
58describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {85describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {
5986
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
18 getCreateItemResult,18 getCreateItemResult,
19 transferExpectFailure,19 transferExpectFailure,
20 transferExpectSuccess,20 transferExpectSuccess,
21 addCollectionAdminExpectSuccess,
21} from './util/helpers';22} from './util/helpers';
2223
23let Alice: IKeyringPair;24let Alice: IKeyringPair;
90 });91 });
91 });92 });
93
94 it('Collection admin can transfer owned token', async () => {
95 await usingApi(async () => {
96 const Alice = privateKey('//Alice');
97 const Bob = privateKey('//Bob');
98 // nft
99 const nftCollectionId = await createCollectionExpectSuccess();
100 await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
101 const newNftTokenId = await createItemExpectSuccess(Bob, nftCollectionId, 'NFT', Bob.address);
102 await transferExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 1, 'NFT');
103 // fungible
104 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
105 await addCollectionAdminExpectSuccess(Alice, fungibleCollectionId, Bob);
106 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible', Bob.address);
107 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, 1, 'Fungible');
108 // reFungible
109 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
110 await addCollectionAdminExpectSuccess(Alice, reFungibleCollectionId, Bob);
111 const newReFungibleTokenId = await createItemExpectSuccess(Bob, reFungibleCollectionId, 'ReFungible', Bob.address);
112 await transferExpectSuccess(
113 reFungibleCollectionId,
114 newReFungibleTokenId,
115 Bob,
116 Alice,
117 100,
118 'ReFungible',
119 );
120 });
121 });
92});122});
93123
94describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {124describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
95 checkMsgSysMethod: string;95 checkMsgSysMethod: string;
96}96}
97
98export interface IFungibleTokenDataType {
99 Value: number;
100}
101
102export interface IChainLimits {
103 CollectionNumbersLimit: number;
104 AccountTokenOwnershipLimit: number;
105 CollectionsAdminsLimit: number;
106 CustomDataLimit: number;
107 NftSponsorTransferTimeout: number;
108 FungibleSponsorTransferTimeout: number;
109 RefungibleSponsorTransferTimeout: number;
110 OffchainSchemaLimit: number;
111 VariableOnChainSchemaLimit: number;
112 ConstOnChainSchemaLimit: number;
113}
97114
98export interface IReFungibleTokenDataType {115export interface IReFungibleTokenDataType {
99 Owner: IReFungibleOwner[];116 Owner: IReFungibleOwner[];
452 });469 });
453}470}
454471
455export async function removeCollectionSponsorExpectFailure(collectionId: number) {472export async function removeCollectionSponsorExpectFailure(collectionId: number, senderSeed = '//Alice') {
456 await usingApi(async (api) => {473 await usingApi(async (api) => {
457474
458 // Run the transaction475 // Run the transaction
459 const alicePrivateKey = privateKey('//Alice');476 const alicePrivateKey = privateKey(senderSeed);
460 const tx = api.tx.nft.removeCollectionSponsor(collectionId);477 const tx = api.tx.nft.removeCollectionSponsor(collectionId);
461 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;478 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;
462 });479 });
765 });782 });
766}783}
784
785export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: IKeyringPair) {
786 await usingApi(async (api) => {
787 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address.address));
788 const events = await submitTransactionAsync(sender, changeAdminTx);
789 const result = getCreateCollectionResult(events);
790 expect(result.success).to.be.true;
791 });
792}
767793
768export async function794export async function
769scheduleTransferExpectSuccess(795scheduleTransferExpectSuccess(
1021 });1047 });
1022}1048}
1049
1050export async function setChainLimitsExpectFailure(sender: IKeyringPair, limits: IChainLimits) {
1051 await usingApi(async (api) => {
1052 // Run the transaction
1053 const tx = api.tx.nft.setChainLimits(limits);
1054 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
1055 const result = getCreateCollectionResult(events);
1056 // tslint:disable-next-line:no-unused-expression
1057 expect(result.success).to.be.false;
1058 });
1059}
10231060
1024export async function isWhitelisted(collectionId: number, address: string) {1061export async function isWhitelisted(collectionId: number, address: string) {
1025 let whitelisted = false;1062 let whitelisted = false;