difftreelog
Merge pull request #61 from usetech-llc/feature/NFTPAR-236_burn_item
in: master
Feature/nftpar 236 burn item
9 files changed
tests/src/burnItem.test.tsdiffbeforeafterbothno changes
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth89 });89 });909091 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');9595115 });115 });116116117 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');121121210 });210 });211211212 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');216216247 });247 });248248249 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');253253tests/src/createCollection.test.tsdiffbeforeafterboth6import 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
tests/src/createItem.test.tsdiffbeforeafterboth18
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});
tests/src/destroyCollection.test.tsdiffbeforeafterboth14 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});tests/src/setCollectionLimits.test.tsdiffbeforeafterboth32 });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});tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth30 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 });4040tests/src/setSchemaVersion.test.tsdiffbeforeafterboth35 });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});tests/src/util/helpers.tsdiffbeforeafterboth88 return result;88 return result;89}89}9091interface Invalid {92 type: 'Invalid'93}9495interface Nft {96 type: 'NFT'97}9899interface Fungible {100 type: 'Fungible',101 decimalPoints: number102}103104interface ReFungible {105 type: 'ReFungible',106 decimalPoints: number107}9010891export type CollectionMode = 'NFT' | 'Fungible' | 'ReFungible';109type CollectionMode = Nft | Fungible | ReFungible | Invalid;11092export 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}105124114 // Run the CreateCollection transaction133 // Run the CreateCollection transaction115 const alicePrivateKey = privateKey('//Alice');134 const alicePrivateKey = privateKey('//Alice');135136 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 }149116 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