Skip to content

Commit

Permalink
negative test + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Jun 2, 2024
1 parent 3a2a610 commit 2fc766e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/foundry/integration/UpgradeSmartAccountTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ contract UpgradeSmartAccountTest is NexusTest_Base {
assertEq(newImplementation, address(newSmartAccount), "New implementation address mismatch");
}

/// @notice Tests the upgrade of the smart account implementation with invalid call data
function test_upgradeImplementation_invalidCallData() public {
address _ENTRYPOINT = 0x0000000071727De22E5E9d8BAf0edAc6f37da032;
Nexus newSmartAccount = new Nexus(_ENTRYPOINT);
bytes memory callData = abi.encodeWithSelector(Nexus.upgradeToAndCall.selector, address(newSmartAccount), bytes(hex"1234"));
Execution[] memory execution = new Execution[](1);
execution[0] = Execution(address(BOB_ACCOUNT), 0, callData);
PackedUserOperation[] memory userOps = buildPackedUserOperation(BOB, BOB_ACCOUNT, EXECTYPE_DEFAULT, execution, address(VALIDATOR_MODULE));
bytes memory expectedRevertReason = abi.encodeWithSelector(MissingFallbackHandler.selector, bytes4(hex"1234"));
bytes32 userOpHash = ENTRYPOINT.getUserOpHash(userOps[0]);
// Expect the UserOperationRevertReason event
vm.expectEmit(true, true, true, true);
emit UserOperationRevertReason(
userOpHash, // userOpHash
address(BOB_ACCOUNT), // sender
userOps[0].nonce, // nonce
expectedRevertReason
);
ENTRYPOINT.handleOps(userOps, payable(address(BOB.addr)));
}

/// @notice Tests the upgrade of the smart account implementation with an invalid address
function test_upgradeImplementation_InvalidAddress() public {
/// @note "" means empty calldata. this will just update the implementation but not setup the account.
Expand Down Expand Up @@ -80,6 +101,10 @@ contract UpgradeSmartAccountTest is NexusTest_Base {
ENTRYPOINT.handleOps(userOps, payable(address(BOB.addr)));
}

/// Could add...
/// Access control on upgrades
/// send setup data instead of empty data

/// @notice Tests the entire upgrade process
function test_upgradeSmartAccount() public {
test_proxiableUUIDSlot();
Expand Down
1 change: 1 addition & 0 deletions test/foundry/unit/fuzz/TestFuzz_ERC4337Account.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ contract TestFuzz_ERC4337Account is NexusTest_Base {
/// @param amount The amount to withdraw.
function testFuzz_WithdrawDepositTo(address to, uint256 amount) public {
vm.assume(!isContract(to)); // Valid 'to' address and skip precompiles
vm.assume(uint160(address(to)) > 10);
vm.assume(amount > 0.01 ether && amount <= 50 ether); // Restricting the amount to a reasonable upper limit and ensuring it's greater than 0
vm.assume(to.balance == 0);
// Fund the BOB_ACCOUNT with more than just the deposit amount to cover potential transaction fees
Expand Down
1 change: 1 addition & 0 deletions test/foundry/utils/EventsAndErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ contract EventsAndErrors {

// Define all errors
// General Errors
error MissingFallbackHandler(bytes4 sig);
error InvalidImplementationAddress();
error AccountInitializationFailed();
error AccountAccessUnauthorized();
Expand Down

0 comments on commit 2fc766e

Please sign in to comment.