Skip to content

Commit

Permalink
add calculate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal committed Jun 3, 2020
1 parent f8b2605 commit 423d657
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (p *CommitmentProof) Calculate() (CommitmentRoot, error) {
default:
return nil, errors.New("unrecognized proof type")
}
return nil, errors.New("unrecognized proof type")
}

// Verify does all checks to ensure this proof proves this key, value -> root
Expand Down
11 changes: 11 additions & 0 deletions go/vectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,19 @@ func TestVectors(t *testing.T) {
}

for _, tc := range cases {
tc := tc
name := fmt.Sprintf("%s/%s", tc.dir, tc.filename)
t.Run(name, func(t *testing.T) {
proof, ref := loadFile(t, tc.dir, tc.filename)
// Test Calculate method
calculatedRoot, err := proof.Calculate()
if err != nil {
t.Fatal("proof.Calculate() returned error")
}
if !bytes.Equal(ref.RootHash, calculatedRoot) {
t.Fatalf("calculated root: %X did not match expected root: %X", calculatedRoot, ref.RootHash)
}
// Test Verify method
if ref.Value == nil {
// non-existence
valid := VerifyNonMembership(tc.spec, ref.RootHash, proof, ref.Key)
Expand Down Expand Up @@ -218,6 +228,7 @@ func TestBatchVectors(t *testing.T) {
}

for name, tc := range cases {
tc := tc
t.Run(name, func(t *testing.T) {
// try one proof
if tc.ref.Value == nil {
Expand Down

0 comments on commit 423d657

Please sign in to comment.