* WIP: using encoding config * Make it compile, test fails * test should be okay * Make tests pass * Add comments * Convert more tests * Make TestAnteHandlerSigErrors work * Make first 2 tests pass * TestAnteHandlerAccountNumbers * Use table tests * Remove print * Use test table * TestAnteHandlerSigErrors * TestAnteHandlerAccountNumbers * TestAnteHandlerAccountNumbers * Refactor TestAccount * Refactor getSignBytes * TestAnteHandlerAccountNumbersAtBlockHeightZero * TestAnteHandlerSequences * TestAnteHandlerFees * TestAnteHandlerMultiSigner * TestAnteHandlerBadSignBytes * TestAnteHandlerSetPubKey * TestAnteHandlerSigLimitExceeded * TestCustomSignatureVerificationGasConsumer * TestAnteHandlerReCheck * Make all tests pass * Refactor a little bit more * Fee test * SetupTest * All tests pass * Refactor to RunTestCase * Don't use StdFee * Revert some little stuff * Finish up last couple of test cases * Less verbose * s/TxGenerator/TxConfig * Add comments * Indent * Move KeyTestPubAddr to testdata * Move testdata to /testutil * Revert to use signature: nil step in signing * Add comments Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package codec_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
)
|
|
|
|
func NewTestInterfaceRegistry() types.InterfaceRegistry {
|
|
registry := types.NewInterfaceRegistry()
|
|
registry.RegisterInterface("Animal", (*testdata.Animal)(nil))
|
|
registry.RegisterImplementations(
|
|
(*testdata.Animal)(nil),
|
|
&testdata.Dog{},
|
|
&testdata.Cat{},
|
|
)
|
|
return registry
|
|
}
|
|
|
|
func TestMarshalAny(t *testing.T) {
|
|
registry := types.NewInterfaceRegistry()
|
|
|
|
cdc := codec.NewProtoCodec(registry)
|
|
|
|
kitty := &testdata.Cat{Moniker: "Kitty"}
|
|
bz, err := codec.MarshalAny(cdc, kitty)
|
|
require.NoError(t, err)
|
|
|
|
var animal testdata.Animal
|
|
|
|
// empty registry should fail
|
|
err = codec.UnmarshalAny(cdc, &animal, bz)
|
|
require.Error(t, err)
|
|
|
|
// wrong type registration should fail
|
|
registry.RegisterImplementations((*testdata.Animal)(nil), &testdata.Dog{})
|
|
err = codec.UnmarshalAny(cdc, &animal, bz)
|
|
require.Error(t, err)
|
|
|
|
// should pass
|
|
registry = NewTestInterfaceRegistry()
|
|
cdc = codec.NewProtoCodec(registry)
|
|
err = codec.UnmarshalAny(cdc, &animal, bz)
|
|
require.NoError(t, err)
|
|
require.Equal(t, kitty, animal)
|
|
|
|
// nil should fail
|
|
registry = NewTestInterfaceRegistry()
|
|
err = codec.UnmarshalAny(cdc, nil, bz)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestMarshalAnyNonProtoErrors(t *testing.T) {
|
|
registry := types.NewInterfaceRegistry()
|
|
cdc := codec.NewProtoCodec(registry)
|
|
|
|
_, err := codec.MarshalAny(cdc, 29)
|
|
require.Error(t, err)
|
|
require.Equal(t, err, errors.New("can't proto marshal int"))
|
|
}
|