From 946ee50bbf855c1cd582766a0fc55c26fb9d8c0f Mon Sep 17 00:00:00 2001 From: kozyrevdev <73348153+kozyrevdev@users.noreply.github.com> Date: Mon, 22 Nov 2021 15:31:16 +0000 Subject: [PATCH] Merge pull request #234 from UniqueNetwork/feature/core-214 CORE-214. Zero value transfer tests --- --- a/tests/src/transfer.test.ts +++ b/tests/src/transfer.test.ts @@ -19,6 +19,10 @@ transferExpectFailure, transferExpectSuccess, addCollectionAdminExpectSuccess, + toSubstrateAddress, + getTokenOwner, + normalizeAccountId, + getBalance as getTokenBalance, } from './util/helpers'; let alice: IKeyringPair; @@ -230,3 +234,61 @@ ); }); }); + +describe('Zero value transfer(From)', () => { + before(async () => { + await usingApi(async () => { + alice = privateKey('//Alice'); + bob = privateKey('//Bob'); + }); + }); + + it('NFT', async () => { + await usingApi(async (api: ApiPromise) => { + const nftCollectionId = await createCollectionExpectSuccess(); + const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT'); + + const transferTx = api.tx.nft.transfer(normalizeAccountId(bob), nftCollectionId, newNftTokenId, 0); + await submitTransactionAsync(alice, transferTx); + const address = normalizeAccountId(await getTokenOwner(api, nftCollectionId, newNftTokenId)); + + expect(toSubstrateAddress(address)).to.be.equal(alice.address); + }); + }); + + it('RFT', async () => { + await usingApi(async (api: ApiPromise) => { + const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}}); + const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible'); + const balanceBeforeAlice = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(alice), newReFungibleTokenId); + const balanceBeforeBob = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(bob), newReFungibleTokenId); + + const transferTx = api.tx.nft.transfer(normalizeAccountId(bob), reFungibleCollectionId, newReFungibleTokenId, 0); + await submitTransactionAsync(alice, transferTx); + + const balanceAfterAlice = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(alice), newReFungibleTokenId); + const balanceAfterBob = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(bob), newReFungibleTokenId); + + expect((balanceBeforeAlice)).to.be.equal(balanceAfterAlice); + expect((balanceBeforeBob)).to.be.equal(balanceAfterBob); + }); + }); + + it('Fungible', async () => { + await usingApi(async (api: ApiPromise) => { + const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); + const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible'); + const balanceBeforeAlice = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(alice), newFungibleTokenId); + const balanceBeforeBob = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(bob), newFungibleTokenId); + + const transferTx = api.tx.nft.transfer(normalizeAccountId(bob), fungibleCollectionId, newFungibleTokenId, 0); + await submitTransactionAsync(alice, transferTx); + + const balanceAfterAlice = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(alice), newFungibleTokenId); + const balanceAfterBob = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(bob), newFungibleTokenId); + + expect((balanceBeforeAlice)).to.be.equal(balanceAfterAlice); + expect((balanceBeforeBob)).to.be.equal(balanceAfterBob); + }); + }); +}); \ No newline at end of file -- gitstuff