difftreelog
Positive createItem tests
in: master
2 files changed
tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -3,55 +3,25 @@
import privateKey from './substrate/privateKey';
import { default as usingApi } from './substrate/substrate-api';
import waitNewBlocks from './substrate/wait-new-blocks';
-import { createCollectionExpectSuccess } from './util/helpers';
+import {
+ createCollectionExpectSuccess,
+ createItemExpectSuccess
+} from './util/helpers';
-describe('integration test: ext. createItem():', () => {
+describe.only('integration test: ext. createItem():', () => {
it('Create new item in NFT collection', async () => {
- await usingApi(async (api) => {
- const createMode = 'NFT';
- const alicePrivateKey = privateKey('//Alice');
- await createCollectionExpectSuccess('0', '0', '0', createMode);
- await waitNewBlocks(api);
- const newCollectionID = await api.query.nft.createdCollectionCount();
- const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
- await api.tx.nft
- .createItem(newCollectionID, alicesPublicKey, createMode)
- .signAndSend(alicePrivateKey);
- await waitNewBlocks(api);
- const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
- if (BnftItemList === AnftItemList) {assert.fail(`Error: new item in ${createMode} collection NOT created.`); }
- });
+ const createMode = 'NFT';
+ const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
+ await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
});
it('Create new item in Fungible collection', async () => {
- await usingApi(async (api) => {
- const createMode = 'Fungible';
- const alicePrivateKey = privateKey('//Alice');
- await createCollectionExpectSuccess('0', '0', '0', createMode);
- await waitNewBlocks(api);
- const newCollectionID = await api.query.nft.createdCollectionCount();
- const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
- await api.tx.nft
- .createItem(newCollectionID, alicesPublicKey, createMode)
- .signAndSend(alicePrivateKey);
- await waitNewBlocks(api);
- const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
- if (BnftItemList === AnftItemList) {assert.fail(`Error: new item in ${createMode} collection NOT created.`); }
- });
+ const createMode = 'Fungible';
+ const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
+ await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
});
it('Create new item in ReFungible collection', async () => {
- await usingApi(async (api) => {
- const createMode = 'ReFungible';
- const alicePrivateKey = privateKey('//Alice');
- await createCollectionExpectSuccess('0', '0', '0', createMode);
- await waitNewBlocks(api);
- const newCollectionID = await api.query.nft.createdCollectionCount();
- const AnftItemList = await api.query.nft.itemListIndex(newCollectionID);
- await api.tx.nft
- .createItem(newCollectionID, alicesPublicKey, 'ReFungible')
- .signAndSend(alicePrivateKey);
- await waitNewBlocks(api);
- const BnftItemList = await api.query.nft.itemListIndex(newCollectionID);
- if (BnftItemList === AnftItemList) {assert.fail(`Error: new item in ${createMode} collection NOT created.`); }
- });
+ const createMode = 'ReFungible';
+ const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
+ await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
});
});
tests/src/util/helpers.tsdiffbeforeafterboth123 return unused; 123 return unused; 124}124}125126export async function createItemExpectSuccess(collectionId: number, createMode: string, senderSeed: string = '//Alice') {127 await usingApi(async (api) => {128129 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());130131 const sender = privateKey(senderSeed);132 const tx = api.tx.nft.createItem(collectionId, sender.address, createMode);133 const events = await submitTransactionAsync(sender, tx);134 const result = getGenericResult(events);135 136 const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());137138 // What to expect139 expect(result.success).to.be.true;140 expect(BItemCount).to.be.equal(AItemCount+1);141 });142}143