Skip to content

Commit

Permalink
feat: add fork tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IsabellaSmallcombe committed Oct 11, 2023
1 parent d20a932 commit 7906607
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
52 changes: 52 additions & 0 deletions test/ZoraNFTCreatorV1_Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {Test} from "forge-std/Test.sol";
import {IMetadataRenderer} from "../src/interfaces/IMetadataRenderer.sol";
import "../src/ZoraNFTCreatorV1.sol";
import "../src/ZoraNFTCreatorProxy.sol";
import {MockContractMetadata} from "./utils/MockContractMetadata.sol";
import {MockMetadataRenderer} from "./metadata/MockMetadataRenderer.sol";
import {FactoryUpgradeGate} from "../src/FactoryUpgradeGate.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {IERC721AUpgradeable} from "erc721a-upgradeable/IERC721AUpgradeable.sol";
import {ForkHelper} from "./utils/ForkHelper.sol";
import {DropDeployment, ChainConfig} from "../src/DeploymentConfig.sol";
import {ProtocolRewards} from "@zoralabs/protocol-rewards/src/ProtocolRewards.sol";

contract ZoraNFTCreatorV1Test is Test, ForkHelper {
address public constant DEFAULT_OWNER_ADDRESS = address(0x23499);
Expand All @@ -24,6 +26,15 @@ contract ZoraNFTCreatorV1Test is Test, ForkHelper {
EditionMetadataRenderer public editionMetadataRenderer;
DropMetadataRenderer public dropMetadataRenderer;

function deployCore() internal {
ProtocolRewards protocolRewards = new ProtocolRewards();

dropImpl = new ERC721Drop(address(1234), FactoryUpgradeGate(address(0)), mintFee, mintFeeRecipient, address(protocolRewards));

editionMetadataRenderer = new EditionMetadataRenderer();
dropMetadataRenderer = new DropMetadataRenderer();
}

function makeDefaultSalesConfiguration(uint104 price) internal returns (IERC721Drop.SalesConfiguration memory) {
return
IERC721Drop.SalesConfiguration({
Expand Down Expand Up @@ -178,4 +189,45 @@ contract ZoraNFTCreatorV1Test is Test, ForkHelper {
drop.purchase{value: fee}(1);
assertEq(drop.tokenURI(1), "DEMO");
}

function test_ForkUpgradeWithDifferentContractName() external {
string[] memory forkTestChains = getForkTestChains();

for (uint256 i = 0; i < forkTestChains.length; i++) {
string memory chainName = forkTestChains[i];
vm.createSelectFork(vm.rpcUrl(chainName));
creator = ZoraNFTCreatorV1(getDeployment().factory);
verifyAddressesFork(chainName);
deployCore();
forkContractNameWithRevert();
forkContractNameSucceed();
}
}

function forkContractNameWithRevert() internal {
ZoraNFTCreatorV1 newCreatorImpl = new ZoraNFTCreatorV1(address(dropImpl), editionMetadataRenderer, dropMetadataRenderer);
address owner = creator.owner();

vm.prank(owner);
creator.upgradeTo(address(newCreatorImpl));

MockContractMetadata mockMetadata = new MockContractMetadata("uri", "test name");

vm.prank(owner);
vm.expectRevert(abi.encodeWithSignature("UpgradeToMismatchedContractName(string,string)", "ZORA NFT Creator", "test name"));
creator.upgradeTo(address(mockMetadata));
}

function forkContractNameSucceed() internal {
ZoraNFTCreatorV1 newCreatorImpl = new ZoraNFTCreatorV1(address(dropImpl), editionMetadataRenderer, dropMetadataRenderer);
address owner = creator.owner();

vm.prank(owner);
creator.upgradeTo(address(newCreatorImpl));

MockContractMetadata mockMetadata = new MockContractMetadata("uri", "ZORA NFT Creator");

vm.prank(owner);
creator.upgradeTo(address(mockMetadata));
}
}
9 changes: 4 additions & 5 deletions test/utils/MockContractMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
pragma solidity ^0.8.10;

import {IContractMetadata} from "../../src/interfaces/IContractMetadata.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract MockContractMetadata is IContractMetadata {
contract MockContractMetadata is IContractMetadata, UUPSUpgradeable {
string public override contractURI;
string public override contractName;

constructor(string memory _contractURI, string memory _contractName) {
contractURI = _contractURI;
contractName = _contractName;

}

function setContractURI(string memory _contractURI) external {
contractURI = _contractURI;

}

function setContractName(string memory _contractName) external {
contractName = _contractName;

}

}
function _authorizeUpgrade(address _newImplementation) internal override {}
}

0 comments on commit 7906607

Please sign in to comment.