Skip to content

Commit

Permalink
feat: add existing contract read for factory upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
IsabellaSmallcombe committed Oct 4, 2023
1 parent 6361928 commit d20a932
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/ZoraNFTCreatorV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {IContractMetadata} from "./interfaces/IContractMetadata.sol";
contract ZoraNFTCreatorV1 is OwnableUpgradeable, UUPSUpgradeable, IContractMetadata, Version(8) {
string private constant CANNOT_BE_ZERO = "Cannot be 0 address";

/// Contract names do not match
error UpgradeToMismatchedContractName(string expected, string actual);

/// @notice Emitted when a edition is created reserving the corresponding token IDs.
event CreatedDrop(
address indexed creator,
Expand Down Expand Up @@ -74,7 +77,11 @@ contract ZoraNFTCreatorV1 is OwnableUpgradeable, UUPSUpgradeable, IContractMetad
internal
override
onlyOwner
{}
{
if (!(keccak256(bytes(IContractMetadata(_newImplementation).contractName())) == keccak256(bytes(this.contractName())))) {
revert UpgradeToMismatchedContractName(this.contractName(), IContractMetadata(_newImplementation).contractName());
}
}

function createAndConfigureDrop(
string memory name,
Expand Down
9 changes: 8 additions & 1 deletion test/ZoraNFTCreatorV1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {ProtocolRewards} from "@zoralabs/protocol-rewards/src/ProtocolRewards.so
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 {IERC721AUpgradeable} from "erc721a-upgradeable/IERC721AUpgradeable.sol";
Expand Down Expand Up @@ -156,5 +157,11 @@ contract ZoraNFTCreatorV1Test is Test {
assertEq(drop.tokenURI(1), "DEMO");
}


function test_UpgradeFailsWithDifferentContractName() public {
MockContractMetadata mockMetadata = new MockContractMetadata("uri", "test name");
address owner = creator.owner();
vm.prank(owner);
vm.expectRevert(abi.encodeWithSignature("UpgradeToMismatchedContractName(string,string)", "ZORA NFT Creator", "test name"));
creator.upgradeTo(address(mockMetadata));
}
}
26 changes: 26 additions & 0 deletions test/utils/MockContractMetadata.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {IContractMetadata} from "../../src/interfaces/IContractMetadata.sol";

contract MockContractMetadata is IContractMetadata {
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;

}

}

0 comments on commit d20a932

Please sign in to comment.