import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; import { anyValue } from '@nomicfoundation/hardhat-chai-matchers/withArgs'; import chai from 'chai'; import '@nomiclabs/hardhat-waffle'; import chaiAsPromised from 'chai-as-promised'; import { BigNumber } from 'ethers'; import { ethers, waffle } from 'hardhat'; import { ForwarderDeployer } from '../scripts/deployers/ForwarderDeployer'; import { VenueRegistarDeployer } from '../scripts/deployers/VenueRegistarDeployer'; import { getInterfaceID, toETH } from './utils'; import { VenueSBTDeployer } from '../scripts/deployers/VenueSBTDeployer'; import { Interface } from '@ethersproject/abi'; import { USDCDeployer } from '../scripts/deployers/USDCDeployer'; import { USDC, VenueRegistar, VenueFactory } from '../types'; import * as IVenueRegistarArtifact from '../artifacts/contracts/interfaces/IVenueRegistar.sol/IVenueRegistar.json'; import { VenueFactoryDeployer } from '../scripts/deployers/VenueFactoryDeployer'; chai.use(chaiAsPromised); const { expect } = chai; let signer: SignerWithAddress; let otherSigner: SignerWithAddress; let venueRegistarDeployer: VenueRegistarDeployer; let venueRegistar: VenueRegistar; let usdc: USDC; const provider = waffle.provider; describe('VenueRegistar', function () { before(async () => { [signer, otherSigner] = await ethers.getSigners(); }); beforeEach(async () => { const USDC = new USDCDeployer(signer); usdc = await USDC.deploy({ name: 'USDC', symbol: 'USDC', }); venueRegistarDeployer = new VenueRegistarDeployer(signer); venueRegistar = await venueRegistarDeployer.deployAndInitialize(toETH(1), signer.address); const Forwarder = new ForwarderDeployer(signer); const forwarder = await Forwarder.deployAndInitialize({ venueRegistar: venueRegistar.address, }); const VenueFactory = new VenueFactoryDeployer(signer); const venueFactory = (await VenueFactory.deploy(venueRegistar.address)) as VenueFactory; await venueRegistar.functions.setVenueFactory(venueFactory.address); await venueRegistar.functions.setForwarder(forwarder.address); await venueRegistar.functions.setVenueSBTVersion('1.0.0-beta.0+fob.rsv.iVenueSBT'); expect(await venueRegistar.isTrustedForwarder(forwarder.address)).to.be.true; }); it('Upgrades', async function () { //tries to upgrade where sender is not owner venueRegistarDeployer = new VenueRegistarDeployer(otherSigner); await expect(venueRegistarDeployer.upgradeToV1(venueRegistar)).to.be.revertedWith( 'Ownable: caller is not the owner', ); //upgrades to V1 venueRegistarDeployer = new VenueRegistarDeployer(signer); const v1 = await venueRegistarDeployer.upgradeToV1(venueRegistar); let version = await v1.versionRegistar(); expect(version).to.be.equal('1.0.1-beta.0+fob.rsv.iVenueRegistar'); await v1.functions.setValue(8); expect(await v1.value()).to.be.equal(8); //upgrades to v2 const v2 = await venueRegistarDeployer.upgradeToV2(v1); version = await v2.versionRegistar(); expect(version).to.be.equal('1.0.2-beta.0+fob.rsv.iVenueRegistar'); await v2.functions.setValue(12); expect(await v2.value()).to.be.equal(12); expect(await v2.getValue()).to.be.equal(12); }); describe('Deploy Venue', () => { it('Fails with invalid value', async () => { await expect( venueRegistar.functions.deployVenue('Santiagos', 'SDV', 'sdv.com/', { value: toETH(1.1), gasLimit: '5000000' }), ).to.be.rejectedWith('RegistarInvalidPrice'); }); it('Deploys with value', async () => { await expect( venueRegistar.connect(otherSigner).functions.deployVenue('Santiagos', 'SDV', 'sdv.com/', { value: toETH(1) }), ) .to.emit(venueRegistar, 'NewVenue') .withArgs(anyValue, anyValue, otherSigner.address, anyValue); const venues = await venueRegistar.getVenues(); expect(venues.length).to.be.equal(1); const venueSBT = await ethers.getContractAt('VenueSBT', venues[0]); expect(await venueSBT.name()).to.be.equal('Santiagos'); expect(await venueSBT.symbol()).to.be.equal('SDV'); const splitterAdd = await venueRegistar.splitterByVenue(venueSBT.address); const splitter = await ethers.getContractAt('PaymentSplitter', splitterAdd); expect(await splitter.totalShares()).to.be.equal(100); expect(await splitter.shares(signer.address)).to.be.equal(36); expect(await splitter.shares(venueSBT.address)).to.be.equal(64); expect(await provider.getBalance(venueRegistar.address)).to.be.equal(toETH(1)); const receiver = ethers.Wallet.createRandom(); await venueRegistar.withdrawETH(receiver.address); expect(await provider.getBalance(venueRegistar.address)).to.be.equal(0); expect(await provider.getBalance(receiver.address)).to.be.equal(toETH(1)); }); it('Deploys by owner', async () => { await expect(venueRegistar.functions.ownerDeployVenue('Santiagos', 'SDV', 'sdv.com/', otherSigner.address)) .to.emit(venueRegistar, 'NewVenue') .withArgs(anyValue, anyValue, otherSigner.address, anyValue); const venues = await venueRegistar.getVenues(); expect(venues.length).to.be.equal(1); const venueSBT = await ethers.getContractAt('VenueSBT', venues[0]); expect(await venueSBT.name()).to.be.equal('Santiagos'); expect(await venueSBT.symbol()).to.be.equal('SDV'); const splitterAdd = await venueRegistar.splitterByVenue(venueSBT.address); const splitter = await ethers.getContractAt('PaymentSplitter', splitterAdd); expect(await splitter.totalShares()).to.be.equal(100); expect(await splitter.shares(signer.address)).to.be.equal(36); expect(await splitter.shares(venueSBT.address)).to.be.equal(64); }); it('Removes And Adds Venue', async () => { await venueRegistar.functions.ownerDeployVenue('Santiagos', 'SDV', 'sdv.com/', otherSigner.address); const venues = await venueRegistar.getVenues(); await venueRegistar.functions.removeVenue(venues[0]); expect((await venueRegistar.getVenues()).length).to.be.equal(0); await venueRegistar.functions.registerVenue(venues[0]); expect((await venueRegistar.getVenues()).length).to.be.equal(1); await expect(venueRegistar.functions.registerVenue(venues[0])).to.be.revertedWith( 'RegistarVenueAlreadyRegistered', ); expect(await venueRegistar.isVenue(venues[0])).to.be.true; }); it('Fails at adding VenueSBT', async () => { const deployer = new VenueSBTDeployer(signer); const venueSBTWrongInterface = await deployer.deployWrongVersionMock({ name: 'Santiagos', symbol: 'SDV', baseUri: 'www.sdv.com/', owner: otherSigner.address, royaltyReceiver: otherSigner.address, royaltyFeeNumerator: BigNumber.from('1000'), royaltyReceiverSecondarySales: otherSigner.address, royaltyFeeNumeratorSecondarySales: BigNumber.from(1000), }); await expect(venueRegistar.functions.registerVenue(venueSBTWrongInterface.address)).to.be.revertedWith( 'RegistarSBTVersionNotSupported', ); const venueSBTWrongRegistar = await deployer.deployWrongRegistar({ name: 'Santiagos', symbol: 'SDV', baseUri: 'www.sdv.com/', owner: otherSigner.address, royaltyReceiver: otherSigner.address, royaltyFeeNumerator: BigNumber.from('1000'), royaltyReceiverSecondarySales: otherSigner.address, royaltyFeeNumeratorSecondarySales: BigNumber.from(1000), }); await expect(venueRegistar.functions.registerVenue(venueSBTWrongRegistar.address)).to.be.revertedWith( 'RegistarWrongVenueRegistar', ); }); it('Sets other values', async () => { await venueRegistar.functions.setPrice(toETH(1.1)); expect(await venueRegistar.price()).to.be.equal(toETH(1.1)); const Forarder = new ForwarderDeployer(signer); const newForwarder = await Forarder.deployAndInitialize({ venueRegistar: venueRegistar.address, }); await venueRegistar.functions.setForwarder(newForwarder.address); expect(await venueRegistar.getForwarder()).to.be.equal(newForwarder.address); expect(await venueRegistar.isTrustedForwarder(newForwarder.address)).to.be.true; await venueRegistar.functions.setVenueSBTVersion('1.0.1'); expect(await venueRegistar.getVenueSBTVersion()).to.be.equal('1.0.1'); const int = new Interface(IVenueRegistarArtifact.abi); const interfaceId = getInterfaceID(int); expect(await venueRegistar.supportsInterface(interfaceId.toHexString())).to.be.true; await venueRegistar.functions.whitelistPaymentToken(usdc.address, true); expect(await venueRegistar.isPaymentTokenWhitelisted(usdc.address)).to.be.true; }); }); });