@@ -158,7 +158,100 @@ func Test_Trie_WriteDirty_ClearPrefix(t *testing.T) {
158
158
assert .Equal (t , trie .String (), trieFromDB .String ())
159
159
}
160
160
161
- func Test_Trie_GetFromDB (t * testing.T ) {
161
+ func Test_PopulateMerkleValues (t * testing.T ) {
162
+ t .Parallel ()
163
+
164
+ someNode := & Node {Key : []byte {1 }, SubValue : []byte {2 }}
165
+
166
+ testCases := map [string ]struct {
167
+ trie * Trie
168
+ node * Node
169
+ merkleValues map [string ]struct {}
170
+ errSentinel error
171
+ errMessage string
172
+ }{
173
+ "nil node" : {
174
+ trie : & Trie {},
175
+ merkleValues : map [string ]struct {}{},
176
+ },
177
+ "leaf node" : {
178
+ trie : & Trie {},
179
+ node : & Node {MerkleValue : []byte ("a" )},
180
+ merkleValues : map [string ]struct {}{
181
+ "a" : {},
182
+ },
183
+ },
184
+ "leaf node without Merkle value" : {
185
+ trie : & Trie {},
186
+ node : & Node {Key : []byte {1 }, SubValue : []byte {2 }},
187
+ merkleValues : map [string ]struct {}{
188
+ "A\x01 \x04 \x02 " : {},
189
+ },
190
+ },
191
+ "root leaf node without Merkle value" : {
192
+ trie : & Trie {
193
+ root : someNode ,
194
+ },
195
+ node : someNode ,
196
+ merkleValues : map [string ]struct {}{
197
+ "`Qm\v \xb6 \xe1 \xbb \xfb \x12 \x93 \xf1 \xb2 v\xea \x95 \x05 \xe9 \xf4 \xa4 \xe7 ُb\r \x05 \x11 ^\v \x85 'J\xe1 " : {}, //nolint:lll
198
+ },
199
+ },
200
+ "branch node" : {
201
+ trie : & Trie {},
202
+ node : & Node {
203
+ MerkleValue : []byte ("a" ),
204
+ Children : padRightChildren ([]* Node {
205
+ {MerkleValue : []byte ("b" )},
206
+ }),
207
+ },
208
+ merkleValues : map [string ]struct {}{
209
+ "a" : {},
210
+ "b" : {},
211
+ },
212
+ },
213
+ "nested branch node" : {
214
+ trie : & Trie {},
215
+ node : & Node {
216
+ MerkleValue : []byte ("a" ),
217
+ Children : padRightChildren ([]* Node {
218
+ {MerkleValue : []byte ("b" )},
219
+ {
220
+ MerkleValue : []byte ("c" ),
221
+ Children : padRightChildren ([]* Node {
222
+ {MerkleValue : []byte ("d" )},
223
+ }),
224
+ },
225
+ }),
226
+ },
227
+ merkleValues : map [string ]struct {}{
228
+ "a" : {},
229
+ "b" : {},
230
+ "c" : {},
231
+ "d" : {},
232
+ },
233
+ },
234
+ }
235
+
236
+ for name , testCase := range testCases {
237
+ testCase := testCase
238
+ t .Run (name , func (t * testing.T ) {
239
+ t .Parallel ()
240
+
241
+ merkleValues := make (map [string ]struct {})
242
+
243
+ err := testCase .trie .PopulateMerkleValues (testCase .node , merkleValues )
244
+
245
+ assert .ErrorIs (t , err , testCase .errSentinel )
246
+ if testCase .errSentinel != nil {
247
+ assert .EqualError (t , err , testCase .errMessage )
248
+ }
249
+ assert .Equal (t , testCase .merkleValues , merkleValues )
250
+ })
251
+ }
252
+ }
253
+
254
+ func Test_GetFromDB (t * testing.T ) {
162
255
t .Parallel ()
163
256
164
257
const size = 1000
0 commit comments