Skip to content

Commit

Permalink
Merge pull request #183 from PaulRBerg/test/rename-utils-deployers
Browse files Browse the repository at this point in the history
test: rename deploy optimized functions
  • Loading branch information
PaulRBerg authored Dec 28, 2023
2 parents 947fef8 + 875eda8 commit 1c43be3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
15 changes: 5 additions & 10 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity >=0.8.18 <0.9.0;

import { eqString } from "@prb/test/src/Helpers.sol";
import { StdCheats } from "forge-std/src/StdCheats.sol";
import { StdUtils } from "forge-std/src/StdUtils.sol";

import { IPRBProxy } from "../src/interfaces/IPRBProxy.sol";
Expand All @@ -24,10 +23,11 @@ import { TargetPanic } from "./mocks/targets/TargetPanic.sol";
import { TargetReverter } from "./mocks/targets/TargetReverter.sol";
import { TargetSelfDestructer } from "./mocks/targets/TargetSelfDestructer.sol";
import { Assertions } from "./utils/Assertions.sol";
import { DeployOptimized } from "./utils/DeployOptimized.sol";
import { Events } from "./utils/Events.sol";

/// @notice Base test contract with common logic needed by all test contracts.
abstract contract Base_Test is Assertions, Events, StdCheats, StdUtils {
abstract contract Base_Test is Assertions, DeployOptimized, Events, StdUtils {
/*//////////////////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -132,23 +132,18 @@ abstract contract Base_Test is Assertions, Events, StdCheats, StdUtils {
vm.deal({ account: addr, newBalance: 100 ether });
}

/// @dev Deploys {PRBProxyRegistry} from a source precompiled with `--via-ir`.
function deployPrecompiledRegistry() internal returns (IPRBProxyRegistry registry_) {
registry_ = IPRBProxyRegistry(deployCode("out-optimized/PRBProxyRegistry.sol/PRBProxyRegistry.json"));
}

/// @dev Conditionally deploy the registry either normally or from a source precompiled with `--via-ir`.
/// @dev Conditionally deploy the registry either normally or from an optimized source compiled with `--via-ir`.
function deployRegistryConditionally() internal {
if (!isTestOptimizedProfile()) {
registry = new PRBProxyRegistry();
} else {
registry = deployPrecompiledRegistry();
registry = deployOptimizedRegistry();
}

vm.label({ account: address(registry), newLabel: "Registry" });
}

/// @dev Reads the proxy bytecode either normally or from precompiled source.
/// @dev Reads the proxy bytecode either normally or from an optimized source.
function getProxyBytecode() internal returns (bytes memory) {
if (!isTestOptimizedProfile()) {
return type(PRBProxy).creationCode;
Expand Down
14 changes: 14 additions & 0 deletions test/utils/DeployOptimized.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <0.9.0;

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

import { IPRBProxyRegistry } from "../../src/interfaces/IPRBProxyRegistry.sol";
import { PRBProxyRegistry } from "../../src/PRBProxyRegistry.sol";

Check warning on line 7 in test/utils/DeployOptimized.sol

View workflow job for this annotation

GitHub Actions / lint

imported name PRBProxyRegistry is not used

Check warning on line 7 in test/utils/DeployOptimized.sol

View workflow job for this annotation

GitHub Actions / lint

imported name PRBProxyRegistry is not used

abstract contract DeployOptimized is StdCheats {
/// @dev Deploys {PRBProxyRegistry} from an optimized source compiled `--via-ir`.
function deployOptimizedRegistry() internal returns (IPRBProxyRegistry registry_) {
registry_ = IPRBProxyRegistry(deployCode("out-optimized/PRBProxyRegistry.sol/PRBProxyRegistry.json"));
}
}
2 changes: 1 addition & 1 deletion test/utils/Precompiles.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract Precompiles_Test is Base_Test {

function test_DeployPRBProxyRegistry() external onlyTestOptimizedProfile {
address actualRegistry = address(precompiles.deployRegistry());
address expectedRegistry = address(deployPrecompiledRegistry());
address expectedRegistry = address(deployOptimizedRegistry());
assertEq(actualRegistry.code, expectedRegistry.code, "registry bytecodes don't match");
}
}

0 comments on commit 1c43be3

Please sign in to comment.