cosmos-sdk/orm/encoding/ormkv/seq_test.go
Aaron Craelius c41ac20c6c
feat(orm): add ormkv.EntryCodec and ormkv.IndexCodec's (#10647)
* feat(orm): add KeyCodec

* WIP

* code coverage

* add DefaultValue test

* fix range key check

* revert DefaultValue

* fix range check

* feat(orm): add ormkv.Codec's

* WIP

* add UniqueKeyCodec

* add IndexKeyCodec

* fixes

* add SeqCodec

* add doc comments

* test fields

* refactor field names

* Update orm/encoding/ormkv/index_key.go

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>

* Update orm/encoding/ormkv/index_key.go

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>

* Update orm/encoding/ormkv/index_key.go

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>

* Update orm/encoding/ormkv/unique_key.go

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>

* add tests for entry strings

* address review comments

* fix non-deterministic string rendering and tests

* Update x/auth/middleware/priority_test.go

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>

* Update x/auth/middleware/priority_test.go

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
2021-12-02 22:21:57 -05:00

48 lines
1.1 KiB
Go

package ormkv_test
import (
"bytes"
"testing"
"github.com/cosmos/cosmos-sdk/orm/encoding/ormkv"
"gotest.tools/v3/assert"
"pgregory.net/rapid"
"github.com/cosmos/cosmos-sdk/orm/internal/testpb"
)
func TestSeqCodec(t *testing.T) {
rapid.Check(t, func(t *rapid.T) {
prefix := rapid.SliceOfN(rapid.Byte(), 0, 5).Draw(t, "prefix").([]byte)
tableName := (&testpb.A{}).ProtoReflect().Descriptor().FullName()
cdc := ormkv.NewSeqCodec(tableName, prefix)
seq, err := cdc.DecodeValue(nil)
assert.NilError(t, err)
assert.Equal(t, uint64(0), seq)
seq, err = cdc.DecodeValue([]byte{})
assert.NilError(t, err)
assert.Equal(t, uint64(0), seq)
seq = rapid.Uint64().Draw(t, "seq").(uint64)
v := cdc.EncodeValue(seq)
seq2, err := cdc.DecodeValue(v)
assert.NilError(t, err)
assert.Equal(t, seq, seq2)
entry := &ormkv.SeqEntry{
TableName: tableName,
Value: seq,
}
k, v, err := cdc.EncodeEntry(entry)
assert.NilError(t, err)
entry2, err := cdc.DecodeEntry(k, v)
assert.NilError(t, err)
assert.DeepEqual(t, entry, entry2)
assert.Assert(t, bytes.Equal(cdc.Prefix(), k))
})
}