diff --git a/test/account/GlobalValidationTest.t.sol b/test/account/GlobalValidationTest.t.sol index c242657c..9f40f806 100644 --- a/test/account/GlobalValidationTest.t.sol +++ b/test/account/GlobalValidationTest.t.sol @@ -5,23 +5,28 @@ import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interface import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol"; +import {FunctionReferenceLib} from "../../src/helpers/FunctionReferenceLib.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; -import {GlobalValidationFactoryFixture} from "../mocks/GlobalValidationFactoryFixture.sol"; contract GlobalValidationTest is AccountTestBase { using MessageHashUtils for bytes32; - GlobalValidationFactoryFixture public globalValidationFactoryFixture; - address public ethRecipient; + // A separate account and owner that isn't deployed yet, used to test initcode + address public owner2; + uint256 public owner2Key; + UpgradeableModularAccount public account2; + function setUp() public { - globalValidationFactoryFixture = new GlobalValidationFactoryFixture(entryPoint, singleOwnerPlugin); + (owner2, owner2Key) = makeAddrAndKey("owner2"); - account1 = UpgradeableModularAccount(payable(globalValidationFactoryFixture.getAddress(owner1, 0))); + // Compute counterfactual address + account2 = UpgradeableModularAccount(payable(factory.getAddress(owner2, 0))); + vm.deal(address(account2), 100 ether); - vm.deal(address(account1), 100 ether); + _ownerValidation = FunctionReferenceLib.pack(address(singleOwnerPlugin), TEST_DEFAULT_OWNER_FUNCTION_ID); ethRecipient = makeAddr("ethRecipient"); vm.deal(ethRecipient, 1 wei); @@ -29,12 +34,9 @@ contract GlobalValidationTest is AccountTestBase { function test_globalValidation_userOp_simple() public { PackedUserOperation memory userOp = PackedUserOperation({ - sender: address(account1), + sender: address(account2), nonce: 0, - initCode: abi.encodePacked( - globalValidationFactoryFixture, - abi.encodeCall(globalValidationFactoryFixture.createAccount, (owner1, 0)) - ), + initCode: abi.encodePacked(address(factory), abi.encodeCall(factory.createAccount, (owner2, 0))), callData: abi.encodeCall(UpgradeableModularAccount.execute, (ethRecipient, 1 wei, "")), accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, @@ -45,7 +47,7 @@ contract GlobalValidationTest is AccountTestBase { // Generate signature bytes32 userOpHash = entryPoint.getUserOpHash(userOp); - (uint8 v, bytes32 r, bytes32 s) = vm.sign(owner1Key, userOpHash.toEthSignedMessageHash()); + (uint8 v, bytes32 r, bytes32 s) = vm.sign(owner2Key, userOpHash.toEthSignedMessageHash()); userOp.signature = _encodeSignature(_ownerValidation, GLOBAL_VALIDATION, abi.encodePacked(r, s, v)); PackedUserOperation[] memory userOps = new PackedUserOperation[](1); @@ -58,10 +60,10 @@ contract GlobalValidationTest is AccountTestBase { function test_globalValidation_runtime_simple() public { // Deploy the account first - globalValidationFactoryFixture.createAccount(owner1, 0); + factory.createAccount(owner2, 0); - vm.prank(owner1); - account1.executeWithAuthorization( + vm.prank(owner2); + account2.executeWithAuthorization( abi.encodeCall(UpgradeableModularAccount.execute, (ethRecipient, 1 wei, "")), _encodeSignature(_ownerValidation, GLOBAL_VALIDATION, "") ); diff --git a/test/account/SelfCallAuthorization.t.sol b/test/account/SelfCallAuthorization.t.sol index c97194fd..5bcf64b3 100644 --- a/test/account/SelfCallAuthorization.t.sol +++ b/test/account/SelfCallAuthorization.t.sol @@ -11,23 +11,14 @@ import {FunctionReference, FunctionReferenceLib} from "../../src/helpers/Functio import {ValidationConfigLib} from "../../src/helpers/ValidationConfigLib.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; -import {GlobalValidationFactoryFixture} from "../mocks/GlobalValidationFactoryFixture.sol"; import {ComprehensivePlugin} from "../mocks/plugins/ComprehensivePlugin.sol"; contract SelfCallAuthorizationTest is AccountTestBase { - GlobalValidationFactoryFixture public globalValidationFactoryFixture; - ComprehensivePlugin public comprehensivePlugin; FunctionReference public comprehensivePluginValidation; function setUp() public { - globalValidationFactoryFixture = new GlobalValidationFactoryFixture(entryPoint, singleOwnerPlugin); - - account1 = UpgradeableModularAccount(payable(globalValidationFactoryFixture.createAccount(owner1, 0))); - - vm.deal(address(account1), 100 ether); - // install the comprehensive plugin to get new exec functions with different validations configured. comprehensivePlugin = new ComprehensivePlugin(); diff --git a/test/mocks/GlobalValidationFactoryFixture.sol b/test/mocks/GlobalValidationFactoryFixture.sol deleted file mode 100644 index abe8c1c9..00000000 --- a/test/mocks/GlobalValidationFactoryFixture.sol +++ /dev/null @@ -1,84 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.19; - -import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; -import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; -import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; - -import {UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol"; -import {ValidationConfigLib} from "../../src/helpers/ValidationConfigLib.sol"; -import {SingleOwnerPlugin} from "../../src/plugins/owner/SingleOwnerPlugin.sol"; - -import {OptimizedTest} from "../utils/OptimizedTest.sol"; -import {TEST_DEFAULT_OWNER_FUNCTION_ID} from "../utils/TestConstants.sol"; - -contract GlobalValidationFactoryFixture is OptimizedTest { - UpgradeableModularAccount public accountImplementation; - SingleOwnerPlugin public singleOwnerPlugin; - bytes32 private immutable _PROXY_BYTECODE_HASH; - - uint32 public constant UNSTAKE_DELAY = 1 weeks; - - IEntryPoint public entryPoint; - - address public self; - - bytes32 public singleOwnerPluginManifestHash; - - constructor(IEntryPoint _entryPoint, SingleOwnerPlugin _singleOwnerPlugin) { - entryPoint = _entryPoint; - accountImplementation = _deployUpgradeableModularAccount(_entryPoint); - _PROXY_BYTECODE_HASH = keccak256( - abi.encodePacked(type(ERC1967Proxy).creationCode, abi.encode(address(accountImplementation), "")) - ); - singleOwnerPlugin = _singleOwnerPlugin; - self = address(this); - // The manifest hash is set this way in this factory just for testing purposes. - // For production factories the manifest hashes should be passed as a constructor argument. - singleOwnerPluginManifestHash = keccak256(abi.encode(singleOwnerPlugin.pluginManifest())); - } - - /** - * create an account, and return its address. - * returns the address even if the account is already deployed. - * Note that during user operation execution, this method is called only if the account is not deployed. - * This method returns an existing account address so that entryPoint.getSenderAddress() would work even after - * account creation - */ - function createAccount(address owner, uint256 salt) public returns (UpgradeableModularAccount) { - address addr = Create2.computeAddress(getSalt(owner, salt), _PROXY_BYTECODE_HASH); - - // short circuit if exists - if (addr.code.length == 0) { - bytes memory pluginInstallData = abi.encode(TEST_DEFAULT_OWNER_FUNCTION_ID, owner); - // not necessary to check return addr since next call will fail if so - new ERC1967Proxy{salt: getSalt(owner, salt)}(address(accountImplementation), ""); - - // point proxy to actual implementation and init plugins - UpgradeableModularAccount(payable(addr)).initializeWithValidation( - ValidationConfigLib.pack(address(singleOwnerPlugin), TEST_DEFAULT_OWNER_FUNCTION_ID, true, true), - new bytes4[](0), - pluginInstallData, - "", - "" - ); - } - - return UpgradeableModularAccount(payable(addr)); - } - - /** - * calculate the counterfactual address of this account as it would be returned by createAccount() - */ - function getAddress(address owner, uint256 salt) public view returns (address) { - return Create2.computeAddress(getSalt(owner, salt), _PROXY_BYTECODE_HASH); - } - - function addStake() external payable { - entryPoint.addStake{value: msg.value}(UNSTAKE_DELAY); - } - - function getSalt(address owner, uint256 salt) public pure returns (bytes32) { - return keccak256(abi.encodePacked(owner, salt)); - } -}