-
Notifications
You must be signed in to change notification settings - Fork 37
/
parameters_test.go
64 lines (53 loc) · 1.85 KB
/
parameters_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package merkletree
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTreeParameters(t *testing.T) {
p, err := parseAndCheckTreeParameters(
WithHashType(nil),
)
assert.Nil(t, p, "prams should be nil on error")
assert.Equal(t, err.Error(), "no hash type specified")
p, err = parseAndCheckTreeParameters()
assert.Nil(t, p, "prams should be nil on error")
assert.Equal(t, err.Error(), "tree must have at least 1 piece of data")
p, err = parseAndCheckTreeParameters(
WithData([][]byte{{'a'}}),
WithValues(1),
)
assert.Nil(t, p, "prams should be nil on error")
assert.Equal(t, err.Error(), "merkle tree does not use the values parameter")
p, err = parseAndCheckTreeParameters(
WithData([][]byte{{'a'}}),
WithHashes(map[uint64][]byte{0: {'a'}}),
)
assert.Nil(t, p, "prams should be nil on error")
assert.Equal(t, err.Error(), "merkle tree does not use the hashes parameter")
p, err = parseAndCheckTreeParameters(
WithData([][]byte{{'a'}}),
WithIndices([]uint64{0}),
)
assert.Nil(t, p, "prams should be nil on error")
assert.Equal(t, err.Error(), "merkle tree does not use the indices parameter")
p, err = parseAndCheckMultiProofParameters(
WithHashType(nil),
)
assert.Nil(t, p, "prams should be nil on error")
assert.Equal(t, err.Error(), "no hash type specified")
p, err = parseAndCheckMultiProofParameters()
assert.Nil(t, p, "prams should be nil on error")
assert.Equal(t, err.Error(), "no values specified")
p, err = parseAndCheckMultiProofParameters(
WithValues(1),
)
assert.Nil(t, p, "prams should be nil on error")
assert.Equal(t, err.Error(), "no indices specified")
p, err = parseAndCheckMultiProofParameters(
WithValues(1),
WithIndices([]uint64{0}),
WithData([][]byte{{'a'}}),
)
assert.Nil(t, p, "prams should be nil on error")
assert.Equal(t, err.Error(), "proof does not use the data parameter")
}