Commit 5330243f authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #4802 from ethereum-optimism/sc/ctb-hashing-test-cleanup

maint(ctb): clean up Hashing tests
parents 679522bd 7d2f66eb
...@@ -46,7 +46,7 @@ GovernanceToken_Test:test_mint_fromNotOwner_reverts() (gas: 17052) ...@@ -46,7 +46,7 @@ GovernanceToken_Test:test_mint_fromNotOwner_reverts() (gas: 17052)
GovernanceToken_Test:test_mint_fromOwner_succeeds() (gas: 108547) GovernanceToken_Test:test_mint_fromOwner_succeeds() (gas: 108547)
GovernanceToken_Test:test_transferFrom_succeeds() (gas: 146295) GovernanceToken_Test:test_transferFrom_succeeds() (gas: 146295)
GovernanceToken_Test:test_transfer_succeeds() (gas: 138085) GovernanceToken_Test:test_transfer_succeeds() (gas: 138085)
Hashing_Test:test_hashDepositSource_succeeds() (gas: 650) Hashing_hashDepositSource_Test:test_hashDepositSource_succeeds() (gas: 566)
L1BlockTest:test_basefee_succeeds() (gas: 7553) L1BlockTest:test_basefee_succeeds() (gas: 7553)
L1BlockTest:test_hash_succeeds() (gas: 7510) L1BlockTest:test_hash_succeeds() (gas: 7510)
L1BlockTest:test_number_succeeds() (gas: 7584) L1BlockTest:test_number_succeeds() (gas: 7584)
......
...@@ -6,20 +6,33 @@ import { Types } from "../libraries/Types.sol"; ...@@ -6,20 +6,33 @@ import { Types } from "../libraries/Types.sol";
import { Hashing } from "../libraries/Hashing.sol"; import { Hashing } from "../libraries/Hashing.sol";
import { Encoding } from "../libraries/Encoding.sol"; import { Encoding } from "../libraries/Encoding.sol";
contract Hashing_Test is CommonTest { contract Hashing_hashDepositSource_Test is CommonTest {
function setUp() external { function setUp() external {
_setUp(); _setUp();
} }
/**
* @notice Tests that hashDepositSource returns the correct hash in a simple case.
*/
function test_hashDepositSource_succeeds() external { function test_hashDepositSource_succeeds() external {
bytes32 sourceHash = Hashing.hashDepositSource( assertEq(
Hashing.hashDepositSource(
0xd25df7858efc1778118fb133ac561b138845361626dfb976699c5287ed0f4959, 0xd25df7858efc1778118fb133ac561b138845361626dfb976699c5287ed0f4959,
0x1 0x1
),
0xf923fb07134d7d287cb52c770cc619e17e82606c21a875c92f4c63b65280a5cc
); );
}
}
assertEq(sourceHash, 0xf923fb07134d7d287cb52c770cc619e17e82606c21a875c92f4c63b65280a5cc); contract Hashing_hashCrossDomainMessage_Test is CommonTest {
function setUp() external {
_setUp();
} }
/**
* @notice Tests that hashCrossDomainMessage returns the correct hash in a simple case.
*/
function testDiff_hashCrossDomainMessage_succeeds( function testDiff_hashCrossDomainMessage_succeeds(
uint240 _nonce, uint240 _nonce,
uint16 _version, uint16 _version,
...@@ -29,31 +42,25 @@ contract Hashing_Test is CommonTest { ...@@ -29,31 +42,25 @@ contract Hashing_Test is CommonTest {
uint256 _gasLimit, uint256 _gasLimit,
bytes memory _data bytes memory _data
) external { ) external {
// Ensure the version is valid // Ensure the version is valid.
uint16 version = uint16(bound(uint256(_version), 0, 1)); uint16 version = uint16(bound(uint256(_version), 0, 1));
uint256 nonce = Encoding.encodeVersionedNonce(_nonce, version); uint256 nonce = Encoding.encodeVersionedNonce(_nonce, version);
bytes32 _hash = ffi.hashCrossDomainMessage( assertEq(
nonce, Hashing.hashCrossDomainMessage(nonce, _sender, _target, _value, _gasLimit, _data),
_sender, ffi.hashCrossDomainMessage(nonce, _sender, _target, _value, _gasLimit, _data)
_target,
_value,
_gasLimit,
_data
);
bytes32 hash = Hashing.hashCrossDomainMessage(
nonce,
_sender,
_target,
_value,
_gasLimit,
_data
); );
}
}
assertEq(hash, _hash); contract Hashing_hashWithdrawal_Test is CommonTest {
function setUp() external {
_setUp();
} }
/**
* @notice Tests that hashWithdrawal returns the correct hash in a simple case.
*/
function testDiff_hashWithdrawal_succeeds( function testDiff_hashWithdrawal_succeeds(
uint256 _nonce, uint256 _nonce,
address _sender, address _sender,
...@@ -62,42 +69,56 @@ contract Hashing_Test is CommonTest { ...@@ -62,42 +69,56 @@ contract Hashing_Test is CommonTest {
uint256 _gasLimit, uint256 _gasLimit,
bytes memory _data bytes memory _data
) external { ) external {
bytes32 hash = Hashing.hashWithdrawal( assertEq(
Hashing.hashWithdrawal(
Types.WithdrawalTransaction(_nonce, _sender, _target, _value, _gasLimit, _data) Types.WithdrawalTransaction(_nonce, _sender, _target, _value, _gasLimit, _data)
),
ffi.hashWithdrawal(_nonce, _sender, _target, _value, _gasLimit, _data)
); );
}
}
bytes32 _hash = ffi.hashWithdrawal(_nonce, _sender, _target, _value, _gasLimit, _data); contract Hashing_hashOutputRootProof_Test is CommonTest {
function setUp() external {
assertEq(hash, _hash); _setUp();
} }
/**
* @notice Tests that hashOutputRootProof returns the correct hash in a simple case.
*/
function testDiff_hashOutputRootProof_succeeds( function testDiff_hashOutputRootProof_succeeds(
bytes32 _version, bytes32 _version,
bytes32 _stateRoot, bytes32 _stateRoot,
bytes32 _messagePasserStorageRoot, bytes32 _messagePasserStorageRoot,
bytes32 _latestBlockhash bytes32 _latestBlockhash
) external { ) external {
Types.OutputRootProof memory proof = Types.OutputRootProof({ assertEq(
Hashing.hashOutputRootProof(
Types.OutputRootProof({
version: _version, version: _version,
stateRoot: _stateRoot, stateRoot: _stateRoot,
messagePasserStorageRoot: _messagePasserStorageRoot, messagePasserStorageRoot: _messagePasserStorageRoot,
latestBlockhash: _latestBlockhash latestBlockhash: _latestBlockhash
}); })
),
bytes32 hash = Hashing.hashOutputRootProof(proof); ffi.hashOutputRootProof(
bytes32 _hash = ffi.hashOutputRootProof(
_version, _version,
_stateRoot, _stateRoot,
_messagePasserStorageRoot, _messagePasserStorageRoot,
_latestBlockhash _latestBlockhash
)
); );
}
}
assertEq(hash, _hash); contract Hashing_hashDepositTransaction_Test is CommonTest {
function setUp() external {
_setUp();
} }
// TODO(tynes): foundry bug cannot serialize /**
// bytes32 as strings with vm.toString * @notice Tests that hashDepositTransaction returns the correct hash in a simple case.
*/
function testDiff_hashDepositTransaction_succeeds( function testDiff_hashDepositTransaction_succeeds(
address _from, address _from,
address _to, address _to,
...@@ -107,7 +128,8 @@ contract Hashing_Test is CommonTest { ...@@ -107,7 +128,8 @@ contract Hashing_Test is CommonTest {
bytes memory _data, bytes memory _data,
uint256 _logIndex uint256 _logIndex
) external { ) external {
bytes32 hash = Hashing.hashDepositTransaction( assertEq(
Hashing.hashDepositTransaction(
Types.UserDepositTransaction( Types.UserDepositTransaction(
_from, _from,
_to, _to,
...@@ -119,18 +141,8 @@ contract Hashing_Test is CommonTest { ...@@ -119,18 +141,8 @@ contract Hashing_Test is CommonTest {
bytes32(uint256(0)), bytes32(uint256(0)),
_logIndex _logIndex
) )
),
ffi.hashDepositTransaction(_from, _to, _mint, _value, _gas, _data, _logIndex)
); );
bytes32 _hash = ffi.hashDepositTransaction(
_from,
_to,
_mint,
_value,
_gas,
_data,
_logIndex
);
assertEq(hash, _hash);
} }
} }
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