@openzeppelin/upgrades-core 1.30.0 → 1.31.0
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/dist/cli/cli.test.js +51 -0
- package/dist/cli/cli.test.js.map +1 -1
- package/dist/cli/validate/contract-report.d.ts +1 -1
- package/dist/cli/validate/contract-report.d.ts.map +1 -1
- package/dist/cli/validate/contract-report.js +4 -1
- package/dist/cli/validate/contract-report.js.map +1 -1
- package/dist/cli/validate/project-report.d.ts +3 -2
- package/dist/cli/validate/project-report.d.ts.map +1 -1
- package/dist/cli/validate/project-report.js +12 -6
- package/dist/cli/validate/project-report.js.map +1 -1
- package/dist/cli/validate/project-report.test.js +1 -1
- package/dist/cli/validate/project-report.test.js.map +1 -1
- package/dist/cli/validate/validate-upgrade-safety.d.ts +5 -1
- package/dist/cli/validate/validate-upgrade-safety.d.ts.map +1 -1
- package/dist/cli/validate/validate-upgrade-safety.js +18 -5
- package/dist/cli/validate/validate-upgrade-safety.js.map +1 -1
- package/dist/cli/validate/validate-upgrade-safety.test.js +8 -0
- package/dist/cli/validate/validate-upgrade-safety.test.js.map +1 -1
- package/dist/cli/validate/validations.test.js +2 -1
- package/dist/cli/validate/validations.test.js.map +1 -1
- package/dist/cli/validate.d.ts.map +1 -1
- package/dist/cli/validate.js +15 -6
- package/dist/cli/validate.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/storage/namespace.d.ts +1 -0
- package/dist/storage/namespace.d.ts.map +1 -1
- package/dist/storage/namespace.js +29 -1
- package/dist/storage/namespace.js.map +1 -1
- package/dist/validate/run.d.ts.map +1 -1
- package/dist/validate/run.js +1 -25
- package/dist/validate/run.js.map +1 -1
- package/package.json +2 -2
- package/src/cli/cli.test.ts +76 -0
- package/src/cli/cli.test.ts.md +65 -9
- package/src/cli/cli.test.ts.snap +0 -0
- package/src/cli/validate/contract-report.ts +6 -2
- package/src/cli/validate/project-report.test.ts +1 -1
- package/src/cli/validate/project-report.test.ts.md +1 -1
- package/src/cli/validate/project-report.test.ts.snap +0 -0
- package/src/cli/validate/project-report.ts +18 -8
- package/src/cli/validate/validate-upgrade-safety.test.ts +13 -1
- package/src/cli/validate/validate-upgrade-safety.ts +20 -6
- package/src/cli/validate/validations.test.ts +2 -1
- package/src/cli/validate.ts +15 -6
- package/src/index.ts +1 -0
- package/src/storage/namespace.ts +5 -0
- package/src/validate/run.ts +2 -3
package/src/cli/validate.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import minimist from 'minimist';
|
|
2
2
|
|
|
3
3
|
import { ValidateUpgradeSafetyOptions, validateUpgradeSafety } from '.';
|
|
4
|
-
import { withValidationDefaults } from '..';
|
|
5
4
|
import { ValidationError, errorKinds } from '../validate/run';
|
|
6
5
|
import debug from '../utils/debug';
|
|
6
|
+
import { withCliDefaults } from './validate/validate-upgrade-safety';
|
|
7
7
|
|
|
8
8
|
const USAGE = 'Usage: npx @openzeppelin/upgrades-core validate [<BUILD_INFO_DIR>] [<OPTIONS>]';
|
|
9
9
|
const DETAILS = `
|
|
@@ -14,7 +14,8 @@ Arguments:
|
|
|
14
14
|
|
|
15
15
|
Options:
|
|
16
16
|
--contract <CONTRACT> The name or fully qualified name of the contract to validate. If not specified, all upgradeable contracts in the build info directory will be validated.
|
|
17
|
-
--reference <REFERENCE_CONTRACT> The name or fully qualified name of the reference contract to use for storage layout comparisons.
|
|
17
|
+
--reference <REFERENCE_CONTRACT> Can only be used when the --contract option is also provided. The name or fully qualified name of the reference contract to use for storage layout comparisons. If not specified, uses the @custom:oz-upgrades-from annotation if it is defined in the contract that is being validated.
|
|
18
|
+
--requireReference Can only be used when the --contract option is also provided. If specified, requires either the --reference option to be provided or the contract to have a @custom:oz-upgrades-from annotation.
|
|
18
19
|
--unsafeAllow "<VALIDATION_ERRORS>" Selectively disable one or more validation errors. Comma-separated list with one or more of the following: ${errorKinds.join(
|
|
19
20
|
', ',
|
|
20
21
|
)}
|
|
@@ -45,6 +46,7 @@ function parseArgs(args: string[]) {
|
|
|
45
46
|
'unsafeSkipStorageCheck',
|
|
46
47
|
'unsafeAllowCustomTypes',
|
|
47
48
|
'unsafeAllowLinkedLibraries',
|
|
49
|
+
'requireReference',
|
|
48
50
|
],
|
|
49
51
|
string: ['unsafeAllow', 'contract', 'reference'],
|
|
50
52
|
alias: { h: 'help' },
|
|
@@ -87,10 +89,15 @@ export function getFunctionArgs(parsedArgs: minimist.ParsedArgs, extraArgs: stri
|
|
|
87
89
|
const buildInfoDir = extraArgs.length === 1 ? undefined : extraArgs[1];
|
|
88
90
|
const contract = getAndValidateString(parsedArgs, 'contract');
|
|
89
91
|
const reference = getAndValidateString(parsedArgs, 'reference');
|
|
90
|
-
if (reference !== undefined && contract === undefined) {
|
|
91
|
-
throw new Error('The --reference option can only be used along with the --contract option.');
|
|
92
|
-
}
|
|
93
92
|
const opts = withDefaults(parsedArgs);
|
|
93
|
+
|
|
94
|
+
if (contract === undefined) {
|
|
95
|
+
if (reference !== undefined) {
|
|
96
|
+
throw new Error('The --reference option can only be used along with the --contract option.');
|
|
97
|
+
} else if (opts.requireReference) {
|
|
98
|
+
throw new Error('The --requireReference option can only be used along with the --contract option.');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
94
101
|
return { buildInfoDir, contract, reference, opts };
|
|
95
102
|
}
|
|
96
103
|
}
|
|
@@ -117,6 +124,7 @@ function validateOptions(parsedArgs: minimist.ParsedArgs) {
|
|
|
117
124
|
'unsafeAllow',
|
|
118
125
|
'contract',
|
|
119
126
|
'reference',
|
|
127
|
+
'requireReference',
|
|
120
128
|
].includes(key),
|
|
121
129
|
);
|
|
122
130
|
if (invalidArgs.length > 0) {
|
|
@@ -152,7 +160,8 @@ export function withDefaults(parsedArgs: minimist.ParsedArgs): Required<Validate
|
|
|
152
160
|
unsafeAllowCustomTypes: parsedArgs['unsafeAllowCustomTypes'],
|
|
153
161
|
unsafeAllowLinkedLibraries: parsedArgs['unsafeAllowLinkedLibraries'],
|
|
154
162
|
unsafeAllow: getUnsafeAllowKinds(parsedArgs['unsafeAllow']),
|
|
163
|
+
requireReference: parsedArgs['requireReference'],
|
|
155
164
|
};
|
|
156
165
|
|
|
157
|
-
return
|
|
166
|
+
return withCliDefaults(allOpts);
|
|
158
167
|
}
|
package/src/index.ts
CHANGED
|
@@ -60,3 +60,4 @@ export { ValidateUpgradeSafetyOptions, validateUpgradeSafety, ProjectReport, Ref
|
|
|
60
60
|
|
|
61
61
|
export { getUpgradeInterfaceVersion } from './upgrade-interface-version';
|
|
62
62
|
export { makeNamespacedInput } from './utils/make-namespaced';
|
|
63
|
+
export { isNamespaceSupported } from './storage/namespace';
|
package/src/storage/namespace.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { getAnnotationArgs, getDocumentation, hasAnnotationTag } from '../utils/
|
|
|
7
7
|
import { Node } from 'solidity-ast/node';
|
|
8
8
|
import { CompilationContext, getTypeMembers, loadLayoutType } from './extract';
|
|
9
9
|
import { UpgradesError } from '../error';
|
|
10
|
+
import * as versions from 'compare-versions';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Loads a contract's namespaces and namespaced type information into the storage layout.
|
|
@@ -260,3 +261,7 @@ function findLayoutStructMember(
|
|
|
260
261
|
function findTypeWithLabel(types: Record<string, TypeItem>, label: string) {
|
|
261
262
|
return Object.values(types).find(type => type.label === label);
|
|
262
263
|
}
|
|
264
|
+
|
|
265
|
+
export function isNamespaceSupported(solcVersion: string) {
|
|
266
|
+
return versions.compare(solcVersion, '0.8.20', '>=');
|
|
267
|
+
}
|
package/src/validate/run.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Node } from 'solidity-ast/node';
|
|
|
2
2
|
import { isNodeType, findAll, ASTDereferencer, astDereferencer } from 'solidity-ast/utils';
|
|
3
3
|
import type { ContractDefinition, FunctionDefinition } from 'solidity-ast';
|
|
4
4
|
import debug from '../utils/debug';
|
|
5
|
-
import * as versions from 'compare-versions';
|
|
6
5
|
|
|
7
6
|
import { SolcOutput, SolcBytecode, SolcInput } from '../solc-api';
|
|
8
7
|
import { SrcDecoder } from '../src-decoder';
|
|
@@ -14,7 +13,7 @@ import { extractStorageLayout } from '../storage/extract';
|
|
|
14
13
|
import { StorageLayout } from '../storage/layout';
|
|
15
14
|
import { getFullyQualifiedName } from '../utils/contract-name';
|
|
16
15
|
import { getAnnotationArgs as getSupportedAnnotationArgs, getDocumentation } from '../utils/annotations';
|
|
17
|
-
import { getStorageLocationAnnotation } from '../storage/namespace';
|
|
16
|
+
import { getStorageLocationAnnotation, isNamespaceSupported } from '../storage/namespace';
|
|
18
17
|
import { UpgradesError } from '../error';
|
|
19
18
|
|
|
20
19
|
export type ValidationRunData = Record<string, ContractValidation>;
|
|
@@ -243,7 +242,7 @@ function checkNamespaceSolidityVersion(source: string, solcVersion?: string, sol
|
|
|
243
242
|
() =>
|
|
244
243
|
`Structs with the @custom:storage-location annotation can only be used with Solidity version 0.8.20 or higher. Pass the solcVersion parameter to the validate function, or remove the annotation if the struct is not used for namespaced storage.`,
|
|
245
244
|
);
|
|
246
|
-
} else if (
|
|
245
|
+
} else if (!isNamespaceSupported(solcVersion)) {
|
|
247
246
|
throw new UpgradesError(
|
|
248
247
|
`${source}: Namespace annotations require Solidity version >= 0.8.20, but ${solcVersion} was used`,
|
|
249
248
|
() =>
|