Commit 5f0ac73c authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: fixup tests for `Storage`

parent cee6fefa
......@@ -657,9 +657,11 @@ SequencerFeeVault_Test:test_receive_succeeds() (gas: 17373)
SequencerFeeVault_Test:test_withdraw_notEnough_reverts() (gas: 9332)
SequencerFeeVault_Test:test_withdraw_toL1_succeeds() (gas: 171675)
SetPrevBaseFee_Test:test_setPrevBaseFee_succeeds() (gas: 11549)
Slot_Getters_Test:test_gettersAndSetters(bytes32,uint256,address,bytes32) (runs: 64, μ: 26835, ~: 26642)
StandardBridge_Stateless_Test:test_isCorrectTokenPair_succeeds() (gas: 49936)
StandardBridge_Stateless_Test:test_isOptimismMintableERC20_succeeds() (gas: 33072)
Storage_Roundtrip_Test:test_setGetAddress_succeeds(bytes32,address) (runs: 64, μ: 31799, ~: 31799)
Storage_Roundtrip_Test:test_setGetBytes32_succeeds(bytes32,bytes32) (runs: 64, μ: 31643, ~: 31643)
Storage_Roundtrip_Test:test_setGetUint_succeeds(bytes32,uint256) (runs: 64, μ: 30998, ~: 31620)
SystemConfig_Initialize_Test:test_initialize_events_succeeds() (gas: 71950)
SystemConfig_Initialize_Test:test_initialize_startBlockOverride_succeeds() (gas: 65132)
SystemConfig_Initialize_Test:test_initialize_values_succeeds() (gas: 64946)
......
......@@ -7,8 +7,8 @@
"src/L1/L1StandardBridge.sol": "0xdafe88c8b1255202eb674f4ebfb0dca791d2c87480c2c8d00cc46859671a5fa8",
"src/L1/L2OutputOracle.sol": "0xd263f43b79b6f1dca3a27f8bdbacf97deb1a3a95b7e1d395079700eecea65402",
"src/L1/OptimismPortal.sol": "0x8fdab55ab7c18bb7e037f0719c749f2cf1b0ca2da17da4ea0d1a4c5e2243ac60",
"src/L1/ProtocolVersions.sol": "0x7db1f41305e694ab726a686ef35daa54ec5bcb06d96704fbfa9cee163ce97e2c",
"src/L1/SystemConfig.sol": "0x0ac0f5dae210d313e184cb39ac02d90ee9bf4b9566568233656ad61e68156a59",
"src/L1/ProtocolVersions.sol": "0xc4f142ed9c195871ee21902245a9e2b902f8e38fcc77e6f61fb98f4d399031e4",
"src/L1/SystemConfig.sol": "0xf23f2c4425996c2719e1baddf468b328de724305f1852b59cd0b09c843075d63",
"src/L2/BaseFeeVault.sol": "0xc347c1aebe69178e72d2b1d3e700bbf84e39975319465bb85d69fd0d60fc1759",
"src/L2/GasPriceOracle.sol": "0x88efffbd40f8d012d700a5d7fde0d92266f65e9d7006cd8f034bacaa036d0eb2",
"src/L2/L1Block.sol": "0x1ed9aa36036ded00a0383692eca81a22f668d64e22af973559d2ccefc86825c0",
......
......@@ -35,8 +35,8 @@ contract ProtocolVersions is OwnableUpgradeable, ISemver {
event ConfigUpdate(uint256 indexed version, UpdateType indexed updateType, bytes data);
/// @notice Semantic version.
/// @custom:semver 0.1.1
string public constant version = "0.1.1";
/// @custom:semver 0.2.0
string public constant version = "0.2.0";
/// @notice Constructs the ProtocolVersion contract. Cannot set
/// the owner to `address(0)` due to the Ownable contract's
......
......@@ -100,8 +100,8 @@ contract SystemConfig is OwnableUpgradeable, ISemver {
uint256 public startBlock;
/// @notice Semantic version.
/// @custom:semver 1.7.2
string public constant version = "1.7.2";
/// @custom:semver 1.8.0
string public constant version = "1.8.0";
/// @notice Constructs the SystemConfig contract. Cannot set
/// the owner to `address(0)` due to the Ownable contract's
......
......@@ -4,32 +4,54 @@ pragma solidity ^0.8.0;
// Target contract
import { Storage } from "src/libraries/Storage.sol";
import { Test } from "forge-std/Test.sol";
import { console } from "forge-std/console.sol";
/// @title StorageWrapper
/// @notice StorageWrapper wraps the Storage library for testing purposes.
/// It exists to prevent storage collisions with the `Test` contract.
contract StorageWrapper {
function getAddress(bytes32 _slot) external view returns (address) {
return Storage.getAddress(_slot);
}
function setAddress(bytes32 _slot, address _address) external {
Storage.setAddress(_slot, _address);
}
function getUint(bytes32 _slot) external view returns (uint256) {
return Storage.getUint(_slot);
}
function setUint(bytes32 _slot, uint256 _value) external {
Storage.setUint(_slot, _value);
}
function getBytes32(bytes32 _slot) external view returns (bytes32) {
return Storage.getBytes32(_slot);
}
function setBytes32(bytes32 _slot, bytes32 _value) external {
Storage.setBytes32(_slot, _value);
}
}
contract Storage_Roundtrip_Test is Test {
StorageWrapper wrapper;
function setUp() external {
wrapper = new StorageWrapper();
}
contract Slot_Getters_Test is Test {
function test_setGetUint_succeeds(bytes32 slot, uint256 num) external {
Storage.setUint(slot, num);
assertEq(Storage.getUint(slot), num);
assertEq(num, uint256(vm.load(address(this), slot)));
wrapper.setUint(slot, num);
assertEq(wrapper.getUint(slot), num);
assertEq(num, uint256(vm.load(address(wrapper), slot)));
}
function test_setGetAddress_succeeds(bytes32 slot, address addr) external {
Storage.setAddress(slot, addr);
assertEq(Storage.getAddress(slot), addr);
assertEq(addr, address(uint160(uint256(vm.load(address(this), slot)))));
wrapper.setAddress(slot, addr);
assertEq(wrapper.getAddress(slot), addr);
assertEq(addr, address(uint160(uint256(vm.load(address(wrapper), slot)))));
}
function test_setGetBytes32_succeeds(bytes32 slot, bytes32 hash) external {
Storage.setBytes32(slot, hash);
assertEq(Storage.getBytes32(slot), hash);
assertEq(hash, vm.load(address(this), slot));
}
function test_setGetBytes32_succeeds() external {
// honestly no idea why this fails
bytes32 slot = 0x0000000000000000000000000000000000000000000000000000000000000000;
bytes32 hash = 0xf7c008fcd8dbdd7cc5f16b63632032e60267b5b3ef0593cf7cf8ff16b65d41f0;
Storage.setBytes32(slot, hash);
assertEq(Storage.getBytes32(slot), hash);
assertEq(hash, vm.load(address(this), slot));
wrapper.setBytes32(slot, hash);
assertEq(wrapper.getBytes32(slot), hash);
assertEq(hash, vm.load(address(wrapper), slot));
}
}
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