--- 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'); }); }); --- 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); + }); +}