@openzeppelin/upgrades-core 1.35.0 → 1.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/utils/make-namespaced.d.ts +6 -2
- package/dist/utils/make-namespaced.d.ts.map +1 -1
- package/dist/utils/make-namespaced.js +27 -14
- package/dist/utils/make-namespaced.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/make-namespaced.test.ts.md +32 -2
- package/src/utils/make-namespaced.test.ts.snap +0 -0
- package/src/utils/make-namespaced.ts +36 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.35.1 (2024-08-13)
|
|
4
|
+
|
|
5
|
+
- Fix Hardhat compile error when `fallback` or `receive` functions are present. ([#1060](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1060))
|
|
6
|
+
|
|
3
7
|
## 1.35.0 (2024-07-31)
|
|
4
8
|
|
|
5
9
|
- Fix Hardhat compile error when public variables are used to implement interface functions. ([#1055](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1055))
|
|
@@ -5,9 +5,13 @@ import { SolcInput, SolcOutput } from '../solc-api';
|
|
|
5
5
|
*
|
|
6
6
|
* This makes the following modifications to the input:
|
|
7
7
|
* - Adds a state variable for each namespaced struct definition
|
|
8
|
-
* - For each contract, for all node types that are not needed for storage layout or may
|
|
8
|
+
* - For each contract, for all node types that are not needed for storage layout or may call functions and constructors, converts them to dummy enums with random id
|
|
9
9
|
* - Converts all using for directives (at file level and in contracts) to dummy enums with random id (do not delete them to avoid orphaning possible NatSpec documentation)
|
|
10
|
-
* - Converts all custom errors
|
|
10
|
+
* - Converts all custom errors and constants (at file level) to dummy enums with the same name (do not delete them since they might be imported by other files)
|
|
11
|
+
* - Replaces functions as follows:
|
|
12
|
+
* - For regular function and free function, keep declarations since they may be referenced by constants (free functions may also be imported by other files). But simplify compilation by removing modifiers and body, and replace return parameters with bools which can be default initialized.
|
|
13
|
+
* - Constructors are not needed, since we removed anything that may call constructors. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
14
|
+
* - Fallback and receive functions are not needed, since they don't have signatures. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
11
15
|
*
|
|
12
16
|
* Also sets the outputSelection to only include storageLayout and ast, since the other outputs are not needed.
|
|
13
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-namespaced.d.ts","sourceRoot":"","sources":["../../src/utils/make-namespaced.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAYpD
|
|
1
|
+
{"version":3,"file":"make-namespaced.d.ts","sourceRoot":"","sources":["../../src/utils/make-namespaced.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAYpD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAgIzG"}
|
|
@@ -16,9 +16,13 @@ const OUTPUT_SELECTION = {
|
|
|
16
16
|
*
|
|
17
17
|
* This makes the following modifications to the input:
|
|
18
18
|
* - Adds a state variable for each namespaced struct definition
|
|
19
|
-
* - For each contract, for all node types that are not needed for storage layout or may
|
|
19
|
+
* - For each contract, for all node types that are not needed for storage layout or may call functions and constructors, converts them to dummy enums with random id
|
|
20
20
|
* - Converts all using for directives (at file level and in contracts) to dummy enums with random id (do not delete them to avoid orphaning possible NatSpec documentation)
|
|
21
|
-
* - Converts all custom errors
|
|
21
|
+
* - Converts all custom errors and constants (at file level) to dummy enums with the same name (do not delete them since they might be imported by other files)
|
|
22
|
+
* - Replaces functions as follows:
|
|
23
|
+
* - For regular function and free function, keep declarations since they may be referenced by constants (free functions may also be imported by other files). But simplify compilation by removing modifiers and body, and replace return parameters with bools which can be default initialized.
|
|
24
|
+
* - Constructors are not needed, since we removed anything that may call constructors. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
25
|
+
* - Fallback and receive functions are not needed, since they don't have signatures. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
22
26
|
*
|
|
23
27
|
* Also sets the outputSelection to only include storageLayout and ast, since the other outputs are not needed.
|
|
24
28
|
*
|
|
@@ -197,21 +201,30 @@ function toDummyEnumWithAstId(astId) {
|
|
|
197
201
|
return `enum $astId_${astId}_${(Math.random() * 1e6).toFixed(0)} { dummy }`;
|
|
198
202
|
}
|
|
199
203
|
function replaceFunction(node, orig, modifications) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
switch (node.kind) {
|
|
205
|
+
case 'freeFunction':
|
|
206
|
+
case 'function': {
|
|
207
|
+
if (node.modifiers.length > 0) {
|
|
208
|
+
for (const modifier of node.modifiers) {
|
|
209
|
+
modifications.push(makeDelete(modifier, orig));
|
|
210
|
+
}
|
|
207
211
|
}
|
|
212
|
+
if (node.returnParameters.parameters.length > 0) {
|
|
213
|
+
modifications.push(makeReplace(node.returnParameters, orig, `(${node.returnParameters.parameters.map(param => toReturnParameterReplacement(param)).join(', ')})`));
|
|
214
|
+
}
|
|
215
|
+
if (node.body) {
|
|
216
|
+
modifications.push(makeReplace(node.body, orig, '{}'));
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
208
219
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
220
|
+
case 'constructor':
|
|
221
|
+
case 'fallback':
|
|
222
|
+
case 'receive': {
|
|
223
|
+
modifications.push(makeReplace(node, orig, toDummyEnumWithAstId(node.id)));
|
|
224
|
+
break;
|
|
214
225
|
}
|
|
226
|
+
default:
|
|
227
|
+
return (0, assert_1.assertUnreachable)(node.kind);
|
|
215
228
|
}
|
|
216
229
|
}
|
|
217
230
|
function toReturnParameterReplacement(param) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-namespaced.js","sourceRoot":"","sources":["../../src/utils/make-namespaced.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"make-namespaced.js","sourceRoot":"","sources":["../../src/utils/make-namespaced.ts"],"names":[],"mappings":";;AAmCA,kDAgIC;AAnKD,8CAAgD;AAGhD,oDAAoE;AACpE,qCAAqD;AAGrD,MAAM,gBAAgB,GAAG;IACvB,GAAG,EAAE;QACH,GAAG,EAAE,CAAC,eAAe,CAAC;QACtB,EAAE,EAAE,CAAC,KAAK,CAAC;KACZ;CACF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,mBAAmB,CAAC,KAAgB,EAAE,MAAkB,EAAE,WAAoB;IAC5F,MAAM,eAAe,GAAyC,EAAE,CAAC;IAEjE,KAAK,MAAM,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACzD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAEzC,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACjC,eAAe,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;YACrC,SAAS;QACX,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAEjD,MAAM,aAAa,GAAmB,EAAE,CAAC;QAEzC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;YACxD,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACtB,KAAK,oBAAoB,CAAC,CAAC,CAAC;oBAC1B,MAAM,WAAW,GA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D,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACxB,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,aAA6B;IACpE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,IAAA,eAAM,EAAC,YAAY,CAAC,KAAK,IAAI,aAAa,CAAC,CAAC;QAC5C,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAEnE,IAAI,YAAY,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACpC,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC;QAC9B,CAAC;QAED,aAAa,GAAG,YAAY,CAAC,GAAG,CAAC;IACnC,CAAC;IAED,IAAA,eAAM,EAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAE/C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -97,6 +97,8 @@ Generated by [AVA](https://avajs.dev).
|
|
|
97
97
|
␊
|
|
98
98
|
abstract contract HasFunction {␊
|
|
99
99
|
␊
|
|
100
|
+
enum $astId_id_random { dummy }␊
|
|
101
|
+
␊
|
|
100
102
|
function foo() pure public returns (bool) {}␊
|
|
101
103
|
}␊
|
|
102
104
|
␊
|
|
@@ -228,6 +230,19 @@ Generated by [AVA](https://avajs.dev).
|
|
|
228
230
|
␊
|
|
229
231
|
abstract contract DeploysContractToImmutable {␊
|
|
230
232
|
enum $astId_id_random { dummy }␊
|
|
233
|
+
}␊
|
|
234
|
+
␊
|
|
235
|
+
abstract contract HasSpecialFunctions {␊
|
|
236
|
+
␊
|
|
237
|
+
␊
|
|
238
|
+
enum $astId_id_random { dummy }␊
|
|
239
|
+
␊
|
|
240
|
+
enum $astId_id_random { dummy }␊
|
|
241
|
+
␊
|
|
242
|
+
// Regular function but payable␊
|
|
243
|
+
function hasPayable() public payable {}␊
|
|
244
|
+
␊
|
|
245
|
+
bytes4 constant PAYABLE_SELECTOR = this.hasPayable.selector;␊
|
|
231
246
|
}`,
|
|
232
247
|
},
|
|
233
248
|
'contracts/test/NamespacedToModifyImported.sol': {
|
|
@@ -344,7 +359,9 @@ Generated by [AVA](https://avajs.dev).
|
|
|
344
359
|
}␊
|
|
345
360
|
␊
|
|
346
361
|
abstract contract HasFunction {␊
|
|
347
|
-
␊
|
|
362
|
+
/// @param myInt an integer␊
|
|
363
|
+
enum $astId_id_random { dummy }␊
|
|
364
|
+
␊
|
|
348
365
|
function foo() pure public returns (bool) {}␊
|
|
349
366
|
}␊
|
|
350
367
|
␊
|
|
@@ -517,6 +534,19 @@ Generated by [AVA](https://avajs.dev).
|
|
|
517
534
|
␊
|
|
518
535
|
abstract contract DeploysContractToImmutable {␊
|
|
519
536
|
enum $astId_id_random { dummy }␊
|
|
537
|
+
}␊
|
|
538
|
+
␊
|
|
539
|
+
abstract contract HasSpecialFunctions {␊
|
|
540
|
+
/// @param data call data␊
|
|
541
|
+
/// @return dataReturn returned data␊
|
|
542
|
+
enum $astId_id_random { dummy }␊
|
|
543
|
+
␊
|
|
544
|
+
enum $astId_id_random { dummy }␊
|
|
545
|
+
␊
|
|
546
|
+
// Regular function but payable␊
|
|
547
|
+
function hasPayable() public payable {}␊
|
|
548
|
+
␊
|
|
549
|
+
bytes4 constant PAYABLE_SELECTOR = this.hasPayable.selector;␊
|
|
520
550
|
}`,
|
|
521
551
|
},
|
|
522
552
|
'contracts/test/NamespacedToModifyImported.sol': {
|
|
@@ -559,7 +589,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
559
589
|
pragma solidity 0.7.6;␊
|
|
560
590
|
␊
|
|
561
591
|
abstract contract HasFunction {␊
|
|
562
|
-
␊
|
|
592
|
+
enum $astId_id_random { dummy }␊
|
|
563
593
|
function foo() pure public returns (bool) {}␊
|
|
564
594
|
}␊
|
|
565
595
|
␊
|
|
Binary file
|
|
@@ -2,7 +2,7 @@ import { isNodeType } from 'solidity-ast/utils';
|
|
|
2
2
|
import { Node } from 'solidity-ast/node';
|
|
3
3
|
import { SolcInput, SolcOutput } from '../solc-api';
|
|
4
4
|
import { getStorageLocationAnnotation } from '../storage/namespace';
|
|
5
|
-
import { assert } from './assert';
|
|
5
|
+
import { assert, assertUnreachable } from './assert';
|
|
6
6
|
import { FunctionDefinition, VariableDeclaration } from 'solidity-ast';
|
|
7
7
|
|
|
8
8
|
const OUTPUT_SELECTION = {
|
|
@@ -18,9 +18,13 @@ const OUTPUT_SELECTION = {
|
|
|
18
18
|
*
|
|
19
19
|
* This makes the following modifications to the input:
|
|
20
20
|
* - Adds a state variable for each namespaced struct definition
|
|
21
|
-
* - For each contract, for all node types that are not needed for storage layout or may
|
|
21
|
+
* - For each contract, for all node types that are not needed for storage layout or may call functions and constructors, converts them to dummy enums with random id
|
|
22
22
|
* - Converts all using for directives (at file level and in contracts) to dummy enums with random id (do not delete them to avoid orphaning possible NatSpec documentation)
|
|
23
|
-
* - Converts all custom errors
|
|
23
|
+
* - Converts all custom errors and constants (at file level) to dummy enums with the same name (do not delete them since they might be imported by other files)
|
|
24
|
+
* - Replaces functions as follows:
|
|
25
|
+
* - For regular function and free function, keep declarations since they may be referenced by constants (free functions may also be imported by other files). But simplify compilation by removing modifiers and body, and replace return parameters with bools which can be default initialized.
|
|
26
|
+
* - Constructors are not needed, since we removed anything that may call constructors. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
27
|
+
* - Fallback and receive functions are not needed, since they don't have signatures. Convert to dummy enums to avoid orphaning possible NatSpec.
|
|
24
28
|
*
|
|
25
29
|
* Also sets the outputSelection to only include storageLayout and ast, since the other outputs are not needed.
|
|
26
30
|
*
|
|
@@ -228,28 +232,39 @@ function toDummyEnumWithAstId(astId: number) {
|
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
function replaceFunction(node: FunctionDefinition, orig: Buffer, modifications: Modification[]) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
switch (node.kind) {
|
|
236
|
+
case 'freeFunction':
|
|
237
|
+
case 'function': {
|
|
238
|
+
if (node.modifiers.length > 0) {
|
|
239
|
+
for (const modifier of node.modifiers) {
|
|
240
|
+
modifications.push(makeDelete(modifier, orig));
|
|
241
|
+
}
|
|
237
242
|
}
|
|
238
|
-
}
|
|
239
243
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
if (node.returnParameters.parameters.length > 0) {
|
|
245
|
+
modifications.push(
|
|
246
|
+
makeReplace(
|
|
247
|
+
node.returnParameters,
|
|
248
|
+
orig,
|
|
249
|
+
`(${node.returnParameters.parameters.map(param => toReturnParameterReplacement(param)).join(', ')})`,
|
|
250
|
+
),
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (node.body) {
|
|
255
|
+
modifications.push(makeReplace(node.body, orig, '{}'));
|
|
256
|
+
}
|
|
249
257
|
|
|
250
|
-
|
|
251
|
-
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
case 'constructor':
|
|
261
|
+
case 'fallback':
|
|
262
|
+
case 'receive': {
|
|
263
|
+
modifications.push(makeReplace(node, orig, toDummyEnumWithAstId(node.id)));
|
|
264
|
+
break;
|
|
252
265
|
}
|
|
266
|
+
default:
|
|
267
|
+
return assertUnreachable(node.kind);
|
|
253
268
|
}
|
|
254
269
|
}
|
|
255
270
|
|