Skip to content

Commit

Permalink
fix(taikoon): fix taikoon contract test dependency issues (#16862)
Browse files Browse the repository at this point in the history
Co-authored-by: bearni95 <[email protected]>
  • Loading branch information
dantaik and bearni95 authored Apr 29, 2024
1 parent 4870fb2 commit bf31bb6
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 85 deletions.
17 changes: 12 additions & 5 deletions packages/taikoon/contracts/MerkleWhitelist.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { UUPSUpgradeable } from
"@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { Ownable2StepUpgradeable } from
"@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import { MerkleProof } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import { ContextUpgradeable } from
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";

/// @title MerkleWhitelist
/// @dev Merkle Tree Whitelist
/// @custom:security-contact [email protected]
contract MerkleWhitelist is ContextUpgradeable {
contract MerkleWhitelist is ContextUpgradeable, UUPSUpgradeable, Ownable2StepUpgradeable {
event RootUpdated(bytes32 _root);
event MintConsumed(address _minter, uint256 _mintAmount);

Expand All @@ -30,9 +34,8 @@ contract MerkleWhitelist is ContextUpgradeable {

/// @notice Contract initializer
/// @param _root Merkle Tree root
function initialize(bytes32 _root) external initializer {
__Context_init();
root = _root;
function initialize(address _owner, bytes32 _root) external initializer {
__MerkleWhitelist_init(_owner, _root);
}

/// @notice Check if a wallet can free mint
Expand All @@ -54,7 +57,8 @@ contract MerkleWhitelist is ContextUpgradeable {

/// @notice Internal initializer
/// @param _root Merkle Tree root
function __MerkleWhitelist_init(bytes32 _root) internal initializer {
function __MerkleWhitelist_init(address _owner, bytes32 _root) internal initializer {
_transferOwnership(_owner == address(0) ? msg.sender : _owner);
__Context_init();
root = _root;
}
Expand All @@ -76,4 +80,7 @@ contract MerkleWhitelist is ContextUpgradeable {
minted[_leaf] = true;
emit MintConsumed(_msgSender(), _maxMints);
}

/// @notice Internal method to authorize an upgrade
function _authorizeUpgrade(address) internal virtual override onlyOwner { }
}
27 changes: 11 additions & 16 deletions packages/taikoon/contracts/TaikoonToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@
pragma solidity 0.8.24;

import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { Ownable2StepUpgradeable } from
"@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

import { ERC721EnumerableUpgradeable } from
"@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import { UUPSUpgradeable } from
"@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

import { MerkleWhitelist } from "./MerkleWhitelist.sol";

/// @title TaikoonToken
/// @dev The Taikoons ERC-721 token
/// @custom:security-contact [email protected]
contract TaikoonToken is
ERC721EnumerableUpgradeable,
UUPSUpgradeable,
Ownable2StepUpgradeable,
MerkleWhitelist
{
contract TaikoonToken is ERC721EnumerableUpgradeable, MerkleWhitelist {
/// @notice The current supply
uint256 private _totalSupply;
// Base URI required to interact with IPFS
Expand All @@ -35,10 +27,16 @@ contract TaikoonToken is
/// @notice Contract initializer
/// @param _rootURI Base URI for the token metadata
/// @param _merkleRoot Merkle tree root for the whitelist
function initialize(string memory _rootURI, bytes32 _merkleRoot) external initializer {
function initialize(
address _owner,
string memory _rootURI,
bytes32 _merkleRoot
)
external
initializer
{
__ERC721_init("Taikoon", "TKOON");
__Ownable_init(_msgSender());
__MerkleWhitelist_init(_merkleRoot);
__MerkleWhitelist_init(_owner, _merkleRoot);
_baseURIExtended = _rootURI;
}

Expand Down Expand Up @@ -99,9 +97,6 @@ contract TaikoonToken is
return _baseURIExtended;
}

/// @notice Internal method to authorize an upgrade
function _authorizeUpgrade(address) internal virtual override onlyOwner { }

/// @notice Internal method to batch mint tokens
/// @param _to The address to mint to
/// @param _amount The amount of tokens to mint
Expand Down
3 changes: 1 addition & 2 deletions packages/taikoon/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ remappings = [
"@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"solady/=node_modules/solady/",
"forge-std/=node_modules/forge-std/src/",
"forge-std/=node_modules/forge-std/",
"ds-test/=node_modules/ds-test/src/",
"p256-verifier/=node_modules/p256-verifier/",
"murky/=node_modules/murky/src/",
"@openzeppelin/foundry-upgrades/=node_modules/@openzeppelin/foundry-upgrades/src/",
"solidity-stringutils/=node_modules/solidity-stringutils/",
]

Expand Down
1 change: 0 additions & 1 deletion packages/taikoon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"dependencies": {
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/contracts-upgradeable": "5.0.2",
"@openzeppelin/foundry-upgrades": "github:OpenZeppelin/openzeppelin-foundry-upgrades",
"@openzeppelin/merkle-tree": "^1.0.6",
"convert-csv-to-json": "^2.46.0",
"ds-test": "github:dapphub/ds-test#e282159d5170298eb2455a6c05280ab5a73a4ef0",
Expand Down
16 changes: 11 additions & 5 deletions packages/taikoon/script/sol/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
pragma solidity 0.8.24;

import { UtilsScript } from "./Utils.s.sol";
import { Script, console } from "forge-std/Script.sol";
import { Script, console } from "forge-std/src/Script.sol";
import { MerkleMintersScript } from "./MerkleMinters.s.sol";
import { Merkle } from "murky/Merkle.sol";
import { Upgrades } from "@openzeppelin/foundry-upgrades/Upgrades.sol";

import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { TaikoonToken } from "../../contracts/TaikoonToken.sol";

contract DeployScript is Script {
Expand All @@ -16,6 +15,9 @@ contract DeployScript is Script {
uint256 public deployerPrivateKey;
address public deployerAddress;

// Please set owner to labs.taiko.eth (0xB73b0FC4C0Cfc73cF6e034Af6f6b42Ebe6c8b49D) on Mainnnet.
address owner = vm.envAddress("OWNER");

function setUp() public {
utils = new UtilsScript();
utils.setUp();
Expand All @@ -30,15 +32,18 @@ contract DeployScript is Script {
function run() public {
string memory jsonRoot = "root";

require(owner != address(0), "Owner must be specified");

vm.startBroadcast(deployerPrivateKey);

bytes32 root = merkleMinters.root();

string memory baseURI = utils.getIpfsBaseURI();

// deploy token with empty root
address proxy = Upgrades.deployUUPSProxy(
"TaikoonToken.sol", abi.encodeCall(TaikoonToken.initialize, (baseURI, root))
address impl = address(new TaikoonToken());
address proxy = address(
new ERC1967Proxy(impl, abi.encodeCall(TaikoonToken.initialize, (owner, baseURI, root)))
);

TaikoonToken token = TaikoonToken(proxy);
Expand All @@ -47,6 +52,7 @@ contract DeployScript is Script {
console.log("Deployed TaikoonToken to:", address(token));

vm.serializeBytes32(jsonRoot, "MerkleRoot", root);
vm.serializeAddress(jsonRoot, "Owner", token.owner());

string memory finalJson = vm.serializeAddress(jsonRoot, "TaikoonToken", address(token));
vm.writeJson(finalJson, jsonLocation);
Expand Down
4 changes: 2 additions & 2 deletions packages/taikoon/script/sol/MerkleMinters.s.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { Script, console } from "forge-std/Script.sol";
import "forge-std/StdJson.sol";
import { Script, console } from "forge-std/src/Script.sol";
import "forge-std/src/StdJson.sol";
import { UtilsScript } from "./Utils.s.sol";
import { Merkle } from "murky/Merkle.sol";
import "./CsvParser.sol";
Expand Down
4 changes: 2 additions & 2 deletions packages/taikoon/script/sol/Utils.s.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { Script, console } from "forge-std/Script.sol";
import "forge-std/StdJson.sol";
import { Script, console } from "forge-std/src/Script.sol";
import "forge-std/src/StdJson.sol";

contract UtilsScript is Script {
using stdJson for string;
Expand Down
28 changes: 18 additions & 10 deletions packages/taikoon/test/MerkleWhitelist.t.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { Test, console } from "forge-std/Test.sol";
import "forge-std/StdJson.sol";
import { Test, console } from "forge-std/src/Test.sol";
import "forge-std/src/StdJson.sol";
import { Merkle } from "murky/Merkle.sol";
import { MerkleWhitelist } from "../contracts/MerkleWhitelist.sol";
import { Upgrades } from "@openzeppelin/foundry-upgrades/Upgrades.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

import { MerkleWhitelistTestWrapper } from "./MerkleWhitelistTestWrapper.sol";
/// @custom:oz-upgrades-from MerkleWhitelist
contract MerkleWhitelistForTest is MerkleWhitelist {
function updateRoot(bytes32 _root) external {
_updateRoot(_root);
}

function consumeMint(bytes32[] calldata _proof, uint256 _freeMints) external {
_consumeMint(_proof, _freeMints);
}
}

contract MerkleWhitelistTest is Test {
Merkle tree;
Expand All @@ -18,7 +27,7 @@ contract MerkleWhitelistTest is Test {

address public owner = vm.addr(0x5);

MerkleWhitelistTestWrapper whitelist;
MerkleWhitelistForTest whitelist;

uint256 constant MAX_MINTS = 5;

Expand All @@ -40,13 +49,12 @@ contract MerkleWhitelistTest is Test {

bytes32 root = tree.getRoot(leaves);

address transparentProxy = Upgrades.deployTransparentProxy(
"MerkleWhitelist.sol", owner, abi.encodeCall(MerkleWhitelist.initialize, (root))
address impl = address(new MerkleWhitelistForTest());
address proxy = address(
new ERC1967Proxy(impl, abi.encodeCall(MerkleWhitelist.initialize, (address(0), root)))
);

Upgrades.upgradeProxy(transparentProxy, "MerkleWhitelistTestWrapper.sol", "");

whitelist = MerkleWhitelistTestWrapper(transparentProxy);
whitelist = MerkleWhitelistForTest(proxy);

vm.stopBroadcast();
}
Expand Down
12 changes: 8 additions & 4 deletions packages/taikoon/test/TaikoonToken.t.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { Test } from "forge-std/Test.sol";
import { Test } from "forge-std/src/Test.sol";

import { TaikoonToken } from "../contracts/TaikoonToken.sol";
import { Merkle } from "murky/Merkle.sol";
import { Upgrades } from "@openzeppelin/foundry-upgrades/Upgrades.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract TaikoonTokenTest is Test {
TaikoonToken public token;
Expand All @@ -24,8 +25,11 @@ contract TaikoonTokenTest is Test {
bytes32 root = tree.getRoot(leaves);

// deploy token with empty root
address proxy = Upgrades.deployUUPSProxy(
"TaikoonToken.sol", abi.encodeCall(TaikoonToken.initialize, ("ipfs://", root))
address impl = address(new TaikoonToken());
address proxy = address(
new ERC1967Proxy(
impl, abi.encodeCall(TaikoonToken.initialize, (address(0), "ipfs://", root))
)
);

token = TaikoonToken(proxy);
Expand Down
13 changes: 8 additions & 5 deletions packages/taikoon/test/Upgradeable.t.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { Test, console } from "forge-std/Test.sol";
import { Test, console } from "forge-std/src/Test.sol";
import { TaikoonToken } from "../contracts/TaikoonToken.sol";
import { Merkle } from "murky/Merkle.sol";
import { MerkleMintersScript } from "../script/sol/MerkleMinters.s.sol";
import "forge-std/StdJson.sol";
import "forge-std/src/StdJson.sol";

import { Upgrades } from "@openzeppelin/foundry-upgrades/Upgrades.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract UpgradeableTest is Test {
using stdJson for string;
Expand All @@ -31,8 +31,11 @@ contract UpgradeableTest is Test {
bytes32 root = tree.getRoot(leaves);

// deploy token with empty root
address proxy = Upgrades.deployUUPSProxy(
"TaikoonToken.sol", abi.encodeCall(TaikoonToken.initialize, ("ipfs://", root))
address impl = address(new TaikoonToken());
address proxy = address(
new ERC1967Proxy(
impl, abi.encodeCall(TaikoonToken.initialize, (address(0), "ipfs://", root))
)
);

token = TaikoonToken(proxy);
Expand Down
Loading

0 comments on commit bf31bb6

Please sign in to comment.