git.delta.rocks / unique-network / refs/commits / ebdb67ffae1d

difftreelog

CORE-159. Transfer through substrate and EVM

str-mv2021-08-11parent: #d49b9b4.patch.diff
in: master

1 file changed

addedtests/src/eth/crossTransfer.test.tsdiffbeforeafterboth
after · tests/src/eth/crossTransfer.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import privateKey from '../substrate/privateKey';7import { createCollectionExpectSuccess, 8  createFungibleItemExpectSuccess, 9  transferExpectSuccess, 10  transferFromExpectSuccess, 11  CrossAccountId,12  createItemExpectSuccess,13  normalizeAccountId } from '../util/helpers';14import { collectionIdToAddress, 15  createEthAccountWithBalance, 16  GAS_ARGS, itWeb3 } from './util/helpers';17import fungibleAbi from './fungibleAbi.json';18import nonFungibleAbi from './nonFungibleAbi.json';1920describe('Token transfer between substrate address and EVM address. Fungible', () => {21  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 () => {22    const collection = await createCollectionExpectSuccess({23      name: 'token name',24      mode: { type: 'Fungible', decimalPoints: 0 },25    });26    const alice = privateKey('//Alice');27    const bob = privateKey('//Bob');28    const charlie = privateKey('//Charlie');29    const ethAccountVariant: CrossAccountId = normalizeAccountId(charlie.address);30    await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });31    await transferExpectSuccess(collection, 0, alice, ethAccountVariant , 200, 'Fungible');32    await transferExpectSuccess(collection, 0, charlie, bob , 200, 'Fungible');33  });3435  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 }) => {36    const collection = await createCollectionExpectSuccess({37      name: 'token name',38      mode: { type: 'Fungible', decimalPoints: 0 },39    });40    const alice = privateKey('//Alice');41    const bob = privateKey('//Bob');42    const bobProxy = await createEthAccountWithBalance(api, web3);43    const aliceProxy = await createEthAccountWithBalance(api, web3);4445    await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, alice.address);46    await transferExpectSuccess(collection, 0, alice, { ethereum: aliceProxy } , 200, 'Fungible');47    const address = collectionIdToAddress(collection);48    const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});4950    await contract.methods.transfer(bobProxy, 50).send({ from: aliceProxy });51    await transferFromExpectSuccess(collection, 0, alice, {ethereum: bobProxy}, bob, 50, 'Fungible');52    await transferExpectSuccess(collection, 0, bob, alice, 50, 'Fungible');53  });54});5556describe.only('Token transfer between substrate address and EVM address. NFT', () => {57  itWeb3.skip('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 () => {58    const collection = await createCollectionExpectSuccess({59      name: 'token name',60      mode: { type: 'NFT' },61    });62    const alice = privateKey('//Alice');63    const bob = privateKey('//Bob');64    const charlie = privateKey('//Charlie');65    const ethAccountVariant: CrossAccountId = normalizeAccountId(charlie.address);66    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });67    await transferExpectSuccess(collection, tokenId, alice, ethAccountVariant, 1, 'NFT');68    await transferExpectSuccess(collection, tokenId, charlie, bob, 1, 'NFT');69  });7071  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 }) => {72    const collection = await createCollectionExpectSuccess({73      name: 'token name',74      mode: { type: 'NFT' },75    });76    const alice = privateKey('//Alice');77    const bob = privateKey('//Bob');78    const charlie = privateKey('//Charlie');79    const bobProxy = await createEthAccountWithBalance(api, web3);80    const aliceProxy = await createEthAccountWithBalance(api, web3);81    const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });82    await transferExpectSuccess(collection, tokenId, alice, { ethereum: aliceProxy } , 1, 'NFT');83    const address = collectionIdToAddress(collection);84    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: aliceProxy, ...GAS_ARGS});85    await contract.methods.transfer(bobProxy, 1).send({ from: aliceProxy });86    await transferFromExpectSuccess(collection, tokenId, alice, {ethereum: bobProxy}, bob, 1, 'NFT');87    await transferExpectSuccess(collection, tokenId, bob, charlie, 1, 'NFT');88  });89});