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

feat: gas tracking tests for core contract operations #108

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ checkout-op-commit:
git remote add origin https://github.com/ethereum-optimism/optimism.git; \
git fetch --depth=1 origin $(OP_COMMIT); \
git reset --hard FETCH_HEAD

.PHONY: gas-report
gas-report:
forge build && forge test --ffi -vvv --gas-report
16 changes: 14 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
[profile.default]
libs = ['lib']
fs_permissions = [ {access = "read-write", path = "./"} ]
fs_permissions = [{ access = "read-write", path = "./" }]
optimizer = true
optimizer_runs = 999999
solc_version = "0.8.15"

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
# Gas reporting settings
gas_reports = ["*"]
gas_reports_ignore = []
gas_per_pub_word = 20000
gas_per_pub_slot_storage = 20000

[profile.gas]
gas_reports = ["*"]
optimizer = true
optimizer_runs = 999999
verbosity = 3

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
82 changes: 82 additions & 0 deletions test/GasReport.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import "forge-std/Test.sol";
import "../src/Challenger1of2.sol";
import "../src/revenue-share/BalanceTracker.sol";
import {FeeVault as CustomFeeVault} from "../src/fee-vault-fixes/FeeVault.sol";
import {Proxy} from "@eth-optimism-bedrock/src/universal/Proxy.sol";

contract GasReportTest is Test {
Challenger1of2 challenger;
BalanceTracker balanceTracker;
CustomFeeVault feeVault;
address opSigner;
address otherSigner;
address proxyAdmin;

// Proxy-related variables
Proxy balanceTrackerProxy;
BalanceTracker balanceTrackerImplementation;

function setUp() public {
opSigner = makeAddr("opSigner");
otherSigner = makeAddr("otherSigner");
proxyAdmin = makeAddr("proxyAdmin");

// Setup Challenger
challenger = new Challenger1of2(
opSigner,
otherSigner,
address(new MockL2OutputOracle())
);

// Setup BalanceTracker
address payable profitWallet = payable(makeAddr("profitWallet"));
balanceTrackerImplementation = new BalanceTracker(profitWallet);
balanceTrackerProxy = new Proxy(proxyAdmin);
vm.prank(proxyAdmin);
balanceTrackerProxy.upgradeTo(address(balanceTrackerImplementation));
balanceTracker = BalanceTracker(payable(address(balanceTrackerProxy)));

// Initialize BalanceTracker
address payable[] memory systemAddresses = new address payable[](2);
systemAddresses[0] = payable(makeAddr("system1"));
systemAddresses[1] = payable(makeAddr("system2"));
uint256[] memory targetBalances = new uint256[](2);
targetBalances[0] = 1 ether;
targetBalances[1] = 2 ether;
balanceTracker.initialize(systemAddresses, targetBalances);

feeVault = new CustomFeeVault();
}

/// @notice Gas report for challenge execution
function test_challenger_execute() public {
bytes memory message = abi.encodeWithSelector(
MockL2OutputOracle.deleteL2Outputs.selector,
0
);
vm.prank(opSigner);
challenger.execute(message);
}

/// @notice Gas report for processing fees in BalanceTracker
function test_balanceTracker_processFees() public {
vm.deal(address(balanceTracker), 10 ether);
balanceTracker.processFees();
}

/// @notice Gas report for setting total processed in FeeVault
function test_feeVault_setTotalProcessed() public {
feeVault.setTotalProcessed(1 ether);
}

receive() external payable {}
}

contract MockL2OutputOracle {
function deleteL2Outputs(uint256) external pure returns (bool) {
return true;
}
}