@openzeppelin/upgrades-core 1.22.0 → 1.24.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.
@@ -24,6 +24,19 @@ const testContracts = [
24
24
  'contracts/test/Storage.sol:StorageUpgrade_Gap_V2_Bad5',
25
25
  'contracts/test/Storage.sol:StorageUpgrade_MultiConsumeGap_V1',
26
26
  'contracts/test/Storage.sol:StorageUpgrade_MultiConsumeGap_V2_Ok',
27
+ 'contracts/test/Storage.sol:StorageUpgrade_CustomGap_V1',
28
+ 'contracts/test/Storage.sol:StorageUpgrade_CustomGap_V2_Ok',
29
+ 'contracts/test/Storage.sol:StorageUpgrade_CustomGap_V2_Bad',
30
+ 'contracts/test/Storage.sol:StorageUpgrade_CustomGap_V2_Bad2',
31
+ 'contracts/test/Storage.sol:StorageUpgrade_CustomGap_V2_Ok_Switched_Gaps',
32
+ 'contracts/test/Storage.sol:StorageUpgrade_CustomGap_V2_Bad_Switched_Gaps',
33
+ 'contracts/test/Storage.sol:StorageUpgrade_CustomGap_V2_Bad_Changed_Gap_Name',
34
+ 'contracts/test/Storage.sol:StorageUpgrade_ConsumeAndAddGap_V1',
35
+ 'contracts/test/Storage.sol:StorageUpgrade_ConsumeAndAddGap_V2',
36
+ 'contracts/test/Storage.sol:StorageUpgrade_ConsumeAndAddGap_V3',
37
+ 'contracts/test/Storage.sol:StorageUpgrade_ConsumeAndAddGap_V3b',
38
+ 'contracts/test/Storage.sol:StorageUpgrade_ConsumeAndAddGap_Storage_V1',
39
+ 'contracts/test/Storage.sol:StorageUpgrade_ConsumeAndAddGap_Storage_V2',
27
40
  ];
28
41
 
29
42
  test.before(async t => {
@@ -117,3 +130,77 @@ test('insert vars without shrink gap (uint128)', t => {
117
130
  t.false(report.ok);
118
131
  t.snapshot(report.explain());
119
132
  });
133
+
134
+ test('custom gap - shrinkgap', t => {
135
+ const v1 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V1');
136
+ const v2 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V2_Ok');
137
+ const report = getReport(v1, v2);
138
+ t.true(report.ok);
139
+ t.is(report.explain(), '');
140
+ });
141
+
142
+ test('custom gap - insert var, did not shrink gaps', t => {
143
+ const v1 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V1');
144
+ const v2 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V2_Bad');
145
+ const report = getReport(v1, v2);
146
+ t.false(report.ok);
147
+ t.snapshot(report.explain());
148
+ });
149
+
150
+ test('custom gap - insert var, shrank only first gap', t => {
151
+ const v1 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V1');
152
+ const v2 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V2_Bad2');
153
+ const report = getReport(v1, v2);
154
+ t.false(report.ok);
155
+ t.snapshot(report.explain());
156
+ });
157
+
158
+ test('custom gap - switched gaps', t => {
159
+ const v1 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V1');
160
+ const v2 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V2_Ok_Switched_Gaps');
161
+ const report = getReport(v1, v2);
162
+ t.true(report.ok);
163
+ t.is(report.explain(), '');
164
+ });
165
+
166
+ test('custom gap - insert var, did not shrink gaps, switched gaps', t => {
167
+ const v1 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V1');
168
+ const v2 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V2_Bad_Switched_Gaps');
169
+ const report = getReport(v1, v2);
170
+ t.false(report.ok);
171
+ t.snapshot(report.explain());
172
+ });
173
+
174
+ test('custom gap - insert var, did not shrink gaps, changed first gap name', t => {
175
+ const v1 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V1');
176
+ const v2 = t.context.extractStorageLayout('StorageUpgrade_CustomGap_V2_Bad_Changed_Gap_Name');
177
+ const report = getReport(v1, v2);
178
+ t.false(report.ok);
179
+ t.snapshot(report.explain());
180
+ });
181
+
182
+ test('consume entire gap and add new gap of different size', t => {
183
+ const v1 = t.context.extractStorageLayout('StorageUpgrade_ConsumeAndAddGap_V1');
184
+ const v2 = t.context.extractStorageLayout('StorageUpgrade_ConsumeAndAddGap_V2');
185
+ const v3 = t.context.extractStorageLayout('StorageUpgrade_ConsumeAndAddGap_V3');
186
+
187
+ t.true(getReport(v1, v2).ok);
188
+ t.true(getReport(v2, v3).ok);
189
+ t.true(getReport(v1, v3).ok);
190
+ });
191
+
192
+ test('consume entire gap and add new gap of same size', t => {
193
+ const v1 = t.context.extractStorageLayout('StorageUpgrade_ConsumeAndAddGap_V1');
194
+ const v2 = t.context.extractStorageLayout('StorageUpgrade_ConsumeAndAddGap_V2');
195
+ const v3b = t.context.extractStorageLayout('StorageUpgrade_ConsumeAndAddGap_V3b');
196
+
197
+ t.true(getReport(v2, v3b).ok);
198
+ t.true(getReport(v1, v3b).ok);
199
+ });
200
+
201
+ test('consume partial gap and add new gap, storage contract pattern', t => {
202
+ const v1 = t.context.extractStorageLayout('StorageUpgrade_ConsumeAndAddGap_Storage_V1');
203
+ const v2 = t.context.extractStorageLayout('StorageUpgrade_ConsumeAndAddGap_Storage_V2');
204
+
205
+ t.true(getReport(v1, v2).ok);
206
+ });
@@ -57,3 +57,33 @@ Generated by [AVA](https://avajs.dev).
57
57
  `file.sol:1: Layout changed for \`__gap\` (uint128[49] -> uint128[49])␊
58
58
  - Slot changed from 1 to 2␊
59
59
  > Set __gap array to size 48`
60
+
61
+ ## custom gap - insert var, did not shrink gaps
62
+
63
+ > Snapshot 1
64
+
65
+ `file.sol:1: Layout changed for \`__gap_part1\` (uint256[24] -> uint256[24])␊
66
+ - Slot changed from 1 to 2␊
67
+ > Set __gap_part1 array to size 23`
68
+
69
+ ## custom gap - insert var, shrank only first gap
70
+
71
+ > Snapshot 1
72
+
73
+ `file.sol:1: Layout changed for \`__gap_part2\` (uint256[23] -> uint256[23])␊
74
+ - Slot changed from 27 to 29␊
75
+ > Set __gap_part2 array to size 21`
76
+
77
+ ## custom gap - insert var, did not shrink gaps, switched gaps
78
+
79
+ > Snapshot 1
80
+
81
+ `file.sol:1: Renamed \`__gap_part1\` to \`__gap_part2\`␊
82
+ ␊
83
+ file.sol:1: Renamed \`__gap_part2\` to \`__gap_part1\``
84
+
85
+ ## custom gap - insert var, did not shrink gaps, changed first gap name
86
+
87
+ > Snapshot 1
88
+
89
+ 'file.sol:1: Renamed `__gap_part1` to `__gap`'
Binary file
@@ -76,7 +76,7 @@ function getExpectedGapSize(original: StorageField, updated: StorageField) {
76
76
  function suggestGapSize(original: StorageField, updated: StorageField): string | undefined {
77
77
  const expectedSize = getExpectedGapSize(original, updated);
78
78
  if (expectedSize !== undefined) {
79
- return `Set __gap array to size ${expectedSize}`;
79
+ return `Set ${updated.label} array to size ${expectedSize}`;
80
80
  }
81
81
  }
82
82