difftreelog
fix(tests) repair createMultipleItem + ..Ex, remove features made obsolete by properties
in: master
9 files changed
tests/src/contracts.test.tsdiffbeforeafterboth--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -139,9 +139,9 @@
await addToAllowListExpectSuccess(alice, collectionId, bob.address);
const transferTx = contract.tx.createMultipleItems(value, gasLimit, bob.address, collectionId, [
- {Nft: {const_data: '0x010203'}},
- {Nft: {const_data: '0x010204'}},
- {Nft: {const_data: '0x010205'}},
+ {NFT: {/*const_data: '0x010203'*/}},
+ {NFT: {/*const_data: '0x010204'*/}},
+ {NFT: {/*const_data: '0x010205'*/}},
]);
const events = await submitTransactionAsync(alice, transferTx);
const result = getGenericResult(events);
@@ -153,15 +153,15 @@
expect(tokensAfter).to.be.deep.equal([
{
Owner: bob.address,
- ConstData: '0x010203',
+ //ConstData: '0x010203',
},
{
Owner: bob.address,
- ConstData: '0x010204',
+ //ConstData: '0x010204',
},
{
Owner: bob.address,
- ConstData: '0x010205',
+ //ConstData: '0x010205',
},
]);
});
tests/src/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -63,17 +63,17 @@
const bob = privateKey('//Bob');
const tx = api.tx.unique.createCollectionEx({
mode: {Fungible: 8},
- access: 'AllowList',
+ //access: 'AllowList',
name: [1],
description: [2],
tokenPrefix: '0x000000',
- offchainSchema: '0x111111',
- schemaVersion: 'Unique',
+ //offchainSchema: '0x111111',
+ //schemaVersion: 'Unique',
pendingSponsor: bob.address,
limits: {
accountTokenOwnershipLimit: 3,
},
- constOnChainSchema: '0x333333',
+ //constOnChainSchema: '0x333333',
});
const events = await submitTransactionAsync(alice, tx);
const result = getCreateCollectionResult(events);
@@ -81,15 +81,15 @@
const collection = (await getDetailedCollectionInfo(api, result.collectionId))!;
expect(collection.owner.toString()).to.equal(alice.address);
expect(collection.mode.asFungible.toNumber()).to.equal(8);
- expect(collection.access.isAllowList).to.be.true;
+ //expect(collection.access.isAllowList).to.be.true;
expect(collection.name.map(v => v.toNumber())).to.deep.equal([1]);
expect(collection.description.map(v => v.toNumber())).to.deep.equal([2]);
expect(collection.tokenPrefix.toString()).to.equal('0x000000');
- expect(collection.offchainSchema.toString()).to.equal('0x111111');
- expect(collection.schemaVersion.isUnique).to.be.true;
+ //expect(collection.offchainSchema.toString()).to.equal('0x111111');
+ //expect(collection.schemaVersion.isUnique).to.be.true;
expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);
expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);
- expect(collection.constOnChainSchema.toString()).to.equal('0x333333');
+ //expect(collection.constOnChainSchema.toString()).to.equal('0x333333');
});
});
});
tests/src/createMultipleItems.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {ApiPromise} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import privateKey from './substrate/privateKey';22import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync, executeTransaction} from './substrate/substrate-api';23import {24 createCollectionExpectSuccess,25 destroyCollectionExpectSuccess,26 getGenericResult,27 normalizeAccountId,28 setCollectionLimitsExpectSuccess,29 addCollectionAdminExpectSuccess,30 getBalance,31 getTokenOwner,32 getLastTokenId,33 getConstMetadata,34 getCreatedCollectionCount,35 createCollectionWithPropsExpectSuccess,36 getCreateItemsResult,37 createMultipleItemsWithPropsExpectSuccess,38 createMultipleItemsWithPropsExpectFailure,39} from './util/helpers';4041chai.use(chaiAsPromised);42const expect = chai.expect;4344describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {45 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {46 await usingApi(async (api: ApiPromise) => {47 const collectionId = await createCollectionExpectSuccess();48 const itemsListIndexBefore = await getLastTokenId(api, collectionId);49 expect(itemsListIndexBefore).to.be.equal(0);50 const alice = privateKey('//Alice');51 const args = [{Nft: {const_data: '0x31'}},52 {Nft: {const_data: '0x32'}},53 {Nft: {const_data: '0x33'}}];54 const createMultipleItemsTx = api.tx.unique55 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);56 await submitTransactionAsync(alice, createMultipleItemsTx);57 const itemsListIndexAfter = await getLastTokenId(api, collectionId);58 expect(itemsListIndexAfter).to.be.equal(3);5960 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));61 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));62 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));6364 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);65 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);66 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);67 });68 });6970 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {71 await usingApi(async (api: ApiPromise) => {72 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});73 const itemsListIndexBefore = await getLastTokenId(api, collectionId);74 expect(itemsListIndexBefore).to.be.equal(0);75 const alice = privateKey('//Alice');76 const args = [77 {Fungible: {value: 1}},78 {Fungible: {value: 2}},79 {Fungible: {value: 3}},80 ];81 const createMultipleItemsTx = api.tx.unique82 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);83 await submitTransactionAsync(alice, createMultipleItemsTx);84 const token1Data = await getBalance(api, collectionId, alice.address, 0);8586 expect(token1Data).to.be.equal(6n); // 1 + 2 + 387 });88 });8990 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {91 await usingApi(async (api: ApiPromise) => {92 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});93 const itemsListIndexBefore = await getLastTokenId(api, collectionId);94 expect(itemsListIndexBefore).to.be.equal(0);95 const alice = privateKey('//Alice');96 const args = [97 {ReFungible: {const_data: [0x31], pieces: 1}},98 {ReFungible: {const_data: [0x32], pieces: 1}},99 {ReFungible: {const_data: [0x33], pieces: 1}},100 ];101 const createMultipleItemsTx = api.tx.unique102 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);103 await submitTransactionAsync(alice, createMultipleItemsTx);104 const itemsListIndexAfter = await getLastTokenId(api, collectionId);105 expect(itemsListIndexAfter).to.be.equal(3);106107 expect(await getBalance(api, collectionId, alice.address, 1)).to.be.equal(1n);108 expect(await getBalance(api, collectionId, alice.address, 2)).to.be.equal(1n);109 expect(await getBalance(api, collectionId, alice.address, 3)).to.be.equal(1n);110111 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);112 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);113 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);114 });115 });116117 it('Can mint amount of items equals to collection limits', async () => {118 await usingApi(async (api) => {119 const alice = privateKey('//Alice');120121 const collectionId = await createCollectionExpectSuccess();122 await setCollectionLimitsExpectSuccess(alice, collectionId, {123 tokenLimit: 2,124 });125 const args = [126 {NFT: {const_data: 'A'}},127 {NFT: {const_data: 'B'}},128 ];129 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);130 const events = await submitTransactionAsync(alice, createMultipleItemsTx);131 const result = getGenericResult(events);132 expect(result.success).to.be.true;133 });134 });135136 it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {137 await usingApi(async (api: ApiPromise) => {138 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});139 const itemsListIndexBefore = await getLastTokenId(api, collectionId);140 expect(itemsListIndexBefore).to.be.equal(0);141 const alice = privateKey('//Alice');142 const bob = privateKey('//Bob');143 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},144 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},145 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];146147 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);148 const itemsListIndexAfter = await getLastTokenId(api, collectionId);149 expect(itemsListIndexAfter).to.be.equal(3);150151 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));152 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));153 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));154155 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);156 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);157 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);158 });159 });160161 it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {162 await usingApi(async (api: ApiPromise) => {163 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});164 const itemsListIndexBefore = await getLastTokenId(api, collectionId);165 expect(itemsListIndexBefore).to.be.equal(0);166 const alice = privateKey('//Alice');167 const bob = privateKey('//Bob');168 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);169 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},170 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},171 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];172173 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);174 const itemsListIndexAfter = await getLastTokenId(api, collectionId);175 expect(itemsListIndexAfter).to.be.equal(3);176177 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));178 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));179 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));180181 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);182 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);183 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);184 });185 });186187 it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {188 await usingApi(async (api: ApiPromise) => {189 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});190 const itemsListIndexBefore = await getLastTokenId(api, collectionId);191 expect(itemsListIndexBefore).to.be.equal(0);192 const alice = privateKey('//Alice');193 const bob = privateKey('//Bob');194 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v1'}]}},195 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'v2'}]}},196 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'v3'}]}}];197198 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);199 const itemsListIndexAfter = await getLastTokenId(api, collectionId);200 expect(itemsListIndexAfter).to.be.equal(3);201202 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));203 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));204 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));205206 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);207 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);208 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);209 });210 });211});212213describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {214215 let alice: IKeyringPair;216 let bob: IKeyringPair;217218 before(async () => {219 await usingApi(async () => {220 alice = privateKey('//Alice');221 bob = privateKey('//Bob');222 });223 });224225 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {226 await usingApi(async (api: ApiPromise) => {227 const collectionId = await createCollectionExpectSuccess();228 const itemsListIndexBefore = await getLastTokenId(api, collectionId);229 expect(itemsListIndexBefore).to.be.equal(0);230 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);231 const args = [{Nft: {const_data: '0x31'}},232 {Nft: {const_data: '0x32'}},233 {Nft: {const_data: '0x33'}}];234 const createMultipleItemsTx = api.tx.unique235 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);236 await submitTransactionAsync(bob, createMultipleItemsTx);237 const itemsListIndexAfter = await getLastTokenId(api, collectionId);238 expect(itemsListIndexAfter).to.be.equal(3);239240 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(bob.address));241 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(bob.address));242 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(bob.address));243244 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);245 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);246 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);247 });248 });249250 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {251 await usingApi(async (api: ApiPromise) => {252 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});253 const itemsListIndexBefore = await getLastTokenId(api, collectionId);254 expect(itemsListIndexBefore).to.be.equal(0);255 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);256 const args = [257 {Fungible: {value: 1}},258 {Fungible: {value: 2}},259 {Fungible: {value: 3}},260 ];261 const createMultipleItemsTx = api.tx.unique262 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);263 await submitTransactionAsync(bob, createMultipleItemsTx);264 const token1Data = await getBalance(api, collectionId, bob.address, 0);265266 expect(token1Data).to.be.equal(6n); // 1 + 2 + 3267 });268 });269270 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {271 await usingApi(async (api: ApiPromise) => {272 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});273 const itemsListIndexBefore = await getLastTokenId(api, collectionId);274 expect(itemsListIndexBefore).to.be.equal(0);275 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);276 const args = [277 {ReFungible: {const_data: [0x31], pieces: 1}},278 {ReFungible: {const_data: [0x32], pieces: 1}},279 {ReFungible: {const_data: [0x33], pieces: 1}},280 ];281 const createMultipleItemsTx = api.tx.unique282 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);283 await submitTransactionAsync(bob, createMultipleItemsTx);284 const itemsListIndexAfter = await getLastTokenId(api, collectionId);285 expect(itemsListIndexAfter).to.be.equal(3);286287 expect(await getBalance(api, collectionId, bob.address, 1)).to.be.equal(1n);288 expect(await getBalance(api, collectionId, bob.address, 2)).to.be.equal(1n);289 expect(await getBalance(api, collectionId, bob.address, 3)).to.be.equal(1n);290291 expect(await getConstMetadata(api, collectionId, 1)).to.be.deep.equal([0x31]);292 expect(await getConstMetadata(api, collectionId, 2)).to.be.deep.equal([0x32]);293 expect(await getConstMetadata(api, collectionId, 3)).to.be.deep.equal([0x33]);294 });295 });296});297298describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {299300 let alice: IKeyringPair;301 let bob: IKeyringPair;302303 before(async () => {304 await usingApi(async () => {305 alice = privateKey('//Alice');306 bob = privateKey('//Bob');307 });308 });309310 it('Regular user cannot create items in active NFT collection', async () => {311 await usingApi(async (api: ApiPromise) => {312 const collectionId = await createCollectionExpectSuccess();313 const itemsListIndexBefore = await getLastTokenId(api, collectionId);314 expect(itemsListIndexBefore).to.be.equal(0);315 const args = [{Nft: {const_data: '0x31'}},316 {Nft: {const_data: '0x32'}},317 {Nft: {const_data: '0x33'}}];318 const createMultipleItemsTx = api.tx.unique319 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);320 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;321 });322 });323324 it('Regular user cannot create items in active Fungible collection', async () => {325 await usingApi(async (api: ApiPromise) => {326 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});327 const itemsListIndexBefore = await getLastTokenId(api, collectionId);328 expect(itemsListIndexBefore).to.be.equal(0);329 const args = [330 {Fungible: {value: 1}},331 {Fungible: {value: 2}},332 {Fungible: {value: 3}},333 ];334 const createMultipleItemsTx = api.tx.unique335 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);336 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;337 });338 });339340 it('Regular user cannot create items in active ReFungible collection', async () => {341 await usingApi(async (api: ApiPromise) => {342 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});343 const itemsListIndexBefore = await getLastTokenId(api, collectionId);344 expect(itemsListIndexBefore).to.be.equal(0);345 const args = [346 {ReFungible: {const_data: [0x31], pieces: 1}},347 {ReFungible: {const_data: [0x32], pieces: 1}},348 {ReFungible: {const_data: [0x33], pieces: 1}},349 ];350 const createMultipleItemsTx = api.tx.unique351 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);352 await expect(submitTransactionAsync(bob, createMultipleItemsTx)).to.be.rejected;353 });354 });355356 it('Create token in not existing collection', async () => {357 await usingApi(async (api: ApiPromise) => {358 const collectionId = await getCreatedCollectionCount(api) + 1;359 const createMultipleItemsTx = api.tx.unique360 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']);361 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;362 });363 });364365 it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {366 await usingApi(async (api: ApiPromise) => {367 // NFT368 const collectionId = await createCollectionExpectSuccess();369 const alice = privateKey('//Alice');370 const args = [371 {NFT: {const_data: 'A'.repeat(2049)}},372 {NFT: {const_data: 'B'.repeat(2049)}},373 {NFT: {const_data: 'C'.repeat(2049)}},374 ];375 const createMultipleItemsTx = api.tx.unique376 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);377 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;378379 // ReFungible380 const collectionIdReFungible =381 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});382 const argsReFungible = [383 {ReFungible: ['1'.repeat(2049), 10]},384 {ReFungible: ['2'.repeat(2049), 10]},385 {ReFungible: ['3'.repeat(2049), 10]},386 ];387 const createMultipleItemsTxFungible = api.tx.unique388 .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);389 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;390 });391 });392393 it('Create tokens with different types', async () => {394 await usingApi(async (api: ApiPromise) => {395 const collectionId = await createCollectionExpectSuccess();396 const createMultipleItemsTx = api.tx.unique397 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'Fungible', 'ReFungible']);398 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;399 // garbage collection :-D400 await destroyCollectionExpectSuccess(collectionId);401 });402 });403404 it('Create tokens with different data limits <> maximum data limit', async () => {405 await usingApi(async (api: ApiPromise) => {406 const collectionId = await createCollectionExpectSuccess();407 const args = [408 {NFT: {const_data: 'A'}},409 {NFT: {const_data: 'B'.repeat(2049)}},410 ];411 const createMultipleItemsTx = await api.tx.unique412 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);413 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;414 });415 });416417 it('Fails when minting tokens exceeds collectionLimits amount', async () => {418 await usingApi(async (api) => {419420 const collectionId = await createCollectionExpectSuccess();421 await setCollectionLimitsExpectSuccess(alice, collectionId, {422 tokenLimit: 1,423 });424 const args = [425 {NFT: {const_data: 'A'}},426 {NFT: {const_data: 'B'}},427 ];428 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);429 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;430 });431 });432433 it('No editing rights', async () => {434 await usingApi(async (api: ApiPromise) => {435 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],436 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: true}}]});437 const itemsListIndexBefore = await getLastTokenId(api, collectionId);438 expect(itemsListIndexBefore).to.be.equal(0);439 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);440 const args = [{Nft: {const_data: '0x31', properties: [{key: 'key1', value: 'v2'}]}},441 {Nft: {const_data: '0x32'}},442 {Nft: {const_data: '0x33'}}];443444 await createMultipleItemsWithPropsExpectFailure(bob, collectionId, args);445 });446 });447448 it('User doesnt have editing rights', async () => {449 await usingApi(async (api: ApiPromise) => {450 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],451 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});452 const itemsListIndexBefore = await getLastTokenId(api, collectionId);453 expect(itemsListIndexBefore).to.be.equal(0);454 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);455 const args = [{Nft: {const_data: '0x31', properties: [{key: 'key1', value: 'v2'}]}},456 {Nft: {const_data: '0x32'}},457 {Nft: {const_data: '0x33'}}];458459 await createMultipleItemsWithPropsExpectFailure(bob, collectionId, args);460 });461 });462463 it('Adding property without access rights', async () => {464 await usingApi(async (api: ApiPromise) => {465 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'k', value: 'v1'}]});466 const itemsListIndexBefore = await getLastTokenId(api, collectionId);467 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);468 expect(itemsListIndexBefore).to.be.equal(0);469 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'v'}]}},470 {Nft: {const_data: '0x32'}},471 {Nft: {const_data: '0x33'}}];472473 await createMultipleItemsWithPropsExpectFailure(bob, collectionId, args);474 });475 });476477 it('Adding more than 64 prps', async () => {478 await usingApi(async (api: ApiPromise) => {479 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],480 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});481 const itemsListIndexBefore = await getLastTokenId(api, collectionId);482 expect(itemsListIndexBefore).to.be.equal(0);483 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);484485 const prps = [];486487 for (let i = 0; i < 65; i++) {488 prps.push({key: `key${i}`, value: `value${i}`});489 }490491 const args = [{Nft: {const_data: '0x31', properties: prps}},492 {Nft: {const_data: '0x32', properties: prps}},493 {Nft: {const_data: '0x33', properties: prps}}];494495 createMultipleItemsWithPropsExpectFailure(alice, collectionId, args);496 });497 });498499 it('Trying to add bigger property than allowed', async () => {500 await usingApi(async (api: ApiPromise) => {501 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});502 const itemsListIndexBefore = await getLastTokenId(api, collectionId);503 expect(itemsListIndexBefore).to.be.equal(0);504 const args = [{Nft: {const_data: '0x31', properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}},505 {Nft: {const_data: '0x32', properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}},506 {Nft: {const_data: '0x33', properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}}];507508 createMultipleItemsWithPropsExpectFailure(alice, collectionId, args);509 });510 });511});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {ApiPromise} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import privateKey from './substrate/privateKey';22import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync, executeTransaction} from './substrate/substrate-api';23import {24 createCollectionExpectSuccess,25 destroyCollectionExpectSuccess,26 getGenericResult,27 normalizeAccountId,28 setCollectionLimitsExpectSuccess,29 addCollectionAdminExpectSuccess,30 getBalance,31 getTokenOwner,32 getLastTokenId,33 getCreatedCollectionCount,34 createCollectionWithPropsExpectSuccess,35 createMultipleItemsWithPropsExpectSuccess,36 getTokenProperties,37} from './util/helpers';3839chai.use(chaiAsPromised);40const expect = chai.expect;4142describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {43 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {44 await usingApi(async (api: ApiPromise) => {45 const collectionId = await createCollectionExpectSuccess();46 const itemsListIndexBefore = await getLastTokenId(api, collectionId);47 expect(itemsListIndexBefore).to.be.equal(0);4849 const alice = privateKey('//Alice');50 await submitTransactionAsync(51 alice, 52 api.tx.unique.setPropertyPermissions(collectionId, [{key: 'data', permission: {tokenOwner: true}}])53 );54 55 const args = [56 {NFT: {properties: [{key: 'data', value: '1'}]}},57 {NFT: {properties: [{key: 'data', value: '2'}]}},58 {NFT: {properties: [{key: 'data', value: '3'}]}}59 ];60 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);61 await submitTransactionAsync(alice, createMultipleItemsTx);62 const itemsListIndexAfter = await getLastTokenId(api, collectionId);63 expect(itemsListIndexAfter).to.be.equal(3);6465 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));66 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));67 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));6869 expect((await getTokenProperties(api, collectionId, 1, ['data']))[0].value).to.be.equal('1');70 expect((await getTokenProperties(api, collectionId, 2, ['data']))[0].value).to.be.equal('2');71 expect((await getTokenProperties(api, collectionId, 3, ['data']))[0].value).to.be.equal('3');72 });73 });7475 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {76 await usingApi(async (api: ApiPromise) => {77 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});78 const itemsListIndexBefore = await getLastTokenId(api, collectionId);79 expect(itemsListIndexBefore).to.be.equal(0);80 const alice = privateKey('//Alice');81 const args = [82 {Fungible: {value: 1}},83 {Fungible: {value: 2}},84 {Fungible: {value: 3}},85 ];86 const createMultipleItemsTx = api.tx.unique87 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);88 await submitTransactionAsync(alice, createMultipleItemsTx);89 const token1Data = await getBalance(api, collectionId, alice.address, 0);9091 expect(token1Data).to.be.equal(6n); // 1 + 2 + 392 });93 });9495 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {96 await usingApi(async (api: ApiPromise) => {97 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});98 const itemsListIndexBefore = await getLastTokenId(api, collectionId);99 expect(itemsListIndexBefore).to.be.equal(0);100 const alice = privateKey('//Alice');101 const args = [102 {ReFungible: {pieces: 1}},103 {ReFungible: {pieces: 2}},104 {ReFungible: {pieces: 3}},105 ];106 const createMultipleItemsTx = api.tx.unique107 .createMultipleItems(collectionId, normalizeAccountId(alice.address), args);108 await submitTransactionAsync(alice, createMultipleItemsTx);109 const itemsListIndexAfter = await getLastTokenId(api, collectionId);110 expect(itemsListIndexAfter).to.be.equal(3);111112 expect(await getBalance(api, collectionId, alice.address, 1)).to.be.equal(1n);113 expect(await getBalance(api, collectionId, alice.address, 2)).to.be.equal(2n);114 expect(await getBalance(api, collectionId, alice.address, 3)).to.be.equal(3n);115 });116 });117118 it('Can mint amount of items equals to collection limits', async () => {119 await usingApi(async (api) => {120 const alice = privateKey('//Alice');121122 const collectionId = await createCollectionExpectSuccess();123 await setCollectionLimitsExpectSuccess(alice, collectionId, {124 tokenLimit: 2,125 });126 const args = [127 {NFT: {}},128 {NFT: {}},129 ];130 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);131 const events = await submitTransactionAsync(alice, createMultipleItemsTx);132 const result = getGenericResult(events);133 expect(result.success).to.be.true;134 });135 });136137 it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {138 await usingApi(async (api: ApiPromise) => {139 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});140 const itemsListIndexBefore = await getLastTokenId(api, collectionId);141 expect(itemsListIndexBefore).to.be.equal(0);142 const alice = privateKey('//Alice');143 const args = [144 {NFT: {properties: [{key: 'k', value: 'v1'}]}},145 {NFT: {properties: [{key: 'k', value: 'v2'}]}},146 {NFT: {properties: [{key: 'k', value: 'v3'}]}}147 ];148149 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);150 const itemsListIndexAfter = await getLastTokenId(api, collectionId);151 expect(itemsListIndexAfter).to.be.equal(3);152153 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));154 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));155 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));156157 expect((await getTokenProperties(api, collectionId, 1, ['k']))[0].value).to.be.equal('v1');158 expect((await getTokenProperties(api, collectionId, 2, ['k']))[0].value).to.be.equal('v2');159 expect((await getTokenProperties(api, collectionId, 3, ['k']))[0].value).to.be.equal('v3');160 });161 });162163 it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {164 await usingApi(async (api: ApiPromise) => {165 const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});166 const itemsListIndexBefore = await getLastTokenId(api, collectionId);167 expect(itemsListIndexBefore).to.be.equal(0);168 const alice = privateKey('//Alice');169 const bob = privateKey('//Bob');170 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);171 const args = [172 {NFT: {properties: [{key: 'k', value: 'v1'}]}},173 {NFT: {properties: [{key: 'k', value: 'v2'}]}},174 {NFT: {properties: [{key: 'k', value: 'v3'}]}}175 ];176177 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);178 const itemsListIndexAfter = await getLastTokenId(api, collectionId);179 expect(itemsListIndexAfter).to.be.equal(3);180181 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));182 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));183 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));184185 expect((await getTokenProperties(api, collectionId, 1, ['k']))[0].value).to.be.equal('v1');186 expect((await getTokenProperties(api, collectionId, 2, ['k']))[0].value).to.be.equal('v2');187 expect((await getTokenProperties(api, collectionId, 3, ['k']))[0].value).to.be.equal('v3');188 });189 });190191 it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {192 await usingApi(async (api: ApiPromise) => {193 const collectionId = await createCollectionWithPropsExpectSuccess(194 {propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]}195 );196 const itemsListIndexBefore = await getLastTokenId(api, collectionId);197 expect(itemsListIndexBefore).to.be.equal(0);198 const alice = privateKey('//Alice');199 const args = [200 {NFT: {properties: [{key: 'k', value: 'v1'}]}},201 {NFT: {properties: [{key: 'k', value: 'v2'}]}},202 {NFT: {properties: [{key: 'k', value: 'v3'}]}}203 ];204205 await createMultipleItemsWithPropsExpectSuccess(alice, collectionId, args);206 const itemsListIndexAfter = await getLastTokenId(api, collectionId);207 expect(itemsListIndexAfter).to.be.equal(3);208209 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(alice.address));210 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(alice.address));211 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(alice.address));212213 expect((await getTokenProperties(api, collectionId, 1, ['k']))[0].value).to.be.equal('v1');214 expect((await getTokenProperties(api, collectionId, 2, ['k']))[0].value).to.be.equal('v2');215 expect((await getTokenProperties(api, collectionId, 3, ['k']))[0].value).to.be.equal('v3');216 });217 });218});219220describe('Integration Test createMultipleItems(collection_id, owner, items_data) with collection admin permissions:', () => {221 let alice: IKeyringPair;222 let bob: IKeyringPair;223224 before(async () => {225 await usingApi(async () => {226 alice = privateKey('//Alice');227 bob = privateKey('//Bob');228 });229 });230231 it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {232 await usingApi(async (api: ApiPromise) => {233 const collectionId = await createCollectionWithPropsExpectSuccess(234 {propPerm: [{key: 'data', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]}235 );236 const itemsListIndexBefore = await getLastTokenId(api, collectionId);237 expect(itemsListIndexBefore).to.be.equal(0);238 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);239 const args = [240 {NFT: {properties: [{key: 'data', value: 'v1'}]}},241 {NFT: {properties: [{key: 'data', value: 'v2'}]}},242 {NFT: {properties: [{key: 'data', value: 'v3'}]}}243 ];244 const createMultipleItemsTx = api.tx.unique245 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);246 await submitTransactionAsync(bob, createMultipleItemsTx);247 const itemsListIndexAfter = await getLastTokenId(api, collectionId);248 expect(itemsListIndexAfter).to.be.equal(3);249250 expect(await getTokenOwner(api, collectionId, 1)).to.be.deep.equal(normalizeAccountId(bob.address));251 expect(await getTokenOwner(api, collectionId, 2)).to.be.deep.equal(normalizeAccountId(bob.address));252 expect(await getTokenOwner(api, collectionId, 3)).to.be.deep.equal(normalizeAccountId(bob.address));253254 expect((await getTokenProperties(api, collectionId, 1, ['data']))[0].value).to.be.equal('v1');255 expect((await getTokenProperties(api, collectionId, 2, ['data']))[0].value).to.be.equal('v2');256 expect((await getTokenProperties(api, collectionId, 3, ['data']))[0].value).to.be.equal('v3');257 });258 });259260 it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {261 await usingApi(async (api: ApiPromise) => {262 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});263 const itemsListIndexBefore = await getLastTokenId(api, collectionId);264 expect(itemsListIndexBefore).to.be.equal(0);265 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);266 const args = [267 {Fungible: {value: 1}},268 {Fungible: {value: 2}},269 {Fungible: {value: 3}},270 ];271 const createMultipleItemsTx = api.tx.unique272 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);273 await submitTransactionAsync(bob, createMultipleItemsTx);274 const token1Data = await getBalance(api, collectionId, bob.address, 0);275276 expect(token1Data).to.be.equal(6n); // 1 + 2 + 3277 });278 });279280 it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {281 await usingApi(async (api: ApiPromise) => {282 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});283 const itemsListIndexBefore = await getLastTokenId(api, collectionId);284 expect(itemsListIndexBefore).to.be.equal(0);285 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);286 const args = [287 {ReFungible: {pieces: 1}},288 {ReFungible: {pieces: 2}},289 {ReFungible: {pieces: 3}},290 ];291 const createMultipleItemsTx = api.tx.unique292 .createMultipleItems(collectionId, normalizeAccountId(bob.address), args);293 await submitTransactionAsync(bob, createMultipleItemsTx);294 const itemsListIndexAfter = await getLastTokenId(api, collectionId);295 expect(itemsListIndexAfter).to.be.equal(3);296297 expect(await getBalance(api, collectionId, bob.address, 1)).to.be.equal(1n);298 expect(await getBalance(api, collectionId, bob.address, 2)).to.be.equal(2n);299 expect(await getBalance(api, collectionId, bob.address, 3)).to.be.equal(3n);300 });301 });302});303304describe('Negative Integration Test createMultipleItems(collection_id, owner, items_data):', () => {305 let alice: IKeyringPair;306 let bob: IKeyringPair;307308 before(async () => {309 await usingApi(async () => {310 alice = privateKey('//Alice');311 bob = privateKey('//Bob');312 });313 });314315 it('Regular user cannot create items in active NFT collection', async () => {316 await usingApi(async (api: ApiPromise) => {317 const collectionId = await createCollectionExpectSuccess();318 const itemsListIndexBefore = await getLastTokenId(api, collectionId);319 expect(itemsListIndexBefore).to.be.equal(0);320 const args = [{NFT: {}},321 {NFT: {}},322 {NFT: {}}];323 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);324 await expect(executeTransaction(api, bob, createMultipleItemsTx)).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);325 });326 });327328 it('Regular user cannot create items in active Fungible collection', async () => {329 await usingApi(async (api: ApiPromise) => {330 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});331 const itemsListIndexBefore = await getLastTokenId(api, collectionId);332 expect(itemsListIndexBefore).to.be.equal(0);333 const args = [334 {Fungible: {value: 1}},335 {Fungible: {value: 2}},336 {Fungible: {value: 3}},337 ];338 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);339 await expect(executeTransaction(api, bob, createMultipleItemsTx)).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);340 });341 });342343 it('Regular user cannot create items in active ReFungible collection', async () => {344 await usingApi(async (api: ApiPromise) => {345 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});346 const itemsListIndexBefore = await getLastTokenId(api, collectionId);347 expect(itemsListIndexBefore).to.be.equal(0);348 const args = [349 {ReFungible: {pieces: 1}},350 {ReFungible: {pieces: 1}},351 {ReFungible: {pieces: 1}},352 ];353 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);354 await expect(executeTransaction(api, bob, createMultipleItemsTx)).to.be.rejectedWith(/common\.PublicMintingNotAllowed/);355 });356 });357358 it('Create token in not existing collection', async () => {359 await usingApi(async (api: ApiPromise) => {360 const collectionId = await getCreatedCollectionCount(api) + 1;361 const createMultipleItemsTx = api.tx.unique.createMultipleItems(362 collectionId, normalizeAccountId(alice.address), ['NFT', 'NFT', 'NFT']363 );364 await expect(executeTransaction(api, alice, createMultipleItemsTx)).to.be.rejectedWith(/common\.CollectionNotFound/);365 });366 });367368 it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {369 await usingApi(async (api: ApiPromise) => {370 // NFT371 const collectionId = await createCollectionWithPropsExpectSuccess({372 propPerm: [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]373 });374 const alice = privateKey('//Alice');375 const args = [376 {NFT: {properties: [{key: 'key', value: 'A'.repeat(32769)}]}},377 {NFT: {properties: [{key: 'key', value: 'B'.repeat(32769)}]}},378 {NFT: {properties: [{key: 'key', value: 'C'.repeat(32769)}]}},379 ];380 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);381 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;382383 // ReFungible384 const collectionIdReFungible =385 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});386 const argsReFungible = [387 {ReFungible: ['1'.repeat(2049), 10]},388 {ReFungible: ['2'.repeat(2049), 10]},389 {ReFungible: ['3'.repeat(2049), 10]},390 ];391 const createMultipleItemsTxFungible = api.tx.unique392 .createMultipleItems(collectionIdReFungible, normalizeAccountId(alice.address), argsReFungible);393 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTxFungible)).to.be.rejected;394 });395 });396397 it('Create tokens with different types', async () => {398 await usingApi(async (api: ApiPromise) => {399 const collectionId = await createCollectionExpectSuccess();400 const createMultipleItemsTx = api.tx.unique401 .createMultipleItems(collectionId, normalizeAccountId(alice.address), ['NFT', 'Fungible', 'ReFungible']);402 await expect(403 executeTransaction(api, alice, createMultipleItemsTx)404 ).to.be.rejectedWith(405 /nonfungible\.NotNonfungibleDataUsedToMintFungibleCollectionToken/406 );407 // garbage collection :-D // lol408 await destroyCollectionExpectSuccess(collectionId);409 });410 });411412 it('Create tokens with different data limits <> maximum data limit', async () => {413 await usingApi(async (api: ApiPromise) => {414 const collectionId = await createCollectionWithPropsExpectSuccess({415 propPerm: [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]416 });417 const args = [418 {NFT: {properties: [{key: 'key', value: 'A'}]}},419 {NFT: {properties: [{key: 'key', value: 'B'.repeat(32769)}]}},420 ];421 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);422 await expect(submitTransactionExpectFailAsync(alice, createMultipleItemsTx)).to.be.rejected;423 });424 });425426 it('Fails when minting tokens exceeds collectionLimits amount', async () => {427 await usingApi(async (api) => {428 const collectionId = await createCollectionExpectSuccess();429 await setCollectionLimitsExpectSuccess(alice, collectionId, {430 tokenLimit: 1,431 });432 const args = [433 {NFT: {}},434 {NFT: {}},435 ];436 const createMultipleItemsTx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);437 await expect(executeTransaction(api, alice, createMultipleItemsTx)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);438 });439 });440441 it('User doesnt have editing rights', async () => {442 await usingApi(async (api: ApiPromise) => {443 const collectionId = await createCollectionWithPropsExpectSuccess({444 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]445 });446 const itemsListIndexBefore = await getLastTokenId(api, collectionId);447 expect(itemsListIndexBefore).to.be.equal(0);448 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);449 const args = [450 {NFT: {properties: [{key: 'key1', value: 'v2'}]}},451 {NFT: {}},452 {NFT: {}}453 ];454455 const tx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(bob.address), args);456 await expect(executeTransaction(api, bob, tx)).to.be.rejectedWith(/common\.NoPermission/);457 });458 });459460 it('Adding property without access rights', async () => {461 await usingApi(async (api: ApiPromise) => {462 const collectionId = await createCollectionWithPropsExpectSuccess({properties: [{key: 'k', value: 'v1'}]});463 const itemsListIndexBefore = await getLastTokenId(api, collectionId);464 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);465 expect(itemsListIndexBefore).to.be.equal(0);466 const args = [{NFT: {properties: [{key: 'k', value: 'v'}]}},467 {NFT: {}},468 {NFT: {}}];469470 const tx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(bob.address), args);471 await expect(executeTransaction(api, bob, tx)).to.be.rejectedWith(/common\.NoPermission/);472 });473 });474475 it('Adding more than 64 prps', async () => {476 await usingApi(async (api: ApiPromise) => {477 const propPerms = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];478 for (let i = 0; i < 65; i++) {479 propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});480 }481482 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});483484 const tx1 = api.tx.unique.setPropertyPermissions(collectionId, propPerms);485 await expect(executeTransaction(api, alice, tx1)).to.be.rejectedWith(/common\.PropertyLimitReached/);486487 const itemsListIndexBefore = await getLastTokenId(api, collectionId);488 expect(itemsListIndexBefore).to.be.equal(0);489 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);490491 const prps = [];492493 for (let i = 0; i < 65; i++) {494 prps.push({key: `key${i}`, value: `value${i}`});495 }496497 const args = [498 {NFT: {properties: prps}},499 {NFT: {properties: prps}},500 {NFT: {properties: prps}}501 ];502503 // there are no permissions, but will fail anyway because of too much weight for a block504 const tx2 = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);;505 await expect(submitTransactionExpectFailAsync(alice, tx2)).to.be.rejected;506 });507 });508509 it('Trying to add bigger property than allowed', async () => {510 await usingApi(async (api: ApiPromise) => {511 const collectionId = await createCollectionWithPropsExpectSuccess({512 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]513 });514 const itemsListIndexBefore = await getLastTokenId(api, collectionId);515 expect(itemsListIndexBefore).to.be.equal(0);516 const args = [{NFT: {properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}},517 {NFT: {properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}},518 {NFT: {properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]}}];519520 const tx = api.tx.unique.createMultipleItems(collectionId, normalizeAccountId(alice.address), args);521 await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);522 });523 });524});tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -29,13 +29,13 @@
const data = [
{
owner: {substrate: alice.address},
- constData: '0x0000',
+ // constData: '0x0000',
}, {
owner: {substrate: bob.address},
- constData: '0x2222',
+ // constData: '0x2222',
}, {
owner: {substrate: charlie.address},
- constData: '0x4444',
+ // constData: '0x4444',
},
];
@@ -57,15 +57,15 @@
const data = [
{
owner: {substrate: alice.address},
- constData: '0x1111',
+ // constData: '0x1111',
properties: [{key: 'k', value: 'v1'}],
}, {
owner: {substrate: bob.address},
- constData: '0x2222',
+ // constData: '0x2222',
properties: [{key: 'k', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
- constData: '0x4444',
+ // constData: '0x4444',
properties: [{key: 'k', value: 'v3'}],
},
];
@@ -88,15 +88,15 @@
const data = [
{
owner: {substrate: alice.address},
- constData: '0x0000',
+ // constData: '0x0000',
properties: [{key: 'k', value: 'v1'}],
}, {
owner: {substrate: bob.address},
- constData: '0x2222',
+ // constData: '0x2222',
properties: [{key: 'k', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
- constData: '0x4444',
+ // constData: '0x4444',
properties: [{key: 'k', value: 'v3'}],
},
];
@@ -119,15 +119,15 @@
const data = [
{
owner: {substrate: alice.address},
- constData: '0x0000',
+ // constData: '0x0000',
properties: [{key: 'k', value: 'v1'}],
}, {
owner: {substrate: bob.address},
- constData: '0x2222',
+ // constData: '0x2222',
properties: [{key: 'k', value: 'v2'}],
}, {
owner: {substrate: charlie.address},
- constData: '0x4444',
+ // constData: '0x4444',
properties: [{key: 'k', value: 'v3'}],
},
];
@@ -154,10 +154,10 @@
owner: {substrate: alice.address},
properties: [{key: 'key1', value: 'v2'}],
}, {
- owner: {substrate: alice.address},
+ owner: {substrate: bob.address},
properties: [{key: 'key1', value: 'v2'}],
}, {
- owner: {substrate: alice.address},
+ owner: {substrate: charlie.address},
properties: [{key: 'key1', value: 'v2'}],
},
];
@@ -165,7 +165,8 @@
const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
// await executeTransaction(api, alice, tx);
- await submitTransactionExpectFailAsync(alice, tx);
+ //await submitTransactionExpectFailAsync(alice, tx);
+ await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);
});
});
@@ -193,7 +194,8 @@
const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
// await executeTransaction(api, alice, tx);
- await submitTransactionExpectFailAsync(alice, tx);
+ //await submitTransactionExpectFailAsync(alice, tx);
+ await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);
});
});
@@ -219,41 +221,24 @@
const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
- await submitTransactionExpectFailAsync(alice, tx);
+ await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);
+ //await submitTransactionExpectFailAsync(alice, tx);
});
});
- it('Adding more than 64 prps', async () => {
- const prps = [{key: 'key', value: 'v'}];
- const propPerm = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];
+ it('Adding more than 64 properties', async () => {
+ const propPerms = [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}];
for (let i = 0; i < 65; i++) {
- prps.push({key: `key${i}`, value: `value${i}`});
- propPerm.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});
+ propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});
}
- const collection = await createCollectionWithPropsExpectSuccess({propPerm: propPerm});
const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await addCollectionAdminExpectSuccess(alice, collection, bob.address);
+ const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
await usingApi(async (api) => {
- const data = [
- {
- owner: {substrate: alice.address},
- properties: prps,
- }, {
- owner: {substrate: alice.address},
- properties: prps,
- }, {
- owner: {substrate: alice.address},
- properties: prps,
- },
- ];
-
- const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
-
- await submitTransactionExpectFailAsync(alice, tx);
+ await expect(
+ executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, propPerms))
+ ).to.be.rejectedWith(/common\.PropertyLimitReached/);
});
});
@@ -276,7 +261,8 @@
const tx = api.tx.unique.createMultipleItemsEx(collection, {NFT: data});
- await submitTransactionExpectFailAsync(alice, tx);
+ //await submitTransactionExpectFailAsync(alice, tx);
+ await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/common\.NoPermission/);
});
});
@@ -289,13 +275,13 @@
const data = [
{
owner: {substrate: alice.address},
- constData: '0x0000',
+ // constData: '0x0000',
}, {
owner: {substrate: bob.address},
- constData: '0x2222',
+ // constData: '0x2222',
}, {
owner: {substrate: charlie.address},
- constData: '0x4444',
+ // constData: '0x4444',
},
];
@@ -317,13 +303,13 @@
const data = [
{
owner: {substrate: alice.address},
- constData: '0x0000',
+ // constData: '0x0000',
}, {
owner: {substrate: bob.address},
- constData: '0x2222',
+ // constData: '0x2222',
}, {
owner: {substrate: charlie.address},
- constData: '0x4444',
+ // constData: '0x4444',
},
];
tests/src/nesting/properties.test.tsdiffbeforeafterboth--- a/tests/src/nesting/properties.test.ts
+++ b/tests/src/nesting/properties.test.ts
@@ -792,7 +792,7 @@
]),
)).to.be.rejectedWith(/common\.NoSpaceForProperty/);
- expect((await api.rpc.unique.tokenProperties(collection, token, ['a_holy_book', 'young years'])).toJSON()).to.be.empty;
+ expect((await api.rpc.unique.tokenProperties(collection, token, ['a_holy_book', 'young_years'])).toJSON()).to.be.empty;
const propertiesMap = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();
expect(propertiesMap.consumedSpace).to.be.equal(originalSpace);
});
tests/src/setConstOnChainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setConstOnChainSchema.test.ts
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-import {Keyring} from '@polkadot/api';
-import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {
- createCollectionExpectSuccess,
- destroyCollectionExpectSuccess,
- addCollectionAdminExpectSuccess,
- queryCollectionExpectSuccess,
- getCreatedCollectionCount,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-let alice: IKeyringPair;
-let bob: IKeyringPair;
-let schema: any;
-let largeSchema: any;
-
-before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
- schema = '0x31';
- largeSchema = new Array(1024 * 1024 + 10).fill(0xff);
- });
-});
-describe('Integration Test ext. setConstOnChainSchema()', () => {
-
- it('Run extrinsic with parameters of the collection id, set the scheme', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const collection = await queryCollectionExpectSuccess(api, collectionId);
- expect(collection.owner.toString()).to.be.eq(alice.address);
- const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);
- await submitTransactionAsync(alice, setSchema);
- });
- });
-
- it('Collection admin can set the scheme', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const collection = await queryCollectionExpectSuccess(api, collectionId);
- expect(collection.owner.toString()).to.be.eq(alice.address);
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);
- await submitTransactionAsync(bob, setSchema);
- });
- });
-
- it('Checking collection data using the ConstOnChainSchema parameter', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);
- await submitTransactionAsync(alice, setSchema);
- const collection = await queryCollectionExpectSuccess(api, collectionId);
- expect(collection.constOnChainSchema.toString()).to.be.eq(schema);
- });
- });
-});
-
-describe('Negative Integration Test ext. setConstOnChainSchema()', () => {
-
- it('Set a non-existent collection', async () => {
- await usingApi(async (api) => {
- // tslint:disable-next-line: radix
- const collectionId = await getCreatedCollectionCount(api) + 1;
- const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);
- await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
- });
- });
-
- it('Set a previously deleted collection', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- await destroyCollectionExpectSuccess(collectionId);
- const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);
- await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
- });
- });
-
- it('Set invalid data in schema (size too large:> 1MB)', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, largeSchema);
- await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;
- });
- });
-
- it('Execute method not on behalf of the collection owner', async () => {
- await usingApi(async (api) => {
- const collectionId = await createCollectionExpectSuccess();
- const collection = await queryCollectionExpectSuccess(api, collectionId);
- expect(collection.owner.toString()).to.be.eq(alice.address);
- const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);
- await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;
- });
- });
-
-});
tests/src/setOffchainSchema.test.tsdiffbeforeafterboth--- a/tests/src/setOffchainSchema.test.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
-import usingApi from './substrate/substrate-api';
-import {
- createCollectionExpectSuccess,
- destroyCollectionExpectSuccess,
- findNotExistingCollection,
- queryCollectionExpectSuccess,
- setOffchainSchemaExpectFailure,
- setOffchainSchemaExpectSuccess,
- addCollectionAdminExpectSuccess,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-const DATA = [1, 2, 3, 4];
-
-describe('Integration Test setOffchainSchema', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- });
- });
-
- it('execute setOffchainSchema, verify data was set', async () => {
- await usingApi(async api => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);
- const collection = await queryCollectionExpectSuccess(api, collectionId);
-
- expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
- });
- });
-
- it('execute setOffchainSchema (collection admin), verify data was set', async () => {
- await usingApi(async api => {
- const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
- await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);
- const collection = await queryCollectionExpectSuccess(api, collectionId);
-
- expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));
- });
- });
-});
-
-describe('Negative Integration Test setOffchainSchema', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- let validCollectionId: number;
-
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
-
- validCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- });
- });
-
- it('fails on not existing collection id', async () => {
- const nonExistingCollectionId = await usingApi(findNotExistingCollection);
-
- await setOffchainSchemaExpectFailure(alice, nonExistingCollectionId, DATA);
- });
-
- it('fails on destroyed collection id', async () => {
- const destroyedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await destroyCollectionExpectSuccess(destroyedCollectionId);
-
- await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);
- });
-
- it('fails on too long data', async () => {
- const tooLongData = new Array(8 * 1024 + 10).fill(0xff);
-
- await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);
- });
-
- it('fails on execution by non-owner', async () => {
- await setOffchainSchemaExpectFailure(bob, validCollectionId, DATA);
- });
-});
tests/src/setSchemaVersion.test.tsdiffbeforeafterboth--- a/tests/src/setSchemaVersion.test.ts
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-// https://unique-network.readthedocs.io/en/latest/jsapi.html#setschemaversion
-import {ApiPromise, Keyring} from '@polkadot/api';
-import {IKeyringPair} from '@polkadot/types/types';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {
- createCollectionExpectSuccess,
- destroyCollectionExpectSuccess,
- getCreatedCollectionCount,
- getCreateItemResult,
- getDetailedCollectionInfo,
- addCollectionAdminExpectSuccess,
-} from './util/helpers';
-
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
-let alice: IKeyringPair;
-let bob: IKeyringPair;
-let charlie: IKeyringPair;
-
-/*
-1. We create collection.
-2. Save just created collection id.
-3. Use this id for setSchemaVersion.
-*/
-describe('setSchemaVersion positive', () => {
- let tx;
- before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- });
- });
- it('execute setSchemaVersion with image url and unique ', async () => {
- await usingApi(async (api: ApiPromise) => {
- const collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
- tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'Unique');
- const events = await submitTransactionAsync(alice, tx);
- const result = getCreateItemResult(events);
- const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);
- // tslint:disable-next-line:no-unused-expression
- expect(result.success).to.be.true;
- // tslint:disable-next-line:no-unused-expression
- expect(collectionInfo).to.be.exist;
- // tslint:disable-next-line:no-unused-expression
- expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');
- });
- });
-});
-
-describe('Collection admin setSchemaVersion positive', () => {
- let tx;
- let collectionIdForTesting: any;
-
- before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
- collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
- await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);
- });
- });
- it('execute setSchemaVersion with image url and unique ', async () => {
- await usingApi(async (api: ApiPromise) => {
- tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'Unique');
- const events = await submitTransactionAsync(bob, tx);
- const result = getCreateItemResult(events);
- const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);
- // tslint:disable-next-line:no-unused-expression
- expect(result.success).to.be.true;
- // tslint:disable-next-line:no-unused-expression
- expect(collectionInfo).to.be.exist;
- // tslint:disable-next-line:no-unused-expression
- expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('Unique');
- });
- });
-
- it('validate schema version with just entered data', async () => {
- await usingApi(async (api: ApiPromise) => {
- tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'ImageURL');
- const events = await submitTransactionAsync(bob, tx);
- const result = getCreateItemResult(events);
- const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);
- // tslint:disable-next-line:no-unused-expression
- expect(result.success).to.be.true;
- // tslint:disable-next-line:no-unused-expression
- expect(collectionInfo).to.be.exist;
- // tslint:disable-next-line:no-unused-expression
- expect(collectionInfo ? collectionInfo.schemaVersion.toString() : '').to.be.equal('ImageURL');
- });
- });
-});
-
-describe('setSchemaVersion negative', () => {
- let tx;
- let collectionIdForTesting: any;
- before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- charlie = keyring.addFromUri('//Charlie');
- collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
- });
- });
- it('execute setSchemaVersion for not exists collection', async () => {
- await usingApi(async (api: ApiPromise) => {
- const collectionCount = await getCreatedCollectionCount(api);
- const nonExistedCollectionId = collectionCount + 1;
- tx = api.tx.unique.setSchemaVersion(nonExistedCollectionId, 'ImageURL');
- await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
- });
- });
- it('execute setSchemaVersion for deleted collection', async () => {
- await usingApi(async (api: ApiPromise) => {
- await destroyCollectionExpectSuccess(collectionIdForTesting);
- tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'ImageURL');
- await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
- });
- });
- it('Regular user can`t execute setSchemaVersion with image url and unique ', async () => {
- await usingApi(async (api: ApiPromise) => {
- tx = api.tx.unique.setSchemaVersion(collectionIdForTesting, 'Unique');
- await expect(submitTransactionAsync(charlie, tx)).to.be.rejected;
- });
- });
-});
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -27,7 +27,7 @@
import privateKey from '../substrate/privateKey';
import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
import {hexToStr, strToUTF16, utf16ToStr} from './util';
-import {UpDataStructsRpcCollection, UpDataStructsCreateItemData} from '@polkadot/types/lookup';
+import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -141,7 +141,6 @@
export interface IReFungibleTokenDataType {
owner: IReFungibleOwner[];
- constData: number[];
}
export function uniqueEventMessage(events: EventRecord[]): IGetMessage {
@@ -784,7 +783,7 @@
});
}
-export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) {
+/*export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) {
await usingApi(async (api) => {
const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));
const events = await submitTransactionAsync(sender, tx);
@@ -799,7 +798,7 @@
const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));
await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
});
-}
+}*/
export interface CreateFungibleData {
readonly Value: bigint;
@@ -1111,12 +1110,20 @@
): Promise<string[]> {
return (await api.rpc.unique.adminlist(collectionId)).toHuman() as any;
}
-export async function getConstMetadata(
+/*export async function getConstMetadata(
api: ApiPromise,
collectionId: number,
tokenId: number,
): Promise<number[]> {
return [...(await api.rpc.unique.constMetadata(collectionId, tokenId))];
+}*/
+export async function getTokenProperties(
+ api: ApiPromise,
+ collectionId: number,
+ tokenId: number,
+ propertyKeys: string[],
+): Promise<UpDataStructsProperty[]> {
+ return (await api.rpc.unique.tokenProperties(collectionId, tokenId, propertyKeys)).toHuman() as any;
}
export async function createFungibleItemExpectSuccess(
@@ -1150,18 +1157,6 @@
});
}
-export async function createMultipleItemsWithPropsExpectFailure(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {
- await usingApi(async (api) => {
- const to = normalizeAccountId(owner);
- const tx = api.tx.unique.createMultipleItems(collectionId, to, itemsData);
-
- const events = await expect(await submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
- const result = getCreateItemsResult(events);
-
- expect(result).to.be.equal(false);
- });
-}
-
export async function createMultipleItemsExWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any) {
await usingApi(async (api) => {
const tx = api.tx.unique.createMultipleItemsEx(collectionId, itemsData);
@@ -1187,10 +1182,10 @@
const createData = {fungible: {value: 10}};
tx = api.tx.unique.createItem(collectionId, to, createData as any);
} else if (createMode === 'ReFungible') {
- const createData = {refungible: {const_data: [], pieces: 100}};
+ const createData = {refungible: {pieces: 100}};
tx = api.tx.unique.createItem(collectionId, to, createData as any);
} else {
- const data = api.createType('UpDataStructsCreateItemData', {NFT: {constData: 'test', properties: props}});
+ const data = api.createType('UpDataStructsCreateItemData', {NFT: {properties: props}});
tx = api.tx.unique.createItem(collectionId, to, data as UpDataStructsCreateItemData);
}
@@ -1225,7 +1220,7 @@
let tx;
if (createMode === 'NFT') {
- const data = api.createType('UpDataStructsCreateItemData', {NFT: {constData: 'test', properties: props}});
+ const data = api.createType('UpDataStructsCreateItemData', {NFT: {properties: props}});
tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), data);
} else {
tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), createMode);
@@ -1251,10 +1246,10 @@
const createData = {fungible: {value: 10}};
tx = api.tx.unique.createItem(collectionId, to, createData as any);
} else if (createMode === 'ReFungible') {
- const createData = {refungible: {const_data: [], pieces: 100}};
+ const createData = {refungible: {pieces: 100}};
tx = api.tx.unique.createItem(collectionId, to, createData as any);
} else {
- const createData = {nft: {const_data: []}};
+ const createData = {nft: {}};
tx = api.tx.unique.createItem(collectionId, to, createData as any);
}