1234567891011121314151617import {createCollectionExpectSuccess,18 createFungibleItemExpectSuccess,19 transferExpectSuccess,20 transferFromExpectSuccess,21 setCollectionLimitsExpectSuccess,22 createItemExpectSuccess} from '../util/helpers';23import {collectionIdToAddress,24 createEthAccountWithBalance,25 subToEth,26 GAS_ARGS, itWeb3} from './util/helpers';27import fungibleAbi from './fungibleAbi.json';28import nonFungibleAbi from './nonFungibleAbi.json';2930describe('Token transfer between substrate address and EVM address. Fungible', () => {31 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}) => {32 const collection = await createCollectionExpectSuccess({33 name: 'token name',34 mode: {type: 'Fungible', decimalPoints: 0},35 });36 const alice = privateKeyWrapper('//Alice');37 const bob = privateKeyWrapper('//Bob');38 const charlie = privateKeyWrapper('//Charlie');39 await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});40 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});41 await transferExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)} , 200, 'Fungible');42 await transferFromExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');43 await transferExpectSuccess(collection, 0, charlie, bob, 50, 'Fungible');44 });4546 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}) => {47 const collection = await createCollectionExpectSuccess({48 name: 'token name',49 mode: {type: 'Fungible', decimalPoints: 0},50 });51 const alice = privateKeyWrapper('//Alice');52 const bob = privateKeyWrapper('//Bob');53 await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});54 const bobProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);55 const aliceProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);5657 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, alice.address);58 await transferExpectSuccess(collection, 0, alice, {Ethereum: aliceProxy} , 200, 'Fungible');59 const address = collectionIdToAddress(collection);60 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});6162 await contract.methods.transfer(bobProxy, 50).send({from: aliceProxy});63 await transferFromExpectSuccess(collection, 0, alice, {Ethereum: bobProxy}, bob, 50, 'Fungible');64 await transferExpectSuccess(collection, 0, bob, alice, 50, 'Fungible');65 });66});6768describe('Token transfer between substrate address and EVM address. NFT', () => {69 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}) => {70 const collection = await createCollectionExpectSuccess({71 name: 'token name',72 mode: {type: 'NFT'},73 });74 const alice = privateKeyWrapper('//Alice');75 const bob = privateKeyWrapper('//Bob');76 const charlie = privateKeyWrapper('//Charlie');77 await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});78 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});79 await transferExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, 1, 'NFT');80 await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');81 await transferExpectSuccess(collection, tokenId, charlie, bob, 1, 'NFT');82 });8384 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}) => {85 const collection = await createCollectionExpectSuccess({86 name: 'token name',87 mode: {type: 'NFT'},88 });89 const alice = privateKeyWrapper('//Alice');90 const bob = privateKeyWrapper('//Bob');91 const charlie = privateKeyWrapper('//Charlie');92 await setCollectionLimitsExpectSuccess(alice, collection, {ownerCanTransfer: true});93 const bobProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);94 const aliceProxy = await createEthAccountWithBalance(api, web3, privateKeyWrapper);95 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});96 await transferExpectSuccess(collection, tokenId, alice, {Ethereum: aliceProxy} , 1, 'NFT');97 const address = collectionIdToAddress(collection);98 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});99 await contract.methods.transfer(bobProxy, 1).send({from: aliceProxy});100 await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: bobProxy}, bob, 1, 'NFT');101 await transferExpectSuccess(collection, tokenId, bob, charlie, 1, 'NFT');102 });103});