Commit 2c7cfb80 authored by Maurelian's avatar Maurelian

feat(ctb): DelayedVetoable as a simple forwarder

Adds a very minimal DelayedVetoable, along with tests for the _handleCall function.

feat(ctb): Add actor to invariant tests

feat(ctb): Simplify by reducing the amount of assembly used.

feat(ctb): remove invariant tests

These tests have proven complex to write due to the transparent proxy pattern.

I believe that the fuzz testing is sufficient for now.
parent f368843d
...@@ -46,6 +46,7 @@ CrossDomainOwnable3_Test:test_transferOwnership_zeroAddress_reverts() (gas: 1208 ...@@ -46,6 +46,7 @@ CrossDomainOwnable3_Test:test_transferOwnership_zeroAddress_reverts() (gas: 1208
CrossDomainOwnableThroughPortal_Test:test_depositTransaction_crossDomainOwner_succeeds() (gas: 81417) CrossDomainOwnableThroughPortal_Test:test_depositTransaction_crossDomainOwner_succeeds() (gas: 81417)
CrossDomainOwnable_Test:test_onlyOwner_notOwner_reverts() (gas: 10597) CrossDomainOwnable_Test:test_onlyOwner_notOwner_reverts() (gas: 10597)
CrossDomainOwnable_Test:test_onlyOwner_succeeds() (gas: 34883) CrossDomainOwnable_Test:test_onlyOwner_succeeds() (gas: 34883)
DelayedVetoable_HandleCall_TestFail:test_handleCall_reverts() (gas: 24969)
DeleteOutput:test_script_succeeds() (gas: 3100) DeleteOutput:test_script_succeeds() (gas: 3100)
DeployerWhitelist_Test:test_owner_succeeds() (gas: 7582) DeployerWhitelist_Test:test_owner_succeeds() (gas: 7582)
DeployerWhitelist_Test:test_storageSlots_succeeds() (gas: 33395) DeployerWhitelist_Test:test_storageSlots_succeeds() (gas: 33395)
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
// TODO(maurelian): remove this when the contract is complete
import { console } from "forge-std/console.sol";
contract DelayedVetoable {
/// @notice An event that is emitted each time a call is forwarded.
/// @param data The address of the implementation contract
event Forwarded(bytes data);
/// @notice The address that all calls are forwarded to after the delay.
address internal _target;
/// @notice Sets the target admin during contract deployment.
/// @param target Address of the target.
constructor(address target) {
_target = target;
}
/// @notice Used when no data is passed to the contract.
receive() external payable {
_handleCall();
}
/// @notice Used for all calls that pass data to the contract.
fallback() external payable {
_handleCall();
}
/// @notice Handles forwards the call to the target.
function _handleCall() internal {
require(_target != address(0), "DelayedVetoable: target not initialized");
emit Forwarded(msg.data);
(bool success,) = _target.call(msg.data);
assembly {
// Success == 0 means a revert. We'll revert too and pass the data up.
if iszero(success) { revert(0x0, returndatasize()) }
// Otherwise we'll just return and pass the data up.
return(0x0, returndatasize())
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { CommonTest, Reverter } from "./CommonTest.t.sol";
import { DelayedVetoable } from "../src/universal/DelayedVetoable.sol";
contract DelayedVetoable_Init is CommonTest {
event Forwarded(bytes data);
address target = address(0xabba);
DelayedVetoable delayedVetoable;
Reverter reverter;
function setUp() public override {
super.setUp();
delayedVetoable = new DelayedVetoable({
target: address(target)
});
reverter = new Reverter();
}
}
contract DelayedVetoable_HandleCall_Test is DelayedVetoable_Init {
function testFuzz_handleCall_succeeds(bytes memory data) external {
vm.expectCall(target, data);
vm.expectEmit(true, false, false, true, address(delayedVetoable));
emit Forwarded(data);
(bool success,) = address(delayedVetoable).call(data);
assert(success);
}
}
contract DelayedVetoable_HandleCall_TestFail is DelayedVetoable_Init {
function test_handleCall_reverts() external {
vm.expectCall(target, NON_ZERO_DATA);
vm.expectRevert();
// including data will call the fallback
(bool success,) = address(delayedVetoable).call(NON_ZERO_DATA);
assertFalse(success);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment