Skip to content

Commit

Permalink
Simplifies contract invocations in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scnale committed Nov 20, 2024
1 parent 50862c3 commit e33002f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 47 deletions.
31 changes: 0 additions & 31 deletions test/components/dispatcher/AccessControl.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
PROPOSE_OWNERSHIP_TRANSFER_ID,
Expand All @@ -40,7 +39,6 @@ contract AcessControlTest is DispatcherTestBase {
commandCount = 2;
bytes memory getRes = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
OWNER_ID,
Expand All @@ -56,14 +54,12 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(newOwner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACQUIRE_OWNERSHIP_ID
)
);

getRes = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,

ACCESS_CONTROL_QUERIES_ID,
commandCount,
Expand All @@ -85,7 +81,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.expectRevert(NotAuthorized.selector);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
PROPOSE_OWNERSHIP_TRANSFER_ID,
Expand All @@ -101,7 +96,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
PROPOSE_OWNERSHIP_TRANSFER_ID,
Expand All @@ -112,7 +106,6 @@ contract AcessControlTest is DispatcherTestBase {
commandCount = 2;
bytes memory getRes = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
OWNER_ID,
Expand All @@ -134,7 +127,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.expectRevert(NotAuthorized.selector);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACQUIRE_OWNERSHIP_ID
)
);
Expand All @@ -147,7 +139,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
PROPOSE_OWNERSHIP_TRANSFER_ID,
Expand All @@ -158,14 +149,12 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(newOwner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACQUIRE_OWNERSHIP_ID
)
);

bytes memory getRes = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,

ACCESS_CONTROL_QUERIES_ID,
commandCount,
Expand Down Expand Up @@ -194,7 +183,6 @@ contract AcessControlTest is DispatcherTestBase {
uint8 commandCount = 2;
bytes memory getRes = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
OWNER_ID,
Expand Down Expand Up @@ -223,7 +211,6 @@ contract AcessControlTest is DispatcherTestBase {
uint8 commandCount = 2;
bytes memory getRes = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
OWNER_ID,
Expand Down Expand Up @@ -252,7 +239,6 @@ contract AcessControlTest is DispatcherTestBase {
uint8 commandCount = 2;
bytes memory getRes = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
OWNER_ID,
Expand All @@ -276,7 +262,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
PROPOSE_OWNERSHIP_TRANSFER_ID,
Expand All @@ -287,7 +272,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(newOwner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACQUIRE_OWNERSHIP_ID,
ACCESS_CONTROL_ID,
commandCount,
Expand All @@ -299,7 +283,6 @@ contract AcessControlTest is DispatcherTestBase {
commandCount = 3;
bytes memory getRes = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
OWNER_ID,
Expand Down Expand Up @@ -328,7 +311,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.expectRevert(NotAuthorized.selector);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
ADD_ADMIN_ID,
Expand All @@ -340,7 +322,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(admin);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
ADD_ADMIN_ID,
Expand All @@ -356,7 +337,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
ADD_ADMIN_ID,
Expand All @@ -367,7 +347,6 @@ contract AcessControlTest is DispatcherTestBase {
commandCount = 2;
bytes memory res = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
IS_ADMIN_ID,
Expand All @@ -392,7 +371,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.expectRevert(NotAuthorized.selector);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
REVOKE_ADMIN_ID,
Expand All @@ -408,7 +386,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
ADD_ADMIN_ID,
Expand All @@ -420,7 +397,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(admin);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
REVOKE_ADMIN_ID,
Expand All @@ -431,7 +407,6 @@ contract AcessControlTest is DispatcherTestBase {
commandCount = 2;
bytes memory res = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
IS_ADMIN_ID,
Expand All @@ -453,7 +428,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(admin);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
REVOKE_ADMIN_ID,
Expand All @@ -464,7 +438,6 @@ contract AcessControlTest is DispatcherTestBase {
bool isAdmin;
(isAdmin, ) = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
IS_ADMIN_ID,
Expand All @@ -481,7 +454,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.expectRevert(NotAuthorized.selector);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
RELINQUISH_OWNERSHIP_ID
Expand All @@ -498,7 +470,6 @@ contract AcessControlTest is DispatcherTestBase {
);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
RELINQUISH_OWNERSHIP_ID,
Expand All @@ -514,7 +485,6 @@ contract AcessControlTest is DispatcherTestBase {
vm.prank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
ACCESS_CONTROL_ID,
commandCount,
RELINQUISH_OWNERSHIP_ID
Expand All @@ -523,7 +493,6 @@ contract AcessControlTest is DispatcherTestBase {

(address owner_, ) = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
ACCESS_CONTROL_QUERIES_ID,
commandCount,
OWNER_ID
Expand Down
2 changes: 0 additions & 2 deletions test/components/dispatcher/SweepTokens.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ contract SweepTokensTest is DispatcherTestBase {
vm.prank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
SWEEP_TOKENS_ID, address(token), tokenAmount
)
);
Expand All @@ -42,7 +41,6 @@ contract SweepTokensTest is DispatcherTestBase {
vm.prank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
SWEEP_TOKENS_ID, address(0), ethAmount
)
);
Expand Down
8 changes: 0 additions & 8 deletions test/components/dispatcher/Upgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ contract UpgradeTest is DispatcherTestBase {
vm.expectRevert(NotAuthorized.selector);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
UPGRADE_CONTRACT_ID,
address(fakeAddress)
)
Expand All @@ -31,7 +30,6 @@ contract UpgradeTest is DispatcherTestBase {
vm.expectRevert(NotAuthorized.selector);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
UPGRADE_CONTRACT_ID,
address(fakeAddress)
)
Expand All @@ -44,7 +42,6 @@ contract UpgradeTest is DispatcherTestBase {
vm.startPrank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
UPGRADE_CONTRACT_ID,
address(upgradeTester)
)
Expand All @@ -59,7 +56,6 @@ contract UpgradeTest is DispatcherTestBase {

bytes memory response = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
IMPLEMENTATION_ID
)
);
Expand All @@ -69,7 +65,6 @@ contract UpgradeTest is DispatcherTestBase {
vm.startPrank(owner);
invokeDispatcher(
abi.encodePacked(
dispatcher.exec768.selector,
UPGRADE_CONTRACT_ID,
address(upgradeTester)
)
Expand All @@ -79,7 +74,6 @@ contract UpgradeTest is DispatcherTestBase {

response = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
IMPLEMENTATION_ID
)
);
Expand Down Expand Up @@ -114,7 +108,6 @@ contract UpgradeTest is DispatcherTestBase {

bytes memory response = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
IMPLEMENTATION_ID
)
);
Expand All @@ -128,7 +121,6 @@ contract UpgradeTest is DispatcherTestBase {

response = invokeStaticDispatcher(
abi.encodePacked(
dispatcher.get1959.selector,
IMPLEMENTATION_ID
)
);
Expand Down
14 changes: 8 additions & 6 deletions test/components/dispatcher/utils/DispatcherTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ contract DispatcherTestBase is Test {
_setUp1();
}

function invokeStaticDispatcher(bytes memory encoded) view internal returns (bytes memory data) {
(bool success, bytes memory result) = address(dispatcher).staticcall(encoded);
function invokeStaticDispatcher(bytes memory messages) view internal returns (bytes memory data) {
bytes memory getCall = abi.encodePacked(dispatcher.get1959.selector, messages);
(bool success, bytes memory result) = address(dispatcher).staticcall(getCall);
return decodeBytesResult(success, result);
}

function invokeDispatcher(bytes memory encoded) internal returns (bytes memory data) {
return invokeDispatcher(encoded, 0);
function invokeDispatcher(bytes memory messages) internal returns (bytes memory data) {
return invokeDispatcher(messages, 0);
}

function invokeDispatcher(bytes memory encoded, uint value) internal returns (bytes memory data) {
(bool success, bytes memory result) = address(dispatcher).call{value: value}(encoded);
function invokeDispatcher(bytes memory messages, uint value) internal returns (bytes memory data) {
bytes memory execCall = abi.encodePacked(dispatcher.exec768.selector, messages);
(bool success, bytes memory result) = address(dispatcher).call{value: value}(execCall);
return decodeBytesResult(success, result);
}

Expand Down

0 comments on commit e33002f

Please sign in to comment.