import { ethers } from 'ethers'; import 'jest'; import { difference } from 'lodash'; import { ChainId } from '../config/constants'; import { Collection } from '../Collection'; import { CollectionCreator } from '../CollectionCreator'; import config from '../config/config'; import { CollectionsRegistry } from '../contracts/CollectionsRegistry'; import { ERC721Native } from '../contracts/ERC721Native'; import { BridgeBroker, DeployType } from '../types'; import { getTestConfig } from './utils'; const chainId = getTestConfig().chainId; describe.only('CollectionCreator', () => { 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], moralisApiKey: '', pinataJWTToken: '', providerRpcUrls: { [chainId]: getTestConfig().rpcUrl, [ChainId.BSCT]: 'https://data-seed-prebsc-1-s1.binance.org:8545/', }, }); }, 30000); it.skip('should return value from collections', async () => { const provider = new ethers.providers.JsonRpcProvider( getTestConfig().rpcUrl ); const wallet = new ethers.Wallet(getTestConfig().privateKey, provider); expect( await CollectionsRegistry.listCollectionsPerOwner( chainId, await wallet.getAddress() ) ).toHaveLength(0); }); 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 ' + Math.random(); 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]) ); console.log({ currentLength, ownerCollections, createdContractAddress, }); expect( await ERC721Native.getName(chainId, createdContractAddress[0]) ).toEqual(collectionName); expect(ownerCollections).toHaveLength(currentLength.length + 1); // console.log( // await ERC721Native.contractURI(chainId, createdContractAddress[0]) // ); // console.log( // await ERC721Native.collectionId(chainId, createdContractAddress[0]) // ); const collection = new Collection( wallet, createdContractAddress[0] ); await collection.mint( { tokenId: '1', chainId, description: 'test', title: 'test', photo: 'ipfs://QmYEjMXM1rFVaxT6iVYd9q6JtrWRkKaEeKFB1q1qZvkdws', }, 'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/1' ); }, 120000); it.only('should create collection on another chain', 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 ' + Math.random(); const collectionCreator = new CollectionCreator( chainId, wallet, DeployType.native, { collectionName, collectionTicker: 'CRO11', userAddress: await wallet.getAddress(), }, [BridgeBroker.LayerZero], BridgeBroker.LayerZero, [ { amount: 10, chainId: chainId }, { amount: 10, chainId: ChainId.BSCT }, ] ); 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]) ); console.log({ currentLength, ownerCollections, createdContractAddress, }); expect( await ERC721Native.getName(chainId, createdContractAddress[0]) ).toEqual(collectionName); expect(ownerCollections).toHaveLength(currentLength.length + 1); }, 240000); }); describe('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 ' + Math.random(); const collectionCreator = new CollectionCreator( chainId, wallet, DeployType.native, { collectionName, collectionTicker: 'TC11', userAddress: await wallet.getAddress(), }, [BridgeBroker.Axelar], BridgeBroker.Axelar, [{ 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]) ); console.log({ currentLength, ownerCollections, createdContractAddress, }); expect( await ERC721Native.getName(chainId, createdContractAddress[0]) ).toEqual(collectionName); expect(ownerCollections).toHaveLength(currentLength.length + 1); const collection = new Collection( wallet, createdContractAddress[0] ); await collection.mint( { tokenId: '1', chainId, description: 'test', title: 'test', photo: 'ipfs://QmYEjMXM1rFVaxT6iVYd9q6JtrWRkKaEeKFB1q1qZvkdws', }, 'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/1' ); }, 120000); it.skip('should create collection on another chain and mint token on source chain', 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 ' + Math.random(); const collectionCreator = new CollectionCreator( chainId, wallet, DeployType.native, { collectionName, collectionTicker: 'CRO11', userAddress: await wallet.getAddress(), }, [BridgeBroker.Axelar], BridgeBroker.Axelar, [ { amount: 10, chainId: chainId }, { amount: 10, chainId: ChainId.BSCT }, ] ); 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]) ); console.log({ currentLength, ownerCollections, createdContractAddress, }); expect( await ERC721Native.getName(chainId, createdContractAddress[0]) ).toEqual(collectionName); expect(ownerCollections).toHaveLength(currentLength.length + 1); const collection = new Collection( wallet, createdContractAddress[0] ); await collection.mint( { tokenId: '1', chainId, description: 'test', title: 'test', photo: 'ipfs://QmYEjMXM1rFVaxT6iVYd9q6JtrWRkKaEeKFB1q1qZvkdws', }, 'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/1' ); }, 240000); }); });