Skip to content

Commit

Permalink
remove duplicate test factory
Browse files Browse the repository at this point in the history
  • Loading branch information
adamegyed committed Jul 11, 2024
1 parent d50ae10 commit 9d56e26
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 108 deletions.
32 changes: 17 additions & 15 deletions test/account/GlobalValidationTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,38 @@ 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);
}

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,
Expand All @@ -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);
Expand All @@ -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, "")
);
Expand Down
9 changes: 0 additions & 9 deletions test/account/SelfCallAuthorization.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
84 changes: 0 additions & 84 deletions test/mocks/GlobalValidationFactoryFixture.sol

This file was deleted.

0 comments on commit 9d56e26

Please sign in to comment.