* build(deps): Bump pgregory.net/rapid from 0.4.8 to 0.5.2 Bumps [pgregory.net/rapid](https://github.com/flyingmutant/rapid) from 0.4.8 to 0.5.2. - [Release notes](https://github.com/flyingmutant/rapid/releases) - [Commits](https://github.com/flyingmutant/rapid/compare/v0.4.8...v0.5.2) --- updated-dependencies: - dependency-name: pgregory.net/rapid dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix group tests * update orm to 0.5.2 * Fix some tests * finish upgrading orm Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Amaury M <1293565+amaurym@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
49 lines
1.1 KiB
Go
49 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")
|
|
typ := (&testpb.ExampleTable{}).ProtoReflect().Type()
|
|
tableName := typ.Descriptor().FullName()
|
|
cdc := ormkv.NewSeqCodec(typ, 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")
|
|
|
|
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))
|
|
})
|
|
}
|