git.delta.rocks / unique-network / refs/commits / 3f2c4d36d2e0

difftreelog

source

js-packages/tests/eth/crossTransfer.test.ts5.1 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {itEth, usingEthPlaygrounds} from './util/index.js';18import {CrossAccountId} from '@unique/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});