Skip to content
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: [v0.8-develop] remove duplicate test factory [2/2] #92

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading