Skip to content

Commit

Permalink
Separate deployment package - move fork tests to it (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan authored Nov 1, 2023
1 parent b62e471 commit be7731d
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 64 deletions.
1 change: 0 additions & 1 deletion .github/workflows/foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ jobs:
run: |
npx turbo run test:fork
env:
FORK_TEST_CHAINS: mainnet,goerli,optimism,optimism_goerli,zora,zora_goerli,base_goerli,base
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}

storage_layout:
Expand Down
3 changes: 1 addition & 2 deletions packages/1155-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
"types": "./dist/package/index.d.ts",
"type": "module",
"scripts": {
"test": "forge test",
"dev": "FOUNDRY_PROFILE=dev forge test --watch -vvv",
"test:fork": "forge test -vvv --match-test fork",
"test": "forge test -vv",
"test-gas": "forge test --gas-report",
"prettier:check": "prettier --check 'src/**/*.sol' 'test/**/*.sol' 'package/**/*.ts' 'wagmi.config.ts'",
"prettier": "prettier --write 'src/**/*.sol' 'test/**/*.sol' 'package/**/*.ts' 'script/**/*.ts' 'wagmi.config.ts'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
import {ZoraCreator1155FactoryImpl} from "../../src/factory/ZoraCreator1155FactoryImpl.sol";
import {ZoraCreator1155PremintExecutorImpl} from "../../src/delegation/ZoraCreator1155PremintExecutorImpl.sol";
import {ZoraCreator1155Attribution, ContractCreationConfig, TokenCreationConfig, PremintConfig} from "../../src/delegation/ZoraCreator1155Attribution.sol";
import {ForkDeploymentConfig, Deployment} from "../../src/deployment/DeploymentConfig.sol";
import {UUPSUpgradeable} from "@zoralabs/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
import {ProxyShim} from "../../src/utils/ProxyShim.sol";

contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
contract ZoraCreator1155PreminterTest is Test {
uint256 internal constant CONTRACT_BASE_ID = 0;
uint256 internal constant PERMISSION_BIT_MINTER = 2 ** 2;

Expand Down Expand Up @@ -212,17 +211,6 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
preminter.premint{value: mintCost}(contractConfig, premintConfig, signature, quantityToMint, comment);
}

/// @notice gets the chains to do fork tests on, by reading environment var FORK_TEST_CHAINS.
/// Chains are by name, and must match whats under `rpc_endpoints` in the foundry.toml
function getForkTestChains() private view returns (string[] memory result) {
try vm.envString("FORK_TEST_CHAINS", ",") returns (string[] memory forkTestChains) {
result = forkTestChains;
} catch {
console.log("could not get fork test chains - make sure the environment variable FORK_TEST_CHAINS is set");
result = new string[](0);
}
}

function preminterCanMintTokens() internal {
// we are for now upgrading to correct preminter impl

Expand Down Expand Up @@ -264,34 +252,6 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
assertEq(balance, quantityToMint, "balance");
}

function testTheForkPremint(string memory chainName) private {
console.log("testing on fork: ", chainName);

// create and select the fork, which will be used for all subsequent calls
// it will also affect the current block chain id based on the rpc url returned
vm.createSelectFork(vm.rpcUrl(chainName));

// get contract hash, which is unique per contract creation config, and can be used
// retreive the address created for a contract
address preminterAddress = getDeployment().preminterProxy;

if (preminterAddress == address(0)) {
console.log("preminter not configured for chain...skipping");
return;
}

// override local preminter to use the addresses from the chain
factory = ZoraCreator1155FactoryImpl(getDeployment().factoryProxy);
preminter = ZoraCreator1155PremintExecutorImpl(preminterAddress);
}

function test_fork_successfullyMintsTokens() external {
string[] memory forkTestChains = getForkTestChains();
for (uint256 i = 0; i < forkTestChains.length; i++) {
testTheForkPremint(forkTestChains[i]);
}
}

function test_signatureForSameContractandUid_shouldMintExistingToken() external {
// 1. Make contract creation params

Expand Down
3 changes: 3 additions & 0 deletions packages/protocol-deployments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"types": "./dist/package/index.d.ts",
"type": "module",
"scripts": {
"dev": "FOUNDRY_PROFILE=dev forge test --watch -vvv",
"test:fork": "FORK_TEST_CHAINS=mainnet,goerli,optimism,optimism_goerli,zora,zora_goerli,base_goerli,base forge test -vvv",
"test": "forge test -vvv",
"build": "yarn wagmi && yarn bundle-configs && tsup",
"bundle-configs": "node script/bundle-chainConfigs.mjs && yarn prettier",
"prettier": "prettier --write 'package/**/*.ts' 'script/**/*.ts' 'wagmi.config.ts'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import {ZoraDeployerUtils} from "@zoralabs/zora-1155-contracts/src/deployment/ZoraDeployerUtils.sol";
import {Zora1155PremintExecutor} from "@zoralabs/zora-1155-contracts/src/proxies/Zora1155PremintExecutor.sol";
import {DeterministicDeployerScript, DeterministicParams} from "@zoralabs/zora-1155-contracts/src/deployment/DeterministicDeployerScript.sol";
import {DeterministicProxyDeployer} from "@zoralabs/zora-1155-contracts/src/deployment/DeterministicProxyDeployer.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

/// @title Gets parameters for deterministically deploying a new 1155 factory proxy at an address starting with 0x777777, regardless of the chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
pragma solidity 0.8.17;

import "forge-std/Test.sol";
import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
import {ZoraDeployerUtils, Create2Deployment} from "../../src/deployment/ZoraDeployerUtils.sol";
import {DeterministicProxyDeployer} from "../../src/deployment/DeterministicProxyDeployer.sol";
import {ProxyShim} from "../../src/utils/ProxyShim.sol";
import {UpgradeGate} from "../../src/upgrades/UpgradeGate.sol";
import {Deployment, ChainConfig} from "../../src/deployment/DeploymentConfig.sol";
import {IMinter1155} from "../../src/interfaces/IMinter1155.sol";
import {Zora1155Factory} from "@zoralabs/zora-1155-contracts/src/proxies/Zora1155Factory.sol";
import {ZoraDeployerUtils, Create2Deployment} from "@zoralabs/zora-1155-contracts/src/deployment/ZoraDeployerUtils.sol";
import {DeterministicProxyDeployer} from "@zoralabs/zora-1155-contracts/src/deployment/DeterministicProxyDeployer.sol";
import {ProxyShim} from "@zoralabs/zora-1155-contracts/src/utils/ProxyShim.sol";
import {UpgradeGate} from "@zoralabs/zora-1155-contracts/src/upgrades/UpgradeGate.sol";
import {Deployment, ChainConfig} from "@zoralabs/zora-1155-contracts/src/deployment/DeploymentConfig.sol";
import {IMinter1155} from "@zoralabs/zora-1155-contracts/src/interfaces/IMinter1155.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import {DeterministicDeployerScript, DeterministicParams} from "../../src/deployment/DeterministicDeployerScript.sol";
import {DeterministicDeployerScript, DeterministicParams} from "@zoralabs/zora-1155-contracts/src/deployment/DeterministicDeployerScript.sol";

contract DeterministicProxyDeployerTest is DeterministicDeployerScript, Test {
using stdJson for string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
pragma solidity 0.8.17;

import "forge-std/Test.sol";
import {IZoraCreator1155Factory} from "../../src/interfaces/IZoraCreator1155Factory.sol";
import {ZoraCreator1155FactoryImpl} from "../../src/factory/ZoraCreator1155FactoryImpl.sol";
import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.sol";
import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {IMinter1155} from "../../src/interfaces/IMinter1155.sol";
import {IOwnable} from "../../src/interfaces/IOwnable.sol";
import {ICreatorRoyaltiesControl} from "../../src/interfaces/ICreatorRoyaltiesControl.sol";
import {MockContractMetadata} from "../mock/MockContractMetadata.sol";
import {IZoraCreator1155Factory} from "@zoralabs/zora-1155-contracts/src/interfaces/IZoraCreator1155Factory.sol";
import {ZoraCreator1155FactoryImpl} from "@zoralabs/zora-1155-contracts/src/factory/ZoraCreator1155FactoryImpl.sol";
import {IZoraCreator1155Errors} from "@zoralabs/zora-1155-contracts/src/interfaces/IZoraCreator1155Errors.sol";
import {IZoraCreator1155} from "@zoralabs/zora-1155-contracts/src/interfaces/IZoraCreator1155.sol";
import {ZoraCreator1155Impl} from "@zoralabs/zora-1155-contracts/src/nft/ZoraCreator1155Impl.sol";
import {IMinter1155} from "@zoralabs/zora-1155-contracts/src/interfaces/IMinter1155.sol";
import {IOwnable} from "@zoralabs/zora-1155-contracts/src/interfaces/IOwnable.sol";
import {ICreatorRoyaltiesControl} from "@zoralabs/zora-1155-contracts/src/interfaces/ICreatorRoyaltiesControl.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "../../src/minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
import {ForkDeploymentConfig, Deployment} from "../../src/deployment/DeploymentConfig.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "@zoralabs/zora-1155-contracts/src/minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
import {ForkDeploymentConfig, Deployment} from "@zoralabs/zora-1155-contracts/src/deployment/DeploymentConfig.sol";

contract ZoraCreator1155FactoryForkTest is ForkDeploymentConfig, Test {
uint256 constant quantityToMint = 3;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "forge-std/Test.sol";
import {ForkDeploymentConfig} from "@zoralabs/zora-1155-contracts/src/deployment/DeploymentConfig.sol";
import {ZoraCreator1155Attribution, ContractCreationConfig, PremintConfig, TokenCreationConfig} from "@zoralabs/zora-1155-contracts/src/delegation/ZoraCreator1155Attribution.sol";
import {ZoraCreator1155PremintExecutorImpl} from "@zoralabs/zora-1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol";
import {ZoraCreator1155FactoryImpl} from "@zoralabs/zora-1155-contracts/src/factory/ZoraCreator1155FactoryImpl.sol";

contract ZoraCreator1155PreminterForkTest is ForkDeploymentConfig, Test {
ZoraCreator1155FactoryImpl factory;
ZoraCreator1155PremintExecutorImpl preminter;
uint256 mintFeeAmount = 0.000777 ether;

/// @notice gets the chains to do fork tests on, by reading environment var FORK_TEST_CHAINS.
/// Chains are by name, and must match whats under `rpc_endpoints` in the foundry.toml
function getForkTestChains() private view returns (string[] memory result) {
try vm.envString("FORK_TEST_CHAINS", ",") returns (string[] memory forkTestChains) {
result = forkTestChains;
} catch {
console.log("could not get fork test chains - make sure the environment variable FORK_TEST_CHAINS is set");
result = new string[](0);
}
}

function testTheForkPremint(string memory chainName) private {
console.log("testing on fork: ", chainName);

// create and select the fork, which will be used for all subsequent calls
// it will also affect the current block chain id based on the rpc url returned
vm.createSelectFork(vm.rpcUrl(chainName));

// get contract hash, which is unique per contract creation config, and can be used
// retreive the address created for a contract
address preminterAddress = getDeployment().preminterProxy;

if (preminterAddress == address(0)) {
console.log("preminter not configured for chain...skipping");
return;
}

// override local preminter to use the addresses from the chain
factory = ZoraCreator1155FactoryImpl(getDeployment().factoryProxy);
preminter = ZoraCreator1155PremintExecutorImpl(preminterAddress);
}

function test_fork_successfullyMintsTokens() external {
string[] memory forkTestChains = getForkTestChains();
for (uint256 i = 0; i < forkTestChains.length; i++) {
testTheForkPremint(forkTestChains[i]);
}
}

function _signAndExecutePremint(
ContractCreationConfig memory contractConfig,
PremintConfig memory premintConfig,
uint256 privateKey,
uint256 chainId,
address executor,
uint256 quantityToMint,
string memory comment
) private returns (uint256 newTokenId) {
bytes memory signature = _signPremint(preminter.getContractAddress(contractConfig), premintConfig, privateKey, chainId);

uint256 mintCost = mintFeeAmount * quantityToMint;
vm.deal(executor, mintCost);

// now call the premint function, using the same config that was used to generate the digest, and the signature
vm.prank(executor);
newTokenId = preminter.premint{value: mintCost}(contractConfig, premintConfig, signature, quantityToMint, comment);
}

function _signPremint(
address contractAddress,
PremintConfig memory premintConfig,
uint256 privateKey,
uint256 chainId
) private pure returns (bytes memory) {
bytes32 digest = ZoraCreator1155Attribution.premintHashedTypeDataV4(premintConfig, contractAddress, chainId);

// 3. Sign the digest
// create a signature with the digest for the params
return _sign(privateKey, digest);
}

function _sign(uint256 privateKey, bytes32 digest) private pure returns (bytes memory) {
// sign the message
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);

// combine into a single bytes array
return abi.encodePacked(r, s, v);
}
}

0 comments on commit be7731d

Please sign in to comment.