-
Notifications
You must be signed in to change notification settings - Fork 15
/
invalid_test.go
63 lines (55 loc) · 1.55 KB
/
invalid_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
package amt
import (
"context"
"testing"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/stretchr/testify/require"
)
func TestInvalidHeightEmpty(t *testing.T) {
runTestWithBitWidths(t, bitWidths2to18, func(t *testing.T, opts ...Option) {
bs := cbor.NewCborStore(newMockBlocks())
ctx := context.Background()
a, err := NewAMT(bs, opts...)
require.NoError(t, err)
a.height = 1
c, err := a.Flush(ctx)
require.NoError(t, err)
_, err = LoadAMT(ctx, bs, c, opts...)
require.Error(t, err)
})
}
func TestInvalidHeightSingle(t *testing.T) {
runTestWithBitWidths(t, bitWidths2to18, func(t *testing.T, opts ...Option) {
bs := cbor.NewCborStore(newMockBlocks())
ctx := context.Background()
a, err := NewAMT(bs, opts...)
require.NoError(t, err)
err = a.Set(ctx, 0, cborstr(""))
require.NoError(t, err)
a.height = 1
c, err := a.Flush(ctx)
require.NoError(t, err)
_, err = LoadAMT(ctx, bs, c, opts...)
require.Error(t, err)
})
}
func TestInvalidHeightTall(t *testing.T) {
// test only valid for widths less than 16 (2^4)
runTestWithBitWidths(t, bitWidths2to3, func(t *testing.T, opts ...Option) {
bs := cbor.NewCborStore(newMockBlocks())
ctx := context.Background()
a, err := NewAMT(bs, opts...)
require.NoError(t, err)
err = a.Set(ctx, 15, cborstr(""))
require.NoError(t, err)
a.height = 2
c, err := a.Flush(ctx)
require.NoError(t, err)
after, err := LoadAMT(ctx, bs, c, opts...)
require.NoError(t, err)
var out CborByteArray
found, err := after.Get(ctx, 31, &out)
require.NoError(t, err)
require.False(t, found)
})
}