// This file contains entire flow test, should be run once import { BigNumber, ethers } from 'ethers'; import 'jest'; import { difference } from 'lodash'; import { Collection } from '../Collection'; import { CollectionCreator } from '../CollectionCreator'; import config from '../config/config'; import { ChainId } from '../config/constants'; import { CollectionsRegistry } from '../contracts/CollectionsRegistry'; import { ERC721Native } from '../contracts/ERC721Native'; import { OmniteLayerZeroBridgeReceiver } from '../contracts/OmniteLayerZeroBridgeReceiver'; import { BridgeBroker, DeployType } from '../types'; import { getTestConfig } from './utils'; const chainId = getTestConfig().chainId; const targetChainId = ChainId.RINKEBY; describe.only('flow', () => { 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, }, }, ]); } await config.initialize({ supportedChains: [ chainId, ChainId.BSCT, ChainId.MUMBAI, ChainId.RINKEBY, ChainId.ROPSTEN, ], moralisApiKey: '', pinataJWTToken: '', providerRpcUrls: { [chainId]: getTestConfig().rpcUrl, [ChainId.BSCT]: 'https://data-seed-prebsc-1-s1.binance.org:8545/', [ChainId.MUMBAI]: getTestConfig().mumbaiRpcUrl, [ChainId.RINKEBY]: 'https://rinkeby.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161', [ChainId.ROPSTEN]: 'https://ropsten.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161', }, }); console.log({ addresses: config.getSystemData(chainId) }); }, 30000); describe('LayerZero', () => { it.skip('should create local collection and 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 collectionName = 'L0Collection ' + new Date().toISOString().slice(0, 10); const collectionCreator = new CollectionCreator( chainId, wallet, DeployType.native, { collectionName, collectionTicker: 'TC11', userAddress: await wallet.getAddress(), }, [BridgeBroker.LayerZero], BridgeBroker.LayerZero, [{ amount: 10, chainId: chainId }] ); const currentLength = await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ); const result = await collectionCreator.deploy(); await result.wait(); const ownerCollections = await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ); const createdContractAddress = difference( ownerCollections.map((v) => v[0]), currentLength.map((v) => v[0]) ).pop()!; const collectionId = await CollectionsRegistry.collections( chainId, createdContractAddress ); expect( await ERC721Native.getName(chainId, createdContractAddress) ).toEqual(collectionName); expect(ownerCollections).toHaveLength(currentLength.length + 1); const collection = new Collection(wallet, createdContractAddress); await collection.mint( { tokenId: '1', chainId, description: 'test', title: 'test', photo: 'ipfs://QmYEjMXM1rFVaxT6iVYd9q6JtrWRkKaEeKFB1q1qZvkdws', }, 'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/1' ); // await new Promise((res) => setTimeout(res, 60000)); // await collection.moveTo( // chainId, // ChainId.BSCT, // collectionId, // '1', // BridgeBroker.LayerZero // ); }, 240000); it('should prepare local collection transaction', async () => { const provider = new ethers.providers.JsonRpcProvider( getTestConfig().rpcUrl ); const wallet = new ethers.Wallet( getTestConfig().privateKey, provider ) as unknown as ethers.providers.JsonRpcSigner; const collectionName = 'L0Collection ' + new Date().toISOString().slice(0, 10); const collectionCreator = new CollectionCreator( chainId, wallet, DeployType.native, { collectionName, collectionTicker: 'TC11', userAddress: await wallet.getAddress(), }, [BridgeBroker.LayerZero], BridgeBroker.LayerZero, [{ amount: 10, chainId: chainId }] ); const currentLength = await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ); const unsignedTx = await collectionCreator.prepareDeployTransaction(); expect( await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ) ).toHaveLength(currentLength.length); const tx = await wallet.sendTransaction(unsignedTx); await tx.wait(); expect( await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ) ).toHaveLength(currentLength.length + 1); }, 240000); it.skip('should create multichain collection and 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 collectionName = 'L0Collection ' + new Date().toISOString().slice(0, 10); const collectionCreator = new CollectionCreator( chainId, wallet, DeployType.native, { collectionName, collectionTicker: 'TC11', userAddress: await wallet.getAddress(), }, [BridgeBroker.LayerZero], // facets support BridgeBroker.LayerZero, [ { amount: 10, chainId: chainId }, { amount: 10, chainId: targetChainId }, ] ); collectionCreator.baseTokenUri = 'ipfs://QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/'; const currentLength = await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ); const result = await collectionCreator.deploy(); await result.wait(); const ownerCollections = await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ); const createdContractAddress = difference( ownerCollections.map((v) => v[0]), currentLength.map((v) => v[0]) ).pop()!; const collectionId = await CollectionsRegistry.collections( chainId, createdContractAddress ); expect( await ERC721Native.getName(chainId, createdContractAddress) ).toEqual(collectionName); expect(ownerCollections).toHaveLength(currentLength.length + 1); const tokenId = 1; const collection = new Collection(wallet, createdContractAddress); await collection.mint( { tokenId: tokenId.toString(), chainId, description: 'test', title: 'test', photo: 'ipfs://QmYEjMXM1rFVaxT6iVYd9q6JtrWRkKaEeKFB1q1qZvkdws', }, 'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/1' ); console.debug('Waiting for moveto'); console.log( await OmniteLayerZeroBridgeReceiver.waitContractDeployed( targetChainId, config.getChainConfig(chainId).layerZeroChainId ) ); await new Promise((res) => setTimeout(res, 60000)); // // mint from source chain to target chain using Axelar // await ( // await collection.mintOnTargetChain( // targetChainId, // BridgeBroker.Axelar, // { // tokenId: BigNumber.from(tokenId + 2), // }, // '' // ) // ).wait(); await collection.mintOnTargetChain( targetChainId, BridgeBroker.LayerZero, { tokenId: BigNumber.from(tokenId + 10) }, 'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3', collectionId ); // await collection.moveTo( // chainId, // targetChainId, // collectionId, // tokenId, // BridgeBroker.LayerZero //which broker should be used to bridge // ); }, 300000); }); describe.skip('Axelar', () => { it.skip('should create local collection and 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 collectionName = 'AxelarCollection ' + new Date().toISOString().slice(0, 10); const currentLength = await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ); const collectionCreator = new CollectionCreator( chainId, wallet, DeployType.native, { collectionName, collectionTicker: 'TC11', userAddress: await wallet.getAddress(), }, [BridgeBroker.Axelar], BridgeBroker.Axelar, [{ amount: 10, chainId: chainId }] ); const result = await collectionCreator.deploy(); console.log('deploy tx hash: ', result.hash); await result.wait(); console.log({ result }); const ownerCollections = await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ); const createdContractAddress = difference( ownerCollections.map((v) => v[0]), currentLength.map((v) => v[0]) ).pop()!; const collectionId = await CollectionsRegistry.collections( chainId, createdContractAddress ); console.log({ collectionId, createdContractAddress }); // expect( // await ERC721Native.getName(chainId, createdContractAddress) // ).toEqual(collectionName); // expect(ownerCollections).toHaveLength(currentLength.length + 1); const collection = new Collection(wallet, createdContractAddress); const mintTx = await collection.mint( { tokenId: '1', chainId, description: 'test', title: 'test', photo: 'ipfs://QmYEjMXM1rFVaxT6iVYd9q6JtrWRkKaEeKFB1q1qZvkdws', }, 'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/1', collectionId ); await mintTx.wait(); // await new Promise((res) => setTimeout(res, 60000)); // await collection.moveTo( // chainId, // ChainId.BSCT, // collectionId, // '1', // BridgeBroker.Axelar // ); }, 480000); it('should create multichain collection and mint token on origin', async () => { const provider = new ethers.providers.JsonRpcProvider( getTestConfig().rpcUrl ); const wallet = new ethers.Wallet( getTestConfig().privateKey, provider ) as unknown as ethers.providers.JsonRpcSigner; const collectionName = 'AxelarCollection ' + new Date().toISOString().slice(0, 10); const currentLength = await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ); // deploy const collectionCreator = new CollectionCreator( chainId, wallet, DeployType.native, { collectionName, collectionTicker: 'TC11', userAddress: await wallet.getAddress(), }, [BridgeBroker.Axelar], BridgeBroker.Axelar, [ { amount: 10, chainId: chainId }, { amount: 10, chainId: targetChainId }, ] ); const result = await collectionCreator.deploy(); // deploy end console.log('deploy tx hash: ', result.hash); await result.wait(); console.log({ result }); const ownerCollections = await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ); const createdContractAddress = difference( ownerCollections.map((v) => v[0]), currentLength.map((v) => v[0]) ).pop()!; const collectionId = await CollectionsRegistry.collections( chainId, createdContractAddress ); console.log({ collectionId, createdContractAddress }); // expect( // await ERC721Native.getName(chainId, createdContractAddress) // ).toEqual(collectionName); // expect(ownerCollections).toHaveLength(currentLength.length + 1); const tokenId = '1'; const collection = new Collection(wallet, createdContractAddress); const mintTx = await collection.mint( { tokenId, chainId, description: 'test', title: 'test', photo: 'ipfs://QmYEjMXM1rFVaxT6iVYd9q6JtrWRkKaEeKFB1q1qZvkdws', }, 'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/1', collectionId ); await mintTx.wait(); // await new Promise((res) => setTimeout(res, 60000)); await collection.moveTo( chainId, ChainId.BSCT, collectionId, tokenId, BridgeBroker.Axelar ); }, 480000); }); });