Skip to content

Commit 53bebf1

Browse files
authored
Fix consistency proof test description with empty proof. (transparency-dev#234)
* fix consistency proof test description with empty proof * better messages * better fileNames
1 parent bfde64d commit 53bebf1

6 files changed

Lines changed: 18 additions & 10 deletions

cmd/proofgen/main.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,16 @@ func staticInclusionProbes(rootDir string) error {
275275
}
276276

277277
func writeInclusionProbe(dir string, probe inclusionProbe) error {
278-
fileName := strings.ReplaceAll(probe.Desc, " ", "-") + ".json"
278+
fn := fileName(probe.Desc)
279279

280280
probeJson, err := json.MarshalIndent(probe, "", " ")
281281
if err != nil {
282282
return fmt.Errorf("marshaling probe: %s", err)
283283
}
284284

285-
fileLocation := filepath.Join(dir, fileName)
285+
fileLocation := filepath.Join(dir, fn)
286286
if err := os.WriteFile(fileLocation, probeJson, 0644); err != nil {
287-
return fmt.Errorf("writing probe: %s: %s", fileName, err)
287+
return fmt.Errorf("writing probe: %s: %s", fn, err)
288288
}
289289

290290
return nil
@@ -403,9 +403,9 @@ func staticConsistencyProbes(dir string) error {
403403
{0, 0, root1, root2, proof1, "sizes are equal (zero) but roots are not", true},
404404
{1, 1, root1, root2, proof1, "sizes are equal (one) but roots are not", true},
405405
// Sizes that are always consistent.
406-
{0, 0, root1, root1, proof1, "sizes are equal and proof is not empty where both sizes are zero", false},
406+
{0, 0, root1, root1, proof1, "sizes are equal (zero) and proof is empty", false},
407407
{0, 1, root1, root2, proof1, "size1 is zero and does not equal size2", true},
408-
{1, 1, root2, root2, proof1, "sizes are equal and proof is not empty where both sizes are one", false},
408+
{1, 1, root2, root2, proof1, "sizes are equal (one) and proof is empty", false},
409409
// Time travel to the past.
410410
{1, 0, root1, root2, proof1, "size1 is greater than size2", true},
411411
{2, 1, root1, root2, proof1, "size1 is greater than size2 again", true},
@@ -431,16 +431,16 @@ func staticConsistencyProbes(dir string) error {
431431
}
432432

433433
func writeConsistencyProbe(dir string, probe consistencyProbe) error {
434-
fileName := strings.ReplaceAll(probe.Desc, " ", "-") + ".json"
434+
fn := fileName(probe.Desc)
435435

436436
probeJson, err := json.MarshalIndent(probe, "", " ")
437437
if err != nil {
438438
return fmt.Errorf("marshaling probe: %s", err)
439439
}
440440

441-
fileLocation := filepath.Join(dir, fileName)
441+
fileLocation := filepath.Join(dir, fn)
442442
if err := os.WriteFile(fileLocation, probeJson, 0644); err != nil {
443-
return fmt.Errorf("writing probe: %s: %s", fileName, err)
443+
return fmt.Errorf("writing probe: %s: %s", fn, err)
444444
}
445445

446446
return nil
@@ -467,6 +467,14 @@ func dh(h string, expLen int) []byte {
467467
return r
468468
}
469469

470+
func fileName(n string) string {
471+
r := strings.NewReplacer(
472+
"(", "",
473+
")", "",
474+
" ", "-")
475+
return r.Replace(n) + ".json"
476+
}
477+
470478
func main() {
471479
inclusionDir := "testdata/inclusion"
472480
if err := inclusionProbes(inclusionDir); err != nil {

testdata/consistency/additional/consistency-check-on-empty-tree-(size1-is-zero)-is-useless.json renamed to testdata/consistency/additional/consistency-check-on-empty-tree-size1-is-zero-is-useless.json

File renamed without changes.

testdata/consistency/additional/sizes-are-equal-and-proof-is-not-empty-where-both-sizes-are-one.json renamed to testdata/consistency/additional/sizes-are-equal-one-and-proof-is-empty.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"root1": "ZG9uJ3QgY2FyZSAy",
55
"root2": "ZG9uJ3QgY2FyZSAy",
66
"proof": [],
7-
"desc": "sizes are equal and proof is not empty where both sizes are one",
7+
"desc": "sizes are equal (one) and proof is empty",
88
"wantErr": false
99
}

testdata/consistency/additional/sizes-are-equal-(one)-but-roots-are-not.json renamed to testdata/consistency/additional/sizes-are-equal-one-but-roots-are-not.json

File renamed without changes.

testdata/consistency/additional/sizes-are-equal-and-proof-is-not-empty-where-both-sizes-are-zero.json renamed to testdata/consistency/additional/sizes-are-equal-zero-and-proof-is-empty.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"root1": "ZG9uJ3QgY2FyZSAx",
55
"root2": "ZG9uJ3QgY2FyZSAx",
66
"proof": [],
7-
"desc": "sizes are equal and proof is not empty where both sizes are zero",
7+
"desc": "sizes are equal (zero) and proof is empty",
88
"wantErr": false
99
}

testdata/consistency/additional/sizes-are-equal-(zero)-but-roots-are-not.json renamed to testdata/consistency/additional/sizes-are-equal-zero-but-roots-are-not.json

File renamed without changes.

0 commit comments

Comments
 (0)