git.delta.rocks / unique-network / refs/commits / f553bd96694d

difftreelog

source

tests/src/eth/crossTransfer.test.ts4.7 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import privateKey from '../substrate/privateKey';7import {createCollectionExpectSuccess,8  createFungibleItemExpectSuccess,9  transferExpectSuccess,10  transferFromExpectSuccess,11  createItemExpectSuccess} from '../util/helpers';12import {collectionIdToAddress,13  createEthAccountWithBalance,14  subToEth,15  GAS_ARGS, itWeb3} from './util/helpers';16import fungibleAbi from './fungibleAbi.json';17import nonFungibleAbi from './nonFungibleAbi.json';1819describe('Token transfer between substrate address and EVM address. Fungible', () => {20  itWeb3('The private key X create a substrate address. Alice sends a token to the corresponding EVM address, and X can send it to Bob in the substrate', async () => {21    const collection = await createCollectionExpectSuccess({22      name: 'token name',23      mode: {type: 'Fungible', decimalPoints: 0},24    });25    const alice = privateKey('//Alice');26    const bob = privateKey('//Bob');27    const charlie = privateKey('//Charlie');28    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});29    await transferExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)} , 200, 'Fungible');30    await transferFromExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');31    await transferExpectSuccess(collection, 0, charlie, bob, 50, 'Fungible');32  });3334  itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({api, web3}) => {35    const collection = await createCollectionExpectSuccess({36      name: 'token name',37      mode: {type: 'Fungible', decimalPoints: 0},38    });39    const alice = privateKey('//Alice');40    const bob = privateKey('//Bob');41    const bobProxy = await createEthAccountWithBalance(api, web3);42    const aliceProxy = await createEthAccountWithBalance(api, web3);4344    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, alice.address);45    await transferExpectSuccess(collection, 0, alice, {Ethereum: aliceProxy} , 200, 'Fungible');46    const address = collectionIdToAddress(collection);47    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});4849    await contract.methods.transfer(bobProxy, 50).send({from: aliceProxy});50    await transferFromExpectSuccess(collection, 0, alice, {Ethereum: bobProxy}, bob, 50, 'Fungible');51    await transferExpectSuccess(collection, 0, bob, alice, 50, 'Fungible');52  });53});5455describe('Token transfer between substrate address and EVM address. NFT', () => {56  itWeb3('The private key X create a substrate address. Alice sends a token to the corresponding EVM address, and X can send it to Bob in the substrate', async () => {57    const collection = await createCollectionExpectSuccess({58      name: 'token name',59      mode: {type: 'NFT'},60    });61    const alice = privateKey('//Alice');62    const bob = privateKey('//Bob');63    const charlie = privateKey('//Charlie');64    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});65    await transferExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, 1, 'NFT');66    await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');67    await transferExpectSuccess(collection, tokenId, charlie, bob, 1, 'NFT');68  });6970  itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({api, web3}) => {71    const collection = await createCollectionExpectSuccess({72      name: 'token name',73      mode: {type: 'NFT'},74    });75    const alice = privateKey('//Alice');76    const bob = privateKey('//Bob');77    const charlie = privateKey('//Charlie');78    const bobProxy = await createEthAccountWithBalance(api, web3);79    const aliceProxy = await createEthAccountWithBalance(api, web3);80    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});81    await transferExpectSuccess(collection, tokenId, alice, {Ethereum: aliceProxy} , 1, 'NFT');82    const address = collectionIdToAddress(collection);83    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});84    await contract.methods.transfer(bobProxy, 1).send({from: aliceProxy});85    await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: bobProxy}, bob, 1, 'NFT');86    await transferExpectSuccess(collection, tokenId, bob, charlie, 1, 'NFT');87  });88});