Commit 2013c903 authored by Michael Amadi's avatar Michael Amadi Committed by GitHub

fix abi.encodecall semgrep check for tests (#12664)

* fix abi.encodecall semgrep for tests

* fix safe call test

* rm unneccessary abi.encodeWithSignature, fix fuzz test

* use comment for semgrep...

* use comment for semgrep...

* use pattern-not for expectRevert cases

* fixes

* fixes

* try fix ci

* fix...
parent db39e52a
......@@ -19,9 +19,11 @@ interface Vm {
library console {
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _castLogPayloadViewToPure(
function(bytes memory) internal view fnIn
) internal pure returns (function(bytes memory) internal pure fnOut) {
function _castLogPayloadViewToPure(function(bytes memory) internal view fnIn)
internal
pure
returns (function(bytes memory) internal pure fnOut)
{
assembly {
fnOut := fnIn
}
......@@ -42,30 +44,29 @@ library console {
}
function log(string memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
_sendLogPayload(abi.encodeWithSignature("log(string)", p0)); // nosemgrep: sol-style-use-abi-encodecall
}
function log(string memory p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1)); // nosemgrep: sol-style-use-abi-encodecall
}
function log(string memory p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1));
_sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1)); // nosemgrep: sol-style-use-abi-encodecall
}
function log(string memory p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1)); // nosemgrep: sol-style-use-abi-encodecall
}
function log(string memory p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2)); // nosemgrep: sol-style-use-abi-encodecall
}
}
/// @title ScriptExample
/// @notice ScriptExample is an example script. The Go forge script code tests that it can run this.
contract ScriptExample {
address internal constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code"))));
Vm internal constant vm = Vm(VM_ADDRESS);
......
......@@ -74,6 +74,7 @@ library Encoding {
pure
returns (bytes memory)
{
// nosemgrep: sol-style-use-abi-encodecall
return abi.encodeWithSignature("relayMessage(address,address,bytes,uint256)", _target, _sender, _data, _nonce);
}
......@@ -97,6 +98,7 @@ library Encoding {
pure
returns (bytes memory)
{
// nosemgrep: sol-style-use-abi-encodecall
return abi.encodeWithSignature(
"relayMessage(uint256,address,address,uint256,uint256,bytes)",
_nonce,
......
......@@ -24,6 +24,7 @@ library LegacyCrossDomainUtils {
pure
returns (bytes memory)
{
// nosemgrep: sol-style-use-abi-encodecall
return abi.encodeWithSignature(
"relayMessage(address,address,bytes,uint256)", _target, _sender, _message, _messageNonce
);
......
......@@ -58,14 +58,16 @@ contract L1CrossDomainMessenger_Test is Bridge_Initializer {
// deposit transaction on the optimism portal should be called
vm.expectCall(
address(optimismPortal),
abi.encodeWithSelector(
IOptimismPortal.depositTransaction.selector,
Predeploys.L2_CROSS_DOMAIN_MESSENGER,
0,
l1CrossDomainMessenger.baseGas(hex"ff", 100),
false,
Encoding.encodeCrossDomainMessage(
l1CrossDomainMessenger.messageNonce(), alice, recipient, 0, 100, hex"ff"
abi.encodeCall(
IOptimismPortal.depositTransaction,
(
Predeploys.L2_CROSS_DOMAIN_MESSENGER,
0,
l1CrossDomainMessenger.baseGas(hex"ff", 100),
false,
Encoding.encodeCrossDomainMessage(
l1CrossDomainMessenger.messageNonce(), alice, recipient, 0, 100, hex"ff"
)
)
)
);
......@@ -604,7 +606,7 @@ contract L1CrossDomainMessenger_Test is Bridge_Initializer {
/// @dev Tests that the superchain config is called by the messengers paused function
function test_pause_callsSuperchainConfig_succeeds() external {
vm.expectCall(address(superchainConfig), abi.encodeWithSelector(ISuperchainConfig.paused.selector));
vm.expectCall(address(superchainConfig), abi.encodeCall(ISuperchainConfig.paused, ()));
l1CrossDomainMessenger.paused();
}
......@@ -624,20 +626,22 @@ contract L1CrossDomainMessenger_Test is Bridge_Initializer {
function test_sendMessage_customGasToken_noValue_succeeds() external {
// Mock the gasPayingToken function to return a custom gas token
vm.mockCall(
address(systemConfig), abi.encodeWithSignature("gasPayingToken()"), abi.encode(address(1), uint8(18))
address(systemConfig), abi.encodeCall(systemConfig.gasPayingToken, ()), abi.encode(address(1), uint8(18))
);
// deposit transaction on the optimism portal should be called
vm.expectCall(
address(optimismPortal),
abi.encodeWithSelector(
IOptimismPortal.depositTransaction.selector,
Predeploys.L2_CROSS_DOMAIN_MESSENGER,
0,
l1CrossDomainMessenger.baseGas(hex"ff", 100),
false,
Encoding.encodeCrossDomainMessage(
l1CrossDomainMessenger.messageNonce(), alice, recipient, 0, 100, hex"ff"
abi.encodeCall(
IOptimismPortal.depositTransaction,
(
Predeploys.L2_CROSS_DOMAIN_MESSENGER,
0,
l1CrossDomainMessenger.baseGas(hex"ff", 100),
false,
Encoding.encodeCrossDomainMessage(
l1CrossDomainMessenger.messageNonce(), alice, recipient, 0, 100, hex"ff"
)
)
)
);
......@@ -670,7 +674,7 @@ contract L1CrossDomainMessenger_Test is Bridge_Initializer {
function test_sendMessage_customGasToken_withValue_reverts() external {
// Mock the gasPayingToken function to return a custom gas token
vm.mockCall(
address(systemConfig), abi.encodeWithSignature("gasPayingToken()"), abi.encode(address(1), uint8(2))
address(systemConfig), abi.encodeCall(systemConfig.gasPayingToken, ()), abi.encode(address(1), uint8(2))
);
vm.expectRevert("CrossDomainMessenger: cannot send value with custom gas token");
......@@ -681,7 +685,7 @@ contract L1CrossDomainMessenger_Test is Bridge_Initializer {
function test_relayMessage_customGasToken_noValue_succeeds() external {
// Mock the gasPayingToken function to return a custom gas token
vm.mockCall(
address(systemConfig), abi.encodeWithSignature("gasPayingToken()"), abi.encode(address(1), uint8(2))
address(systemConfig), abi.encodeCall(systemConfig.gasPayingToken, ()), abi.encode(address(1), uint8(2))
);
address target = address(0xabcd);
......@@ -721,7 +725,7 @@ contract L1CrossDomainMessenger_Test is Bridge_Initializer {
function test_relayMessage_customGasToken_withValue_reverts() external virtual {
// Mock the gasPayingToken function to return a custom gas token
vm.mockCall(
address(systemConfig), abi.encodeWithSignature("gasPayingToken()"), abi.encode(address(1), uint8(2))
address(systemConfig), abi.encodeCall(systemConfig.gasPayingToken, ()), abi.encode(address(1), uint8(2))
);
vm.expectRevert("CrossDomainMessenger: value must be zero unless message is from a system address");
......@@ -743,7 +747,7 @@ contract L1CrossDomainMessenger_ReinitReentryTest is Bridge_Initializer {
// Common values used across functions
uint256 constant messageValue = 50;
bytes constant selector = abi.encodeWithSelector(this.reinitAndReenter.selector);
bytes selector = abi.encodeCall(this.reinitAndReenter, ());
address sender;
bytes32 hash;
address target;
......@@ -760,7 +764,7 @@ contract L1CrossDomainMessenger_ReinitReentryTest is Bridge_Initializer {
/// @dev This method will be called by the relayed message, and will attempt to reenter the relayMessage function
/// exactly once.
function reinitAndReenter() public payable {
function reinitAndReenter() external payable {
// only attempt the attack once
if (!attacked) {
attacked = true;
......
......@@ -250,7 +250,7 @@ contract L1ERC721Bridge_Test is Bridge_Initializer {
// Finalize a withdrawal.
vm.mockCall(
address(l1CrossDomainMessenger),
abi.encodeWithSelector(l1CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(l1CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(Predeploys.L2_ERC721_BRIDGE)
);
vm.prank(address(l1CrossDomainMessenger));
......@@ -276,7 +276,7 @@ contract L1ERC721Bridge_Test is Bridge_Initializer {
// Finalize a withdrawal.
vm.mockCall(
address(l1CrossDomainMessenger),
abi.encodeWithSelector(l1CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(l1CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(alice)
);
vm.prank(address(l1CrossDomainMessenger));
......@@ -290,7 +290,7 @@ contract L1ERC721Bridge_Test is Bridge_Initializer {
// Finalize a withdrawal.
vm.mockCall(
address(l1CrossDomainMessenger),
abi.encodeWithSelector(l1CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(l1CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(Predeploys.L2_ERC721_BRIDGE)
);
vm.prank(address(l1CrossDomainMessenger));
......@@ -306,7 +306,7 @@ contract L1ERC721Bridge_Test is Bridge_Initializer {
// Finalize a withdrawal.
vm.mockCall(
address(l1CrossDomainMessenger),
abi.encodeWithSelector(l1CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(l1CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(Predeploys.L2_ERC721_BRIDGE)
);
vm.prank(address(l1CrossDomainMessenger));
......@@ -325,7 +325,7 @@ contract L1ERC721Bridge_Pause_Test is Bridge_Initializer {
/// @dev Ensures that the `paused` function of the bridge contract actually calls the `paused` function of the
/// `superchainConfig`.
function test_pause_callsSuperchainConfig_succeeds() external {
vm.expectCall(address(superchainConfig), abi.encodeWithSelector(ISuperchainConfig.paused.selector));
vm.expectCall(address(superchainConfig), abi.encodeCall(ISuperchainConfig.paused, ()));
l1ERC721Bridge.paused();
}
......@@ -354,7 +354,7 @@ contract L1ERC721Bridge_Pause_TestFail is Bridge_Initializer {
vm.mockCall(
address(l1ERC721Bridge.messenger()),
abi.encodeWithSelector(ICrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(ICrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(address(l1ERC721Bridge.otherBridge()))
);
}
......
......@@ -422,7 +422,7 @@ contract L2OutputOracleUpgradeable_Test is L2OutputOracle_TestBase {
vm.startPrank(EIP1967Helper.getAdmin(address(proxy)));
// Reviewer note: the NextImpl() still uses reinitializer. If we want to remove that, we'll need to use a
// two step upgrade with the Storage lib.
proxy.upgradeToAndCall(address(nextImpl), abi.encodeWithSelector(NextImpl.initialize.selector, 2));
proxy.upgradeToAndCall(address(nextImpl), abi.encodeCall(NextImpl.initialize, (2)));
assertEq(proxy.implementation(), address(nextImpl));
// Verify that the NextImpl contract initialized its values according as expected
......
......@@ -36,7 +36,7 @@ contract SuperchainConfig_Init_Test is CommonTest {
vm.startPrank(alice);
newProxy.upgradeToAndCall(
address(newImpl),
abi.encodeWithSelector(ISuperchainConfig.initialize.selector, deploy.cfg().superchainConfigGuardian(), true)
abi.encodeCall(ISuperchainConfig.initialize, (deploy.cfg().superchainConfigGuardian(), true))
);
assertTrue(ISuperchainConfig(address(newProxy)).paused());
......
......@@ -375,9 +375,9 @@ contract SystemConfig_Init_CustomGasToken is SystemConfig_Init {
vm.assume(bytes(_name).length <= 32);
vm.assume(bytes(_symbol).length <= 32);
vm.mockCall(_token, abi.encodeWithSelector(token.decimals.selector), abi.encode(18));
vm.mockCall(_token, abi.encodeWithSelector(token.name.selector), abi.encode(_name));
vm.mockCall(_token, abi.encodeWithSelector(token.symbol.selector), abi.encode(_symbol));
vm.mockCall(_token, abi.encodeCall(token.decimals, ()), abi.encode(18));
vm.mockCall(_token, abi.encodeCall(token.name, ()), abi.encode(_name));
vm.mockCall(_token, abi.encodeCall(token.symbol, ()), abi.encode(_symbol));
cleanStorageAndInit(_token);
......@@ -421,7 +421,7 @@ contract SystemConfig_Init_CustomGasToken is SystemConfig_Init {
/// @dev Tests that initialization fails if decimals are not 18.
function test_initialize_customGasToken_wrongDecimals_fails() external {
vm.mockCall(address(token), abi.encodeWithSelector(token.decimals.selector), abi.encode(8));
vm.mockCall(address(token), abi.encodeCall(token.decimals, ()), abi.encode(8));
vm.expectRevert("SystemConfig: bad decimals of gas paying token");
cleanStorageAndInit(address(token));
......@@ -432,7 +432,7 @@ contract SystemConfig_Init_CustomGasToken is SystemConfig_Init {
string memory name = new string(32);
name = string.concat(name, "a");
vm.mockCall(address(token), abi.encodeWithSelector(token.name.selector), abi.encode(name));
vm.mockCall(address(token), abi.encodeCall(token.name, ()), abi.encode(name));
vm.expectRevert("GasPayingToken: string cannot be greater than 32 bytes");
cleanStorageAndInit(address(token));
......@@ -443,7 +443,7 @@ contract SystemConfig_Init_CustomGasToken is SystemConfig_Init {
string memory symbol = new string(33);
symbol = string.concat(symbol, "a");
vm.mockCall(address(token), abi.encodeWithSelector(token.symbol.selector), abi.encode(symbol));
vm.mockCall(address(token), abi.encodeCall(token.symbol, ()), abi.encode(symbol));
vm.expectRevert("GasPayingToken: string cannot be greater than 32 bytes");
cleanStorageAndInit(address(token));
......
......@@ -41,9 +41,9 @@ contract SystemConfigInterop_Test is CommonTest {
vm.assume(bytes(_name).length <= 32);
vm.assume(bytes(_symbol).length <= 32);
vm.mockCall(_token, abi.encodeWithSelector(ERC20.decimals.selector), abi.encode(18));
vm.mockCall(_token, abi.encodeWithSelector(ERC20.name.selector), abi.encode(_name));
vm.mockCall(_token, abi.encodeWithSelector(ERC20.symbol.selector), abi.encode(_symbol));
vm.mockCall(_token, abi.encodeCall(ERC20.decimals, ()), abi.encode(18));
vm.mockCall(_token, abi.encodeCall(ERC20.name, ()), abi.encode(_name));
vm.mockCall(_token, abi.encodeCall(ERC20.symbol, ()), abi.encode(_symbol));
vm.expectCall(
address(optimismPortal),
......
......@@ -68,7 +68,7 @@ contract CrossDomainOwnableThroughPortal_Test is CommonTest {
_value: 0,
_gasLimit: 30_000,
_isCreation: false,
_data: abi.encodeWithSelector(XDomainSetter.set.selector, 1)
_data: abi.encodeCall(XDomainSetter.set, (1))
});
// Simulate the operation of the `op-node` by parsing data
......
......@@ -58,7 +58,7 @@ contract CrossDomainOwnable2_Test is Bridge_Initializer {
address target = address(setter);
uint256 value = 0;
uint256 minGasLimit = 0;
bytes memory message = abi.encodeWithSelector(XDomainSetter2.set.selector, 1);
bytes memory message = abi.encodeCall(XDomainSetter2.set, (1));
bytes32 hash = Hashing.hashCrossDomainMessage(
Encoding.encodeVersionedNonce(nonce, 1), sender, target, value, minGasLimit, message
......@@ -85,12 +85,7 @@ contract CrossDomainOwnable2_Test is Bridge_Initializer {
// the L1CrossDomainMessenger
vm.prank(AddressAliasHelper.applyL1ToL2Alias(address(l1CrossDomainMessenger)));
l2CrossDomainMessenger.relayMessage(
Encoding.encodeVersionedNonce(1, 1),
owner,
address(setter),
0,
0,
abi.encodeWithSelector(XDomainSetter2.set.selector, 2)
Encoding.encodeVersionedNonce(1, 1), owner, address(setter), 0, 0, abi.encodeCall(XDomainSetter2.set, (2))
);
assertEq(setter.value(), 2);
......
......@@ -101,7 +101,7 @@ contract CrossDomainOwnable3_Test is Bridge_Initializer {
address target = address(setter);
uint256 value = 0;
uint256 minGasLimit = 0;
bytes memory message = abi.encodeWithSelector(XDomainSetter3.set.selector, 1);
bytes memory message = abi.encodeCall(XDomainSetter3.set, (1));
bytes32 hash = Hashing.hashCrossDomainMessage(
Encoding.encodeVersionedNonce(nonce, 1), sender, target, value, minGasLimit, message
......@@ -216,12 +216,7 @@ contract CrossDomainOwnable3_Test is Bridge_Initializer {
// the L1CrossDomainMessenger
vm.prank(AddressAliasHelper.applyL1ToL2Alias(address(l1CrossDomainMessenger)));
l2CrossDomainMessenger.relayMessage(
Encoding.encodeVersionedNonce(1, 1),
bob,
address(setter),
0,
0,
abi.encodeWithSelector(XDomainSetter3.set.selector, 2)
Encoding.encodeVersionedNonce(1, 1), bob, address(setter), 0, 0, abi.encodeCall(XDomainSetter3.set, (2))
);
assertEq(setter.value(), 2);
......
......@@ -160,7 +160,7 @@ contract CrossL2InboxTest is Test {
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
......@@ -170,7 +170,7 @@ contract CrossL2InboxTest is Test {
// Ensure that the chain ID is in the dependency set
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(L1BlockIsInDependencySetSelector, _id.chainId),
data: abi.encodeCall(IL1BlockInterop.isInDependencySet, (_id.chainId)),
returnData: abi.encode(true)
});
......@@ -222,27 +222,27 @@ contract CrossL2InboxTest is Test {
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
// Ensure that id1's chain ID is in the dependency set
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(L1BlockIsInDependencySetSelector, _id1.chainId),
data: abi.encodeCall(IL1BlockInterop.isInDependencySet, (_id1.chainId)),
returnData: abi.encode(true)
});
// Ensure that id2's chain ID is in the dependency set
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(L1BlockIsInDependencySetSelector, _id2.chainId),
data: abi.encodeCall(IL1BlockInterop.isInDependencySet, (_id2.chainId)),
returnData: abi.encode(true)
});
// Set the target and message for the reentrant call
address target = address(this);
bytes memory message = abi.encodeWithSelector(this.mockReentrant.selector, _id2);
bytes memory message = abi.encodeCall(this.mockReentrant, (_id2));
// Ensure that the contract has enough balance to send with value
vm.deal(address(this), _value);
......@@ -282,7 +282,7 @@ contract CrossL2InboxTest is Test {
// Ensure it is a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(true)
});
......@@ -312,7 +312,7 @@ contract CrossL2InboxTest is Test {
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
......@@ -346,7 +346,7 @@ contract CrossL2InboxTest is Test {
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
......@@ -375,14 +375,14 @@ contract CrossL2InboxTest is Test {
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
// Ensure that the chain ID is NOT in the dependency set
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(L1BlockIsInDependencySetSelector, _id.chainId),
data: abi.encodeCall(IL1BlockInterop.isInDependencySet, (_id.chainId)),
returnData: abi.encode(false)
});
......@@ -419,14 +419,14 @@ contract CrossL2InboxTest is Test {
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
// Ensure that the chain ID is in the dependency set
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(L1BlockIsInDependencySetSelector, _id.chainId),
data: abi.encodeCall(IL1BlockInterop.isInDependencySet, (_id.chainId)),
returnData: abi.encode(true)
});
......@@ -451,14 +451,14 @@ contract CrossL2InboxTest is Test {
// Ensure that the chain ID is in the dependency set
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(L1BlockIsInDependencySetSelector, _id.chainId),
data: abi.encodeCall(IL1BlockInterop.isInDependencySet, (_id.chainId)),
returnData: abi.encode(true)
});
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
......@@ -474,7 +474,7 @@ contract CrossL2InboxTest is Test {
// Ensure it is a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(true)
});
......@@ -497,7 +497,7 @@ contract CrossL2InboxTest is Test {
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
......@@ -526,7 +526,7 @@ contract CrossL2InboxTest is Test {
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
......@@ -553,14 +553,14 @@ contract CrossL2InboxTest is Test {
// Ensure that the chain ID is NOT in the dependency set.
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(L1BlockIsInDependencySetSelector, _id.chainId),
data: abi.encodeCall(IL1BlockInterop.isInDependencySet, (_id.chainId)),
returnData: abi.encode(false)
});
// Ensure is not a deposit transaction
vm.mockCall({
callee: Predeploys.L1_BLOCK_ATTRIBUTES,
data: abi.encodeWithSelector(IL1BlockInterop.isDeposit.selector),
data: abi.encodeCall(IL1BlockInterop.isDeposit, ()),
returnData: abi.encode(false)
});
......
......@@ -93,6 +93,7 @@ contract GasPriceOracleBedrock_Test is GasPriceOracle_Test {
/// @dev Tests that `setGasPrice` reverts since it was removed in bedrock.
function test_setGasPrice_doesNotExist_reverts() external {
// nosemgrep: sol-style-use-abi-encodecall
(bool success, bytes memory returndata) =
address(gasPriceOracle).call(abi.encodeWithSignature("setGasPrice(uint256)", 1));
......@@ -102,6 +103,7 @@ contract GasPriceOracleBedrock_Test is GasPriceOracle_Test {
/// @dev Tests that `setL1BaseFee` reverts since it was removed in bedrock.
function test_setL1BaseFee_doesNotExist_reverts() external {
// nosemgrep: sol-style-use-abi-encodecall
(bool success, bytes memory returndata) =
address(gasPriceOracle).call(abi.encodeWithSignature("setL1BaseFee(uint256)", 1));
......
......@@ -48,11 +48,9 @@ contract L2CrossDomainMessenger_Test is Bridge_Initializer {
Encoding.encodeCrossDomainMessage(l2CrossDomainMessenger.messageNonce(), alice, recipient, 0, 100, hex"ff");
vm.expectCall(
address(l2ToL1MessagePasser),
abi.encodeWithSelector(
IL2ToL1MessagePasser.initiateWithdrawal.selector,
address(l1CrossDomainMessenger),
l2CrossDomainMessenger.baseGas(hex"ff", 100),
xDomainCallData
abi.encodeCall(
IL2ToL1MessagePasser.initiateWithdrawal,
(address(l1CrossDomainMessenger), l2CrossDomainMessenger.baseGas(hex"ff", 100), xDomainCallData)
)
);
......@@ -230,17 +228,15 @@ contract L2CrossDomainMessenger_Test is Bridge_Initializer {
/// @dev Tests that sendMessage succeeds with a custom gas token when the call value is zero.
function test_sendMessage_customGasToken_noValue_succeeds() external {
// Mock the gasPayingToken function to return a custom gas token
vm.mockCall(address(l1Block), abi.encodeWithSignature("gasPayingToken()"), abi.encode(address(1), uint8(2)));
vm.mockCall(address(l1Block), abi.encodeCall(systemConfig.gasPayingToken, ()), abi.encode(address(1), uint8(2)));
bytes memory xDomainCallData =
Encoding.encodeCrossDomainMessage(l2CrossDomainMessenger.messageNonce(), alice, recipient, 0, 100, hex"ff");
vm.expectCall(
address(l2ToL1MessagePasser),
abi.encodeWithSelector(
IL2ToL1MessagePasser.initiateWithdrawal.selector,
address(l1CrossDomainMessenger),
l2CrossDomainMessenger.baseGas(hex"ff", 100),
xDomainCallData
abi.encodeCall(
IL2ToL1MessagePasser.initiateWithdrawal,
(address(l1CrossDomainMessenger), l2CrossDomainMessenger.baseGas(hex"ff", 100), xDomainCallData)
)
);
......@@ -272,7 +268,7 @@ contract L2CrossDomainMessenger_Test is Bridge_Initializer {
/// @dev Tests that the sendMessage reverts when call value is non-zero with custom gas token.
function test_sendMessage_customGasToken_withValue_reverts() external {
// Mock the gasPayingToken function to return a custom gas token
vm.mockCall(address(l1Block), abi.encodeWithSignature("gasPayingToken()"), abi.encode(address(1), uint8(2)));
vm.mockCall(address(l1Block), abi.encodeCall(systemConfig.gasPayingToken, ()), abi.encode(address(1), uint8(2)));
vm.expectRevert("CrossDomainMessenger: cannot send value with custom gas token");
l2CrossDomainMessenger.sendMessage{ value: 1 }(recipient, hex"ff", uint32(100));
......@@ -281,7 +277,7 @@ contract L2CrossDomainMessenger_Test is Bridge_Initializer {
/// @dev Tests that the relayMessage succeeds with a custom gas token when the call value is zero.
function test_relayMessage_customGasToken_noValue_succeeds() external {
// Mock the gasPayingToken function to return a custom gas token
vm.mockCall(address(l1Block), abi.encodeWithSignature("gasPayingToken()"), abi.encode(address(1), uint8(2)));
vm.mockCall(address(l1Block), abi.encodeCall(systemConfig.gasPayingToken, ()), abi.encode(address(1), uint8(2)));
address target = address(0xabcd);
address sender = address(l1CrossDomainMessenger);
......@@ -317,7 +313,7 @@ contract L2CrossDomainMessenger_Test is Bridge_Initializer {
/// The L1CrossDomainMessenger `sendMessage` function cannot send value with a custom gas token.
function test_relayMessage_customGasToken_withValue_reverts() external virtual {
// Mock the gasPayingToken function to return a custom gas token
vm.mockCall(address(l1Block), abi.encodeWithSignature("gasPayingToken()"), abi.encode(address(1), uint8(2)));
vm.mockCall(address(l1Block), abi.encodeCall(systemConfig.gasPayingToken, ()), abi.encode(address(1), uint8(2)));
vm.expectRevert("CrossDomainMessenger: value must be zero unless message is from a system address");
l2CrossDomainMessenger.relayMessage{ value: 1 }(
......
......@@ -240,7 +240,7 @@ contract L2ERC721Bridge_Test is Bridge_Initializer {
// Finalize a withdrawal.
vm.mockCall(
address(l2CrossDomainMessenger),
abi.encodeWithSelector(l2CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(l2CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(l1ERC721Bridge)
);
vm.prank(address(l2CrossDomainMessenger));
......@@ -264,7 +264,7 @@ contract L2ERC721Bridge_Test is Bridge_Initializer {
// to be compliant with the `IOptimismMintableERC721` interface.
vm.mockCall(
address(l2CrossDomainMessenger),
abi.encodeWithSelector(l2CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(l2CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(l1ERC721Bridge)
);
vm.prank(address(l2CrossDomainMessenger));
......@@ -287,7 +287,7 @@ contract L2ERC721Bridge_Test is Bridge_Initializer {
// Finalize a withdrawal.
vm.mockCall(
address(l2CrossDomainMessenger),
abi.encodeWithSelector(l2CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(l2CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(alice)
);
vm.prank(address(l2CrossDomainMessenger));
......@@ -301,7 +301,7 @@ contract L2ERC721Bridge_Test is Bridge_Initializer {
// Finalize a withdrawal.
vm.mockCall(
address(l2CrossDomainMessenger),
abi.encodeWithSelector(l2CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(l2CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(address(l1ERC721Bridge))
);
vm.prank(address(l2CrossDomainMessenger));
......@@ -316,7 +316,7 @@ contract L2ERC721Bridge_Test is Bridge_Initializer {
// Finalize a withdrawal.
vm.mockCall(
address(l2CrossDomainMessenger),
abi.encodeWithSelector(l2CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(l2CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(address(l1ERC721Bridge))
);
vm.prank(address(l2CrossDomainMessenger));
......
......@@ -139,9 +139,7 @@ contract L2GenesisTest is Test {
/// @notice Tests the genesis predeploys setup.
function _test_genesis_predeploys(string memory _path, bool _useInterop) internal {
// Set the useInterop value
vm.mockCall(
address(genesis.cfg()), abi.encodeWithSelector(genesis.cfg().useInterop.selector), abi.encode(_useInterop)
);
vm.mockCall(address(genesis.cfg()), abi.encodeCall(genesis.cfg().useInterop, ()), abi.encode(_useInterop));
// Set the predeploy proxies into state
genesis.setPredeployProxies();
......
......@@ -31,21 +31,17 @@ contract L2StandardBridgeInterop_Test is Bridge_Initializer {
/// @notice Mock ERC20 decimals
function _mockDecimals(address _token, uint8 _decimals) internal {
_mockAndExpect(_token, abi.encodeWithSelector(IERC20Metadata.decimals.selector), abi.encode(_decimals));
_mockAndExpect(_token, abi.encodeCall(IERC20Metadata.decimals, ()), abi.encode(_decimals));
}
/// @notice Mock ERC165 interface
function _mockInterface(address _token, bytes4 _interfaceId, bool _supported) internal {
_mockAndExpect(
_token, abi.encodeWithSelector(IERC165.supportsInterface.selector, _interfaceId), abi.encode(_supported)
);
_mockAndExpect(_token, abi.encodeCall(IERC165.supportsInterface, (_interfaceId)), abi.encode(_supported));
}
/// @notice Mock factory deployment
function _mockDeployments(address _factory, address _token, address _deployed) internal {
_mockAndExpect(
_factory, abi.encodeWithSelector(IOptimismERC20Factory.deployments.selector, _token), abi.encode(_deployed)
);
_mockAndExpect(_factory, abi.encodeCall(IOptimismERC20Factory.deployments, (_token)), abi.encode(_deployed));
}
/// @notice Assume a valid address for fuzzing
......@@ -198,12 +194,8 @@ contract L2StandardBridgeInterop_LegacyToSuper_Test is L2StandardBridgeInterop_T
emit Converted(_from, _to, _caller, _amount);
// Mock and expect the `burn` and `mint` functions
_mockAndExpect(
_from, abi.encodeWithSelector(IMintableAndBurnableERC20.burn.selector, _caller, _amount), abi.encode()
);
_mockAndExpect(
_to, abi.encodeWithSelector(IMintableAndBurnableERC20.mint.selector, _caller, _amount), abi.encode()
);
_mockAndExpect(_from, abi.encodeCall(IMintableAndBurnableERC20.burn, (_caller, _amount)), abi.encode());
_mockAndExpect(_to, abi.encodeCall(IMintableAndBurnableERC20.mint, (_caller, _amount)), abi.encode());
// Act
vm.prank(_caller);
......@@ -356,12 +348,8 @@ contract L2StandardBridgeInterop_SuperToLegacy_Test is L2StandardBridgeInterop_T
emit Converted(_from, _to, _caller, _amount);
// Mock and expect the `burn` and `mint` functions
_mockAndExpect(
_from, abi.encodeWithSelector(IMintableAndBurnableERC20.burn.selector, _caller, _amount), abi.encode()
);
_mockAndExpect(
_to, abi.encodeWithSelector(IMintableAndBurnableERC20.mint.selector, _caller, _amount), abi.encode()
);
_mockAndExpect(_from, abi.encodeCall(IMintableAndBurnableERC20.burn, (_caller, _amount)), abi.encode());
_mockAndExpect(_to, abi.encodeCall(IMintableAndBurnableERC20.mint, (_caller, _amount)), abi.encode());
// Act
vm.prank(_caller);
......
......@@ -227,7 +227,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure the CrossL2Inbox validates this message
vm.mockCall({
callee: Predeploys.CROSS_L2_INBOX,
data: abi.encodeWithSelector(CrossL2Inbox.validateMessage.selector, id, sentMessage),
data: abi.encodeCall(CrossL2Inbox.validateMessage, (id, keccak256(sentMessage))),
returnData: ""
});
......@@ -271,7 +271,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure the CrossL2Inbox validates this message
vm.mockCall({
callee: Predeploys.CROSS_L2_INBOX,
data: abi.encodeWithSelector(CrossL2Inbox.validateMessage.selector, id, sentMessage),
data: abi.encodeCall(CrossL2Inbox.validateMessage, (id, keccak256(sentMessage))),
returnData: ""
});
......@@ -312,7 +312,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Set the target and message for the reentrant call
address target = address(this);
bytes memory message = abi.encodeWithSelector(this.mockTarget.selector, _source, _sender);
bytes memory message = abi.encodeCall(this.mockTarget, (_source, _sender));
bytes32 msgHash = keccak256(abi.encode(block.chainid, _source, _nonce, _sender, target, message));
......@@ -334,7 +334,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure the CrossL2Inbox validates this message
vm.mockCall({
callee: Predeploys.CROSS_L2_INBOX,
data: abi.encodeWithSelector(CrossL2Inbox.validateMessage.selector, id, sentMessage),
data: abi.encodeCall(CrossL2Inbox.validateMessage, (id, keccak256(sentMessage))),
returnData: ""
});
......@@ -399,7 +399,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Set the target and message for the reentrant call
address target = address(this);
bytes memory message = abi.encodeWithSelector(this.mockTargetReentrant.selector, _source2, _nonce, _sender2);
bytes memory message = abi.encodeCall(this.mockTargetReentrant, (_source2, _nonce, _sender2));
// Ensure the target contract is called with the correct parameters
vm.expectCall({ callee: target, msgValue: _value, data: message });
......@@ -415,7 +415,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure the CrossL2Inbox validates this message
vm.mockCall({
callee: Predeploys.CROSS_L2_INBOX,
data: abi.encodeWithSelector(CrossL2Inbox.validateMessage.selector, id, sentMessage),
data: abi.encodeCall(CrossL2Inbox.validateMessage, (id, keccak256(sentMessage))),
returnData: ""
});
......@@ -497,7 +497,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure the CrossL2Inbox validates this message
vm.mockCall({
callee: Predeploys.CROSS_L2_INBOX,
data: abi.encodeWithSelector(CrossL2Inbox.validateMessage.selector, id, sentMessage),
data: abi.encodeCall(CrossL2Inbox.validateMessage, (id, keccak256(sentMessage))),
returnData: ""
});
......@@ -536,7 +536,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure the CrossL2Inbox validates this message
vm.mockCall({
callee: Predeploys.CROSS_L2_INBOX,
data: abi.encodeWithSelector(CrossL2Inbox.validateMessage.selector, id, sentMessage),
data: abi.encodeCall(CrossL2Inbox.validateMessage, (id, keccak256(sentMessage))),
returnData: ""
});
......@@ -578,7 +578,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure the CrossL2Inbox validates this message
vm.mockCall({
callee: Predeploys.CROSS_L2_INBOX,
data: abi.encodeWithSelector(CrossL2Inbox.validateMessage.selector, id, sentMessage),
data: abi.encodeCall(CrossL2Inbox.validateMessage, (id, keccak256(sentMessage))),
returnData: ""
});
......@@ -628,7 +628,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure the CrossL2Inbox validates this message
vm.mockCall({
callee: Predeploys.CROSS_L2_INBOX,
data: abi.encodeWithSelector(CrossL2Inbox.validateMessage.selector, id, sentMessage),
data: abi.encodeCall(CrossL2Inbox.validateMessage, (id, keccak256(sentMessage))),
returnData: ""
});
......@@ -678,7 +678,7 @@ contract L2ToL2CrossDomainMessengerTest is Test {
// Ensure the CrossL2Inbox validates this message
vm.mockCall({
callee: Predeploys.CROSS_L2_INBOX,
data: abi.encodeWithSelector(CrossL2Inbox.validateMessage.selector, id, sentMessage),
data: abi.encodeCall(CrossL2Inbox.validateMessage, (id, keccak256(sentMessage))),
returnData: ""
});
......
......@@ -63,11 +63,7 @@ contract OptimismSuperchainERC20Test is Test {
EIP1967Helper.setImplementation(_addr, _impl);
// Mock implementation address
vm.mockCall(
_impl,
abi.encodeWithSelector(IBeacon.implementation.selector),
abi.encode(address(optimismSuperchainERC20Impl))
);
vm.mockCall(_impl, abi.encodeCall(IBeacon.implementation, ()), abi.encode(address(optimismSuperchainERC20Impl)));
}
/// @notice Helper function to deploy a proxy of the OptimismSuperchainERC20 contract.
......
......@@ -96,8 +96,8 @@ contract SuperchainTokenBridgeTest is Bridge_Initializer {
abi.encodeCall(superchainTokenBridge.relayERC20, (address(superchainERC20), _sender, _to, _amount));
_mockAndExpect(
Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER,
abi.encodeWithSelector(
IL2ToL2CrossDomainMessenger.sendMessage.selector, _chainId, address(superchainTokenBridge), _message
abi.encodeCall(
IL2ToL2CrossDomainMessenger.sendMessage, (_chainId, address(superchainTokenBridge), _message)
),
abi.encode(_msgHash)
);
......@@ -150,7 +150,7 @@ contract SuperchainTokenBridgeTest is Bridge_Initializer {
// Mock the call over the `crossDomainMessageContext` function setting a wrong sender
vm.mockCall(
Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER,
abi.encodeWithSelector(IL2ToL2CrossDomainMessenger.crossDomainMessageContext.selector),
abi.encodeCall(IL2ToL2CrossDomainMessenger.crossDomainMessageContext, ()),
abi.encode(_crossDomainMessageSender, _source)
);
......@@ -169,7 +169,7 @@ contract SuperchainTokenBridgeTest is Bridge_Initializer {
// Mock the call over the `crossDomainMessageContext` function setting the same address as value
_mockAndExpect(
Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER,
abi.encodeWithSelector(IL2ToL2CrossDomainMessenger.crossDomainMessageContext.selector),
abi.encodeCall(IL2ToL2CrossDomainMessenger.crossDomainMessageContext, ()),
abi.encode(address(superchainTokenBridge), _source)
);
......
......@@ -322,7 +322,8 @@ contract SuperchainWETH_Test is CommonTest {
/// @notice Test that the internal mint function reverts to protect against accidentally changing the visibility.
function testFuzz_calling_internal_mint_function_reverts(address _caller, address _to, uint256 _amount) public {
// Arrange
bytes memory _calldata = abi.encodeWithSignature("_mint(address,uint256)", _to, _amount);
bytes memory _calldata = abi.encodeWithSignature("_mint(address,uint256)", _to, _amount); // nosemgrep:
// sol-style-use-abi-encodecall
vm.expectRevert(bytes(""));
// Act
......@@ -336,7 +337,8 @@ contract SuperchainWETH_Test is CommonTest {
/// @notice Test that the mint function reverts to protect against accidentally changing the visibility.
function testFuzz_calling_mint_function_reverts(address _caller, address _to, uint256 _amount) public {
// Arrange
bytes memory _calldata = abi.encodeWithSignature("mint(address,uint256)", _to, _amount);
bytes memory _calldata = abi.encodeWithSignature("mint(address,uint256)", _to, _amount); // nosemgrep:
// sol-style-use-abi-encodecall
vm.expectRevert(bytes(""));
// Act
......@@ -350,7 +352,8 @@ contract SuperchainWETH_Test is CommonTest {
/// @notice Test that the internal burn function reverts to protect against accidentally changing the visibility.
function testFuzz_calling_internal_burn_function_reverts(address _caller, address _from, uint256 _amount) public {
// Arrange
bytes memory _calldata = abi.encodeWithSignature("_burn(address,uint256)", _from, _amount);
bytes memory _calldata = abi.encodeWithSignature("_burn(address,uint256)", _from, _amount); // nosemgrep:
// sol-style-use-abi-encodecall
vm.expectRevert(bytes(""));
// Act
......@@ -364,7 +367,8 @@ contract SuperchainWETH_Test is CommonTest {
/// @notice Test that the burn function reverts to protect against accidentally changing the visibility.
function testFuzz_calling_burn_function_reverts(address _caller, address _from, uint256 _amount) public {
// Arrange
bytes memory _calldata = abi.encodeWithSignature("burn(address,uint256)", _from, _amount);
bytes memory _calldata = abi.encodeWithSignature("burn(address,uint256)", _from, _amount); // nosemgrep:
// sol-style-use-abi-encodecall
vm.expectRevert(bytes(""));
// Act
......
......@@ -10,7 +10,7 @@ import { WETH } from "src/L2/WETH.sol";
contract WETH_Test is CommonTest {
/// @dev Tests that the name function returns the correct value.
function testFuzz_name_succeeds(string memory _gasPayingTokenName) external {
vm.mockCall(address(l1Block), abi.encodeWithSignature("gasPayingTokenName()"), abi.encode(_gasPayingTokenName));
vm.mockCall(address(l1Block), abi.encodeCall(l1Block.gasPayingTokenName, ()), abi.encode(_gasPayingTokenName));
assertEq(string.concat("Wrapped ", _gasPayingTokenName), weth.name());
}
......@@ -18,7 +18,7 @@ contract WETH_Test is CommonTest {
/// @dev Tests that the symbol function returns the correct value.
function testFuzz_symbol_succeeds(string memory _gasPayingTokenSymbol) external {
vm.mockCall(
address(l1Block), abi.encodeWithSignature("gasPayingTokenSymbol()"), abi.encode(_gasPayingTokenSymbol)
address(l1Block), abi.encodeCall(l1Block.gasPayingTokenSymbol, ()), abi.encode(_gasPayingTokenSymbol)
);
assertEq(string.concat("W", _gasPayingTokenSymbol), weth.symbol());
......
......@@ -49,9 +49,7 @@ contract AnchorStateRegistry_TryUpdateAnchorState_Test is AnchorStateRegistry_In
assert(l2BlockNumber < gameProxy.l2BlockNumber());
// Mock the state that we want.
vm.mockCall(
address(gameProxy), abi.encodeWithSelector(gameProxy.status.selector), abi.encode(GameStatus.DEFENDER_WINS)
);
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.status, ()), abi.encode(GameStatus.DEFENDER_WINS));
// Try to update the anchor state.
vm.prank(address(gameProxy));
......@@ -66,15 +64,13 @@ contract AnchorStateRegistry_TryUpdateAnchorState_Test is AnchorStateRegistry_In
/// @dev Tests that updating the anchor state fails when the game state is valid but older.
function test_tryUpdateAnchorState_validOlderState_fails() public {
// Confirm that the anchor state is newer than the game state.
vm.mockCall(address(gameProxy), abi.encodeWithSelector(gameProxy.l2BlockNumber.selector), abi.encode(0));
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.l2BlockNumber, ()), abi.encode(0));
(Hash root, uint256 l2BlockNumber) = anchorStateRegistry.anchors(gameProxy.gameType());
assert(l2BlockNumber >= gameProxy.l2BlockNumber());
// Mock the state that we want.
vm.mockCall(address(gameProxy), abi.encodeWithSelector(gameProxy.l2BlockNumber.selector), abi.encode(0));
vm.mockCall(
address(gameProxy), abi.encodeWithSelector(gameProxy.status.selector), abi.encode(GameStatus.DEFENDER_WINS)
);
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.l2BlockNumber, ()), abi.encode(0));
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.status, ()), abi.encode(GameStatus.DEFENDER_WINS));
// Try to update the anchor state.
vm.prank(address(gameProxy));
......@@ -93,11 +89,7 @@ contract AnchorStateRegistry_TryUpdateAnchorState_Test is AnchorStateRegistry_In
assert(l2BlockNumber < gameProxy.l2BlockNumber());
// Mock the state that we want.
vm.mockCall(
address(gameProxy),
abi.encodeWithSelector(gameProxy.status.selector),
abi.encode(GameStatus.CHALLENGER_WINS)
);
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.status, ()), abi.encode(GameStatus.CHALLENGER_WINS));
// Try to update the anchor state.
vm.prank(address(gameProxy));
......@@ -118,8 +110,8 @@ contract AnchorStateRegistry_TryUpdateAnchorState_Test is AnchorStateRegistry_In
// Mock the state that we want.
vm.mockCall(
address(disputeGameFactory),
abi.encodeWithSelector(
disputeGameFactory.games.selector, gameProxy.gameType(), gameProxy.rootClaim(), gameProxy.extraData()
abi.encodeCall(
disputeGameFactory.games, (gameProxy.gameType(), gameProxy.rootClaim(), gameProxy.extraData())
),
abi.encode(address(0), 0)
);
......@@ -146,8 +138,8 @@ contract AnchorStateRegistry_TryUpdateAnchorState_Test is AnchorStateRegistry_In
// Mock the state that we want.
vm.mockCall(
address(disputeGameFactory),
abi.encodeWithSelector(
disputeGameFactory.games.selector, gameProxy.gameType(), gameProxy.rootClaim(), gameProxy.extraData()
abi.encodeCall(
disputeGameFactory.games, (gameProxy.gameType(), gameProxy.rootClaim(), gameProxy.extraData())
),
abi.encode(address(0), 0)
);
......@@ -168,11 +160,7 @@ contract AnchorStateRegistry_TryUpdateAnchorState_Test is AnchorStateRegistry_In
(Hash root, uint256 l2BlockNumber) = anchorStateRegistry.anchors(gameProxy.gameType());
// Mock the state that we want.
vm.mockCall(
address(gameProxy),
abi.encodeWithSelector(gameProxy.status.selector),
abi.encode(GameStatus.CHALLENGER_WINS)
);
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.status, ()), abi.encode(GameStatus.CHALLENGER_WINS));
// Set the anchor state.
vm.prank(superchainConfig.guardian());
......@@ -190,9 +178,7 @@ contract AnchorStateRegistry_TryUpdateAnchorState_Test is AnchorStateRegistry_In
(Hash root, uint256 l2BlockNumber) = anchorStateRegistry.anchors(gameProxy.gameType());
// Mock the state that we want.
vm.mockCall(
address(gameProxy), abi.encodeWithSelector(gameProxy.status.selector), abi.encode(GameStatus.IN_PROGRESS)
);
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.status, ()), abi.encode(GameStatus.IN_PROGRESS));
// Set the anchor state.
vm.prank(superchainConfig.guardian());
......@@ -208,9 +194,7 @@ contract AnchorStateRegistry_TryUpdateAnchorState_Test is AnchorStateRegistry_In
/// @dev Tests that setting the anchor state succeeds.
function test_setAnchorState_succeeds() public {
// Mock the state that we want.
vm.mockCall(
address(gameProxy), abi.encodeWithSelector(gameProxy.status.selector), abi.encode(GameStatus.DEFENDER_WINS)
);
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.status, ()), abi.encode(GameStatus.DEFENDER_WINS));
// Set the anchor state.
vm.prank(superchainConfig.guardian());
......
......@@ -6,6 +6,7 @@ import { Test } from "forge-std/Test.sol";
import { Vm } from "forge-std/Vm.sol";
import { DisputeGameFactory_Init } from "test/dispute/DisputeGameFactory.t.sol";
import { AlphabetVM } from "test/mocks/AlphabetVM.sol";
import { stdError } from "forge-std/StdError.sol";
// Scripts
import { DeployUtils } from "scripts/libraries/DeployUtils.sol";
......@@ -186,9 +187,7 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
// PreimageOracle constructor will revert if the challenge period is too large, so we need
// to mock the call to pretend this is a bugged implementation where the challenge period
// is allowed to be too large.
vm.mockCall(
address(oracle), abi.encodeWithSelector(oracle.challengePeriod.selector), abi.encode(_challengePeriod)
);
vm.mockCall(address(oracle), abi.encodeCall(IPreimageOracle.challengePeriod, ()), abi.encode(_challengePeriod));
vm.expectRevert(InvalidChallengePeriod.selector);
DeployUtils.create1({
......@@ -536,11 +535,11 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
Claim claim = _dummyClaim();
// Expect an out of bounds revert for an attack
vm.expectRevert(abi.encodeWithSignature("Panic(uint256)", 0x32));
vm.expectRevert(stdError.indexOOBError);
gameProxy.attack(_dummyClaim(), 1, claim);
// Expect an out of bounds revert for a defense
vm.expectRevert(abi.encodeWithSignature("Panic(uint256)", 0x32));
vm.expectRevert(stdError.indexOOBError);
gameProxy.defend(_dummyClaim(), 1, claim);
}
......@@ -1704,14 +1703,14 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
/// resolves in favor of the defender but the game state is not newer than the anchor state.
function test_resolve_validOlderStateSameAnchor_succeeds() public {
// Mock the game block to be older than the game state.
vm.mockCall(address(gameProxy), abi.encodeWithSelector(gameProxy.l2BlockNumber.selector), abi.encode(0));
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.l2BlockNumber, ()), abi.encode(0));
// Confirm that the anchor state is newer than the game state.
(Hash root, uint256 l2BlockNumber) = anchorStateRegistry.anchors(gameProxy.gameType());
assert(l2BlockNumber >= gameProxy.l2BlockNumber());
// Resolve the game.
vm.mockCall(address(gameProxy), abi.encodeWithSelector(gameProxy.l2BlockNumber.selector), abi.encode(0));
vm.mockCall(address(gameProxy), abi.encodeCall(gameProxy.l2BlockNumber, ()), abi.encode(0));
vm.warp(block.timestamp + 3 days + 12 hours);
gameProxy.resolveClaim(0, 0);
assertEq(uint8(gameProxy.resolve()), uint8(GameStatus.DEFENDER_WINS));
......
......@@ -103,10 +103,7 @@ contract SafeCaller_Actor is StdUtils {
vm.expectCallMinGas(to, value, minGas, hex"");
bool success = SafeCall.call(
msg.sender,
gas,
value,
abi.encodeWithSelector(SafeCall_Succeeds_Invariants.performSafeCallMinGas.selector, to, minGas)
msg.sender, gas, value, abi.encodeCall(SafeCall_Succeeds_Invariants.performSafeCallMinGas, (to, minGas))
);
if (success && FAILS) numCalls++;
......
......@@ -34,7 +34,7 @@ contract L1ERC721BridgeKontrol is DeploymentSummaryFaultProofs, KontrolUtils {
vm.mockCall(
address(l1ERC721Bridge.messenger()),
abi.encodeWithSelector(CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(address(l1ERC721Bridge.otherBridge()))
);
......
......@@ -34,7 +34,7 @@ contract L1StandardBridgeKontrol is DeploymentSummaryFaultProofs, KontrolUtils {
vm.mockCall(
address(l1standardBridge.messenger()),
abi.encodeWithSelector(CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(address(l1standardBridge.otherBridge()))
);
......@@ -59,7 +59,7 @@ contract L1StandardBridgeKontrol is DeploymentSummaryFaultProofs, KontrolUtils {
vm.mockCall(
address(l1standardBridge.messenger()),
abi.encodeWithSelector(CrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(CrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(address(l1standardBridge.otherBridge()))
);
......
......@@ -43,14 +43,14 @@ contract ResolvedDelegateProxy_Test is Test {
/// @dev Tests that the proxy properly bubbles up returndata when the delegatecall succeeds.
function testFuzz_fallback_delegateCallFoo_succeeds(uint256 x) public {
vm.expectCall(address(impl), abi.encodeWithSelector(impl.foo.selector, x));
vm.expectCall(address(impl), abi.encodeCall(impl.foo, (x)));
assertEq(proxy.foo(x), x);
}
/// @dev Tests that the proxy properly bubbles up returndata when the delegatecall reverts.
function test_fallback_delegateCallBar_reverts() public {
vm.expectRevert("SimpleImplementation: revert");
vm.expectCall(address(impl), abi.encodeWithSelector(impl.bar.selector));
vm.expectCall(address(impl), abi.encodeCall(impl.bar, ()));
proxy.bar();
}
......
......@@ -122,12 +122,12 @@ contract SafeCall_Test is Test {
for (uint64 i = 40_000; i < 100_000; i++) {
uint256 snapshot = vm.snapshot();
// 65_907 is the exact amount of gas required to make the safe call
// 65_922 is the exact amount of gas required to make the safe call
// successfully.
if (i < 65_907) {
if (i < 65_922) {
assertFalse(caller.makeSafeCall(i, 25_000));
} else {
vm.expectCallMinGas(address(caller), 0, 25_000, abi.encodeWithSelector(caller.setA.selector, 1));
vm.expectCallMinGas(address(caller), 0, 25_000, abi.encodeCall(caller.setA, (1)));
assertTrue(caller.makeSafeCall(i, 25_000));
}
......@@ -142,12 +142,12 @@ contract SafeCall_Test is Test {
for (uint64 i = 15_200_000; i < 15_300_000; i++) {
uint256 snapshot = vm.snapshot();
// 15_278_606 is the exact amount of gas required to make the safe call
// 15_278_621 is the exact amount of gas required to make the safe call
// successfully.
if (i < 15_278_606) {
if (i < 15_278_621) {
assertFalse(caller.makeSafeCall(i, 15_000_000));
} else {
vm.expectCallMinGas(address(caller), 0, 15_000_000, abi.encodeWithSelector(caller.setA.selector, 1));
vm.expectCallMinGas(address(caller), 0, 15_000_000, abi.encodeCall(caller.setA, (1)));
assertTrue(caller.makeSafeCall(i, 15_000_000));
}
......@@ -160,11 +160,11 @@ contract SimpleSafeCaller {
uint256 public a;
function makeSafeCall(uint64 gas, uint64 minGas) external returns (bool) {
return SafeCall.call(address(this), gas, 0, abi.encodeWithSelector(this.makeSafeCallMinGas.selector, minGas));
return SafeCall.call(address(this), gas, 0, abi.encodeCall(this.makeSafeCallMinGas, (minGas)));
}
function makeSafeCallMinGas(uint64 minGas) external returns (bool) {
return SafeCall.callWithMinGas(address(this), minGas, 0, abi.encodeWithSelector(this.setA.selector, 1));
return SafeCall.callWithMinGas(address(this), minGas, 0, abi.encodeCall(this.setA, (1)));
}
function setA(uint256 _a) external {
......
......@@ -41,7 +41,7 @@ contract TransactorTest is Transactor_Initializer {
/// @notice Tests CALL, should do a call to target
function test_call_succeeds() external {
// Initialize call data
bytes memory data = abi.encodeWithSelector(callRecorded.record.selector);
bytes memory data = abi.encodeCall(CallRecorder.record, ());
// Run CALL
vm.prank(alice);
vm.expectCall(address(callRecorded), 200_000 wei, data);
......@@ -51,7 +51,7 @@ contract TransactorTest is Transactor_Initializer {
/// @notice It should revert if called by non-owner
function test_call_unauthorized_reverts() external {
// Initialize call data
bytes memory data = abi.encodeWithSelector(callRecorded.record.selector);
bytes memory data = abi.encodeCall(CallRecorder.record, ());
// Run CALL
vm.prank(bob);
vm.expectRevert("UNAUTHORIZED");
......@@ -61,7 +61,7 @@ contract TransactorTest is Transactor_Initializer {
/// @notice Deletate call succeeds.
function test_delegateCall_succeeds() external {
// Initialize call data
bytes memory data = abi.encodeWithSelector(reverter.doRevert.selector);
bytes memory data = abi.encodeCall(Reverter.doRevert, ());
// Run CALL
vm.prank(alice);
vm.expectCall(address(reverter), data);
......@@ -71,7 +71,7 @@ contract TransactorTest is Transactor_Initializer {
/// @notice It should revert if called by non-owner
function test_delegateCall_unauthorized_reverts() external {
// Initialize call data
bytes memory data = abi.encodeWithSelector(reverter.doRevert.selector);
bytes memory data = abi.encodeCall(Reverter.doRevert, ());
// Run CALL
vm.prank(bob);
vm.expectRevert("UNAUTHORIZED");
......
......@@ -353,7 +353,7 @@ contract Drippie_Test is Test {
// Add in an action
cfg.actions[0] = Drippie.DripAction({
target: payable(address(simpleStorage)),
data: abi.encodeWithSelector(SimpleStorage.set.selector, key, value),
data: abi.encodeCall(SimpleStorage.set, (key, value)),
value: 0
});
......@@ -365,7 +365,7 @@ contract Drippie_Test is Test {
vm.prank(drippie.owner());
drippie.status(dripName, Drippie.DripStatus.ACTIVE);
vm.expectCall(address(simpleStorage), 0, abi.encodeWithSelector(SimpleStorage.set.selector, key, value));
vm.expectCall(address(simpleStorage), 0, abi.encodeCall(SimpleStorage.set, (key, value)));
vm.expectEmit(address(drippie));
emit DripExecuted(dripName, dripName, address(this), block.timestamp);
......@@ -383,7 +383,7 @@ contract Drippie_Test is Test {
bytes32 valueOne = bytes32(uint256(3));
actions[0] = Drippie.DripAction({
target: payable(address(simpleStorage)),
data: abi.encodeWithSelector(simpleStorage.set.selector, keyOne, valueOne),
data: abi.encodeCall(SimpleStorage.set, (keyOne, valueOne)),
value: 0
});
......@@ -391,7 +391,7 @@ contract Drippie_Test is Test {
bytes32 valueTwo = bytes32(uint256(5));
actions[1] = Drippie.DripAction({
target: payable(address(simpleStorage)),
data: abi.encodeWithSelector(simpleStorage.set.selector, keyTwo, valueTwo),
data: abi.encodeCall(SimpleStorage.set, (keyTwo, valueTwo)),
value: 0
});
......@@ -407,9 +407,9 @@ contract Drippie_Test is Test {
vm.expectCall(drippie.dripConfigCheckAddress(dripName), drippie.dripConfigCheckParams(dripName));
vm.expectCall(address(simpleStorage), 0, abi.encodeWithSelector(SimpleStorage.set.selector, keyOne, valueOne));
vm.expectCall(address(simpleStorage), 0, abi.encodeCall(SimpleStorage.set, (keyOne, valueOne)));
vm.expectCall(address(simpleStorage), 0, abi.encodeWithSelector(SimpleStorage.set.selector, keyTwo, valueTwo));
vm.expectCall(address(simpleStorage), 0, abi.encodeCall(SimpleStorage.set, (keyTwo, valueTwo)));
vm.expectEmit(address(drippie));
emit DripExecuted(dripName, dripName, address(this), block.timestamp);
......
......@@ -130,9 +130,7 @@ contract Optimist_Initializer is Test {
/// @notice Mocks the allowlistAttestor to always return true for a given address.
function _mockAllowlistTrueFor(address _claimer) internal {
vm.mockCall(
address(optimistAllowlist),
abi.encodeWithSelector(OptimistAllowlist.isAllowedToMint.selector, _claimer),
abi.encode(true)
address(optimistAllowlist), abi.encodeCall(OptimistAllowlist.isAllowedToMint, (_claimer)), abi.encode(true)
);
assertTrue(optimist.isOnAllowList(_claimer));
......@@ -210,7 +208,7 @@ contract OptimistTest is Optimist_Initializer {
assertTrue(optimistAllowlist.isAllowedToMint(bob));
// Check that the OptimistAllowlist is checked
bytes memory data = abi.encodeWithSelector(optimistAllowlist.isAllowedToMint.selector, bob);
bytes memory data = abi.encodeCall(OptimistAllowlist.isAllowedToMint, (bob));
vm.expectCall(address(optimistAllowlist), data);
// mint an NFT and expect mint transfer event to be emitted
......@@ -236,7 +234,7 @@ contract OptimistTest is Optimist_Initializer {
assertTrue(optimistAllowlist.isAllowedToMint(bob));
// Check that the OptimistAllowlist is checked
bytes memory data = abi.encodeWithSelector(optimistAllowlist.isAllowedToMint.selector, bob);
bytes memory data = abi.encodeCall(OptimistAllowlist.isAllowedToMint, (bob));
vm.expectCall(address(optimistAllowlist), data);
// mint an NFT and expect mint transfer event to be emitted
......@@ -262,7 +260,7 @@ contract OptimistTest is Optimist_Initializer {
assertTrue(optimistAllowlist.isAllowedToMint(bob));
// Check that the OptimistAllowlist is checked
bytes memory data = abi.encodeWithSelector(optimistAllowlist.isAllowedToMint.selector, bob);
bytes memory data = abi.encodeCall(OptimistAllowlist.isAllowedToMint, (bob));
vm.expectCall(address(optimistAllowlist), data);
// mint an NFT and expect mint transfer event to be emitted
......@@ -293,7 +291,7 @@ contract OptimistTest is Optimist_Initializer {
assertTrue(optimistAllowlist.isAllowedToMint(bob));
// Check that the OptimistAllowlist is checked
bytes memory data = abi.encodeWithSelector(optimistAllowlist.isAllowedToMint.selector, bob);
bytes memory data = abi.encodeCall(OptimistAllowlist.isAllowedToMint, (bob));
vm.expectCall(address(optimistAllowlist), data);
// mint an NFT and expect mint transfer event to be emitted
......@@ -350,11 +348,9 @@ contract OptimistTest is Optimist_Initializer {
function test_baseURI_returnsCorrectBaseURI_succeeds() external {
_attestBaseURI(base_uri);
bytes memory data = abi.encodeWithSelector(
attestationStation.attestations.selector,
carol_baseURIAttestor,
address(optimist),
optimist.BASE_URI_ATTESTATION_KEY()
bytes memory data = abi.encodeCall(
attestationStation.attestations,
(carol_baseURIAttestor, address(optimist), optimist.BASE_URI_ATTESTATION_KEY())
);
vm.expectCall(address(attestationStation), data);
vm.prank(carol_baseURIAttestor);
......@@ -527,14 +523,14 @@ contract OptimistTest is Optimist_Initializer {
// First call is to claim the invite, receiving the attestation
calls[0] = IMulticall3.Call3({
target: address(optimistInviter),
callData: abi.encodeWithSelector(optimistInviter.claimInvite.selector, bob, claimableInvite, signature),
callData: abi.encodeCall(OptimistInviter.claimInvite, (bob, claimableInvite, signature)),
allowFailure: false
});
// Second call is to mint the Optimist NFT
calls[1] = IMulticall3.Call3({
target: address(optimist),
callData: abi.encodeWithSelector(optimist.mint.selector, bob),
callData: abi.encodeCall(Optimist.mint, (bob)),
allowFailure: false
});
......
......@@ -260,7 +260,7 @@ library SafeTestLib {
instance,
address(instance.safe),
0,
abi.encodeWithSelector(ModuleManager.enableModule.selector, module),
abi.encodeCall(ModuleManager.enableModule, (module)),
Enum.Operation.Call,
0,
0,
......@@ -289,7 +289,7 @@ library SafeTestLib {
instance,
address(instance.safe),
0,
abi.encodeWithSelector(ModuleManager.disableModule.selector, prevModule, module),
abi.encodeCall(ModuleManager.disableModule, (prevModule, module)),
Enum.Operation.Call,
0,
0,
......@@ -308,7 +308,7 @@ library SafeTestLib {
instance,
address(instance.safe),
0,
abi.encodeWithSelector(GuardManager.setGuard.selector, guard),
abi.encodeCall(GuardManager.setGuard, (guard)),
Enum.Operation.Call,
0,
0,
......@@ -326,7 +326,7 @@ library SafeTestLib {
instance: instance,
to: signMessageLib,
value: 0,
data: abi.encodeWithSelector(SignMessageLib.signMessage.selector, data),
data: abi.encodeCall(SignMessageLib.signMessage, (data)),
operation: Enum.Operation.DelegateCall,
safeTxGas: 0,
baseGas: 0,
......@@ -350,21 +350,13 @@ library SafeTestLib {
/// @dev Adds a new owner to the safe
function changeThreshold(SafeInstance memory instance, uint256 threshold) internal {
execTransaction(
instance,
address(instance.safe),
0,
abi.encodeWithSelector(OwnerManager.changeThreshold.selector, threshold)
);
execTransaction(instance, address(instance.safe), 0, abi.encodeCall(OwnerManager.changeThreshold, (threshold)));
}
/// @dev Adds a new owner to the safe
function addOwnerWithThreshold(SafeInstance memory instance, address owner, uint256 threshold) internal {
execTransaction(
instance,
address(instance.safe),
0,
abi.encodeWithSelector(OwnerManager.addOwnerWithThreshold.selector, owner, threshold)
instance, address(instance.safe), 0, abi.encodeCall(OwnerManager.addOwnerWithThreshold, (owner, threshold))
);
}
......@@ -373,10 +365,7 @@ library SafeTestLib {
function removeOwner(SafeInstance memory instance, address prevOwner, address owner, uint256 threshold) internal {
prevOwner = prevOwner > address(0) ? prevOwner : SafeTestLib.getPrevOwner(instance, owner);
execTransaction(
instance,
address(instance.safe),
0,
abi.encodeWithSelector(OwnerManager.removeOwner.selector, prevOwner, owner, threshold)
instance, address(instance.safe), 0, abi.encodeCall(OwnerManager.removeOwner, (prevOwner, owner, threshold))
);
}
......@@ -385,10 +374,7 @@ library SafeTestLib {
function swapOwner(SafeInstance memory instance, address prevOwner, address oldOwner, address newOwner) internal {
prevOwner = prevOwner > address(0) ? prevOwner : SafeTestLib.getPrevOwner(instance, oldOwner);
execTransaction(
instance,
address(instance.safe),
0,
abi.encodeWithSelector(OwnerManager.swapOwner.selector, prevOwner, oldOwner, newOwner)
instance, address(instance.safe), 0, abi.encodeCall(OwnerManager.swapOwner, (prevOwner, oldOwner, newOwner))
);
}
......@@ -537,16 +523,18 @@ contract SafeTestTools {
bytes memory initData = advancedParams.initData.length > 0
? advancedParams.initData
: abi.encodeWithSelector(
GnosisSafe.setup.selector,
owners,
threshold,
advancedParams.setupModulesCall_to,
advancedParams.setupModulesCall_data,
advancedParams.includeFallbackHandler ? address(handler) : address(0),
advancedParams.refundToken,
advancedParams.refundAmount,
advancedParams.refundReceiver
: abi.encodeCall(
GnosisSafe.setup,
(
owners,
threshold,
advancedParams.setupModulesCall_to,
advancedParams.setupModulesCall_data,
advancedParams.includeFallbackHandler ? address(handler) : address(0),
advancedParams.refundToken,
advancedParams.refundAmount,
advancedParams.refundReceiver
)
);
DeployedSafe safe0 = DeployedSafe(
......
......@@ -100,7 +100,7 @@ contract DeputyGuardianModule_Pause_TestFail is DeputyGuardianModule_TestInit {
function test_pause_targetReverts_reverts() external {
vm.mockCallRevert(
address(superchainConfig),
abi.encodeWithSelector(superchainConfig.pause.selector),
abi.encodePacked(superchainConfig.pause.selector),
"SuperchainConfig: pause() reverted"
);
......@@ -150,7 +150,7 @@ contract DeputyGuardianModule_Unpause_TestFail is DeputyGuardianModule_Unpause_T
function test_unpause_targetReverts_reverts() external {
vm.mockCallRevert(
address(superchainConfig),
abi.encodeWithSelector(superchainConfig.unpause.selector),
abi.encodePacked(superchainConfig.unpause.selector),
"SuperchainConfig: unpause reverted"
);
......@@ -170,9 +170,7 @@ contract DeputyGuardianModule_SetAnchorState_TestFail is DeputyGuardianModule_Te
function test_setAnchorState_targetReverts_reverts() external {
IAnchorStateRegistry asr = IAnchorStateRegistry(makeAddr("asr"));
vm.mockCallRevert(
address(asr),
abi.encodeWithSelector(asr.setAnchorState.selector),
"AnchorStateRegistry: setAnchorState reverted"
address(asr), abi.encodePacked(asr.setAnchorState.selector), "AnchorStateRegistry: setAnchorState reverted"
);
vm.prank(address(deputyGuardian));
vm.expectRevert(
......@@ -186,9 +184,7 @@ contract DeputyGuardianModule_SetAnchorState_Test is DeputyGuardianModule_TestIn
function test_setAnchorState_succeeds() external {
IAnchorStateRegistry asr = IAnchorStateRegistry(makeAddr("asr"));
vm.mockCall(
address(asr),
abi.encodeWithSelector(IAnchorStateRegistry.setAnchorState.selector, IFaultDisputeGame(address(0))),
""
address(asr), abi.encodeCall(IAnchorStateRegistry.setAnchorState, (IFaultDisputeGame(address(0)))), ""
);
vm.expectEmit(address(safeInstance.safe));
emit ExecutionFromModuleSuccess(address(deputyGuardianModule));
......@@ -228,7 +224,7 @@ contract DeputyGuardianModule_BlacklistDisputeGame_TestFail is DeputyGuardianMod
function test_blacklistDisputeGame_targetReverts_reverts() external {
vm.mockCallRevert(
address(optimismPortal2),
abi.encodeWithSelector(optimismPortal2.blacklistDisputeGame.selector),
abi.encodePacked(optimismPortal2.blacklistDisputeGame.selector),
"OptimismPortal2: blacklistDisputeGame reverted"
);
......@@ -271,7 +267,7 @@ contract DeputyGuardianModule_setRespectedGameType_TestFail is DeputyGuardianMod
function test_setRespectedGameType_targetReverts_reverts() external {
vm.mockCallRevert(
address(optimismPortal2),
abi.encodeWithSelector(optimismPortal2.setRespectedGameType.selector),
abi.encodePacked(optimismPortal2.setRespectedGameType.selector),
"OptimismPortal2: setRespectedGameType reverted"
);
......
......@@ -110,7 +110,7 @@ contract LivenessGuard_CheckTx_Test is LivenessGuard_TestInit {
vm.expectEmit(address(livenessGuard));
emit OwnerRecorded(signers[i]);
}
vm.expectCall(address(safeInstance.safe), abi.encodeWithSignature("nonce()"));
vm.expectCall(address(safeInstance.safe), abi.encodeCall(safeInstance.safe.nonce, ()));
vm.expectCall(address(safeInstance.safe), abi.encodeCall(OwnerManager.getThreshold, ()));
safeInstance.execTransaction({ to: address(1111), value: 0, data: hex"abba" });
for (uint256 i; i < safeInstance.threshold; i++) {
......@@ -228,6 +228,7 @@ contract LivenessGuard_FuzzOwnerManagement_Test is StdCheats, StdUtils, Liveness
mapping(address => uint256) privateKeys;
/// @dev Tests that the guard correctly manages the lastLive mapping when owners are added, removed, or swapped
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_OwnerManagement_works(
uint256 initialOwners,
uint256 threshold,
......
......@@ -75,6 +75,7 @@ contract SafeSigners_Test is Test, SafeTestTools {
contractSigs++;
address addr = SafeTestLib.decodeSmartContractWalletAsAddress(pks[i]);
r = bytes32(uint256(uint160(addr)));
// nosemgrep: sol-style-use-abi-encodecall
vm.mockCall(
addr, abi.encodeWithSignature("isValidSignature(bytes,bytes)"), abi.encode(EIP1271_MAGIC_VALUE)
);
......
......@@ -187,7 +187,7 @@ contract GasBenchMark_L1StandardBridge_Finalize is Bridge_Initializer {
deal(address(L1Token), address(l1StandardBridge), 100, true);
vm.mockCall(
address(l1StandardBridge.messenger()),
abi.encodeWithSelector(ICrossDomainMessenger.xDomainMessageSender.selector),
abi.encodeCall(ICrossDomainMessenger.xDomainMessageSender, ()),
abi.encode(address(l1StandardBridge.OTHER_BRIDGE()))
);
vm.startPrank(address(l1StandardBridge.messenger()));
......@@ -302,7 +302,7 @@ contract GasBenchMark_L1BlockInterop_DepositsComplete is GasBenchMark_L1BlockInt
function test_depositsComplete_benchmark() external {
SafeCall.call({
_target: address(l1BlockInterop),
_calldata: abi.encodeWithSelector(l1BlockInterop.depositsComplete.selector)
_calldata: abi.encodeCall(IL1BlockInterop.depositsComplete, ())
});
}
}
......@@ -317,7 +317,7 @@ contract GasBenchMark_L1BlockInterop_DepositsComplete_Warm is GasBenchMark_L1Blo
function test_depositsComplete_benchmark() external {
SafeCall.call({
_target: address(l1BlockInterop),
_calldata: abi.encodeWithSelector(l1BlockInterop.depositsComplete.selector)
_calldata: abi.encodeCall(l1BlockInterop.depositsComplete, ())
});
}
}
......@@ -99,7 +99,7 @@ contract ExternalRelay is Test {
/// @notice Helper function to get the callData for an `externalCallWithMinGas
function getCallData() public pure returns (bytes memory) {
return abi.encodeWithSelector(ExternalRelay.externalCallWithMinGas.selector);
return abi.encodeCall(ExternalRelay.externalCallWithMinGas, ());
}
/// @notice Helper function to set the fuzzed sender
......
......@@ -42,7 +42,7 @@ contract OptimismMintableTokenFactory_Test is Bridge_Initializer {
vm.startPrank(EIP1967Helper.getAdmin(address(proxy)));
// Reviewer note: the NextImpl() still uses reinitializer. If we want to remove that, we'll need to use a
// two step upgrade with the Storage lib.
proxy.upgradeToAndCall(address(nextImpl), abi.encodeWithSelector(NextImpl.initialize.selector, 2));
proxy.upgradeToAndCall(address(nextImpl), abi.encodeCall(NextImpl.initialize, (2)));
assertEq(proxy.implementation(), address(nextImpl));
// Verify that the NextImpl contract initialized its values according as expected
......
......@@ -160,7 +160,7 @@ contract Proxy_Test is Test {
vm.expectEmit(true, true, true, true);
emit Upgraded(address(simpleStorage));
vm.prank(alice);
proxy.upgradeToAndCall(address(simpleStorage), abi.encodeWithSelector(simpleStorage.set.selector, 1, 1));
proxy.upgradeToAndCall(address(simpleStorage), abi.encodeCall(SimpleStorage.set, (1, 1)));
// The call should have impacted the state
uint256 result = SimpleStorage(address(proxy)).get(1);
......@@ -193,7 +193,7 @@ contract Proxy_Test is Test {
// The attempt to `upgradeToAndCall`
// should revert when it is not called by the owner.
vm.expectRevert(bytes(""));
proxy.upgradeToAndCall(address(simpleStorage), abi.encodeWithSelector(simpleStorage.set.selector, 1, 1));
proxy.upgradeToAndCall(address(simpleStorage), abi.encodeCall(simpleStorage.set, (1, 1)));
}
function test_upgradeToAndCall_isPayable_succeeds() external {
......@@ -202,9 +202,7 @@ contract Proxy_Test is Test {
// Set the implementation and call and send
// value.
vm.prank(alice);
proxy.upgradeToAndCall{ value: 1 ether }(
address(simpleStorage), abi.encodeWithSelector(simpleStorage.set.selector, 1, 1)
);
proxy.upgradeToAndCall{ value: 1 ether }(address(simpleStorage), abi.encodeCall(simpleStorage.set, (1, 1)));
// The implementation address should be correct
vm.prank(alice);
......@@ -265,7 +263,8 @@ contract Proxy_Test is Test {
(bool success, bytes memory returndata) = address(proxy).call(hex"");
assertEq(success, false);
bytes memory err = abi.encodeWithSignature("Error(string)", "Proxy: implementation not initialized");
bytes memory err = abi.encodeWithSignature("Error(string)", "Proxy: implementation not initialized"); // nosemgrep:
// sol-style-use-abi-encodecall
assertEq(returndata, err);
}
......
......@@ -248,7 +248,7 @@ contract ProxyAdmin_Test is Test {
function upgradeAndCall(address payable _proxy) internal {
vm.prank(alice);
admin.upgradeAndCall(_proxy, address(implementation), abi.encodeWithSelector(SimpleStorage.set.selector, 1, 1));
admin.upgradeAndCall(_proxy, address(implementation), abi.encodeCall(SimpleStorage.set, (1, 1)));
address impl = admin.getProxyImplementation(_proxy);
assertEq(impl, address(implementation));
......
......@@ -54,7 +54,8 @@ rules:
version\(\) public pure virtual returns \(string memory\)
\{\s+return
"(?P<VERSION2>[0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9.]+)?)";
- pattern-regex: /// @custom:semver (?P<VERSION1>[a-zA-Z0-9.+-]+)\s+function
- pattern-regex:
/// @custom:semver (?P<VERSION1>[a-zA-Z0-9.+-]+)\s+function
version\(\) public pure override returns \(string memory\)
\{\s+return string\.concat\(super\.version\(\),
"(?P<VERSION2>[a-zA-Z0-9.+-]+)"\);
......@@ -152,11 +153,14 @@ rules:
severity: ERROR
message: Use abi.encodeCall instead of abi.encodeWithSelector
patterns:
- pattern: |
abi.encodeWithSelector(...);
- pattern-either:
- pattern: |
abi.encodeWithSelector(...);
- pattern: |
abi.encodeWithSignature(...);
- pattern-not: vm.expectRevert(abi.encodeWithSelector(...));
paths:
exclude:
- packages/contracts-bedrock/test
- packages/contracts-bedrock/src/L1/OPContractsManager.sol
- packages/contracts-bedrock/src/L1/OPContractsManagerInterop.sol
- packages/contracts-bedrock/src/legacy/L1ChugSplashProxy.sol
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