@@ -3,7 +3,6 @@ pragma solidity ^0.8.18;
3
3
4
4
import "ds-test/test.sol " ;
5
5
import "cheats/Vm.sol " ;
6
- import "./StateDiffTestUtils.sol " ;
7
6
8
7
contract MappingStorage {
9
8
// Simple mappings only
@@ -30,7 +29,7 @@ contract MappingStorage {
30
29
}
31
30
}
32
31
33
- contract StateDiffMappingsTest is StateDiffTestUtils {
32
+ contract StateDiffMappingsTest is DSTest {
34
33
Vm constant vm = Vm (HEVM_ADDRESS);
35
34
MappingStorage public mappingStorage;
36
35
@@ -52,53 +51,35 @@ contract StateDiffMappingsTest is StateDiffTestUtils {
52
51
emit log_string (stateDiffText);
53
52
54
53
// Verify text format contains the mapping label
55
- assertContains (
56
- stateDiffText,
57
- "balances[0x0000000000000000000000000000000000001234] " ,
58
- "Text format should contain mapping label "
59
- );
54
+ assertTrue (vm.contains (stateDiffText, "balances[0x0000000000000000000000000000000000001234] " ));
60
55
61
56
// Verify text format contains the value type
62
- assertContains ( stateDiffText, "uint256 " , " Text format should contain value type " );
57
+ assertTrue (vm. contains ( stateDiffText, "uint256 " ) );
63
58
64
59
// Verify text format contains decoded values (shown with arrow)
65
- assertContains (stateDiffText, ": 0 " , "Text format should contain initial value " );
66
- assertContains (
67
- stateDiffText, "1000000000000000000000 " , "Text format should contain new value (1000 ether in wei) "
68
- );
60
+ assertTrue (vm.contains (stateDiffText, ": 0 " ));
61
+ assertTrue (vm.contains (stateDiffText, "1000000000000000000000 " ));
69
62
70
63
// Test JSON format output
71
64
string memory json = vm.getStateDiffJson ();
72
65
emit log_string ("State diff JSON (simple mapping): " );
73
66
emit log_string (json);
74
67
75
68
// The JSON should contain the decoded mapping slot with proper label
76
- assertContains (
77
- json,
78
- '"label":"balances[0x0000000000000000000000000000000000001234]" ' ,
79
- "JSON should contain 'balances[0x0000...1234]' label "
80
- );
69
+ assertTrue (vm.contains (json, '"label":"balances[0x0000000000000000000000000000000000001234]" ' ));
81
70
82
71
// Check the type is correctly identified
83
- assertContains ( json, '"type":"mapping(address => uint256)" ' , " JSON should contain mapping type " );
72
+ assertTrue (vm. contains ( json, '"type":"mapping(address => uint256)" ' ) );
84
73
85
74
// Check decoded values
86
- assertContains (
87
- json,
88
- '"decoded":{"previousValue":"0","newValue":"1000000000000000000000"} ' ,
89
- "JSON should decode balance value correctly (1000 ether = 1000000000000000000000 wei) "
90
- );
75
+ assertTrue (vm.contains (json, '"decoded":{"previousValue":"0","newValue":"1000000000000000000000"} ' ));
91
76
92
77
// Check that the key field is present for simple mapping
93
- assertContains (
94
- json,
95
- '"key":"0x0000000000000000000000000000000000001234" ' ,
96
- "JSON should contain decoded key field for simple mapping "
97
- );
78
+ assertTrue (vm.contains (json, '"key":"0x0000000000000000000000000000000000001234" ' ));
98
79
99
80
// Stop recording and verify we have account accesses
100
81
Vm.AccountAccess[] memory accesses = vm.stopAndReturnStateDiff ();
101
- assertTrue (accesses.length > 0 , " Should have account accesses " );
82
+ assertTrue (accesses.length > 0 );
102
83
103
84
// The AccountAccess structure contains information about storage changes
104
85
// but the label and decoded values are only available in the string/JSON outputs
@@ -122,19 +103,13 @@ contract StateDiffMappingsTest is StateDiffTestUtils {
122
103
emit log_string (stateDiffText);
123
104
124
105
// Verify text format contains decoded values for uint256 key
125
- assertContains (stateDiffText, "owners[12345] " , "Text format should contain owners mapping with decimal key " );
126
- assertContains (
127
- stateDiffText,
128
- "address): 0x0000000000000000000000000000000000000000 " ,
129
- "Text format should contain initial address value "
130
- );
131
- assertContains (
132
- stateDiffText, "0x0000000000000000000000000000000000007777 " , "Text format should contain new address value "
133
- );
106
+ assertTrue (vm.contains (stateDiffText, "owners[12345] " ));
107
+ assertTrue (vm.contains (stateDiffText, "address): 0x0000000000000000000000000000000000000000 " ));
108
+ assertTrue (vm.contains (stateDiffText, "0x0000000000000000000000000000000000007777 " ));
134
109
135
110
// Verify text format contains decoded values for bytes32 key
136
- assertContains ( stateDiffText, "bool): false " , " Text format should contain initial bool value " );
137
- assertContains ( stateDiffText, "true " , " Text format should contain new bool value " );
111
+ assertTrue (vm. contains ( stateDiffText, "bool): false " ) );
112
+ assertTrue (vm. contains ( stateDiffText, "true " ) );
138
113
139
114
// Get state diff JSON
140
115
string memory json = vm.getStateDiffJson ();
@@ -144,23 +119,22 @@ contract StateDiffMappingsTest is StateDiffTestUtils {
144
119
emit log_string (json);
145
120
146
121
// Check uint256 key mapping
147
- assertContains (json, '"label":"owners[12345]" ' , "Should contain owners mapping with uint256 key " );
148
- assertContains (json, '"type":"mapping(uint256 => address)" ' , "Should contain uint256=>address mapping type " );
149
- assertContains (
150
- json,
151
- '"decoded":{"previousValue":"0x0000000000000000000000000000000000000000","newValue":"0x0000000000000000000000000000000000007777"} ' ,
152
- "Should decode owner address correctly "
122
+ assertTrue (vm.contains (json, '"label":"owners[12345]" ' ));
123
+ assertTrue (vm.contains (json, '"type":"mapping(uint256 => address)" ' ));
124
+ assertTrue (
125
+ vm.contains (
126
+ json,
127
+ '"decoded":{"previousValue":"0x0000000000000000000000000000000000000000","newValue":"0x0000000000000000000000000000000000007777"} '
128
+ )
153
129
);
154
130
155
131
// Check bytes32 key mapping - the key will be shown as hex
156
- assertContains (json, '"label":"flags[ ' , "Should contain flags mapping label " );
157
- assertContains (json, '"type":"mapping(bytes32 => bool)" ' , "Should contain bytes32=>bool mapping type " );
158
- assertContains (
159
- json, '"decoded":{"previousValue":"false","newValue":"true"} ' , "Should decode flag bool value correctly "
160
- );
132
+ assertTrue (vm.contains (json, '"label":"flags[ ' ));
133
+ assertTrue (vm.contains (json, '"type":"mapping(bytes32 => bool)" ' ));
134
+ assertTrue (vm.contains (json, '"decoded":{"previousValue":"false","newValue":"true"} ' ));
161
135
162
136
// Check that the key field is present for uint256 key mapping
163
- assertContains ( json, '"key":"12345" ' , " JSON should contain decoded key field for uint256 mapping " );
137
+ assertTrue (vm. contains ( json, '"key":"12345" ' ) );
164
138
165
139
// Stop recording
166
140
vm.stopAndReturnStateDiff ();
@@ -190,35 +164,25 @@ contract StateDiffMappingsTest is StateDiffTestUtils {
190
164
emit log_string (stateDiffText);
191
165
192
166
// Verify text format contains nested mapping labels
193
- assertContains (
194
- stateDiffText,
195
- "allowances[0x0000000000000000000000000000000000001111][0x0000000000000000000000000000000000002222] " ,
196
- "Text format should contain first nested mapping label "
197
- );
198
- assertContains (
199
- stateDiffText,
200
- "allowances[0x0000000000000000000000000000000000001111][0x0000000000000000000000000000000000003333] " ,
201
- "Text format should contain second nested mapping label "
167
+ assertTrue (
168
+ vm.contains (
169
+ stateDiffText,
170
+ "allowances[0x0000000000000000000000000000000000001111][0x0000000000000000000000000000000000002222] "
171
+ )
172
+ );
173
+ assertTrue (
174
+ vm.contains (
175
+ stateDiffText,
176
+ "allowances[0x0000000000000000000000000000000000001111][0x0000000000000000000000000000000000003333] "
177
+ )
202
178
);
203
179
// The text format shows the value type (uint256) not the full mapping type
204
- assertContains ( stateDiffText, "uint256): 0 " , " Text format should contain value type " );
180
+ assertTrue (vm. contains ( stateDiffText, "uint256): 0 " ) );
205
181
206
182
// Verify text format contains decoded values for nested mappings
207
- assertContains (
208
- stateDiffText,
209
- "500000000000000000000 " ,
210
- "Text format should contain decoded value for owner1->spender1 (500 ether) "
211
- );
212
- assertContains (
213
- stateDiffText,
214
- "750000000000000000000 " ,
215
- "Text format should contain decoded value for owner1->spender2 (750 ether) "
216
- );
217
- assertContains (
218
- stateDiffText,
219
- "1000000000000000000000 " ,
220
- "Text format should contain decoded value for owner2->spender3 (1000 ether) "
221
- );
183
+ assertTrue (vm.contains (stateDiffText, "500000000000000000000 " ));
184
+ assertTrue (vm.contains (stateDiffText, "750000000000000000000 " ));
185
+ assertTrue (vm.contains (stateDiffText, "1000000000000000000000 " ));
222
186
223
187
// Test JSON format output
224
188
string memory json = vm.getStateDiffJson ();
@@ -228,57 +192,55 @@ contract StateDiffMappingsTest is StateDiffTestUtils {
228
192
// Check that all three nested mapping entries are correctly decoded
229
193
230
194
// Entry 1: owner1 -> spender1
231
- assertContains (
232
- json,
233
- '"label":"allowances[0x0000000000000000000000000000000000001111][0x0000000000000000000000000000000000002222]" ' ,
234
- "Should contain first nested mapping label (owner1 -> spender1) "
235
- );
236
- assertContains (
237
- json, '"newValue":"500000000000000000000" ' , "Should have correct value for owner1 -> spender1 (500 ether) "
195
+ assertTrue (
196
+ vm.contains (
197
+ json,
198
+ '"label":"allowances[0x0000000000000000000000000000000000001111][0x0000000000000000000000000000000000002222]" '
199
+ )
238
200
);
201
+ assertTrue (vm.contains (json, '"newValue":"500000000000000000000" ' ));
239
202
240
203
// Entry 2: owner1 -> spender2 (same owner, different spender)
241
- assertContains (
242
- json,
243
- '"label":"allowances[0x0000000000000000000000000000000000001111][0x0000000000000000000000000000000000003333]" ' ,
244
- "Should contain second nested mapping label (owner1 -> spender2) "
245
- );
246
- assertContains (
247
- json, '"newValue":"750000000000000000000" ' , "Should have correct value for owner1 -> spender2 (750 ether) "
204
+ assertTrue (
205
+ vm.contains (
206
+ json,
207
+ '"label":"allowances[0x0000000000000000000000000000000000001111][0x0000000000000000000000000000000000003333]" '
208
+ )
248
209
);
210
+ assertTrue (vm.contains (json, '"newValue":"750000000000000000000" ' ));
249
211
250
212
// Entry 3: owner2 -> spender3 (different owner)
251
- assertContains (
252
- json,
253
- '"label":"allowances[0x0000000000000000000000000000000000004444][0x0000000000000000000000000000000000005555]" ' ,
254
- "Should contain third nested mapping label (owner2 -> spender3) "
255
- );
256
- assertContains (
257
- json, '"newValue":"1000000000000000000000" ' , "Should have correct value for owner2 -> spender3 (1000 ether) "
213
+ assertTrue (
214
+ vm.contains (
215
+ json,
216
+ '"label":"allowances[0x0000000000000000000000000000000000004444][0x0000000000000000000000000000000000005555]" '
217
+ )
258
218
);
219
+ assertTrue (vm.contains (json, '"newValue":"1000000000000000000000" ' ));
259
220
260
221
// Check the type is correctly identified for all entries
261
- assertContains (
262
- json, '"type":"mapping(address => mapping(address => uint256))" ' , "Should contain nested mapping type "
263
- );
222
+ assertTrue (vm.contains (json, '"type":"mapping(address => mapping(address => uint256))" ' ));
264
223
265
224
// Check that the keys field is present for nested mappings
266
- assertContains (
267
- json,
268
- '"keys":["0x0000000000000000000000000000000000001111","0x0000000000000000000000000000000000002222"] ' ,
269
- "JSON should contain decoded keys array for owner1->spender1 nested mapping "
225
+ assertTrue (
226
+ vm.contains (
227
+ json,
228
+ '"keys":["0x0000000000000000000000000000000000001111","0x0000000000000000000000000000000000002222"] '
229
+ )
270
230
);
271
231
272
- assertContains (
273
- json,
274
- '"keys":["0x0000000000000000000000000000000000001111","0x0000000000000000000000000000000000003333"] ' ,
275
- "JSON should contain decoded keys array for owner1->spender2 nested mapping "
232
+ assertTrue (
233
+ vm.contains (
234
+ json,
235
+ '"keys":["0x0000000000000000000000000000000000001111","0x0000000000000000000000000000000000003333"] '
236
+ )
276
237
);
277
238
278
- assertContains (
279
- json,
280
- '"keys":["0x0000000000000000000000000000000000004444","0x0000000000000000000000000000000000005555"] ' ,
281
- "JSON should contain decoded keys array for owner2->spender3 nested mapping "
239
+ assertTrue (
240
+ vm.contains (
241
+ json,
242
+ '"keys":["0x0000000000000000000000000000000000004444","0x0000000000000000000000000000000000005555"] '
243
+ )
282
244
);
283
245
284
246
// Stop recording
0 commit comments