1234567891011121314151617import {createCollectionExpectSuccess,18 createFungibleItemExpectSuccess,19 transferExpectSuccess,20 transferFromExpectSuccess,21 createItemExpectSuccess} from '../util/helpers';22import {collectionIdToAddress,23 createEthAccountWithBalance,24 subToEth,25 GAS_ARGS, itWeb3} from './util/helpers';26import fungibleAbi from './fungibleAbi.json';27import nonFungibleAbi from './nonFungibleAbi.json';2829describe('Token transfer between substrate address and EVM address. Fungible', () => {30 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 ({privateKeyWrapper}) => {31 const collection = await createCollectionExpectSuccess({32 name: 'token name',33 mode: {type: 'Fungible', decimalPoints: 0},34 });35 const alice = privateKeyWrapper('//Alice');36 const bob = privateKeyWrapper('//Bob');37 const charlie = privateKeyWrapper('//Charlie');38 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});39 await transferExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)} , 200, 'Fungible');40 await transferFromExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');41 await transferExpectSuccess(collection, 0, charlie, bob, 50, 'Fungible');42 });4344 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, privateKeyWrapper}) => {45 const collection = await createCollectionExpectSuccess({46 name: 'token name',47 mode: {type: 'Fungible', decimalPoints: 0},48 });49 const alice = privateKeyWrapper('//Alice');50 const bob = privateKeyWrapper('//Bob');51 const bobProxy = await createEthAccountWithBalance(api, web3);52 const aliceProxy = await createEthAccountWithBalance(api, web3);5354 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, alice.address);55 await transferExpectSuccess(collection, 0, alice, {Ethereum: aliceProxy} , 200, 'Fungible');56 const address = collectionIdToAddress(collection);57 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});5859 await contract.methods.transfer(bobProxy, 50).send({from: aliceProxy});60 await transferFromExpectSuccess(collection, 0, alice, {Ethereum: bobProxy}, bob, 50, 'Fungible');61 await transferExpectSuccess(collection, 0, bob, alice, 50, 'Fungible');62 });63});6465describe('Token transfer between substrate address and EVM address. NFT', () => {66 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 ({privateKeyWrapper}) => {67 const collection = await createCollectionExpectSuccess({68 name: 'token name',69 mode: {type: 'NFT'},70 });71 const alice = privateKeyWrapper('//Alice');72 const bob = privateKeyWrapper('//Bob');73 const charlie = privateKeyWrapper('//Charlie');74 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});75 await transferExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, 1, 'NFT');76 await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');77 await transferExpectSuccess(collection, tokenId, charlie, bob, 1, 'NFT');78 });7980 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, privateKeyWrapper}) => {81 const collection = await createCollectionExpectSuccess({82 name: 'token name',83 mode: {type: 'NFT'},84 });85 const alice = privateKeyWrapper('//Alice');86 const bob = privateKeyWrapper('//Bob');87 const charlie = privateKeyWrapper('//Charlie');88 const bobProxy = await createEthAccountWithBalance(api, web3);89 const aliceProxy = await createEthAccountWithBalance(api, web3);90 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});91 await transferExpectSuccess(collection, tokenId, alice, {Ethereum: aliceProxy} , 1, 'NFT');92 const address = collectionIdToAddress(collection);93 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});94 await contract.methods.transfer(bobProxy, 1).send({from: aliceProxy});95 await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: bobProxy}, bob, 1, 'NFT');96 await transferExpectSuccess(collection, tokenId, bob, charlie, 1, 'NFT');97 });98});