Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: rename deploy optimized functions #183

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

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");
}
}