Skip to content

Commit

Permalink
Leave constants as is when making namespaced input (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau authored Apr 16, 2024
1 parent 9932c6a commit 20f0207
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

## Unreleased
## 1.32.6 (2024-04-16)

- This plugin is now compiled with TypeScript v5. ([#760](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/760))
- Fix Hardhat compile error when referencing a constant within a struct definition. ([#1009](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1009))

## 1.32.5 (2024-02-21)

Expand Down
15 changes: 15 additions & 0 deletions packages/core/contracts/test/NamespacedToModify.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,18 @@ enum FreeEnum { MyEnum }
* @param example example parameter
*/
error CustomErrorOutsideContract(Example example);

contract StructArrayUsesConstant {
uint16 private constant MAX_SIZE = 10;

struct NotNamespaced {
uint16 a;
uint256[MAX_SIZE] b;
}

/// @custom:storage-location erc7201:uses.constant
struct MainStorage {
uint256 x;
uint256[MAX_SIZE] y;
}
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openzeppelin/upgrades-core",
"version": "1.32.5",
"version": "1.32.6",
"description": "",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/core",
"license": "MIT",
Expand Down
19 changes: 17 additions & 2 deletions packages/core/src/utils/make-namespaced.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Generated by [AVA](https://avajs.dev).
struct MyStruct { uint b; }␊
// keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊
enum $astId_id_random { dummy }␊
bytes32 private constant MAIN_STORAGE_LOCATION =␊
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;␊
enum $astId_id_random { dummy }␊
Expand Down Expand Up @@ -171,7 +172,21 @@ Generated by [AVA](https://avajs.dev).
* @param example example parameter␊
*/␊
enum CustomErrorOutsideContract { dummy }␊
`,
contract StructArrayUsesConstant {␊
uint16 private constant MAX_SIZE = 10;␊
struct NotNamespaced {␊
uint16 a;␊
uint256[MAX_SIZE] b;␊
}␊
/// @custom:storage-location erc7201:uses.constant␊
struct MainStorage {␊
uint256 x;␊
uint256[MAX_SIZE] y;␊
} MainStorage $MainStorage_random;␊
}`,
},
'contracts/test/NamespacedToModifyImported.sol': {
content: `// SPDX-License-Identifier: MIT␊
Expand Down
Binary file modified packages/core/src/utils/make-namespaced.test.ts.snap
Binary file not shown.
10 changes: 8 additions & 2 deletions packages/core/src/utils/make-namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI
const contractNodes = contractDef.nodes;
for (const contractNode of contractNodes) {
switch (contractNode.nodeType) {
case 'VariableDeclaration': {
// If variable is a constant, keep it since it may be referenced in a struct
if (contractNode.constant) {
break;
}
// Otherwise, fall through to convert to dummy enum
}
case 'ErrorDefinition':
case 'EventDefinition':
case 'FunctionDefinition':
case 'ModifierDefinition':
case 'UsingForDirective':
case 'VariableDeclaration': {
case 'UsingForDirective': {
// Replace with an enum based on astId (the original name is not needed, since nothing should reference it)
modifications.push(makeReplace(contractNode, orig, toDummyEnumWithAstId(contractNode.id)));
break;
Expand Down

0 comments on commit 20f0207

Please sign in to comment.