Skip to content

Commit

Permalink
VerifyInclusion InvalidInput
Browse files Browse the repository at this point in the history
  • Loading branch information
andrijamitrovic23 committed Mar 24, 2023
1 parent 5f30795 commit 9e1abe7
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,61 @@ func TestProof_MultipleLeaves(t *testing.T) {
}
}

func TestProof_VerifyInclusion_InvalidInput(t *testing.T) {
const testNidLen = 1

n := New(sha256.New(), NamespaceIDSize(testNidLen))

data := [][]byte{
append(namespace.ID{1}, []byte("leaf_0")...),
append(namespace.ID{1}, []byte("leaf_1")...),
append(namespace.ID{2}, []byte("leaf_2")...),
append(namespace.ID{2}, []byte("leaf_3")...),
append(namespace.ID{3}, []byte("leaf_4")...),
append(namespace.ID{3}, []byte("leaf_5")...),
}
for _, d := range data {
err := n.Push(d)
if err != nil {
t.Fatalf("invalid test setup: error on Push(): %v", err)
}
}

validProof, err := n.ProveNamespace([]byte{1})
if err != nil {
t.Fatalf("invalid test setup: error on ProveNamespace(): %v", err)
}

type args struct {
nID namespace.ID
data [][]byte
root []byte
}

rawDataForNSOne := [][]byte{[]byte("leaf_0"), []byte("leaf_1")}
tests := []struct {
name string
proof Proof
args args
want bool
}{
{
"invalid nid (too long)", validProof,
args{[]byte{1, 1}, rawDataForNSOne, n.Root()},
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

got := tt.proof.VerifyInclusion(sha256.New(), tt.args.nID, tt.args.data, tt.args.root)
if got != tt.want {
t.Errorf("VerifyInclusion() got = %v, want %v", got, tt.want)
}
})
}
}

func safeAppend(id, data []byte) []byte {
return append(append(make([]byte, 0, len(id)+len(data)), id...), data...)
}
Expand Down

0 comments on commit 9e1abe7

Please sign in to comment.