-
Notifications
You must be signed in to change notification settings - Fork 26
/
node_leaf_test.go
57 lines (43 loc) · 1.61 KB
/
node_leaf_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
package graviton
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestHashPanic(t *testing.T) {
store, err := NewMemStore()
//store,err := NewDiskStore("/tmp/test")
require.NoError(t, err)
var l leaf
l.loaded_partial = true
_, err = l.Hash(store) // it will panic and thus successfully complete the test
require.Error(t, err)
}
func TestLoadfullleaffromstore(t *testing.T) {
store, err := NewMemStore()
//store,err := NewDiskStore("/tmp/test")
require.NoError(t, err)
var l leaf
l.loaded_partial = true
_, err = l.Get(store, sum([]byte("dummykey"))) // trigger load error for Get
require.Error(t, err)
_, _, err = l.Delete(store, sum([]byte("dummykey"))) // trigger load error for Delete
require.Error(t, err)
var p Proof
err = l.Prove(store, sum([]byte("dummykey")), &p) // trigger load error for Prove
require.Error(t, err)
err = l.Put(store, sum([]byte("dummykey")), []byte("dummyvalue")) // trigger load error for Get
require.Error(t, err)
l.findex = 100000
err = l.loadfullleaffromstore(store)
require.Error(t, err)
keysizeerror := []byte{0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88} // more than 2^64
l.findex, l.fpos, err = store.write(keysizeerror)
require.NoError(t, err)
err = l.loadfullleaffromstore(store) // loading it will give keysize error
require.Error(t, err)
valuesizeerror := []byte{0x1, 0x0, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88} // more than 2^64
l.findex, l.fpos, err = store.write(valuesizeerror)
require.NoError(t, err)
err = l.loadfullleaffromstore(store) // loading it will give value size error
require.Error(t, err)
}