forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcollections_test.go
43 lines (35 loc) · 949 Bytes
/
collections_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
package collections
import (
"context"
"math"
"testing"
"github.com/stretchr/testify/require"
"cosmossdk.io/core/store"
"cosmossdk.io/core/testing"
)
func deps() (store.KVStoreService, context.Context) {
ctx := coretesting.Context()
kv := coretesting.KVStoreService(ctx, "test")
return kv, ctx
}
func TestPrefix(t *testing.T) {
t.Run("panics on invalid int", func(t *testing.T) {
require.Panics(t, func() {
NewPrefix(math.MaxUint8 + 1)
})
})
t.Run("string", func(t *testing.T) {
require.Equal(t, []byte("prefix"), NewPrefix("prefix").Bytes())
})
t.Run("int", func(t *testing.T) {
require.Equal(t, []byte{0x1}, NewPrefix(1).Bytes())
})
t.Run("[]byte", func(t *testing.T) {
bytes := []byte("prefix")
prefix := NewPrefix(bytes)
require.Equal(t, bytes, prefix.Bytes())
// assert if modification happen they do not propagate to prefix
bytes[0] = 0x0
require.Equal(t, []byte("prefix"), prefix.Bytes())
})
}