forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnaming_test.go
59 lines (50 loc) · 2.29 KB
/
naming_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
package collections
import (
"testing"
"github.com/stretchr/testify/require"
"cosmossdk.io/collections/codec"
)
func TestNaming(t *testing.T) {
expectKeyCodecName(t, "u16", Uint16Key.WithName("u16"))
expectKeyCodecName(t, "u32", Uint32Key.WithName("u32"))
expectKeyCodecName(t, "u64", Uint64Key.WithName("u64"))
expectKeyCodecName(t, "i32", Int32Key.WithName("i32"))
expectKeyCodecName(t, "i64", Int64Key.WithName("i64"))
expectKeyCodecName(t, "str", StringKey.WithName("str"))
expectKeyCodecName(t, "bytes", BytesKey.WithName("bytes"))
expectKeyCodecName(t, "bool", BoolKey.WithName("bool"))
expectValueCodecName(t, "vu16", Uint16Value.WithName("vu16"))
expectValueCodecName(t, "vu32", Uint32Value.WithName("vu32"))
expectValueCodecName(t, "vu64", Uint64Value.WithName("vu64"))
expectValueCodecName(t, "vi32", Int32Value.WithName("vi32"))
expectValueCodecName(t, "vi64", Int64Value.WithName("vi64"))
expectValueCodecName(t, "vstr", StringValue.WithName("vstr"))
expectValueCodecName(t, "vbytes", BytesValue.WithName("vbytes"))
expectValueCodecName(t, "vbool", BoolValue.WithName("vbool"))
expectKeyCodecNames(t, NamedPairKeyCodec[bool, string]("abc", BoolKey, "def", StringKey), "abc", "def")
expectKeyCodecNames(t, NamedTripleKeyCodec[bool, string, int32]("abc", BoolKey, "def", StringKey, "ghi", Int32Key), "abc", "def", "ghi")
expectKeyCodecNames(t, NamedQuadKeyCodec[bool, string, int32, uint64]("abc", BoolKey, "def", StringKey, "ghi", Int32Key, "jkl", Uint64Key), "abc", "def", "ghi", "jkl")
}
func expectKeyCodecName[T any](t *testing.T, name string, cdc codec.KeyCodec[T]) {
t.Helper()
schema, err := codec.KeySchemaCodec(cdc)
require.NoError(t, err)
require.Equal(t, 1, len(schema.Fields))
require.Equal(t, name, schema.Fields[0].Name)
}
func expectValueCodecName[T any](t *testing.T, name string, cdc codec.ValueCodec[T]) {
t.Helper()
schema, err := codec.ValueSchemaCodec(cdc)
require.NoError(t, err)
require.Equal(t, 1, len(schema.Fields))
require.Equal(t, name, schema.Fields[0].Name)
}
func expectKeyCodecNames[T any](t *testing.T, cdc codec.KeyCodec[T], names ...string) {
t.Helper()
schema, err := codec.KeySchemaCodec(cdc)
require.NoError(t, err)
require.Equal(t, len(names), len(schema.Fields))
for i, name := range names {
require.Equal(t, name, schema.Fields[i].Name)
}
}