-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add swap owner to allowlist, test #37
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"version": "1.0", | ||
"chainId": "1", | ||
"createdAt": 1738828295179, | ||
"meta": { | ||
"name": "Transactions Batch", | ||
"description": "enable-swap-owner", | ||
"txBuilderVersion": "1.10.0", | ||
"createdFromSafeAddress": "0x9D89745fD63Af482ce93a9AdB8B0BbDbb98D3e06", | ||
"createdFromOwnerAddress": "", | ||
"checksum": "0x102a3dcd91b01f97351f36f92ab491ab09e4b218f3525dc41c30cd1e89eb820c" | ||
}, | ||
"transactions": [ | ||
{ | ||
"to": "0x9000fef2846a5253fd2c6ed5241de0fddb404302", | ||
"value": "0x0", | ||
"data": "0x5534fa0c0000000000000000000000000000000000000000000000000000000000000000e318b52b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" | ||
} | ||
] | ||
} |
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,85 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity =0.8.24; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
import {RumpelGuard} from "../src/RumpelGuard.sol"; | ||
import {RumpelModule} from "../src/RumpelModule.sol"; | ||
import {InitializationScript} from "../src/InitializationScript.sol"; | ||
import {RumpelWalletFactory} from "../src/RumpelWalletFactory.sol"; | ||
|
||
import {ISafe, Enum} from "../src/interfaces/external/ISafe.sol"; | ||
import {RumpelWalletFactoryScripts} from "../script/RumpelWalletFactory.s.sol"; | ||
|
||
contract RumpelWalletSwapOwnerTest is Test { | ||
RumpelModule public rumpelModule = RumpelModule(0x28c3498B4956f4aD8d4549ACA8F66260975D361a); | ||
RumpelGuard public rumpelGuard = RumpelGuard(0x9000FeF2846A5253fD2C6ed5241De0fddb404302); | ||
RumpelWalletFactory public rumpelWalletFactory = RumpelWalletFactory(0x5774AbCF415f34592514698EB075051E97Db2937); | ||
|
||
address alice; | ||
uint256 alicePk; | ||
|
||
struct SafeTX { | ||
address to; | ||
uint256 value; | ||
bytes data; | ||
Enum.Operation operation; | ||
} | ||
|
||
function setUp() public { | ||
(alice, alicePk) = makeAddrAndKey("alice"); | ||
|
||
string memory MAINNET_RPC_URL = vm.envString("MAINNET_RPC_URL"); | ||
uint256 FORK_BLOCK_NUMBER = 21748243; // Feb-01-2025 12:59:47 AM +UTC | ||
vm.createSelectFork(MAINNET_RPC_URL, FORK_BLOCK_NUMBER); | ||
} | ||
|
||
function test_SwapOwner() public { | ||
RumpelWalletFactoryScripts scripts = new RumpelWalletFactoryScripts(); | ||
|
||
address[] memory owners = new address[](1); | ||
owners[0] = address(alice); | ||
|
||
InitializationScript.InitCall[] memory initCalls = new InitializationScript.InitCall[](0); | ||
address safe = rumpelWalletFactory.createWallet(owners, 1, initCalls); | ||
|
||
address NEW_OWNER = address(0x123); | ||
|
||
assertEq(ISafe(safe).getOwners().length, 1); | ||
assertEq(ISafe(safe).getOwners()[0], address(alice)); | ||
|
||
bytes memory swapOwnerData = | ||
abi.encodeWithSelector(ISafe.swapOwner.selector, address(0x1), address(alice), NEW_OWNER); | ||
vm.expectRevert( | ||
abi.encodeWithSelector(RumpelGuard.CallNotAllowed.selector, address(safe), bytes4(swapOwnerData)) | ||
); | ||
this._execSafeTx(ISafe(safe), safe, 0, swapOwnerData, Enum.Operation.Call); | ||
|
||
assertEq(ISafe(safe).getOwners().length, 1); | ||
assertEq(ISafe(safe).getOwners()[0], address(alice)); | ||
|
||
// Run the script to enable the swapOwner call | ||
scripts.updateGuardAndModuleLists(rumpelGuard, rumpelModule, "enable-swap-owner"); | ||
|
||
this._execSafeTx(ISafe(safe), safe, 0, swapOwnerData, Enum.Operation.Call); | ||
|
||
assertEq(ISafe(safe).getOwners().length, 1); | ||
assertEq(ISafe(safe).getOwners()[0], NEW_OWNER); | ||
} | ||
|
||
function _execSafeTx(ISafe safe, address to, uint256 value, bytes memory data, Enum.Operation operation) public { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A future clean up could be adding this function to a base test contract helper since its in most test files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for sure! |
||
SafeTX memory safeTX = SafeTX({to: to, value: value, data: data, operation: operation}); | ||
|
||
uint256 nonce = safe.nonce(); | ||
|
||
bytes32 txHash = safe.getTransactionHash( | ||
safeTX.to, safeTX.value, safeTX.data, safeTX.operation, 0, 0, 0, address(0), payable(address(0)), nonce | ||
); | ||
(uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, txHash); | ||
bytes memory signature = abi.encodePacked(r, s, v); | ||
|
||
safe.execTransaction( | ||
safeTX.to, safeTX.value, safeTX.data, safeTX.operation, 0, 0, 0, address(0), payable(address(0)), signature | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work so nicely with my print-state script, since it knows functions in the config contract but not sure we should make decisions based on that.
I can also update the print functionality to also get all functions from contracts in the src folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easy enough to change – moved it into the config file