difftreelog
Update createItem.test.ts
in: master
1 file changed
tests/src/createItem.test.tsdiffbeforeafterboth1import { stringToU8a, u8aToString } from '@polkadot/util';
2import { assert, expect } from 'chai';
1import { assert } from 'chai';
3import { alicesPublicKey } from './accounts';
2import { alicesPublicKey } from './accounts';
4import privateKey from './substrate/privateKey';
3import privateKey from './substrate/privateKey';
5import usingApi from './substrate/substrate-api';
4import { default as usingApi } from './substrate/substrate-api';
6import waitNewBlocks from './substrate/wait-new-blocks';
5import waitNewBlocks from './substrate/wait-new-blocks';
7
8async function createCollection(name, desk, pref, mode) {
9 await usingApi(async (api) => {
6import { createCollectionExpectSuccess } from './util/helpers';
10 const alicePrivateKey = privateKey('//Alice');
7
11 const AcollectionCount = await api.query.nft.collectionCount();
12 try {await api.tx.nft
13 .createCollection(name, desk, pref, mode)
14 .signAndSend(alicePrivateKey);
15 await waitNewBlocks(api);
16 const BcollectionCount = await api.query.nft.collectionCount();
17 // tslint:disable-next-line: max-line-length
18 if (BcollectionCount === AcollectionCount) {assert.fail('Error: collection NOT created.'); }} catch { assert.fail('Create collection error.'); }
19 });
20}
21
22describe('integration test: ext. createItem():', () => {
8describe('integration test: ext. createItem():', () => {
23 it('Create new item in NFT collection', async () => {
9 it('Create new item in NFT collection', async () => {
24 await usingApi(async (api) => {
10 await usingApi(async (api) => {
11 const createMode = 'NFT';
12 const alicePrivateKey = privateKey('//Alice');
25 createCollection('1', '1', '0', 'NFT');
13 await createCollectionExpectSuccess('0', '0', '0', createMode);
14 await waitNewBlocks(api);
26 const newCollectionID = await api.query.nft.createdCollectionCount();
15 const newCollectionID = await api.query.nft.createdCollectionCount();
27 const alicePrivateKey = privateKey('//Alice');
28 const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
16 const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
29 await api.tx.nft
17 await api.tx.nft
30 .createItem(newCollectionID, alicesPublicKey, 'NFT')
18 .createItem(newCollectionID, alicesPublicKey, createMode)
31 .signAndSend(alicePrivateKey);
19 .signAndSend(alicePrivateKey);
32 await waitNewBlocks(api);
20 await waitNewBlocks(api);
33 const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
21 const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
34 if (BnftItemList === AnftItemList) {assert.fail('Error: new item in NFT collection NOT created.'); }
22 if (BnftItemList === AnftItemList) {assert.fail(`Error: new item in ${createMode} collection NOT created.`); }
35 });
23 });
36 });
24 });
37 it('Create new item in Fungible collection', async () => {
25 it('Create new item in Fungible collection', async () => {
38 await usingApi(async (api) => {
26 await usingApi(async (api) => {
27 const createMode = 'Fungible';
28 const alicePrivateKey = privateKey('//Alice');
39 createCollection('1', '1', '0', 'Fungible');
29 await createCollectionExpectSuccess('0', '0', '0', createMode);
30 await waitNewBlocks(api);
40 const newCollectionID = await api.query.nft.createdCollectionCount();
31 const newCollectionID = await api.query.nft.createdCollectionCount();
41 const alicePrivateKey = privateKey('//Alice');
42 const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
32 const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
43 await api.tx.nft
33 await api.tx.nft
44 .createItem(newCollectionID, alicesPublicKey, 'Fungible')
34 .createItem(newCollectionID, alicesPublicKey, createMode)
45 .signAndSend(alicePrivateKey);
35 .signAndSend(alicePrivateKey);
46 await waitNewBlocks(api);
36 await waitNewBlocks(api);
47 const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
37 const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
48 if (BnftItemList === AnftItemList) {assert.fail('Error: new item in Fungible collection NOT created.'); }
38 if (BnftItemList === AnftItemList) {assert.fail(`Error: new item in ${createMode} collection NOT created.`); }
49 });
39 });
50 });
40 });
51 it('Create new item in ReFungible collection', async () => {
41 it('Create new item in ReFungible collection', async () => {
52 await usingApi(async (api) => {
42 await usingApi(async (api) => {
43 const createMode = 'ReFungible';
44 const alicePrivateKey = privateKey('//Alice');
53 createCollection('1', '1', '0', 'ReFungible');
45 await createCollectionExpectSuccess('0', '0', '0', createMode);
46 await waitNewBlocks(api);
54 const newCollectionID = await api.query.nft.createdCollectionCount();
47 const newCollectionID = await api.query.nft.createdCollectionCount();
55 const alicePrivateKey = privateKey('//Alice');
56 const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
48 const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
57 await api.tx.nft
49 await api.tx.nft
58 .createItem(newCollectionID, alicesPublicKey, 'ReFungible')
50 .createItem(newCollectionID, alicesPublicKey, 'ReFungible')
59 .signAndSend(alicePrivateKey);
51 .signAndSend(alicePrivateKey);
60 await waitNewBlocks(api);
52 await waitNewBlocks(api);
61 const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
53 const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
62 if (BnftItemList === AnftItemList) {assert.fail('Error: new item in ReFungible collection NOT created.'); }
54 if (BnftItemList === AnftItemList) {assert.fail(`Error: new item in ${createMode} collection NOT created.`); }
63 });
55 });
64 });
56 });
65});
57});