diff --git a/src/transform-namespaces.test.ts.md b/src/transform-namespaces.test.ts.md index 54127c8..8a7e283 100644 --- a/src/transform-namespaces.test.ts.md +++ b/src/transform-namespaces.test.ts.md @@ -38,12 +38,17 @@ Generated by [AVA](https://avajs.dev). string s1;␊ }␊ ␊ - // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C2")) - 1)) & ~bytes32(uint256(0xff))␊ - bytes32 private constant C2StorageLocation = 0xf05a05e0e3d15983ea921cad031aaea3040e9d631039045748753d29c5d24800;␊ + /// @dev Consider updating the struct's storage location annotation␊ + /// See https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable#namespaced-storage-layout␊ + function _C2StorageLocation() internal pure virtual returns (bytes32) {␊ + // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C2")) - 1)) & ~bytes32(uint256(0xff))␊ + return 0xf05a05e0e3d15983ea921cad031aaea3040e9d631039045748753d29c5d24800;␊ + }␊ ␊ function _getC2Storage() private pure returns (C2Storage storage $) {␊ + bytes32 slot = _C2StorageLocation();␊ assembly {␊ - $.slot := C2StorageLocation␊ + $.slot := slot␊ }␊ }␊ ␊ @@ -75,12 +80,17 @@ Generated by [AVA](https://avajs.dev). address x;␊ }␊ ␊ - // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C3")) - 1)) & ~bytes32(uint256(0xff))␊ - bytes32 private constant C3StorageLocation = 0xaa7e0685867d809c517036b8f21e99d58bd04b1da2b202f167c355fdf82b4a00;␊ + /// @dev Consider updating the struct's storage location annotation␊ + /// See https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable#namespaced-storage-layout␊ + function _C3StorageLocation() internal pure virtual returns (bytes32) {␊ + // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C3")) - 1)) & ~bytes32(uint256(0xff))␊ + return 0xaa7e0685867d809c517036b8f21e99d58bd04b1da2b202f167c355fdf82b4a00;␊ + }␊ ␊ function _getC3Storage() private pure returns (C3Storage storage $) {␊ + bytes32 slot = _C3StorageLocation();␊ assembly {␊ - $.slot := C3StorageLocation␊ + $.slot := slot␊ }␊ }␊ }␊ @@ -91,12 +101,17 @@ Generated by [AVA](https://avajs.dev). address x;␊ }␊ ␊ - // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C4")) - 1)) & ~bytes32(uint256(0xff))␊ - bytes32 private constant C4StorageLocation = 0x536a56e760d844b098efcc16711808e0b18bad9e07c2e82c78312ab719318d00;␊ + /// @dev Consider updating the struct's storage location annotation␊ + /// See https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable#namespaced-storage-layout␊ + function _C4StorageLocation() internal pure virtual returns (bytes32) {␊ + // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C4")) - 1)) & ~bytes32(uint256(0xff))␊ + return 0x536a56e760d844b098efcc16711808e0b18bad9e07c2e82c78312ab719318d00;␊ + }␊ ␊ function _getC4Storage() private pure returns (C4Storage storage $) {␊ + bytes32 slot = _C4StorageLocation();␊ assembly {␊ - $.slot := C4StorageLocation␊ + $.slot := slot␊ }␊ }␊ function __C4_init() internal onlyInitializing {␊ @@ -123,12 +138,17 @@ Generated by [AVA](https://avajs.dev). address x;␊ }␊ ␊ - // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C5")) - 1)) & ~bytes32(uint256(0xff))␊ - bytes32 private constant C5StorageLocation = 0xd94dd1cf5c0ce3bfbbd2555b11ad43bf11eeff03081ca744441b0fb7c0a6ec00;␊ + /// @dev Consider updating the struct's storage location annotation␊ + /// See https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable#namespaced-storage-layout␊ + function _C5StorageLocation() internal pure virtual returns (bytes32) {␊ + // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C5")) - 1)) & ~bytes32(uint256(0xff))␊ + return 0xd94dd1cf5c0ce3bfbbd2555b11ad43bf11eeff03081ca744441b0fb7c0a6ec00;␊ + }␊ ␊ function _getC5Storage() private pure returns (C5Storage storage $) {␊ + bytes32 slot = _C5StorageLocation();␊ assembly {␊ - $.slot := C5StorageLocation␊ + $.slot := slot␊ }␊ }␊ }␊ @@ -154,12 +174,17 @@ Generated by [AVA](https://avajs.dev). uint y;␊ }␊ ␊ - // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C7")) - 1)) & ~bytes32(uint256(0xff))␊ - bytes32 private constant C7StorageLocation = 0x931371859ca5c5440d3850c7cf9c14adb9d1257b7ddd15562d561cd48871d300;␊ + /// @dev Consider updating the struct's storage location annotation␊ + /// See https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable#namespaced-storage-layout␊ + function _C7StorageLocation() internal pure virtual returns (bytes32) {␊ + // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C7")) - 1)) & ~bytes32(uint256(0xff))␊ + return 0x931371859ca5c5440d3850c7cf9c14adb9d1257b7ddd15562d561cd48871d300;␊ + }␊ ␊ function _getC7Storage() private pure returns (C7Storage storage $) {␊ + bytes32 slot = _C7StorageLocation();␊ assembly {␊ - $.slot := C7StorageLocation␊ + $.slot := slot␊ }␊ }␊ // a separate comment␊ @@ -172,12 +197,17 @@ Generated by [AVA](https://avajs.dev). address y;␊ }␊ ␊ - // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C8")) - 1)) & ~bytes32(uint256(0xff))␊ - bytes32 private constant C8StorageLocation = 0xb93ad5010b0e46eab6ce47e44cb42c85a263d4e8daf058e8a66e4f114144f200;␊ + /// @dev Consider updating the struct's storage location annotation␊ + /// See https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable#namespaced-storage-layout␊ + function _C8StorageLocation() internal pure virtual returns (bytes32) {␊ + // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.C8")) - 1)) & ~bytes32(uint256(0xff))␊ + return 0xb93ad5010b0e46eab6ce47e44cb42c85a263d4e8daf058e8a66e4f114144f200;␊ + }␊ ␊ function _getC8Storage() private pure returns (C8Storage storage $) {␊ + bytes32 slot = _C8StorageLocation();␊ assembly {␊ - $.slot := C8StorageLocation␊ + $.slot := slot␊ }␊ }␊ ␊ diff --git a/src/transform-namespaces.test.ts.snap b/src/transform-namespaces.test.ts.snap index 2ef5f9b..60d4cba 100644 Binary files a/src/transform-namespaces.test.ts.snap and b/src/transform-namespaces.test.ts.snap differ diff --git a/src/transformations/add-namespace-struct.ts b/src/transformations/add-namespace-struct.ts index 9f2af24..e810cbb 100644 --- a/src/transformations/add-namespace-struct.ts +++ b/src/transformations/add-namespace-struct.ts @@ -131,11 +131,17 @@ export function addNamespaceStruct(include?: (source: string) => boolean) { ...rest.split('\n'), `}`, ``, - `// keccak256(abi.encode(uint256(keccak256("${id}")) - 1)) & ~bytes32(uint256(0xff))`, - `bytes32 private constant ${namespace}Location = ${erc7201Location(id)};`, + `/// @dev Consider updating the struct's storage location annotation`, + `/// See https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable#namespaced-storage-layout`, + `function _${namespace}Location() internal pure virtual returns (bytes32) {`, + [ + `// keccak256(abi.encode(uint256(keccak256("${id}")) - 1)) & ~bytes32(uint256(0xff))`, + `return ${erc7201Location(id)};`, + ], + `}`, ``, `function _get${namespace}() private pure returns (${namespace} storage $) {`, - [`assembly {`, [`$.slot := ${namespace}Location`], `}`], + [`bytes32 slot = _${namespace}Location();`, `assembly {`, [`$.slot := slot`], `}`], `}`, ]).trimEnd() );