diff --git a/contracts/IPAccountStorage.sol b/contracts/IPAccountStorage.sol index 0cd218d04..18d088d3c 100644 --- a/contracts/IPAccountStorage.sol +++ b/contracts/IPAccountStorage.sol @@ -20,19 +20,6 @@ contract IPAccountStorage is ERC165, IIPAccountStorage { mapping(bytes32 => mapping(bytes32 => address)) public addressData; mapping(bytes32 => mapping(bytes32 => bool)) public boolData; - /// @inheritdoc IIPAccountStorage - function setString(bytes32 key, string calldata value) external { - stringData[_toBytes32(msg.sender)][key] = value; - } - /// @inheritdoc IIPAccountStorage - function getString(bytes32 key) external view returns (string memory) { - return stringData[_toBytes32(msg.sender)][key]; - } - /// @inheritdoc IIPAccountStorage - function getString(bytes32 namespace, bytes32 key) external view returns (string memory) { - return stringData[namespace][key]; - } - /// @inheritdoc IIPAccountStorage function setBytes(bytes32 key, bytes calldata value) external { bytesData[_toBytes32(msg.sender)][key] = value; @@ -59,45 +46,7 @@ contract IPAccountStorage is ERC165, IIPAccountStorage { return bytes32Data[namespace][key]; } - /// @inheritdoc IIPAccountStorage - function setUint256(bytes32 key, uint256 value) external { - uint256Data[_toBytes32(msg.sender)][key] = value; - } - /// @inheritdoc IIPAccountStorage - function getUint256(bytes32 key) external view returns (uint256) { - return uint256Data[_toBytes32(msg.sender)][key]; - } - /// @inheritdoc IIPAccountStorage - function getUint256(bytes32 namespace, bytes32 key) external view returns (uint256) { - return uint256Data[namespace][key]; - } - - /// @inheritdoc IIPAccountStorage - function setAddress(bytes32 key, address value) external { - addressData[_toBytes32(msg.sender)][key] = value; - } - /// @inheritdoc IIPAccountStorage - function getAddress(bytes32 key) external view returns (address) { - return addressData[_toBytes32(msg.sender)][key]; - } - /// @inheritdoc IIPAccountStorage - function getAddress(bytes32 namespace, bytes32 key) external view returns (address) { - return addressData[namespace][key]; - } - - /// @inheritdoc IIPAccountStorage - function getBool(bytes32 key) external view returns (bool) { - return boolData[_toBytes32(msg.sender)][key]; - } - /// @inheritdoc IIPAccountStorage - function getBool(bytes32 namespace, bytes32 key) external view returns (bool) { - return boolData[namespace][key]; - } - /// @inheritdoc IIPAccountStorage - function setBool(bytes32 key, bool value) external { - boolData[_toBytes32(msg.sender)][key] = value; - } - + /// @notice ERC165 interface identifier for IIPAccountStorage function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165) returns (bool) { return interfaceId == type(IIPAccountStorage).interfaceId || super.supportsInterface(interfaceId); } diff --git a/contracts/interfaces/IIPAccountStorage.sol b/contracts/interfaces/IIPAccountStorage.sol index 560d8b3bd..f088dd197 100644 --- a/contracts/interfaces/IIPAccountStorage.sol +++ b/contracts/interfaces/IIPAccountStorage.sol @@ -16,22 +16,6 @@ pragma solidity ^0.8.23; /// - Only the owning Module (i.e., the Module whose address is used as the namespace) can write data into /// its respective namespace. interface IIPAccountStorage { - /// @dev Sets a string value under a given key within the default namespace, determined by `msg.sender`. - /// @param key The key under which to store the value. - /// @param value The string value to be stored. - function setString(bytes32 key, string calldata value) external; - - /// @dev Retrieves a string value by a given key from the default namespace. - /// @param key The key whose value is to be retrieved. - /// @return The string value stored under the specified key. - function getString(bytes32 key) external view returns (string memory); - - /// @dev Retrieves a string value by a given key from a specified namespace. - /// @param namespace The namespace from which to retrieve the value. - /// @param key The key whose value is to be retrieved. - /// @return The string value stored under the specified key in the given namespace. - function getString(bytes32 namespace, bytes32 key) external view returns (string memory); - /// @dev Sets a bytes value under a given key within the default namespace, determined by `msg.sender`. /// @param key The key under which to store the value. /// @param value The bytes value to be stored. @@ -63,52 +47,4 @@ interface IIPAccountStorage { /// @param key The key whose value is to be retrieved. /// @return The bytes32 value stored under the specified key in the given namespace. function getBytes32(bytes32 namespace, bytes32 key) external view returns (bytes32); - - /// @dev Sets a uint256 value under a given key within the default namespace, determined by `msg.sender`. - /// @param key The key under which to store the value. - /// @param value The uint256 value to be stored. - function setUint256(bytes32 key, uint256 value) external; - - /// @dev Retrieves a uint256 value by a given key from the default namespace. - /// @param key The key whose value is to be retrieved. - /// @return The uint256 value stored under the specified key. - function getUint256(bytes32 key) external view returns (uint256); - - /// @dev Retrieves a uint256 value by a given key from a specified namespace. - /// @param namespace The namespace from which to retrieve the value. - /// @param key The key whose value is to be retrieved. - /// @return The uint256 value stored under the specified key in the given namespace. - function getUint256(bytes32 namespace, bytes32 key) external view returns (uint256); - - /// @dev Sets an address value under a given key within the default namespace, determined by `msg.sender`. - /// @param key The key under which to store the value. - /// @param value The address value to be stored. - function setAddress(bytes32 key, address value) external; - - /// @dev Retrieves an address value by a given key from the default namespace. - /// @param key The key whose value is to be retrieved. - /// @return The address value stored under the specified key. - function getAddress(bytes32 key) external view returns (address); - - /// @dev Retrieves an address value by a given key from a specified namespace. - /// @param namespace The namespace from which to retrieve the value. - /// @param key The key whose value is to be retrieved. - /// @return The address value stored under the specified key in the given namespace. - function getAddress(bytes32 namespace, bytes32 key) external view returns (address); - - /// @dev Sets a boolean value under a given key within the default namespace, determined by `msg.sender`. - /// @param key The key under which to store the value. - /// @param value The boolean value to be stored. - function setBool(bytes32 key, bool value) external; - - /// @dev Retrieves a boolean value by a given key from the default namespace. - /// @param key The key whose value is to be retrieved. - /// @return The boolean value stored under the specified key. - function getBool(bytes32 key) external view returns (bool); - - /// @dev Retrieves a boolean value by a given key from a specified namespace. - /// @param namespace The namespace from which to retrieve the value. - /// @param key The key whose value is to be retrieved. - /// @return The boolean value stored under the specified key in the given namespace. - function getBool(bytes32 namespace, bytes32 key) external view returns (bool); } diff --git a/contracts/lib/IPAccountStorageOps.sol b/contracts/lib/IPAccountStorageOps.sol index 8e78ba6ed..ba3018bc0 100644 --- a/contracts/lib/IPAccountStorageOps.sol +++ b/contracts/lib/IPAccountStorageOps.sol @@ -16,13 +16,42 @@ library IPAccountStorageOps { using ShortStrings for *; using Strings for *; + /// @dev Sets a string value under a given key within the default namespace, determined by `msg.sender`. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param key The key under which to store the value. + /// @param value The string value to be stored. + function setString(IIPAccountStorage ipStorage, bytes32 key, string memory value) internal { + ipStorage.setBytes(key, bytes(value)); + } + + /// @dev Retrieves a string value by a given key from the default namespace. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param key The key whose value is to be retrieved. + /// @return The string value stored under the specified key. + function getString(IIPAccountStorage ipStorage, bytes32 key) internal view returns (string memory) { + return string(ipStorage.getBytes(key)); + } + + /// @dev Retrieves a string value by a given key from a specified namespace. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param namespace The namespace from which to retrieve the value. + /// @param key The key whose value is to be retrieved. + /// @return The string value stored under the specified key in the given namespace. + function getString( + IIPAccountStorage ipStorage, + bytes32 namespace, + bytes32 key + ) internal view returns (string memory) { + return string(ipStorage.getBytes(namespace, key)); + } + /// @notice Sets a string value in the storage using a `ShortString` key. /// @dev Converts the `ShortString` key to a `bytes32` representation before storing the value. /// @param ipStorage The instance of the IPAccountStorage contract. /// @param key The `ShortString` key under which to store the value. /// @param value The string value to be stored. function setString(IIPAccountStorage ipStorage, ShortString key, string memory value) internal { - ipStorage.setString(toBytes32(key), value); + setString(ipStorage, toBytes32(key), value); } /// @notice Retrieves a string value from the storage using a `ShortString` key. @@ -31,7 +60,7 @@ library IPAccountStorageOps { /// @param key The `ShortString` key whose value is to be retrieved. /// @return The string value stored under the specified key. function getString(IIPAccountStorage ipStorage, ShortString key) internal view returns (string memory) { - return ipStorage.getString(toBytes32(key)); + return getString(ipStorage, toBytes32(key)); } /// @notice Retrieves a string value from the storage under a specified namespace using a bytes32 key. @@ -44,7 +73,7 @@ library IPAccountStorageOps { address namespace, bytes32 key ) internal view returns (string memory) { - return ipStorage.getString(toBytes32(namespace), key); + return getString(ipStorage, toBytes32(namespace), key); } /// @notice Retrieves a string value from the storage under a specified namespace using a `ShortString` key. @@ -57,7 +86,32 @@ library IPAccountStorageOps { address namespace, ShortString key ) internal view returns (string memory) { - return ipStorage.getString(toBytes32(namespace), toBytes32(key)); + return getString(ipStorage, toBytes32(namespace), toBytes32(key)); + } + + /// @dev Sets an address value under a given key within the default namespace, determined by `msg.sender`. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param key The key under which to store the value. + /// @param value The address value to be stored. + function setAddress(IIPAccountStorage ipStorage, bytes32 key, address value) internal { + ipStorage.setBytes32(key, toBytes32(value)); + } + + /// @dev Retrieves an address value by a given key from the default namespace. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param key The key whose value is to be retrieved. + /// @return The address value stored under the specified key. + function getAddress(IIPAccountStorage ipStorage, bytes32 key) internal view returns (address) { + return address(uint160(uint256(ipStorage.getBytes32(key)))); + } + + /// @dev Retrieves an address value by a given key from a specified namespace. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param namespace The namespace from which to retrieve the value. + /// @param key The key whose value is to be retrieved. + /// @return The address value stored under the specified key in the given namespace. + function getAddress(IIPAccountStorage ipStorage, bytes32 namespace, bytes32 key) internal view returns (address) { + return address(uint160(uint256(ipStorage.getBytes32(namespace, key)))); } /// @notice Sets an address value in the storage using a `ShortString` key. @@ -67,7 +121,7 @@ library IPAccountStorageOps { /// @param key The `ShortString` key under which to store the address value. /// @param value The address value to be stored. function setAddress(IIPAccountStorage ipStorage, ShortString key, address value) internal { - ipStorage.setAddress(toBytes32(key), value); + setAddress(ipStorage, toBytes32(key), value); } /// @notice Retrieves an address value from the storage using a `ShortString` key. @@ -77,7 +131,7 @@ library IPAccountStorageOps { /// @param key The `ShortString` key whose address value is to be retrieved. /// @return The address value stored under the specified key. function getAddress(IIPAccountStorage ipStorage, ShortString key) internal view returns (address) { - return ipStorage.getAddress(toBytes32(key)); + return getAddress(ipStorage, toBytes32(key)); } /// @notice Retrieves an address value from the storage under a specified namespace using a bytes32 key. @@ -87,7 +141,7 @@ library IPAccountStorageOps { /// @param key The bytes32 key whose address value is to be retrieved. /// @return The address value stored under the specified key in the given namespace. function getAddress(IIPAccountStorage ipStorage, address namespace, bytes32 key) internal view returns (address) { - return ipStorage.getAddress(toBytes32(namespace), key); + return getAddress(ipStorage, toBytes32(namespace), key); } /// @notice Retrieves an address value from the storage under a specified namespace using a `ShortString` key. @@ -101,7 +155,32 @@ library IPAccountStorageOps { address namespace, ShortString key ) internal view returns (address) { - return ipStorage.getAddress(toBytes32(namespace), toBytes32(key)); + return getAddress(ipStorage, toBytes32(namespace), toBytes32(key)); + } + + /// @dev Sets a uint256 value under a given key within the default namespace, determined by `msg.sender`. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param key The key under which to store the value. + /// @param value The uint256 value to be stored. + function setUint256(IIPAccountStorage ipStorage, bytes32 key, uint256 value) internal { + ipStorage.setBytes32(key, bytes32(value)); + } + + /// @dev Retrieves a uint256 value by a given key from the default namespace. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param key The key whose value is to be retrieved. + /// @return The uint256 value stored under the specified key. + function getUint256(IIPAccountStorage ipStorage, bytes32 key) internal view returns (uint256) { + return uint256(ipStorage.getBytes32(key)); + } + + /// @dev Retrieves a uint256 value by a given key from a specified namespace. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param namespace The namespace from which to retrieve the value. + /// @param key The key whose value is to be retrieved. + /// @return The uint256 value stored under the specified key in the given namespace. + function getUint256(IIPAccountStorage ipStorage, bytes32 namespace, bytes32 key) internal view returns (uint256) { + return uint256(ipStorage.getBytes32(namespace, key)); } /// @notice Sets a uint256 value in the storage using a `ShortString` key. @@ -111,7 +190,7 @@ library IPAccountStorageOps { /// @param key The `ShortString` key under which to store the uint256 value. /// @param value The uint256 value to be stored. function setUint256(IIPAccountStorage ipStorage, ShortString key, uint256 value) internal { - ipStorage.setUint256(toBytes32(key), value); + setUint256(ipStorage, toBytes32(key), value); } /// @notice Retrieves a uint256 value from the storage using a `ShortString` key. @@ -121,7 +200,7 @@ library IPAccountStorageOps { /// @param key The `ShortString` key whose uint256 value is to be retrieved. /// @return The uint256 value stored under the specified key. function getUint256(IIPAccountStorage ipStorage, ShortString key) internal view returns (uint256) { - return ipStorage.getUint256(toBytes32(key)); + return getUint256(ipStorage, toBytes32(key)); } /// @notice Retrieves a uint256 value from the storage under a specified namespace using a bytes32 key. @@ -131,7 +210,7 @@ library IPAccountStorageOps { /// @param key The bytes32 key whose uint256 value is to be retrieved. /// @return The uint256 value stored under the specified key in the given namespace. function getUint256(IIPAccountStorage ipStorage, address namespace, bytes32 key) internal view returns (uint256) { - return ipStorage.getUint256(toBytes32(namespace), key); + return getUint256(ipStorage, toBytes32(namespace), key); } /// @notice Retrieves a uint256 value from the storage under a specified namespace using a `ShortString` key. @@ -145,7 +224,32 @@ library IPAccountStorageOps { address namespace, ShortString key ) internal view returns (uint256) { - return ipStorage.getUint256(toBytes32(namespace), toBytes32(key)); + return getUint256(ipStorage, toBytes32(namespace), toBytes32(key)); + } + + /// @dev Sets a boolean value under a given key within the default namespace, determined by `msg.sender`. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param key The key under which to store the value. + /// @param value The boolean value to be stored. + function setBool(IIPAccountStorage ipStorage, bytes32 key, bool value) internal { + ipStorage.setBytes32(key, value ? bytes32(uint256(1)) : bytes32(0)); + } + + /// @dev Retrieves a boolean value by a given key from the default namespace. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param key The key whose value is to be retrieved. + /// @return The boolean value stored under the specified key. + function getBool(IIPAccountStorage ipStorage, bytes32 key) internal view returns (bool) { + return ipStorage.getBytes32(key) != 0; + } + + /// @dev Retrieves a boolean value by a given key from a specified namespace. + /// @param ipStorage The instance of the IPAccountStorage contract. + /// @param namespace The namespace from which to retrieve the value. + /// @param key The key whose value is to be retrieved. + /// @return The boolean value stored under the specified key in the given namespace. + function getBool(IIPAccountStorage ipStorage, bytes32 namespace, bytes32 key) internal view returns (bool) { + return ipStorage.getBytes32(namespace, key) != 0; } /// @notice Sets a bool value in the storage using a `ShortString` key. @@ -155,7 +259,7 @@ library IPAccountStorageOps { /// @param key The `ShortString` key under which to store the bool value. /// @param value The bool value to be stored. function setBool(IIPAccountStorage ipStorage, ShortString key, bool value) internal { - ipStorage.setBool(toBytes32(key), value); + setBool(ipStorage, toBytes32(key), value); } /// @notice Retrieves a bool value from the storage using a `ShortString` key. @@ -165,7 +269,7 @@ library IPAccountStorageOps { /// @param key The `ShortString` key whose bool value is to be retrieved. /// @return The bool value stored under the specified key. function getBool(IIPAccountStorage ipStorage, ShortString key) internal view returns (bool) { - return ipStorage.getBool(toBytes32(key)); + return getBool(ipStorage, toBytes32(key)); } /// @notice Retrieves a bool value from the storage under a specified namespace using a bytes32 key. @@ -175,7 +279,7 @@ library IPAccountStorageOps { /// @param key The bytes32 key whose bool value is to be retrieved. /// @return The bool value stored under the specified key in the given namespace. function getBool(IIPAccountStorage ipStorage, address namespace, bytes32 key) internal view returns (bool) { - return ipStorage.getBool(toBytes32(namespace), key); + return getBool(ipStorage, toBytes32(namespace), key); } /// @notice Retrieves a bool value from the storage under a specified namespace using a `ShortString` key. @@ -185,7 +289,7 @@ library IPAccountStorageOps { /// @param key The `ShortString` key whose bool value is to be retrieved. /// @return The bool value stored under the specified key in the given namespace. function getBool(IIPAccountStorage ipStorage, address namespace, ShortString key) internal view returns (bool) { - return ipStorage.getBool(toBytes32(namespace), toBytes32(key)); + return getBool(ipStorage, toBytes32(namespace), toBytes32(key)); } /// @notice Sets a bytes value in the storage using a `ShortString` key. diff --git a/test/foundry/IPAccountStorage.t.sol b/test/foundry/IPAccountStorage.t.sol index 472b27c53..0048e4df5 100644 --- a/test/foundry/IPAccountStorage.t.sol +++ b/test/foundry/IPAccountStorage.t.sol @@ -101,54 +101,6 @@ contract IPAccountStorageTest is BaseTest { assertEq(result[1], "test2"); } - function test_IPAccountStorage_storeUint256() public { - ipAccount.setUint256("test", 1); - assertEq(ipAccount.getUint256("test"), 1); - } - - function test_IPAccountStorage_readUint256_differentNameSpace() public { - vm.prank(vm.addr(1)); - ipAccount.setUint256("test", 1); - vm.prank(vm.addr(2)); - assertEq(ipAccount.getUint256(_toBytes32(vm.addr(1)), "test"), 1); - } - - function test_IPAccountStorage_storeBool() public { - ipAccount.setBool("test", true); - assertTrue(ipAccount.getBool("test")); - } - - function test_IPAccountStorage_readBool_differentNameSpace() public { - vm.prank(vm.addr(1)); - ipAccount.setBool("test", true); - vm.prank(vm.addr(2)); - assertTrue(ipAccount.getBool(_toBytes32(vm.addr(1)), "test")); - } - - function test_IPAccountStorage_storeString() public { - ipAccount.setString("test", "test"); - assertEq(ipAccount.getString("test"), "test"); - } - - function test_IPAccountStorage_readString_differentNameSpace() public { - vm.prank(vm.addr(1)); - ipAccount.setString("test", "test"); - vm.prank(vm.addr(2)); - assertEq(ipAccount.getString(_toBytes32(vm.addr(1)), "test"), "test"); - } - - function test_IPAccountStorage_storeAddress() public { - ipAccount.setAddress("test", vm.addr(1)); - assertEq(ipAccount.getAddress("test"), vm.addr(1)); - } - - function test_IPAccountStorage_readAddress_differentNameSpace() public { - vm.prank(vm.addr(1)); - ipAccount.setAddress("test", vm.addr(1)); - vm.prank(vm.addr(2)); - assertEq(ipAccount.getAddress(_toBytes32(vm.addr(1)), "test"), vm.addr(1)); - } - function test_IPAccountStorage_storeBytes32() public { ipAccount.setBytes32("test", bytes32(uint256(111))); assertEq(ipAccount.getBytes32("test"), bytes32(uint256(111))); diff --git a/test/foundry/IPAccountStorageOps.t.sol b/test/foundry/IPAccountStorageOps.t.sol index cf4fe9155..80ac39d3b 100644 --- a/test/foundry/IPAccountStorageOps.t.sol +++ b/test/foundry/IPAccountStorageOps.t.sol @@ -39,7 +39,7 @@ contract IPAccountStorageOpsTest is BaseTest { function test_IPAccountStorageOps_setString_bytes32() public { vm.prank(vm.addr(1)); - ipAccount.setString(bytes32("test"), "test"); + IPAccountStorageOps.setString(ipAccount, bytes32("test"), "test"); vm.prank(vm.addr(1)); assertEq(IPAccountStorageOps.getString(ipAccount, "test".toShortString()), "test"); vm.prank(vm.addr(2)); @@ -59,7 +59,7 @@ contract IPAccountStorageOpsTest is BaseTest { function test_IPAccountStorageOps_setAddress_bytes32() public { vm.prank(vm.addr(1)); - ipAccount.setAddress(bytes32("test"), vm.addr(2)); + IPAccountStorageOps.setAddress(ipAccount, bytes32("test"), vm.addr(2)); vm.prank(vm.addr(1)); assertEq(IPAccountStorageOps.getAddress(ipAccount, "test".toShortString()), vm.addr(2)); vm.prank(vm.addr(2)); @@ -79,7 +79,7 @@ contract IPAccountStorageOpsTest is BaseTest { function test_IPAccountStorageOps_setUint256_bytes32() public { vm.prank(vm.addr(1)); - ipAccount.setUint256(bytes32("test"), 1); + IPAccountStorageOps.setUint256(ipAccount, bytes32("test"), 1); vm.prank(vm.addr(1)); assertEq(IPAccountStorageOps.getUint256(ipAccount, "test".toShortString()), 1); vm.prank(vm.addr(2)); @@ -99,7 +99,7 @@ contract IPAccountStorageOpsTest is BaseTest { function test_IPAccountStorageOps_setBool_bytes32() public { vm.prank(vm.addr(1)); - ipAccount.setBool(bytes32("test"), true); + IPAccountStorageOps.setBool(ipAccount, bytes32("test"), true); vm.prank(vm.addr(1)); assertTrue(IPAccountStorageOps.getBool(ipAccount, "test".toShortString())); vm.prank(vm.addr(2)); @@ -147,4 +147,56 @@ contract IPAccountStorageOpsTest is BaseTest { abi.encodePacked("test") ); } + + function test_IPAccountStorage_storeUint256() public { + IPAccountStorageOps.setUint256(ipAccount, "test", 1); + assertEq(IPAccountStorageOps.getUint256(ipAccount, "test"), 1); + } + + function test_IPAccountStorage_readUint256_differentNameSpace() public { + vm.prank(vm.addr(1)); + IPAccountStorageOps.setUint256(ipAccount, "test", 1); + vm.prank(vm.addr(2)); + assertEq(IPAccountStorageOps.getUint256(ipAccount, _toBytes32(vm.addr(1)), "test"), 1); + } + + function test_IPAccountStorage_storeBool() public { + IPAccountStorageOps.setBool(ipAccount, "test", true); + assertTrue(IPAccountStorageOps.getBool(ipAccount, "test")); + } + + function test_IPAccountStorage_readBool_differentNameSpace() public { + vm.prank(vm.addr(1)); + IPAccountStorageOps.setBool(ipAccount, "test", true); + vm.prank(vm.addr(2)); + assertTrue(IPAccountStorageOps.getBool(ipAccount, _toBytes32(vm.addr(1)), "test")); + } + + function test_IPAccountStorage_storeString() public { + IPAccountStorageOps.setString(ipAccount, "test", "test"); + assertEq(IPAccountStorageOps.getString(ipAccount, "test"), "test"); + } + + function test_IPAccountStorage_readString_differentNameSpace() public { + vm.prank(vm.addr(1)); + IPAccountStorageOps.setString(ipAccount, "test", "test"); + vm.prank(vm.addr(2)); + assertEq(IPAccountStorageOps.getString(ipAccount, _toBytes32(vm.addr(1)), "test"), "test"); + } + + function test_IPAccountStorage_storeAddress() public { + IPAccountStorageOps.setAddress(ipAccount, "test", vm.addr(1)); + assertEq(IPAccountStorageOps.getAddress(ipAccount, "test"), vm.addr(1)); + } + + function test_IPAccountStorage_readAddress_differentNameSpace() public { + vm.prank(vm.addr(1)); + IPAccountStorageOps.setAddress(ipAccount, "test", vm.addr(1)); + vm.prank(vm.addr(2)); + assertEq(IPAccountStorageOps.getAddress(ipAccount, _toBytes32(vm.addr(1)), "test"), vm.addr(1)); + } + + function _toBytes32(address a) internal pure returns (bytes32) { + return bytes32(uint256(uint160(a))); + } } diff --git a/test/foundry/mocks/module/MockMetadataModule.sol b/test/foundry/mocks/module/MockMetadataModule.sol index d8a4679e1..b375e23ce 100644 --- a/test/foundry/mocks/module/MockMetadataModule.sol +++ b/test/foundry/mocks/module/MockMetadataModule.sol @@ -5,6 +5,7 @@ import { IModule } from "../../../../contracts/interfaces/modules/base/IModule.s import { IIPAccount } from "../../../../contracts/interfaces/IIPAccount.sol"; import { IIPAccountRegistry } from "../../../../contracts/interfaces/registries/IIPAccountRegistry.sol"; import { IPAccountChecker } from "../../../../contracts/lib/registries/IPAccountChecker.sol"; +import { IPAccountStorageOps } from "../../../../contracts/lib/IPAccountStorageOps.sol"; import { AccessControlled } from "../../../../contracts/access/AccessControlled.sol"; import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import { BaseModule } from "../../../../contracts/modules/BaseModule.sol"; @@ -15,6 +16,7 @@ import { BaseModule } from "../../../../contracts/modules/BaseModule.sol"; contract MockMetadataModule is BaseModule, AccessControlled { using ERC165Checker for address; using IPAccountChecker for IIPAccountRegistry; + using IPAccountStorageOps for IIPAccount; string public name = "MockMetadataModule"; mapping(string => bool) public ipTypesSupported;