1234567891011121314151617181920212223242526272829import {itEth, usingEthPlaygrounds} from './util/playgrounds';30import {CrossAccountId} from '../util/playgrounds/unique';31import {IKeyringPair} from '@polkadot/types/types';3233describe('Token transfer between substrate address and EVM address. Fungible', () => {34 let donor: IKeyringPair;35 let alice: IKeyringPair;36 let bob: IKeyringPair;37 let charlie: IKeyringPair;3839 before(async function() {40 await usingEthPlaygrounds(async (helper, privateKey) => {41 donor = privateKey('//Alice');42 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);43 });44 });45 46 itEth('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 ({helper}) => { 47 const bobCA = CrossAccountId.fromKeyring(bob);48 const charlieCA = CrossAccountId.fromKeyring(charlie);4950 const collection = await helper.ft.mintCollection(alice);51 await collection.setLimits(alice, {ownerCanTransfer: true});5253 await collection.mint(alice, 200n);54 await collection.transfer(alice, charlieCA.toEthereum(), 200n);55 await collection.transferFrom(alice, charlieCA.toEthereum(), charlieCA, 50n);56 await collection.transfer(charlie, bobCA, 50n);57 });5859 itEth('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 ({helper}) => {60 const aliceProxy = await helper.eth.createAccountWithBalance(donor);61 const bobProxy = await helper.eth.createAccountWithBalance(donor);6263 const collection = await helper.ft.mintCollection(alice);64 await collection.setLimits(alice, {ownerCanTransfer: true});6566 const address = helper.ethAddress.fromCollectionId(collection.collectionId);67 const contract = helper.ethNativeContract.collection(address, 'ft', aliceProxy);6869 await collection.mint(alice, 200n, {Ethereum: aliceProxy});70 await contract.methods.transfer(bobProxy, 50).send({from: aliceProxy});71 await collection.transferFrom(alice, {Ethereum: bobProxy}, CrossAccountId.fromKeyring(bob), 50n);72 await collection.transfer(bob, CrossAccountId.fromKeyring(alice), 50n);73 });74});7576describe('Token transfer between substrate address and EVM address. NFT', () => {77 let donor: IKeyringPair;78 let alice: IKeyringPair;79 let bob: IKeyringPair;80 let charlie: IKeyringPair;8182 before(async function() {83 await usingEthPlaygrounds(async (helper, privateKey) => {84 donor = privateKey('//Alice');85 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);86 });87 });88 89 itEth('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 ({helper}) => {90 const charlieEth = CrossAccountId.fromKeyring(charlie, 'Ethereum');91 92 const collection = await helper.nft.mintCollection(alice);93 await collection.setLimits(alice, {ownerCanTransfer: true});94 const token = await collection.mintToken(alice);95 await token.transfer(alice, charlieEth);96 await token.transferFrom(alice, charlieEth, CrossAccountId.fromKeyring(charlie));97 await token.transfer(charlie, CrossAccountId.fromKeyring(bob));98 });99100 itEth('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 ({helper}) => {101 const aliceProxy = await helper.eth.createAccountWithBalance(donor);102 const bobProxy = await helper.eth.createAccountWithBalance(donor);103104 const collection = await helper.nft.mintCollection(alice);105 await collection.setLimits(alice, {ownerCanTransfer: true});106107 const address = helper.ethAddress.fromCollectionId(collection.collectionId);108 const contract = helper.ethNativeContract.collection(address, 'nft', aliceProxy);109110 const token = await collection.mintToken(alice);111 await token.transfer(alice, {Ethereum: aliceProxy});112 await contract.methods.transfer(bobProxy, 1).send({from: aliceProxy});113 await token.transferFrom(alice, {Ethereum: bobProxy}, {Substrate: bob.address});114 await token.transfer(bob, {Substrate: charlie.address});115 });116});