@@ -64,6 +64,20 @@ type consistencyProbe struct {
6464 WantError bool `json:"wantErr"`
6565}
6666
67+ // subtreeConsistencyProbe is a parameter set for subtree consistency proof
68+ // verification.
69+ type subtreeConsistencyProbe struct {
70+ Start uint64 `json:"start"`
71+ End uint64 `json:"end"`
72+ Size uint64 `json:"size"`
73+ Root1 []byte `json:"root1"`
74+ Root2 []byte `json:"root2"`
75+ Proof [][]byte `json:"proof"`
76+
77+ Desc string `json:"desc"`
78+ WantError bool `json:"wantErr"`
79+ }
80+
6781func TestVerifyInclusionProbes (t * testing.T ) {
6882 var probes []inclusionProbe
6983
@@ -219,3 +233,55 @@ func TestVerifyConsistencyProbes(t *testing.T) {
219233 t .Errorf ("errors verifying consistency probes: \n %d out of %d failures \n Error messages: \n %s" , len (wrong ), len (probes ), strings .Join (wrong , "\n " ))
220234 }
221235}
236+
237+ func TestVerifySubtreeConsistencyProbes (t * testing.T ) {
238+ var probes []subtreeConsistencyProbe
239+
240+ if err := filepath .WalkDir ("../testdata/subtreeconsistency" , func (path string , d fs.DirEntry , err error ) error {
241+ if err != nil {
242+ return err
243+ }
244+
245+ if d .IsDir () {
246+ return nil
247+ }
248+
249+ if filepath .Ext (d .Name ()) != ".json" {
250+ return nil
251+ }
252+
253+ data , err := os .ReadFile (path )
254+ if err != nil {
255+ return err
256+ }
257+
258+ var probe subtreeConsistencyProbe
259+ if err := json .Unmarshal (data , & probe ); err != nil {
260+ return fmt .Errorf ("failed to parse subtree consistency probe json: %s" , err )
261+ }
262+
263+ probes = append (probes , probe )
264+
265+ return nil
266+ }); err != nil {
267+ t .Errorf ("failed to read subtree consistency probes: %s" , err )
268+ }
269+
270+ var wrong []string
271+ for _ , p := range probes {
272+ err := VerifySubtreeConsistency (rfc6962 .DefaultHasher , p .Start , p .End , p .Size , p .Proof , p .Root1 , p .Root2 )
273+ if p .WantError && err == nil {
274+ wrong = append (wrong , fmt .Sprintf ("expected error but didn't get one: %s" , p .Desc ))
275+ continue
276+ }
277+
278+ if ! p .WantError && err != nil {
279+ wrong = append (wrong , fmt .Sprintf ("unexpected error: %s, %s" , p .Desc , err ))
280+ continue
281+ }
282+ }
283+
284+ if len (wrong ) > 0 {
285+ t .Errorf ("errors verifying subtree consistency probes: \n %d out of %d failures \n Error messages: \n %s" , len (wrong ), len (probes ), strings .Join (wrong , "\n " ))
286+ }
287+ }
0 commit comments