Skip to content

Commit

Permalink
test: modify tests to use fallback signer rather than single signer v…
Browse files Browse the repository at this point in the history
…alidation
  • Loading branch information
Zer0dot committed Aug 1, 2024
1 parent 4bf481f commit df8f80e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/account/UpgradeableModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ contract UpgradeableModularAccount is
selector == this.execute.selector || selector == this.executeBatch.selector
|| selector == this.installExecution.selector || selector == this.uninstallExecution.selector
|| selector == this.installValidation.selector || selector == this.uninstallValidation.selector
|| selector == this.upgradeToAndCall.selector
|| selector == this.upgradeToAndCall.selector || selector == this.updateFallbackSigner.selector
) {
return true;
}
Expand Down
12 changes: 2 additions & 10 deletions test/account/AccountReturnData.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ contract AccountReturnDataTest is AccountTestBase {
account1.execute,
(address(regularResultContract), 0, abi.encodeCall(RegularResultContract.foo, ()))
),
_encodeSignature(
ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID),
GLOBAL_VALIDATION,
""
)
_encodeSignature(_signerValidation, GLOBAL_VALIDATION, "")
);

bytes32 result = abi.decode(abi.decode(returnData, (bytes)), (bytes32));
Expand All @@ -95,11 +91,7 @@ contract AccountReturnDataTest is AccountTestBase {

bytes memory retData = account1.executeWithAuthorization(
abi.encodeCall(account1.executeBatch, (calls)),
_encodeSignature(
ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID),
GLOBAL_VALIDATION,
""
)
_encodeSignature(_signerValidation, GLOBAL_VALIDATION, "")
);

bytes[] memory returnDatas = abi.decode(retData, (bytes[]));
Expand Down
36 changes: 36 additions & 0 deletions test/account/ImmutableAppend.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

import {IEntryPoint, UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol";
import {ModuleEntity, ModuleEntityLib} from "../../src/helpers/ModuleEntityLib.sol";
import {ValidationConfig, ValidationConfigLib} from "../../src/helpers/ValidationConfigLib.sol";
import {ExecutionHook} from "../../src/interfaces/IAccountLoupe.sol";
import {Call, IStandardExecutor} from "../../src/interfaces/IStandardExecutor.sol";
import {DirectCallModule} from "../mocks/modules/DirectCallModule.sol";

import {AccountTestBase} from "../utils/AccountTestBase.sol";

import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {LibClone} from "solady/utils/LibClone.sol";

contract ImmutableAppendTest is AccountTestBase {
using ValidationConfigLib for ValidationConfig;

/* -------------------------------------------------------------------------- */
/* Negatives */
/* -------------------------------------------------------------------------- */

/* -------------------------------------------------------------------------- */
/* Positives */
/* -------------------------------------------------------------------------- */

function test_success_getData() public {
bytes memory expectedArgs = abi.encodePacked(owner1);

assertEq(keccak256(LibClone.argsOnERC1967(address(account1))), keccak256(expectedArgs));
}

/* -------------------------------------------------------------------------- */
/* Internals */
/* -------------------------------------------------------------------------- */
}
2 changes: 1 addition & 1 deletion test/account/MultiValidation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract MultiValidationTest is AccountTestBase {
);

ModuleEntity[] memory validations = new ModuleEntity[](2);
validations[0] = ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID);
validations[0] = _signerValidation;
validations[1] = ModuleEntityLib.pack(address(validator2), TEST_DEFAULT_VALIDATION_ENTITY_ID);

bytes4[] memory selectors0 = account1.getSelectors(validations[0]);
Expand Down
5 changes: 4 additions & 1 deletion test/account/PerHookData.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/Messa
import {UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol";

import {HookConfigLib} from "../../src/helpers/HookConfigLib.sol";
import {ModuleEntity} from "../../src/helpers/ModuleEntityLib.sol";
import {ModuleEntity, ModuleEntityLib} from "../../src/helpers/ModuleEntityLib.sol";

import {Counter} from "../mocks/Counter.sol";
import {MockAccessControlHookModule} from "../mocks/modules/MockAccessControlHookModule.sol";
Expand All @@ -22,6 +22,9 @@ contract PerHookDataTest is CustomValidationTestBase {
Counter internal _counter;

function setUp() public {
_signerValidation =
ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID);

_counter = new Counter();

_accessControlHookModule = new MockAccessControlHookModule();
Expand Down
25 changes: 12 additions & 13 deletions test/account/UpgradeableModularAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract UpgradeableModularAccountTest is AccountTestBase {
(owner2, owner2Key) = makeAddrAndKey("owner2");

// Compute counterfactual address
account2 = UpgradeableModularAccount(payable(factory.getAddress(owner2, 0)));
account2 = UpgradeableModularAccount(payable(factory.getAddressFallbackSigner(owner2, 0)));
vm.deal(address(account2), 100 ether);

ethRecipient = makeAddr("ethRecipient");
Expand Down Expand Up @@ -95,15 +95,10 @@ contract UpgradeableModularAccountTest is AccountTestBase {
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account2),
nonce: 0,
initCode: abi.encodePacked(address(factory), abi.encodeCall(factory.createAccount, (owner2, 0))),
callData: abi.encodeCall(
UpgradeableModularAccount.execute,
(
address(singleSignerValidation),
0,
abi.encodeCall(SingleSignerValidation.transferSigner, (TEST_DEFAULT_VALIDATION_ENTITY_ID, owner2))
)
initCode: abi.encodePacked(
address(factory), abi.encodeCall(factory.createAccountWithFallbackValidation, (owner2, 0))
),
callData: abi.encodeCall(UpgradeableModularAccount.updateFallbackSigner, (owner2)),
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
gasFees: _encodeGas(1, 2),
Expand All @@ -128,7 +123,9 @@ contract UpgradeableModularAccountTest is AccountTestBase {
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account2),
nonce: 0,
initCode: abi.encodePacked(address(factory), abi.encodeCall(factory.createAccount, (owner2, 0))),
initCode: abi.encodePacked(
address(factory), abi.encodeCall(factory.createAccountWithFallbackValidation, (owner2, 0))
),
callData: abi.encodeCall(UpgradeableModularAccount.execute, (recipient, 1 wei, "")),
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
Expand Down Expand Up @@ -353,8 +350,11 @@ contract UpgradeableModularAccountTest is AccountTestBase {
assertEq(address(account3), address(uint160(uint256(vm.load(address(account1), slot)))));
}

// TODO: Consider if this test belongs here or in the tests specific to the SingleSignerValidation
function test_transferOwnership() public {
assertEq(singleSignerValidation.signerOf(TEST_DEFAULT_VALIDATION_ENTITY_ID, address(account1)), owner1);
// Note: replaced "owner1" with address(0), this doesn't actually affect the account, but allows the test
// to pass by ensuring the signer can be set in the validation
assertEq(singleSignerValidation.signerOf(TEST_DEFAULT_VALIDATION_ENTITY_ID, address(account1)), address(0));

vm.prank(address(entryPoint));
account1.execute(
Expand All @@ -373,8 +373,7 @@ contract UpgradeableModularAccountTest is AccountTestBase {

// singleSignerValidation.ownerOf(address(account1));

bytes memory signature =
abi.encodePacked(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID, r, s, v);
bytes memory signature = abi.encodePacked(_signerValidation, r, s, v);

bytes4 validationResult = IERC1271(address(account1)).isValidSignature(message, signature);

Expand Down
5 changes: 4 additions & 1 deletion test/module/AllowlistModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntry
import {UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol";

import {HookConfigLib} from "../../src/helpers/HookConfigLib.sol";
import {ModuleEntity} from "../../src/helpers/ModuleEntityLib.sol";
import {ModuleEntity, ModuleEntityLib} from "../../src/helpers/ModuleEntityLib.sol";
import {Call} from "../../src/interfaces/IStandardExecutor.sol";

import {AllowlistModule} from "../../src/modules/permissionhooks/AllowlistModule.sol";
Expand All @@ -22,6 +22,9 @@ contract AllowlistModuleTest is CustomValidationTestBase {
Counter[] public counters;

function setUp() public {
_signerValidation =
ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID);

allowlistModule = new AllowlistModule();

counters = new Counter[](10);
Expand Down
46 changes: 7 additions & 39 deletions test/utils/AccountTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ abstract contract AccountTestBase is OptimizedTest {
singleSignerValidation = _deploySingleSignerValidation();
factory = new SingleSignerFactoryFixture(entryPoint, singleSignerValidation);

account1 = factory.createAccount(owner1, 0);
account1 = factory.createAccountWithFallbackValidation(owner1, 0);
vm.deal(address(account1), 100 ether);

_signerValidation =
ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID);
_signerValidation = ModuleEntity.wrap(bytes24(type(uint192).max));
}

function _runExecUserOp(address target, bytes memory callData) internal {
Expand Down Expand Up @@ -102,11 +101,7 @@ abstract contract AccountTestBase is OptimizedTest {
bytes32 userOpHash = entryPoint.getUserOpHash(userOp);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner1Key, userOpHash.toEthSignedMessageHash());

userOp.signature = _encodeSignature(
ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID),
GLOBAL_VALIDATION,
abi.encodePacked(r, s, v)
);
userOp.signature = _encodeSignature(_signerValidation, GLOBAL_VALIDATION, abi.encodePacked(r, s, v));

PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;
Expand Down Expand Up @@ -153,50 +148,23 @@ abstract contract AccountTestBase is OptimizedTest {
}

vm.prank(owner1);
account1.executeWithAuthorization(
callData,
_encodeSignature(
ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID),
GLOBAL_VALIDATION,
""
)
);
account1.executeWithAuthorization(callData, _encodeSignature(_signerValidation, GLOBAL_VALIDATION, ""));
}

// Always expects a revert, even if the revert data is zero-length.
function _runtimeCallExpFail(bytes memory callData, bytes memory expectedRevertData) internal {
vm.expectRevert(expectedRevertData);

vm.prank(owner1);
account1.executeWithAuthorization(
callData,
_encodeSignature(
ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID),
GLOBAL_VALIDATION,
""
)
);
account1.executeWithAuthorization(callData, _encodeSignature(_signerValidation, GLOBAL_VALIDATION, ""));
}

function _transferOwnershipToTest() internal {
// Transfer ownership to test contract for easier invocation.
vm.prank(owner1);
account1.executeWithAuthorization(
abi.encodeCall(
account1.execute,
(
address(singleSignerValidation),
0,
abi.encodeCall(
SingleSignerValidation.transferSigner, (TEST_DEFAULT_VALIDATION_ENTITY_ID, address(this))
)
)
),
_encodeSignature(
ModuleEntityLib.pack(address(singleSignerValidation), TEST_DEFAULT_VALIDATION_ENTITY_ID),
GLOBAL_VALIDATION,
""
)
abi.encodeCall(account1.updateFallbackSigner, (address(this))),
_encodeSignature(_signerValidation, GLOBAL_VALIDATION, "")
);
}

Expand Down

0 comments on commit df8f80e

Please sign in to comment.