From d22ad5ff0f4fc6423a71ee6fb629b97e23fbe4ef Mon Sep 17 00:00:00 2001 From: Grigoriy Simonov Date: Thu, 23 Jun 2022 07:38:30 +0000 Subject: [PATCH] splitted test into multiple test cases --- --- a/tests/src/refungible.test.ts +++ b/tests/src/refungible.test.ts @@ -47,39 +47,89 @@ }); }); - it('Create refungible collection and token. Token pieces transfer. Token repartition.', async () => { + it('Create refungible collection and token. Token pieces transfer.', async () => { const createMode = 'ReFungible'; const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}}); const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); + let aliceBalance = BigInt(0); + await usingApi(async api => { + aliceBalance = await getBalance(api, collectionId, alice.address, tokenId); + }); + const transferAmount = BigInt(60); + await transferExpectSuccess(collectionId, tokenId, alice, bob, transferAmount, 'ReFungible'); + aliceBalance = aliceBalance - transferAmount; + await transferExpectFailure(collectionId, tokenId, alice, bob, aliceBalance + BigInt(1)); + }); + + it('Create multiple tokens', async () => { + const createMode = 'ReFungible'; + const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}}); const args = [ {ReFungible: {pieces: 1}}, {ReFungible: {pieces: 2}}, - {ReFungible: {pieces: 3}}, + {ReFungible: {pieces: 100}}, ]; await createMultipleItemsExpectSuccess(alice, collectionId, args); + let tokenId = 0; + await usingApi(async api => { + tokenId = await getLastTokenId(api, collectionId); + expect(tokenId).to.be.equal(3); + }); + + const transferAmount = BigInt(60); + await transferExpectSuccess(collectionId, tokenId, alice, bob, transferAmount, 'ReFungible'); + }); + + it('Burn some pieces', async () => { + const createMode = 'ReFungible'; + const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}}); + const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); + + let aliceBalance = BigInt(0); + await usingApi(async api => { + aliceBalance = await getBalance(api, collectionId, alice.address, tokenId); + expect(await isTokenExists(api, collectionId, tokenId)).to.be.true; + }); + await burnItemExpectSuccess(alice, collectionId, tokenId, aliceBalance - BigInt(1)); + await usingApi(async api => { + expect(await isTokenExists(api, collectionId, tokenId)).to.be.true; + }); + }); + + it('Burn all pieces', async () => { + const createMode = 'ReFungible'; + const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}}); + const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); + let aliceBalance = BigInt(0); await usingApi(async api => { + aliceBalance = await getBalance(api, collectionId, alice.address, tokenId); expect(await isTokenExists(api, collectionId, tokenId)).to.be.true; - - const itemsListIndexAfter = await getLastTokenId(api, collectionId); - expect(itemsListIndexAfter).to.be.equal(4); + }); + await burnItemExpectSuccess(alice, collectionId, tokenId, aliceBalance); + await usingApi(async api => { + expect(await isTokenExists(api, collectionId, tokenId)).to.be.false; + }); + }); + it('Set allowance for token', async () => { + const createMode = 'ReFungible'; + const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}}); + const tokenId = await createItemExpectSuccess(alice, collectionId, createMode); + + let aliceBalance = BigInt(0); + await usingApi(async api => { aliceBalance = await getBalance(api, collectionId, alice.address, tokenId); }); - const transferAmount = BigInt(60); - await transferExpectSuccess(collectionId, tokenId, alice, bob, transferAmount, 'ReFungible'); - aliceBalance = aliceBalance - transferAmount; - await transferExpectFailure(collectionId, tokenId, alice, bob, aliceBalance + BigInt(1)); - await burnItemExpectSuccess(alice, collectionId, tokenId, aliceBalance - BigInt(1)); - await approveExpectSuccess(collectionId, tokenId, bob, alice.address, transferAmount); - const bobBalance = transferAmount; const allowedAmount = BigInt(60); - await transferFromExpectSuccess(collectionId, tokenId, alice, bob, alice, 40, 'ReFungible'); + await approveExpectSuccess(collectionId, tokenId, alice, bob.address, allowedAmount); + const transferAmount = BigInt(20); + await transferFromExpectSuccess(collectionId, tokenId, bob, alice, bob, transferAmount, 'ReFungible'); await usingApi(async api => { - expect(await getAllowance(api, collectionId, bob.address, alice.address, 0)).to.equal(bobBalance - allowedAmount); + expect(await getAllowance(api, collectionId, alice.address, bob.address, tokenId)).to.equal(allowedAmount - transferAmount); }); }); -- gitstuff