From c9f8f5ad7956b7354498c26504fcd570c44946da Mon Sep 17 00:00:00 2001 From: Fangting Liu Date: Wed, 17 Jul 2024 11:14:40 -0700 Subject: [PATCH 1/3] add PluginEntityLib test --- test/libraries/PluginEntityLib.t.sol | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/libraries/PluginEntityLib.t.sol diff --git a/test/libraries/PluginEntityLib.t.sol b/test/libraries/PluginEntityLib.t.sol new file mode 100644 index 00000000..c93e1b61 --- /dev/null +++ b/test/libraries/PluginEntityLib.t.sol @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.19; + +import {Test} from "forge-std/Test.sol"; + +import {PluginEntityLib} from "../../src/helpers/PluginEntityLib.sol"; +import {PluginEntity} from "../../src/interfaces/IPluginManager.sol"; + +contract PluginEntityLibTest is Test { + using PluginEntityLib for PluginEntity; + + function testFuzz_pluginEntity_packing(address addr, uint32 entityId) public { + // console.log("addr: ", addr); + // console.log("entityId: ", vm.toString(entityId)); + PluginEntity fr = PluginEntityLib.pack(addr, entityId); + // console.log("packed: ", vm.toString(PluginEntity.unwrap(fr))); + (address addr2, uint32 entityId2) = PluginEntityLib.unpack(fr); + // console.log("addr2: ", addr2); + // console.log("entityId2: ", vm.toString(entityId2)); + assertEq(addr, addr2); + assertEq(entityId, entityId2); + } + + function testFuzz_pluginEntity_operators(PluginEntity a, PluginEntity b) public { + assertTrue(a.eq(a)); + assertTrue(b.eq(b)); + + if (PluginEntity.unwrap(a) == PluginEntity.unwrap(b)) { + assertTrue(a.eq(b)); + assertTrue(b.eq(a)); + assertFalse(a.notEq(b)); + assertFalse(b.notEq(a)); + } else { + assertTrue(a.notEq(b)); + assertTrue(b.notEq(a)); + assertFalse(a.eq(b)); + assertFalse(b.eq(a)); + } + } +} From 063e9d26142845ddeaeaf92d1b4185acc464d17d Mon Sep 17 00:00:00 2001 From: Fangting Liu Date: Wed, 17 Jul 2024 11:15:06 -0700 Subject: [PATCH 2/3] update old ref to functionReference --- src/account/AccountStorage.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/account/AccountStorage.sol b/src/account/AccountStorage.sol index ea2f4551..7b4b083e 100644 --- a/src/account/AccountStorage.sol +++ b/src/account/AccountStorage.sol @@ -59,8 +59,8 @@ function getAccountStorage() pure returns (AccountStorage storage _storage) { using EnumerableSet for EnumerableSet.Bytes32Set; -function toSetValue(PluginEntity functionReference) pure returns (bytes32) { - return bytes32(PluginEntity.unwrap(functionReference)); +function toSetValue(PluginEntity pluginEntity) pure returns (bytes32) { + return bytes32(PluginEntity.unwrap(pluginEntity)); } function toPluginEntity(bytes32 setValue) pure returns (PluginEntity) { From 47da6e0561bca9b2cf0ebea4a0947b7937f2488e Mon Sep 17 00:00:00 2001 From: Fangting Liu Date: Wed, 17 Jul 2024 11:16:46 -0700 Subject: [PATCH 3/3] add comments for isPublic --- src/account/AccountStorage.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/account/AccountStorage.sol b/src/account/AccountStorage.sol index 7b4b083e..dbf0d956 100644 --- a/src/account/AccountStorage.sol +++ b/src/account/AccountStorage.sol @@ -15,7 +15,8 @@ struct SelectorData { // The plugin that implements this execution function. // If this is a native function, the address must remain address(0). address plugin; - // Whether or not the function needs runtime validation, or can be called by anyone. + // Whether or not the function needs runtime validation, or can be called by anyone. The function can still be + // state changing if this flag is set to true. // Note that even if this is set to true, user op validation will still be required, otherwise anyone could // drain the account of native tokens by wasting gas. bool isPublic;