git.delta.rocks / unique-network / refs/commits / 2d2fd30b7a2b

difftreelog

source

tests/src/eth/crossTransfer.test.ts5.3 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 privateKey from '../substrate/privateKey';18import {createCollectionExpectSuccess,19  createFungibleItemExpectSuccess,20  transferExpectSuccess,21  transferFromExpectSuccess,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 () => {32    const collection = await createCollectionExpectSuccess({33      name: 'token name',34      mode: {type: 'Fungible', decimalPoints: 0},35    });36    const alice = privateKey('//Alice');37    const bob = privateKey('//Bob');38    const charlie = privateKey('//Charlie');39    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});40    await transferExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)} , 200, 'Fungible');41    await transferFromExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');42    await transferExpectSuccess(collection, 0, charlie, bob, 50, 'Fungible');43  });4445  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}) => {46    const collection = await createCollectionExpectSuccess({47      name: 'token name',48      mode: {type: 'Fungible', decimalPoints: 0},49    });50    const alice = privateKey('//Alice');51    const bob = privateKey('//Bob');52    const bobProxy = await createEthAccountWithBalance(api, web3);53    const aliceProxy = await createEthAccountWithBalance(api, web3);5455    await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, alice.address);56    await transferExpectSuccess(collection, 0, alice, {Ethereum: aliceProxy} , 200, 'Fungible');57    const address = collectionIdToAddress(collection);58    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});5960    await contract.methods.transfer(bobProxy, 50).send({from: aliceProxy});61    await transferFromExpectSuccess(collection, 0, alice, {Ethereum: bobProxy}, bob, 50, 'Fungible');62    await transferExpectSuccess(collection, 0, bob, alice, 50, 'Fungible');63  });64});6566describe('Token transfer between substrate address and EVM address. NFT', () => {67  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 () => {68    const collection = await createCollectionExpectSuccess({69      name: 'token name',70      mode: {type: 'NFT'},71    });72    const alice = privateKey('//Alice');73    const bob = privateKey('//Bob');74    const charlie = privateKey('//Charlie');75    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});76    await transferExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, 1, 'NFT');77    await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');78    await transferExpectSuccess(collection, tokenId, charlie, bob, 1, 'NFT');79  });8081  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}) => {82    const collection = await createCollectionExpectSuccess({83      name: 'token name',84      mode: {type: 'NFT'},85    });86    const alice = privateKey('//Alice');87    const bob = privateKey('//Bob');88    const charlie = privateKey('//Charlie');89    const bobProxy = await createEthAccountWithBalance(api, web3);90    const aliceProxy = await createEthAccountWithBalance(api, web3);91    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});92    await transferExpectSuccess(collection, tokenId, alice, {Ethereum: aliceProxy} , 1, 'NFT');93    const address = collectionIdToAddress(collection);94    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});95    await contract.methods.transfer(bobProxy, 1).send({from: aliceProxy});96    await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: bobProxy}, bob, 1, 'NFT');97    await transferExpectSuccess(collection, tokenId, bob, charlie, 1, 'NFT');98  });99});