@openzeppelin/upgrades-core 1.20.6 → 1.21.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/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol/BeaconProxy.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol/UpgradeableBeacon.dbg.json +1 -1
- package/artifacts/build-info.json +117 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +2 -0
- package/dist/provider.js.map +1 -1
- package/dist/src-decoder.js +1 -1
- package/dist/src-decoder.js.map +1 -1
- package/dist/validate/query.d.ts.map +1 -1
- package/dist/validate/query.js +12 -8
- package/dist/validate/query.js.map +1 -1
- package/dist/validate/run.d.ts +5 -0
- package/dist/validate/run.d.ts.map +1 -1
- package/dist/validate/run.js +119 -26
- package/dist/validate/run.js.map +1 -1
- package/dist/validate/run.test.d.ts +2 -0
- package/dist/validate/run.test.d.ts.map +1 -0
- package/dist/validate/run.test.js +43 -0
- package/dist/validate/run.test.js.map +1 -0
- package/dist/validate-ignore-errors.test.d.ts +2 -0
- package/dist/validate-ignore-errors.test.d.ts.map +1 -0
- package/dist/validate-ignore-errors.test.js +123 -0
- package/dist/validate-ignore-errors.test.js.map +1 -0
- package/package.json +2 -2
- package/src/provider.ts +2 -0
- package/src/src-decoder.ts +1 -1
- package/src/validate/query.ts +15 -11
- package/src/validate/run.test.ts +49 -0
- package/src/validate/run.ts +190 -31
- package/src/validate-ignore-errors.test.ts +137 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import _test, { TestFn } from 'ava';
|
|
2
|
+
import { artifacts } from 'hardhat';
|
|
3
|
+
|
|
4
|
+
import { validate, getContractVersion, assertUpgradeSafe, ValidationOptions, RunValidation } from './validate';
|
|
5
|
+
import { solcInputOutputDecoder } from './src-decoder';
|
|
6
|
+
|
|
7
|
+
interface Context {
|
|
8
|
+
validation: RunValidation;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const test = _test as TestFn<Context>;
|
|
12
|
+
|
|
13
|
+
test.before(async t => {
|
|
14
|
+
const contracts = [
|
|
15
|
+
'contracts/test/ignore-errors/SafeContract.sol:SafeContract',
|
|
16
|
+
'contracts/test/ignore-errors/SafeContractWithFreeFunctionCall.sol:SafeContractWithFreeFunctionCall',
|
|
17
|
+
'contracts/test/ignore-errors/SafeContractWithLibraryCall.sol:SafeContractWithLibraryCall',
|
|
18
|
+
'contracts/test/ignore-errors/SafeContractWithLibraryImport.sol:SafeContractWithLibraryImport',
|
|
19
|
+
'contracts/test/ignore-errors/SafeContractWithLibraryUsingFor.sol:SafeContractWithLibraryUsingFor',
|
|
20
|
+
'contracts/test/ignore-errors/SafeContractWithTransitiveLibraryCall.sol:SafeContractWithTransitiveLibraryCall',
|
|
21
|
+
'contracts/test/ignore-errors/SafeContractWithParentCall.sol:SafeContractWithParentCall',
|
|
22
|
+
'contracts/test/ignore-errors/RiskyParentContract.sol:RiskyParentContract',
|
|
23
|
+
'contracts/test/ignore-errors/UnsafeContract.sol:UnsafeContract',
|
|
24
|
+
'contracts/test/ignore-errors/UnsafeContractWithFreeFunctionCall.sol:UnsafeContractWithFreeFunctionCall',
|
|
25
|
+
'contracts/test/ignore-errors/UnsafeContractWithLibraryCall.sol:UnsafeContractWithLibraryCall',
|
|
26
|
+
'contracts/test/ignore-errors/UnsafeContractWithLibraryUsingFor.sol:UnsafeContractWithLibraryUsingFor',
|
|
27
|
+
'contracts/test/ignore-errors/UnsafeContractWithTransitiveLibraryCall.sol:UnsafeContractWithTransitiveLibraryCall',
|
|
28
|
+
'contracts/test/ignore-errors/UnsafeContractWithParentCall.sol:UnsafeContractWithParentCall',
|
|
29
|
+
'contracts/test/ignore-errors/UnsafeContractWithInheritedParent.sol:UnsafeContractWithInheritedParent',
|
|
30
|
+
'contracts/test/ignore-errors/UnsafeContractWithInheritedTransitiveParent.sol:UnsafeContractWithInheritedTransitiveParent',
|
|
31
|
+
'contracts/test/ignore-errors/UnsafeAllow.sol:UnsafeAllow',
|
|
32
|
+
'contracts/test/ignore-errors/AllowReachable.sol:AllowReachable',
|
|
33
|
+
'contracts/test/ignore-errors/UnsafeAllowReachableDifferentOpcode.sol:UnsafeAllowReachableDifferentOpcode',
|
|
34
|
+
'contracts/test/ignore-errors/UnsafeAllowParent.sol:UnsafeAllowParent',
|
|
35
|
+
'contracts/test/ignore-errors/AllowReachableParent.sol:AllowReachableParent',
|
|
36
|
+
'contracts/test/ignore-errors/UnsafeAllowReachableParentDifferentOpcode.sol:UnsafeAllowReachableParentDifferentOpcode',
|
|
37
|
+
'contracts/test/ignore-errors/AllowChildInheritedTransitive.sol:AllowChildInheritedTransitive',
|
|
38
|
+
'contracts/test/ignore-errors/AllowChild.sol:AllowChild',
|
|
39
|
+
'contracts/test/ignore-errors/AllowChildCallTransitive.sol:AllowChildCallTransitive',
|
|
40
|
+
'contracts/test/ignore-errors/AllowChildSelfReachable.sol:AllowChildSelfReachable',
|
|
41
|
+
'contracts/test/ignore-errors/SafeRecursion.sol:SafeRecursion',
|
|
42
|
+
'contracts/test/ignore-errors/UnsafeRecursion.sol:UnsafeRecursion',
|
|
43
|
+
'contracts/test/ignore-errors/Constructors.sol:UnsafeChild1',
|
|
44
|
+
'contracts/test/ignore-errors/Constructors.sol:UnsafeChild2',
|
|
45
|
+
'contracts/test/ignore-errors/Constructors.sol:UnsafeChild3',
|
|
46
|
+
'contracts/test/ignore-errors/Constructors.sol:UnsafeChild4',
|
|
47
|
+
'contracts/test/ignore-errors/Constructors.sol:AllowChild5',
|
|
48
|
+
'contracts/test/ignore-errors/Constructors.sol:AllowChild6',
|
|
49
|
+
'contracts/test/ignore-errors/Constructors.sol:UnsafeAllowChild7',
|
|
50
|
+
'contracts/test/ignore-errors/Constructors.sol:AllowReachableChild8',
|
|
51
|
+
'contracts/test/ignore-errors/Constructors.sol:UnsafeChild9',
|
|
52
|
+
// 'contracts/test/ignore-errors/Modifiers.sol:ModifierNotUsed',
|
|
53
|
+
'contracts/test/ignore-errors/Modifiers.sol:ModifierUsed',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
t.context.validation = {} as RunValidation;
|
|
57
|
+
for (const contract of contracts) {
|
|
58
|
+
const buildInfo = await artifacts.getBuildInfo(contract);
|
|
59
|
+
if (buildInfo === undefined) {
|
|
60
|
+
throw new Error(`Build info not found for contract ${contract}`);
|
|
61
|
+
}
|
|
62
|
+
const solcOutput = buildInfo.output;
|
|
63
|
+
const solcInput = buildInfo.input;
|
|
64
|
+
const decodeSrc = solcInputOutputDecoder(solcInput, solcOutput);
|
|
65
|
+
Object.assign(t.context.validation, validate(solcOutput, decodeSrc));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function testValid(name: string, kind: ValidationOptions['kind'], valid: boolean) {
|
|
70
|
+
testOverride(name, kind, {}, valid);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function testOverride(name: string, kind: ValidationOptions['kind'], opts: ValidationOptions, valid: boolean) {
|
|
74
|
+
const optKeys = Object.keys(opts);
|
|
75
|
+
const describeOpts = optKeys.length > 0 ? '(' + optKeys.join(', ') + ')' : '';
|
|
76
|
+
const testName = [valid ? 'accepts' : 'rejects', kind, name, describeOpts].join(' ');
|
|
77
|
+
test(testName, t => {
|
|
78
|
+
const version = getContractVersion(t.context.validation, name);
|
|
79
|
+
const assertUpgSafe = () => assertUpgradeSafe([t.context.validation], version, { kind, ...opts });
|
|
80
|
+
if (valid) {
|
|
81
|
+
t.notThrows(assertUpgSafe);
|
|
82
|
+
} else {
|
|
83
|
+
t.throws(assertUpgSafe);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
testValid('SafeContract', 'transparent', true);
|
|
89
|
+
testValid('SafeContractWithFreeFunctionCall', 'transparent', true);
|
|
90
|
+
testValid('SafeContractWithLibraryCall', 'transparent', true);
|
|
91
|
+
testValid('SafeContractWithLibraryImport', 'transparent', true);
|
|
92
|
+
testValid('SafeContractWithLibraryUsingFor', 'transparent', true);
|
|
93
|
+
testValid('SafeContractWithTransitiveLibraryCall', 'transparent', true);
|
|
94
|
+
testValid('SafeContractWithParentCall', 'transparent', true);
|
|
95
|
+
|
|
96
|
+
testValid('RiskyParentContract', 'transparent', false);
|
|
97
|
+
|
|
98
|
+
testValid('UnsafeContract', 'transparent', false);
|
|
99
|
+
testValid('UnsafeContractWithFreeFunctionCall', 'transparent', false);
|
|
100
|
+
testValid('UnsafeContractWithLibraryCall', 'transparent', false);
|
|
101
|
+
testValid('UnsafeContractWithLibraryUsingFor', 'transparent', false);
|
|
102
|
+
testValid('UnsafeContractWithTransitiveLibraryCall', 'transparent', false);
|
|
103
|
+
testValid('UnsafeContractWithParentCall', 'transparent', false);
|
|
104
|
+
testValid('UnsafeContractWithInheritedParent', 'transparent', false);
|
|
105
|
+
testValid('UnsafeContractWithInheritedTransitiveParent', 'transparent', false);
|
|
106
|
+
|
|
107
|
+
testValid('UnsafeAllow', 'transparent', false);
|
|
108
|
+
testValid('AllowReachable', 'transparent', true);
|
|
109
|
+
testValid('UnsafeAllowReachableDifferentOpcode', 'transparent', false);
|
|
110
|
+
|
|
111
|
+
testValid('UnsafeAllowParent', 'transparent', false);
|
|
112
|
+
testValid('AllowReachableParent', 'transparent', true);
|
|
113
|
+
testValid('UnsafeAllowReachableParentDifferentOpcode', 'transparent', false);
|
|
114
|
+
|
|
115
|
+
testValid('AllowChildInheritedTransitive', 'transparent', true);
|
|
116
|
+
testValid('AllowChild', 'transparent', true);
|
|
117
|
+
testValid('AllowChildCallTransitive', 'transparent', true);
|
|
118
|
+
|
|
119
|
+
testValid('AllowChildSelfReachable', 'transparent', true);
|
|
120
|
+
|
|
121
|
+
testValid('SafeRecursion', 'transparent', true);
|
|
122
|
+
testValid('UnsafeRecursion', 'transparent', false);
|
|
123
|
+
|
|
124
|
+
testValid('UnsafeChild1', 'transparent', false);
|
|
125
|
+
testValid('UnsafeChild2', 'transparent', false);
|
|
126
|
+
testValid('UnsafeChild3', 'transparent', false);
|
|
127
|
+
testValid('UnsafeChild4', 'transparent', false);
|
|
128
|
+
testValid('AllowChild5', 'transparent', true);
|
|
129
|
+
testValid('AllowChild6', 'transparent', true);
|
|
130
|
+
testValid('UnsafeAllowChild7', 'transparent', false);
|
|
131
|
+
testValid('AllowReachableChild8', 'transparent', true);
|
|
132
|
+
testValid('UnsafeChild9', 'transparent', false);
|
|
133
|
+
|
|
134
|
+
// TODO: do not throw an error in this case
|
|
135
|
+
// testValid('ModifierNotUsed', 'transparent', true);
|
|
136
|
+
|
|
137
|
+
testValid('ModifierUsed', 'transparent', false);
|