-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: add Unit-test to verify revert any transfer of ETH to Palmera Mo…
…dule, Palmera Guard or Palmera Roles
- Loading branch information
1 parent
98326f1
commit 7e1dac8
Showing
6 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity ^0.8.15; | ||
|
||
import "./helpers/DeployHelper.t.sol"; | ||
|
||
contract PalmeraGuardTestFallbackAndReceive is DeployHelper { | ||
/// @notice Set up the environment for testing | ||
function setUp() public { | ||
deployAllContracts(60); | ||
} | ||
/// @notice Calling a non-existent function | ||
|
||
function testFallbackFunctionNonExistentFunction() public { | ||
(bool success,) = address(palmeraGuard).call( | ||
abi.encodeWithSignature("nonExistentFunction()") | ||
); | ||
assertFalse( | ||
success, | ||
"Fallback function should revert on non-existent function call" | ||
); | ||
} | ||
|
||
/// @notice Sending ETH without data | ||
function testReceiveFunctionSendETHWithoutData() public { | ||
vm.deal(address(this), 1 ether); // Give this contract 1 ether to work with | ||
(bool success,) = address(palmeraGuard).call{value: 1 ether}(""); | ||
assertFalse( | ||
success, "Receive function should revert on ETH send without data" | ||
); | ||
} | ||
|
||
/// @notice Sending ETH with data that does not match any function | ||
function testFallbackFunctionSendETHWithInvalidData() public { | ||
vm.deal(address(this), 1 ether); // Give this contract 1 ether to work with | ||
(bool success,) = address(palmeraGuard).call{value: 1 ether}( | ||
abi.encodeWithSignature("checkTransaction()") | ||
); | ||
assertFalse( | ||
success, | ||
"Fallback function should revert on ETH send with invalid data" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity ^0.8.15; | ||
|
||
import "./helpers/DeployHelper.t.sol"; | ||
|
||
contract PalmeraModuleTestFallbackAndReceive is DeployHelper { | ||
/// @notice Set up the environment for testing | ||
function setUp() public { | ||
deployAllContracts(60); | ||
} | ||
|
||
/// @notice Sending ETH without data | ||
function testReceiveFunctionSendETHWithoutData() public { | ||
vm.deal(address(this), 1 ether); // Give this contract 1 ether to work with | ||
(bool success,) = address(palmeraModule).call{value: 1 ether}(""); | ||
assertFalse( | ||
success, "Receive function should revert on ETH send without data" | ||
); | ||
} | ||
|
||
/// @notice Sending ETH with data that does not match any function | ||
function testFallbackFunctionSendETHWithInvalidData() public { | ||
vm.deal(address(this), 1 ether); // Give this contract 1 ether to work with | ||
(bool success,) = address(palmeraModule).call{value: 1 ether}( | ||
abi.encodeWithSignature("execTransactionOnBehalf()") | ||
); | ||
assertFalse( | ||
success, | ||
"Fallback function should revert on ETH send with invalid data" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity ^0.8.15; | ||
|
||
import "./helpers/DeployHelper.t.sol"; | ||
|
||
contract PalmeraRolesTestFallbackAndReceive is DeployHelper { | ||
/// @notice Set up the environment for testing | ||
function setUp() public { | ||
deployAllContracts(60); | ||
} | ||
/// @notice Calling a non-existent function | ||
|
||
function testFallbackFunctionNonExistentFunction() public { | ||
(bool success,) = address(palmeraRolesContract).call( | ||
abi.encodeWithSignature("nonExistentFunction()") | ||
); | ||
assertFalse( | ||
success, | ||
"Fallback function should revert on non-existent function call" | ||
); | ||
} | ||
|
||
/// @notice Sending ETH without data | ||
function testReceiveFunctionSendETHWithoutData() public { | ||
vm.deal(address(this), 1 ether); // Give this contract 1 ether to work with | ||
(bool success,) = address(palmeraRolesContract).call{value: 1 ether}(""); | ||
assertFalse( | ||
success, "Receive function should revert on ETH send without data" | ||
); | ||
} | ||
|
||
/// @notice Sending ETH with data that does not match any function | ||
function testFallbackFunctionSendETHWithInvalidData() public { | ||
vm.deal(address(this), 1 ether); // Give this contract 1 ether to work with | ||
(bool success,) = address(palmeraRolesContract).call{value: 1 ether}( | ||
abi.encodeWithSignature("setUserRole()") | ||
); | ||
assertFalse( | ||
success, | ||
"Fallback function should revert on ETH send with invalid data" | ||
); | ||
} | ||
} |