From e93af88bdd8af4a7755130c2505e2e64e3de5b27 Mon Sep 17 00:00:00 2001 From: kozyrevdev <73348153+kozyrevdev@users.noreply.github.com> Date: Tue, 01 Mar 2022 08:18:34 +0000 Subject: [PATCH] Merge pull request #249 from UniqueNetwork/feature/CORE-215 CORE-215 --- --- a/tests/src/transfer.test.ts +++ b/tests/src/transfer.test.ts @@ -24,7 +24,13 @@ getTokenOwner, normalizeAccountId, getBalance as getTokenBalance, + transferFromExpectSuccess, + transferFromExpectFail, } from './util/helpers'; +import { + subToEth, + itWeb3, +} from './eth/util/helpers'; let alice: IKeyringPair; let bob: IKeyringPair; @@ -292,4 +298,52 @@ expect((balanceBeforeBob)).to.be.equal(balanceAfterBob); }); }); -}); \ No newline at end of file +}); + +describe('Transfers to self (potentially over substrate-evm boundary)', () => { + itWeb3('Transfers to self. In case of same frontend', async ({api}) => { + const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); + const alice = privateKey('//Alice'); + const aliceProxy = subToEth(alice.address); + const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address}); + await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, 10, 'Fungible'); + const balanceAliceBefore = await getTokenBalance(api, collectionId, {Ethereum: aliceProxy}, tokenId); + await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, {Ethereum: aliceProxy}, 10, 'Fungible'); + const balanceAliceAfter = await getTokenBalance(api, collectionId, {Ethereum: aliceProxy}, tokenId); + expect(balanceAliceBefore).to.be.eq(balanceAliceAfter); + }); + + itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api}) => { + const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); + const alice = privateKey('//Alice'); + const aliceProxy = subToEth(alice.address); + const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address}); + const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId); + await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy} , 10, 'Fungible'); + await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, alice, 10, 'Fungible'); + const balanceAliceAfter = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId); + expect(balanceAliceBefore).to.be.eq(balanceAliceAfter); + }); + + itWeb3.only('Transfers to self. In case of inside substrate-evm', async ({api}) => { + const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); + const alice = privateKey('//Alice'); + const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address}); + const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId); + await transferExpectSuccess(collectionId, tokenId, alice, alice , 10, 'Fungible'); + await transferFromExpectSuccess(collectionId, tokenId, alice, alice, alice, 10, 'Fungible'); + const balanceAliceAfter = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId); + expect(balanceAliceBefore).to.be.eq(balanceAliceAfter); + }); + + itWeb3('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({api}) => { + const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}}); + const alice = privateKey('//Alice'); + const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address}); + const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId); + await transferExpectFailure(collectionId, tokenId, alice, alice , 11); + await transferFromExpectFail(collectionId, tokenId, alice, alice, alice, 11); + const balanceAliceAfter = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId); + expect(balanceAliceBefore).to.be.eq(balanceAliceAfter); + }); +}); -- gitstuff