x/auth/ante: Migrate tests to use the new client.TxConfig (#6661)

* 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>
This commit is contained in:
Amaury Martiny
2020-07-20 08:30:12 -04:00
committed by GitHub
co-authored by Alexander Bezobchuk
parent cc96e5c16f
commit 5c0e3b4de5
82 changed files with 1685 additions and 1183 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/testdata"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)
func createTestCodec() *codec.Codec {
+1 -1
View File
@@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec/testdata"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)
func NewTestInterfaceRegistry() types.InterfaceRegistry {
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/testdata"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)
func TestHybridCodec(t *testing.T) {
+1 -1
View File
@@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/testdata"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)
func createTestInterfaceRegistry() types.InterfaceRegistry {
-73
View File
@@ -1,73 +0,0 @@
package testdata
// DONTCOVER
// nolint
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec/types"
)
type Animal interface {
Greet() string
}
func (c Cat) Greet() string {
return fmt.Sprintf("Meow, my name is %s", c.Moniker)
}
func (d Dog) Greet() string {
return fmt.Sprintf("Roof, my name is %s", d.Name)
}
var _ types.UnpackInterfacesMessage = HasAnimal{}
func (m HasAnimal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
var animal Animal
return unpacker.UnpackAny(m.Animal, &animal)
}
type HasAnimalI interface {
TheAnimal() Animal
}
var _ HasAnimalI = &HasAnimal{}
func (m HasAnimal) TheAnimal() Animal {
return m.Animal.GetCachedValue().(Animal)
}
type HasHasAnimalI interface {
TheHasAnimal() HasAnimalI
}
var _ HasHasAnimalI = &HasHasAnimal{}
func (m HasHasAnimal) TheHasAnimal() HasAnimalI {
return m.HasAnimal.GetCachedValue().(HasAnimalI)
}
var _ types.UnpackInterfacesMessage = HasHasAnimal{}
func (m HasHasAnimal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
var animal HasAnimalI
return unpacker.UnpackAny(m.HasAnimal, &animal)
}
type HasHasHasAnimalI interface {
TheHasHasAnimal() HasHasAnimalI
}
var _ HasHasAnimalI = &HasHasAnimal{}
func (m HasHasHasAnimal) TheHasHasAnimal() HasHasAnimalI {
return m.HasHasAnimal.GetCachedValue().(HasHasAnimalI)
}
var _ types.UnpackInterfacesMessage = HasHasHasAnimal{}
func (m HasHasHasAnimal) UnpackInterfaces(unpacker types.AnyUnpacker) error {
var animal HasHasAnimalI
return unpacker.UnpackAny(m.HasHasAnimal, &animal)
}
-2818
View File
File diff suppressed because it is too large Load Diff
-72
View File
@@ -1,72 +0,0 @@
syntax = "proto3";
package testdata;
import "google/protobuf/any.proto";
import "gogoproto/gogo.proto";
option go_package = "github.com/cosmos/cosmos-sdk/codec/testdata";
message Dog {
string size = 1;
string name = 2;
}
message Cat {
string moniker = 1;
int32 lives = 2;
}
message HasAnimal {
google.protobuf.Any animal = 1;
int64 x = 2;
}
message HasHasAnimal {
google.protobuf.Any has_animal = 1;
}
message HasHasHasAnimal {
google.protobuf.Any has_has_animal = 1;
}
service TestService {
rpc Echo(EchoRequest) returns (EchoResponse);
rpc SayHello(SayHelloRequest) returns (SayHelloResponse);
rpc TestAny(TestAnyRequest) returns (TestAnyResponse);
}
message EchoRequest {
string message = 1;
}
message EchoResponse {
string message = 1;
}
message SayHelloRequest {
string name = 1;
}
message SayHelloResponse {
string greeting = 1;
}
message TestAnyRequest {
google.protobuf.Any any_animal = 1;
}
message TestAnyResponse {
HasAnimal has_animal = 1;
}
// msg type for testing
message TestMsg {
repeated bytes signers = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// bad MultiSignature with extra fields
message BadMultiSignature {
option (gogoproto.goproto_unrecognized) = true;
repeated bytes signatures = 1;
bytes malicious_field = 5;
}
-41
View File
@@ -1,41 +0,0 @@
package testdata
import (
"github.com/tendermint/go-amino"
"github.com/cosmos/cosmos-sdk/codec/types"
)
func NewTestInterfaceRegistry() types.InterfaceRegistry {
registry := types.NewInterfaceRegistry()
registry.RegisterInterface("Animal", (*Animal)(nil))
registry.RegisterImplementations(
(*Animal)(nil),
&Dog{},
&Cat{},
)
registry.RegisterImplementations(
(*HasAnimalI)(nil),
&HasAnimal{},
)
registry.RegisterImplementations(
(*HasHasAnimalI)(nil),
&HasHasAnimal{},
)
return registry
}
func NewTestAmino() *amino.Codec {
cdc := amino.NewCodec()
cdc.RegisterInterface((*Animal)(nil), nil)
cdc.RegisterConcrete(&Dog{}, "testdata/Dog", nil)
cdc.RegisterConcrete(&Cat{}, "testdata/Cat", nil)
cdc.RegisterInterface((*HasAnimalI)(nil), nil)
cdc.RegisterConcrete(&HasAnimal{}, "testdata/HasAnimal", nil)
cdc.RegisterInterface((*HasHasAnimalI)(nil), nil)
cdc.RegisterConcrete(&HasHasAnimal{}, "testdata/HasHasAnimal", nil)
return cdc
}
-26
View File
@@ -1,26 +0,0 @@
package testdata
import (
"encoding/json"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg {
return &TestMsg{
Signers: addrs,
}
}
var _ sdk.Msg = (*TestMsg)(nil)
func (msg *TestMsg) Route() string { return "TestMsg" }
func (msg *TestMsg) Type() string { return "Test message" }
func (msg *TestMsg) GetSignBytes() []byte {
bz, err := json.Marshal(msg.Signers)
if err != nil {
panic(err)
}
return sdk.MustSortJSON(bz)
}
func (msg *TestMsg) ValidateBasic() error { return nil }
-53
View File
@@ -1,53 +0,0 @@
package testdata
import (
"context"
"fmt"
"github.com/gogo/protobuf/proto"
"github.com/cosmos/cosmos-sdk/codec/types"
)
type TestServiceImpl struct{}
func (e TestServiceImpl) TestAny(_ context.Context, request *TestAnyRequest) (*TestAnyResponse, error) {
animal, ok := request.AnyAnimal.GetCachedValue().(Animal)
if !ok {
return nil, fmt.Errorf("expected Animal")
}
any, err := types.NewAnyWithValue(animal.(proto.Message))
if err != nil {
return nil, err
}
return &TestAnyResponse{HasAnimal: &HasAnimal{
Animal: any,
X: 10,
}}, nil
}
func (e TestServiceImpl) Echo(_ context.Context, req *EchoRequest) (*EchoResponse, error) {
return &EchoResponse{Message: req.Message}, nil
}
func (e TestServiceImpl) SayHello(_ context.Context, request *SayHelloRequest) (*SayHelloResponse, error) {
greeting := fmt.Sprintf("Hello %s!", request.Name)
return &SayHelloResponse{Greeting: greeting}, nil
}
var _ TestServiceServer = TestServiceImpl{}
var _ types.UnpackInterfacesMessage = &TestAnyRequest{}
func (m *TestAnyRequest) UnpackInterfaces(unpacker types.AnyUnpacker) error {
var animal Animal
return unpacker.UnpackAny(m.AnyAnimal, &animal)
}
var _ types.UnpackInterfacesMessage = &TestAnyResponse{}
func (m *TestAnyResponse) UnpackInterfaces(unpacker types.AnyUnpacker) error {
return m.HasAnimal.UnpackInterfaces(unpacker)
}
+1 -1
View File
@@ -6,8 +6,8 @@ import (
"github.com/stretchr/testify/suite"
amino "github.com/tendermint/go-amino"
"github.com/cosmos/cosmos-sdk/codec/testdata"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)
type TypeWithInterface struct {
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec/testdata"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)
func TestPackUnpack(t *testing.T) {