cosmos-sdk/codec/collections_test.go
testinginprod 2b7a1102ed
refactor(bank): use collections for state management (#15293)
Co-authored-by: testinginprod <testinginprod@somewhere.idk>
2023-03-09 11:36:39 +00:00

38 lines
936 B
Go

package codec
import (
"testing"
"github.com/stretchr/testify/require"
"cosmossdk.io/collections/colltest"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
gogotypes "github.com/cosmos/gogoproto/types"
)
func TestCollectionsCorrectness(t *testing.T) {
cdc := NewProtoCodec(codectypes.NewInterfaceRegistry())
t.Run("CollValue", func(t *testing.T) {
colltest.TestValueCodec(t, CollValue[gogotypes.UInt64Value](cdc), gogotypes.UInt64Value{
Value: 500,
})
})
t.Run("BoolValue", func(t *testing.T) {
colltest.TestValueCodec(t, BoolValue, true)
colltest.TestValueCodec(t, BoolValue, false)
// asserts produced bytes are equal
valueAssert := func(b bool) {
wantBytes, err := (&gogotypes.BoolValue{Value: b}).Marshal()
require.NoError(t, err)
gotBytes, err := BoolValue.Encode(b)
require.NoError(t, err)
require.Equal(t, wantBytes, gotBytes)
}
valueAssert(true)
valueAssert(false)
})
}