1234567891011121314151617import {itEth, usingEthPlaygrounds} from '@unique/test-utils/eth/util.js';18import {CrossAccountId} from '@unique-nft/playgrounds/unique.js';19import type {IKeyringPair} from '@polkadot/types/types';2021describe('Token transfer between substrate address and EVM address. Fungible', () => {22 let donor: IKeyringPair;23 let alice: IKeyringPair;24 let bob: IKeyringPair;25 let charlie: IKeyringPair;2627 before(async function() {28 await usingEthPlaygrounds(async (helper, privateKey) => {29 donor = await privateKey({url: import.meta.url});30 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);31 });32 });3334 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}) => {35 const bobCA = CrossAccountId.fromKeyring(bob).toICrossAccountId();36 const charlieCA = CrossAccountId.fromKeyring(charlie).toICrossAccountId();37 const charlieCAEth = CrossAccountId.fromKeyring(charlie).toEthereum().toICrossAccountId();3839 const collection = await helper.ft.mintCollection(alice);40 await collection.setLimits(alice, {ownerCanTransfer: true});4142 await collection.mint(alice, 200n);43 await collection.transfer(alice, charlieCAEth, 200n);44 await collection.transferFrom(alice, charlieCAEth, charlieCA, 50n);45 await collection.transfer(charlie, bobCA, 50n);46 });4748 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}) => {49 const aliceProxy = await helper.eth.createAccountWithBalance(donor);50 const bobProxy = await helper.eth.createAccountWithBalance(donor);5152 const collection = await helper.ft.mintCollection(alice);53 await collection.setLimits(alice, {ownerCanTransfer: true});5455 const address = helper.ethAddress.fromCollectionId(collection.collectionId);56 const contract = await helper.ethNativeContract.collection(address, 'ft', aliceProxy);5758 await collection.mint(alice, 200n, {Ethereum: aliceProxy});59 await contract.methods.transfer(bobProxy, 50).send({from: aliceProxy});60 await collection.transferFrom(alice, {Ethereum: bobProxy}, CrossAccountId.fromKeyring(bob).toICrossAccountId(), 50n);61 await collection.transfer(bob, CrossAccountId.fromKeyring(alice).toICrossAccountId(), 50n);62 });63});6465describe('Token transfer between substrate address and EVM address. NFT', () => {66 let donor: IKeyringPair;67 let alice: IKeyringPair;68 let bob: IKeyringPair;69 let charlie: IKeyringPair;7071 before(async function() {72 await usingEthPlaygrounds(async (helper, privateKey) => {73 donor = await privateKey({url: import.meta.url});74 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);75 });76 });7778 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}) => {79 const charlieEth = CrossAccountId.fromKeyring(charlie, 'Ethereum').toICrossAccountId();8081 const collection = await helper.nft.mintCollection(alice);82 await collection.setLimits(alice, {ownerCanTransfer: true});83 const token = await collection.mintToken(alice);84 await token.transfer(alice, charlieEth);85 await token.transferFrom(alice, charlieEth, CrossAccountId.fromKeyring(charlie).toICrossAccountId());86 await token.transfer(charlie, CrossAccountId.fromKeyring(bob).toICrossAccountId());87 });8889 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}) => {90 const aliceProxy = await helper.eth.createAccountWithBalance(donor);91 const bobProxy = await helper.eth.createAccountWithBalance(donor);9293 const collection = await helper.nft.mintCollection(alice);94 await collection.setLimits(alice, {ownerCanTransfer: true});9596 const address = helper.ethAddress.fromCollectionId(collection.collectionId);97 const contract = await helper.ethNativeContract.collection(address, 'nft', aliceProxy);9899 const token = await collection.mintToken(alice);100 await token.transfer(alice, {Ethereum: aliceProxy});101 await contract.methods.transfer(bobProxy, 1).send({from: aliceProxy});102 await token.transferFrom(alice, {Ethereum: bobProxy}, {Substrate: bob.address});103 await token.transfer(bob, {Substrate: charlie.address});104 });105});