import { ethers } from 'ethers'; import 'jest'; import { FacetId } from '../contracts/constants'; import { Collection } from '../Collection'; import config from '../config/config'; import { ChainId } from '../config/constants'; import { ERC721Native } from '../contracts/ERC721Native'; import { OmniteLayerZeroBridgeSender } from '../contracts/OmniteLayerZeroBridgeSender'; import { LayerZero } from '../LayerZero'; import { translateChainIdToLayer0ChainId } from '../utils/chainUtils'; import { getTestConfig } from './utils'; const chainId = getTestConfig().chainId; const targetChainId = ChainId.MUMBAI; const sourceChainTokenAddress = '0xbd2b298c4728d33bd3ae49e0601c37609a0a66fe'; const targetChainTokenAddress = '0xc72035e740a733fa60466f522ffd9d878cfd4f5d'; const collectionId = '0xc071dfd115f044675830fd6156f750e40ddbf24a77e148eab403fc09bcabd449'; const tokenId = 1; describe.only('ERC721Native', () => { beforeAll(async () => { await config.initialize({ supportedChains: [chainId, targetChainId], moralisApiKey: '', pinataJWTToken: '', providerRpcUrls: { [ChainId.MUMBAI]: getTestConfig().mumbaiRpcUrl, [ChainId.BSCT]: 'https://data-seed-prebsc-1-s1.binance.org:8545/', }, }); }); beforeEach(async () => { if (getTestConfig().rpcUrl.includes('localhost')) { const provider = new ethers.providers.JsonRpcProvider( getTestConfig().rpcUrl ); await provider.send('hardhat_reset', [ { forking: { blockNumber: require('../../hardhat/hardhat.config.js') .networks.hardhat.forking.blockNumber, jsonRpcUrl: require('../../hardhat/hardhat.config.js') .networks.hardhat.forking.url, }, }, ]); } }, 30000); it('should return name', async () => { expect( await ERC721Native.getName(chainId, sourceChainTokenAddress) ).toContain('Collection'); }, 120000); it('should return contractURI', async () => { expect( await ERC721Native.contractURI(chainId, sourceChainTokenAddress) ).toContain('omnite'); }, 120000); it('should return ownerOf', async () => { expect( await ERC721Native.ownerOf( chainId, sourceChainTokenAddress, tokenId.toString() ) ).toContain('0x20cc92488dE321F0d448afe4D4cfFF4406E7AA4D'); }, 120000); it('should return collectionId', async () => { expect( await ERC721Native.collectionId(chainId, sourceChainTokenAddress) ).toContain(collectionId); }, 120000); it('should return tokenURI', async () => { expect( ( await ERC721Native.tokenURI( chainId, sourceChainTokenAddress, tokenId.toString() ) ).length ).toBeGreaterThan(0); }, 120000); it('should return cross chain collectionId', async () => { const provider = new ethers.providers.JsonRpcProvider( getTestConfig().rpcUrl ); expect( await ERC721Native.collectionId( targetChainId, targetChainTokenAddress ) ).toContain(collectionId); }, 120000); it.skip('should mint token', async () => { const provider = new ethers.providers.JsonRpcProvider( getTestConfig().rpcUrl ); const wallet = new ethers.Wallet( getTestConfig().privateKey, provider ) as unknown as ethers.providers.JsonRpcSigner; const collection = new Collection(wallet, sourceChainTokenAddress); await collection.mint( { tokenId: tokenId.toString(), chainId, description: 'test', title: 'test', photo: 'ipfs://QmYEjMXM1rFVaxT6iVYd9q6JtrWRkKaEeKFB1q1qZvkdws', }, 'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/1' ); }, 120000); it.skip('should remove and add facet cut', async () => { const provider = new ethers.providers.JsonRpcProvider( getTestConfig().rpcUrl ); const wallet = new ethers.Wallet( getTestConfig().privateKey, provider ) as unknown as ethers.providers.JsonRpcSigner; const collection = new Collection(wallet, sourceChainTokenAddress); const removeReceipt = await collection.removeFacet( FacetId.ERC721OmniteNativeFacetsPack ); await removeReceipt.wait(); const facetsAfterRemove = await ERC721Native.getFacets( chainId, sourceChainTokenAddress ); const addReceipt = await collection.addFacet( FacetId.ERC721OmniteNativeFacetsPack ); await addReceipt.wait(); const facetsAfterAdd = await ERC721Native.getFacets( chainId, sourceChainTokenAddress ); expect(facetsAfterAdd.length).toBeGreaterThan(facetsAfterRemove.length); }, 120000); it.skip('should transfer token', async () => { const provider = new ethers.providers.JsonRpcProvider( getTestConfig().rpcUrl ); const wallet = new ethers.Wallet( getTestConfig().privateKey, provider ) as unknown as ethers.providers.JsonRpcSigner; const userAddress = await wallet.getAddress(); console.log({ chainId }); const collection = await ERC721Native.create( wallet, sourceChainTokenAddress ); await collection.transfer( userAddress, '0xFf5Fe3dde9623A89D71a71933C14E1F281ea1226', tokenId ); }, 120000); describe('LayerZero', () => { it('should bridge crosschain token', async () => { const provider = new ethers.providers.JsonRpcProvider( getTestConfig().rpcUrl ); const wallet = new ethers.Wallet( getTestConfig().privateKey, provider ) as unknown as ethers.providers.JsonRpcSigner; const userAddress = await wallet.getAddress(); console.log({ chainId }); const payload = await OmniteLayerZeroBridgeSender.mintOnTargetChainEncode( chainId, collectionId, userAddress, tokenId, '' ); const estimatedGasLimit = await LayerZero.estimateReceiveGas( chainId, userAddress, targetChainId, payload ); const fee = await LayerZero.estimateFees( chainId, targetChainId, sourceChainTokenAddress, payload, estimatedGasLimit ); const collection = await ERC721Native.create( wallet, sourceChainTokenAddress ); // await ( // await collection.approve( // config.getSystemData(chainId).omniteLayerZeroBridgeSender, // tokenId // ) // ).wait(); await collection.moveToViaLayerZero( translateChainIdToLayer0ChainId(targetChainId), config.getSystemData(targetChainId) .omniteLayerZeroBridgeReceiver, tokenId, estimatedGasLimit, fee ); }, 120000); }); });