Commit 406e92e3 authored by Michael Amadi's avatar Michael Amadi Committed by GitHub

improve universal and libraries tests and coverage (#12996)

* improve universal and libraries tests and coverage

* fixes
parent f3701d79
...@@ -71,6 +71,18 @@ contract Encoding_Test is CommonTest { ...@@ -71,6 +71,18 @@ contract Encoding_Test is CommonTest {
assertEq(legacyEncoding, bedrockEncoding); assertEq(legacyEncoding, bedrockEncoding);
} }
/// @dev Tests that encodeCrossDomainMessage reverts if version is greater than 1.
function testFuzz_encodeCrossDomainMessage_versionGreaterThanOne_reverts(uint256 nonce) external {
// nonce >> 240 must be greater than 1
uint256 minInvalidNonce = (uint256(type(uint240).max) + 1) * 2;
nonce = bound(nonce, minInvalidNonce, type(uint256).max);
EncodingContract encoding = new EncodingContract();
vm.expectRevert(bytes("Encoding: unknown cross domain message version"));
encoding.encodeCrossDomainMessage(nonce, address(this), address(this), 1, 100, hex"");
}
/// @dev Tests deposit transaction encoding. /// @dev Tests deposit transaction encoding.
function testDiff_encodeDepositTransaction_succeeds( function testDiff_encodeDepositTransaction_succeeds(
address _from, address _from,
...@@ -94,3 +106,20 @@ contract Encoding_Test is CommonTest { ...@@ -94,3 +106,20 @@ contract Encoding_Test is CommonTest {
assertEq(txn, _txn); assertEq(txn, _txn);
} }
} }
contract EncodingContract {
function encodeCrossDomainMessage(
uint256 nonce,
address sender,
address target,
uint256 value,
uint256 gasLimit,
bytes memory data
)
external
pure
returns (bytes memory)
{
return Encoding.encodeCrossDomainMessage(nonce, sender, target, value, gasLimit, data);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { SafeSend } from "src/universal/SafeSend.sol";
import { CommonTest } from "test/setup/CommonTest.sol";
contract SafeSendTest is CommonTest {
/// @notice Tests that sending to an EOA succeeds.
function test_send_toEOA_succeeds() public {
assertNotEq(alice, address(0));
assertNotEq(bob, address(0));
assertEq(bob.code.length, 0);
vm.deal(alice, 100 ether);
uint256 aliceBalanceBefore = alice.balance;
uint256 bobBalanceBefore = bob.balance;
vm.prank(alice);
SafeSend safeSend = new SafeSend{ value: 100 ether }(payable(bob));
assertEq(address(safeSend).code.length, 0);
assertEq(address(safeSend).balance, 0);
assertEq(alice.balance, aliceBalanceBefore - 100 ether);
assertEq(bob.balance, bobBalanceBefore + 100 ether);
}
/// @notice Tests that sending to a contract succeeds without executing the
/// contract's code.
function test_send_toContract_succeeds() public {
// etch reverting code into bob
vm.etch(bob, hex"fe");
vm.deal(alice, 100 ether);
uint256 aliceBalanceBefore = alice.balance;
uint256 bobBalanceBefore = bob.balance;
vm.prank(alice);
SafeSend safeSend = new SafeSend{ value: 100 ether }(payable(bob));
assertEq(address(safeSend).code.length, 0);
assertEq(address(safeSend).balance, 0);
assertEq(alice.balance, aliceBalanceBefore - 100 ether);
assertEq(bob.balance, bobBalanceBefore + 100 ether);
}
}
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