git.delta.rocks / unique-network / refs/commits / 147c8928fe2f

difftreelog

Merge pull request #61 from usetech-llc/feature/NFTPAR-236_burn_item

str-mv2021-01-14parents: #aa3aa05 #c356c0a.patch.diff
in: master
Feature/nftpar 236 burn item

9 files changed

addedtests/src/burnItem.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
89 });89 });
9090
91 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {91 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {
92 const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});92 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
93 await setCollectionSponsorExpectSuccess(collectionId, bob.address);93 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
94 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');94 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
9595
115 });115 });
116116
117 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {117 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {
118 const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});118 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});
119 await setCollectionSponsorExpectSuccess(collectionId, bob.address);119 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
121121
210 });210 });
211211
212 it('Fungible: Sponsoring is rate limited', async () => {212 it('Fungible: Sponsoring is rate limited', async () => {
213 const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});213 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
214 await setCollectionSponsorExpectSuccess(collectionId, bob.address);214 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
215 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');215 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
216216
247 });247 });
248248
249 it('ReFungible: Sponsoring is rate limited', async () => {249 it('ReFungible: Sponsoring is rate limited', async () => {
250 const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});250 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});
251 await setCollectionSponsorExpectSuccess(collectionId, bob.address);251 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
252 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');252 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
253253
modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
6import chai from 'chai'; 6import chai from 'chai';
7import chaiAsPromised from 'chai-as-promised'; 7import chaiAsPromised from 'chai-as-promised';
8import { default as usingApi } from "./substrate/substrate-api"; 8import { default as usingApi } from "./substrate/substrate-api";
9import { createCollectionExpectSuccess, createCollectionExpectFailure, CollectionMode } from "./util/helpers"; 9import { createCollectionExpectSuccess, createCollectionExpectFailure } from "./util/helpers";
10 10
11chai.use(chaiAsPromised); 11chai.use(chaiAsPromised);
12const expect = chai.expect; 12const expect = chai.expect;
13 13
14describe('integration test: ext. createCollection():', () => { 14describe('integration test: ext. createCollection():', () => {
15 it('Create new NFT collection', async () => { 15 it('Create new NFT collection', async () => {
16 await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'}); 16 await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
17 }); 17 });
18 it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => { 18 it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {
19 await createCollectionExpectSuccess({name: 'A'.repeat(64)}); 19 await createCollectionExpectSuccess({name: 'A'.repeat(64)});
25 await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)}); 25 await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});
26 }); 26 });
27 it('Create new Fungible collection', async () => { 27 it('Create new Fungible collection', async () => {
28 await createCollectionExpectSuccess({mode: 'Fungible'}); 28 await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
29 }); 29 });
30 it('Create new ReFungible collection', async () => { 30 it('Create new ReFungible collection', async () => {
31 await createCollectionExpectSuccess({mode: 'ReFungible'}); 31 await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
32 }); 32 });
33}); 33});
34 34
38 const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString()); 38 const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString());
39 39
40 const badTransaction = async function () { 40 const badTransaction = async function () {
41 await createCollectionExpectSuccess({mode: 'BadMode' as CollectionMode}); 41 await createCollectionExpectSuccess({mode: {type: 'Invalid'}});
42 }; 42 };
43 expect(badTransaction()).to.be.rejected; 43 expect(badTransaction()).to.be.rejected;
44 44
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
18 18
19 it('Create new item in NFT collection', async () => { 19 it('Create new item in NFT collection', async () => {
20 const createMode = 'NFT'; 20 const createMode = 'NFT';
21 const newCollectionID = await createCollectionExpectSuccess({mode: createMode}); 21 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
22 await createItemExpectSuccess(alice, newCollectionID, createMode); 22 await createItemExpectSuccess(alice, newCollectionID, createMode);
23 }); 23 });
24 it('Create new item in Fungible collection', async () => { 24 it('Create new item in Fungible collection', async () => {
25 const createMode = 'Fungible'; 25 const createMode = 'Fungible';
26 const newCollectionID = await createCollectionExpectSuccess({mode: createMode}); 26 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
27 await createItemExpectSuccess(alice, newCollectionID, createMode); 27 await createItemExpectSuccess(alice, newCollectionID, createMode);
28 }); 28 });
29 it('Create new item in ReFungible collection', async () => { 29 it('Create new item in ReFungible collection', async () => {
30 const createMode = 'ReFungible'; 30 const createMode = 'ReFungible';
31 const newCollectionID = await createCollectionExpectSuccess({mode: createMode}); 31 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
32 await createItemExpectSuccess(alice, newCollectionID, createMode); 32 await createItemExpectSuccess(alice, newCollectionID, createMode);
33 }); 33 });
34}); 34});
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
14 await destroyCollectionExpectSuccess(collectionId);14 await destroyCollectionExpectSuccess(collectionId);
15 });15 });
16 it('Fungible collection can be destroyed', async () => {16 it('Fungible collection can be destroyed', async () => {
17 const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });17 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
18 await destroyCollectionExpectSuccess(collectionId);18 await destroyCollectionExpectSuccess(collectionId);
19 });19 });
20 it('ReFungible collection can be destroyed', async () => {20 it('ReFungible collection can be destroyed', async () => {
21 const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });21 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
22 await destroyCollectionExpectSuccess(collectionId);22 await destroyCollectionExpectSuccess(collectionId);
23 });23 });
24});24});
modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
32 });32 });
33 it('choose or create collection for testing', async () => {33 it('choose or create collection for testing', async () => {
34 await usingApi(async () => {34 await usingApi(async () => {
35 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});35 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
36 });36 });
37 });37 });
38});38});
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
30 await setCollectionSponsorExpectSuccess(collectionId, bob.address);30 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
31 });31 });
32 it('Set Fungible collection sponsor', async () => {32 it('Set Fungible collection sponsor', async () => {
33 const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });33 const collectionId = await createCollectionExpectSuccess({ mode: {type: 'Fungible', decimalPoints: 0} });
34 await setCollectionSponsorExpectSuccess(collectionId, bob.address);34 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
35 });35 });
36 it('Set ReFungible collection sponsor', async () => {36 it('Set ReFungible collection sponsor', async () => {
37 const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });37 const collectionId = await createCollectionExpectSuccess({ mode: {type: 'ReFungible', decimalPoints: 0} });
38 await setCollectionSponsorExpectSuccess(collectionId, bob.address);38 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
39 });39 });
4040
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
35 });35 });
36 it('choose or create collection for testing', async () => {36 it('choose or create collection for testing', async () => {
37 await usingApi(async () => {37 await usingApi(async () => {
38 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});38 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
39 });39 });
40 });40 });
41});41});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
88 return result;88 return result;
89}89}
90
91interface Invalid {
92 type: 'Invalid'
93}
94
95interface Nft {
96 type: 'NFT'
97}
98
99interface Fungible {
100 type: 'Fungible',
101 decimalPoints: number
102}
103
104interface ReFungible {
105 type: 'ReFungible',
106 decimalPoints: number
107}
90108
91export type CollectionMode = 'NFT' | 'Fungible' | 'ReFungible';109type CollectionMode = Nft | Fungible | ReFungible | Invalid;
110
92export type CreateCollectionParams = {111export type CreateCollectionParams = {
93 mode: CollectionMode,112 mode: CollectionMode,
99const defaultCreateCollectionParams: CreateCollectionParams = {118const defaultCreateCollectionParams: CreateCollectionParams = {
100 name: 'name',119 name: 'name',
101 description: 'description',120 description: 'description',
102 mode: 'NFT',121 mode: { type: "NFT" },
103 tokenPrefix: 'prefix'122 tokenPrefix: 'prefix'
104}123}
105124
114 // Run the CreateCollection transaction133 // Run the CreateCollection transaction
115 const alicePrivateKey = privateKey('//Alice');134 const alicePrivateKey = privateKey('//Alice');
135
136 let modeprm = {};
137 if (mode.type == 'NFT') {
138 modeprm = {nft: null};
139 }
140 else if (mode.type == 'Fungible') {
141 modeprm = {fungible: mode.decimalPoints};
142 }
143 else if (mode.type == 'ReFungible') {
144 modeprm = {refungible: mode.decimalPoints};
145 }
146 else if (mode.type == 'Invalid') {
147 modeprm = {invalid: null};
148 }
149
116 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), mode);150 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);
117 const events = await submitTransactionAsync(alicePrivateKey, tx);151 const events = await submitTransactionAsync(alicePrivateKey, tx);
118 const result = getCreateCollectionResult(events);152 const result = getCreateCollectionResult(events);
119153