From f0a36432dea2582601d76c2cf9e4a6d5d2133b24 Mon Sep 17 00:00:00 2001 From: howydev <132113803+howydev@users.noreply.github.com> Date: Sat, 20 Apr 2024 17:04:47 -0400 Subject: [PATCH] chore: update PackedUO struct usage --- test/account/UpgradeableModularAccount.t.sol | 41 ++++++++------------ test/comparison/CompareSimpleAccount.t.sol | 32 +++++++-------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/test/account/UpgradeableModularAccount.t.sol b/test/account/UpgradeableModularAccount.t.sol index 6d4ebeeb..23af820b 100644 --- a/test/account/UpgradeableModularAccount.t.sol +++ b/test/account/UpgradeableModularAccount.t.sol @@ -42,6 +42,11 @@ contract UpgradeableModularAccountTest is AccountTestBase { event PluginUninstalled(address indexed plugin, bool indexed callbacksSucceeded); event ReceivedCall(bytes msgData, uint256 msgValue); + // helper function to compress 2 gas values into a single bytes32 + function _encodeGas(uint256 g1, uint256 g2) internal returns (bytes32) { + return bytes32(uint256(g1 << 128 + uint128(g2))); + } + function setUp() public { tokenReceiverPlugin = _deployTokenReceiverPlugin(); @@ -67,11 +72,9 @@ contract UpgradeableModularAccountTest is AccountTestBase { nonce: 0, initCode: "", callData: abi.encodeCall(UpgradeableModularAccount.execute, (ethRecipient, 1 wei, "")), - callGasLimit: CALL_GAS_LIMIT, - verificationGasLimit: VERIFICATION_GAS_LIMIT, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 1, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 1), paymasterAndData: "", signature: "" }); @@ -95,11 +98,9 @@ contract UpgradeableModularAccountTest is AccountTestBase { nonce: 0, initCode: abi.encodePacked(address(factory), abi.encodeCall(factory.createAccount, (owner2, 0))), callData: abi.encodeCall(SingleOwnerPlugin.transferOwnership, (owner2)), - callGasLimit: CALL_GAS_LIMIT, - verificationGasLimit: VERIFICATION_GAS_LIMIT, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 2, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 2), paymasterAndData: "", signature: "" }); @@ -123,11 +124,9 @@ contract UpgradeableModularAccountTest is AccountTestBase { nonce: 0, initCode: abi.encodePacked(address(factory), abi.encodeCall(factory.createAccount, (owner2, 0))), callData: abi.encodeCall(UpgradeableModularAccount.execute, (recipient, 1 wei, "")), - callGasLimit: CALL_GAS_LIMIT, - verificationGasLimit: VERIFICATION_GAS_LIMIT, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 2, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 1), paymasterAndData: "", signature: "" }); @@ -151,11 +150,9 @@ contract UpgradeableModularAccountTest is AccountTestBase { nonce: 0, initCode: "", callData: abi.encodeCall(UpgradeableModularAccount.execute, (ethRecipient, 1 wei, "")), - callGasLimit: CALL_GAS_LIMIT, - verificationGasLimit: VERIFICATION_GAS_LIMIT, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 1, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 1), paymasterAndData: "", signature: "" }); @@ -181,11 +178,9 @@ contract UpgradeableModularAccountTest is AccountTestBase { callData: abi.encodeCall( UpgradeableModularAccount.execute, (address(counter), 0, abi.encodeCall(counter.increment, ())) ), - callGasLimit: CALL_GAS_LIMIT, - verificationGasLimit: VERIFICATION_GAS_LIMIT, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 1, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 1), paymasterAndData: "", signature: "" }); @@ -214,11 +209,9 @@ contract UpgradeableModularAccountTest is AccountTestBase { nonce: 0, initCode: "", callData: abi.encodeCall(UpgradeableModularAccount.executeBatch, (calls)), - callGasLimit: CALL_GAS_LIMIT, - verificationGasLimit: VERIFICATION_GAS_LIMIT, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 1, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 1), paymasterAndData: "", signature: "" }); diff --git a/test/comparison/CompareSimpleAccount.t.sol b/test/comparison/CompareSimpleAccount.t.sol index 88512560..ba70d79b 100644 --- a/test/comparison/CompareSimpleAccount.t.sol +++ b/test/comparison/CompareSimpleAccount.t.sol @@ -32,6 +32,14 @@ contract CompareSimpleAccountTest is Test { Counter public counter; + uint256 public constant CALL_GAS_LIMIT = 500000; + uint256 public constant VERIFICATION_GAS_LIMIT = 500000; + + // helper function to compress 2 gas values into a single bytes32 + function _encodeGas(uint256 g1, uint256 g2) internal returns (bytes32) { + return bytes32(uint256(g1 << 128 + uint128(g2))); + } + function setUp() public { entryPoint = new EntryPoint(); (owner1, owner1Key) = makeAddrAndKey("owner1"); @@ -59,11 +67,9 @@ contract CompareSimpleAccountTest is Test { nonce: 0, initCode: abi.encodePacked(address(factory), abi.encodeCall(factory.createAccount, (owner1, 0))), callData: abi.encodeCall(SimpleAccount.execute, (beneficiary, 1, "")), - callGasLimit: 5000000, - verificationGasLimit: 5000000, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 2, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 2), paymasterAndData: "", signature: "" }); @@ -84,11 +90,9 @@ contract CompareSimpleAccountTest is Test { nonce: 0, initCode: abi.encodePacked(address(factory), abi.encodeCall(factory.createAccount, (owner1, 0))), callData: "", - callGasLimit: 5000000, - verificationGasLimit: 5000000, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 2, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 2), paymasterAndData: "", signature: "" }); @@ -109,11 +113,9 @@ contract CompareSimpleAccountTest is Test { nonce: 0, initCode: "", callData: abi.encodeCall(SimpleAccount.execute, (beneficiary, 1, "")), - callGasLimit: 5000000, - verificationGasLimit: 5000000, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 2, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 2), paymasterAndData: "", signature: "" }); @@ -136,11 +138,9 @@ contract CompareSimpleAccountTest is Test { callData: abi.encodeCall( SimpleAccount.execute, (address(counter), 0, abi.encodeCall(Counter.increment, ())) ), - callGasLimit: 5000000, - verificationGasLimit: 5000000, + accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT), preVerificationGas: 0, - maxFeePerGas: 2, - maxPriorityFeePerGas: 1, + gasFees: _encodeGas(1, 2), paymasterAndData: "", signature: "" });