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

difftreelog

Positive createItem tests

Greg Zaitsev2020-12-23parent: #fbf1789.patch.diff
in: master

2 files changed

modifiedtests/src/createItem.test.tsdiffbeforeafterboth
before · tests/src/createItem.test.ts
1import { assert } from 'chai';
2import { alicesPublicKey } from './accounts';
3import privateKey from './substrate/privateKey';
4import { default as usingApi } from './substrate/substrate-api';
5import waitNewBlocks from './substrate/wait-new-blocks';
6import { createCollectionExpectSuccess } from './util/helpers';
7
8describe('integration test: ext. createItem():', () => {
9  it('Create new item in NFT collection', async () => {
10    await usingApi(async (api) => {
11      const createMode = 'NFT';
12      const alicePrivateKey = privateKey('//Alice');
13      await createCollectionExpectSuccess('0', '0', '0', createMode);
14      await waitNewBlocks(api);
15      const newCollectionID = await api.query.nft.createdCollectionCount();
16      const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
17      await api.tx.nft
18            .createItem(newCollectionID, alicesPublicKey, createMode)
19            .signAndSend(alicePrivateKey);
20      await waitNewBlocks(api);
21      const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
22      if (BnftItemList === AnftItemList) {assert.fail(`Error: new item in ${createMode} collection NOT created.`); }
23    });
24  });
25  it('Create new item in Fungible collection', async () => {
26    await usingApi(async (api) => {
27      const createMode = 'Fungible';
28      const alicePrivateKey = privateKey('//Alice');
29      await createCollectionExpectSuccess('0', '0', '0', createMode);
30      await waitNewBlocks(api);
31      const newCollectionID = await api.query.nft.createdCollectionCount();
32      const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
33      await api.tx.nft
34            .createItem(newCollectionID, alicesPublicKey, createMode)
35            .signAndSend(alicePrivateKey);
36      await waitNewBlocks(api);
37      const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
38      if (BnftItemList === AnftItemList) {assert.fail(`Error: new item in ${createMode} collection NOT created.`); }
39    });
40  });
41  it('Create new item in ReFungible collection', async () => {
42    await usingApi(async (api) => {
43      const createMode = 'ReFungible';
44      const alicePrivateKey = privateKey('//Alice');
45      await createCollectionExpectSuccess('0', '0', '0', createMode);
46      await waitNewBlocks(api);
47      const newCollectionID = await api.query.nft.createdCollectionCount();
48      const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
49      await api.tx.nft
50            .createItem(newCollectionID, alicesPublicKey, 'ReFungible')
51            .signAndSend(alicePrivateKey);
52      await waitNewBlocks(api);
53      const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
54      if (BnftItemList === AnftItemList) {assert.fail(`Error: new item in ${createMode} collection NOT created.`); }
55    });
56  });
57});
after · tests/src/createItem.test.ts
1import { assert } from 'chai';
2import { alicesPublicKey } from './accounts';
3import privateKey from './substrate/privateKey';
4import { default as usingApi } from './substrate/substrate-api';
5import waitNewBlocks from './substrate/wait-new-blocks';
6import { 
7  createCollectionExpectSuccess, 
8  createItemExpectSuccess
9} from './util/helpers';
10
11describe.only('integration test: ext. createItem():', () => {
12  it('Create new item in NFT collection', async () => {
13    const createMode = 'NFT';
14    const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
15    await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
16  });
17  it('Create new item in Fungible collection', async () => {
18    const createMode = 'Fungible';
19    const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
20    await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
21  });
22  it('Create new item in ReFungible collection', async () => {
23    const createMode = 'ReFungible';
24    const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
25    await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
26  });
27});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -121,4 +121,22 @@
     bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());
   } while (bal.toFixed() != '0');
   return unused; 
-}
\ No newline at end of file
+}
+
+export async function createItemExpectSuccess(collectionId: number, createMode: string, senderSeed: string = '//Alice') {
+  await usingApi(async (api) => {
+
+    const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());
+
+    const sender = privateKey(senderSeed);
+    const tx = api.tx.nft.createItem(collectionId, sender.address, createMode);
+    const events = await submitTransactionAsync(sender, tx);
+    const result = getGenericResult(events);
+  
+    const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());
+
+    // What to expect
+    expect(result.success).to.be.true;
+    expect(BItemCount).to.be.equal(AItemCount+1);
+  });
+}