diff --git a/testutil/cli/tm_mocks.go b/testutil/cli/tm_mocks.go new file mode 100644 index 000000000000..bfbcaca1196e --- /dev/null +++ b/testutil/cli/tm_mocks.go @@ -0,0 +1,41 @@ +package cli + +import ( + "context" + + abci "github.com/tendermint/tendermint/abci/types" + tmbytes "github.com/tendermint/tendermint/libs/bytes" + rpcclient "github.com/tendermint/tendermint/rpc/client" + rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" + coretypes "github.com/tendermint/tendermint/rpc/core/types" + tmtypes "github.com/tendermint/tendermint/types" + + "github.com/cosmos/cosmos-sdk/client" +) + +var _ client.TendermintRPC = (*MockTendermintRPC)(nil) + +type MockTendermintRPC struct { + rpcclientmock.Client + + responseQuery abci.ResponseQuery +} + +// NewMockTendermintRPC returns a mock TendermintRPC implementation. +// It is used for CLI testing. +func NewMockTendermintRPC(respQuery abci.ResponseQuery) MockTendermintRPC { + return MockTendermintRPC{responseQuery: respQuery} +} + +func (MockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { + return &coretypes.ResultBroadcastTx{Code: 0}, nil +} + +func (m MockTendermintRPC) ABCIQueryWithOptions( + _ context.Context, + _ string, + _ tmbytes.HexBytes, + _ rpcclient.ABCIQueryOptions, +) (*coretypes.ResultABCIQuery, error) { + return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil +} diff --git a/x/auth/client/cli/suite_test.go b/x/auth/client/cli/suite_test.go index 74358446143c..3da473db2cb5 100644 --- a/x/auth/client/cli/suite_test.go +++ b/x/auth/client/cli/suite_test.go @@ -11,12 +11,8 @@ import ( "cosmossdk.io/math" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmbytes "github.com/tendermint/tendermint/libs/bytes" tmcli "github.com/tendermint/tendermint/libs/cli" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -42,30 +38,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{Code: 0}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmbytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - type CLITestSuite struct { suite.Suite @@ -88,7 +60,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -96,7 +68,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) diff --git a/x/authz/client/cli/tx_test.go b/x/authz/client/cli/tx_test.go index a0bf682f48ff..91903bdcf41f 100644 --- a/x/authz/client/cli/tx_test.go +++ b/x/authz/client/cli/tx_test.go @@ -2,7 +2,6 @@ package cli_test import ( "bytes" - "context" "fmt" "io" "testing" @@ -11,11 +10,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -41,30 +36,6 @@ var ( typeMsgSubmitProposal = sdk.MsgTypeURL(&govv1.MsgSubmitProposal{}) ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{Code: 0}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmbytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - type CLITestSuite struct { suite.Suite @@ -87,7 +58,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -95,7 +66,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) diff --git a/x/bank/client/cli/query_test.go b/x/bank/client/cli/query_test.go index dfb6f0d784d9..243513c60611 100644 --- a/x/bank/client/cli/query_test.go +++ b/x/bank/client/cli/query_test.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/client/cli" "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -35,7 +36,7 @@ func (s *CLITestSuite) TestGetBalancesCmd() { "valid query", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&types.QueryAllBalancesResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -53,7 +54,7 @@ func (s *CLITestSuite) TestGetBalancesCmd() { bz, _ := s.encCfg.Codec.Marshal(&types.QueryBalanceResponse{ Balance: &sdk.Coin{}, }) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -80,7 +81,7 @@ func (s *CLITestSuite) TestGetBalancesCmd() { { "invalid denom", func() client.Context { - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Code: 1, }) return s.baseCtx.WithClient(c) @@ -134,7 +135,7 @@ func (s *CLITestSuite) TestGetCmdDenomsMetadata() { "valid query", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&types.QueryDenomsMetadataResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -149,7 +150,7 @@ func (s *CLITestSuite) TestGetCmdDenomsMetadata() { "valid query with denom", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&types.QueryDenomMetadataResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -164,7 +165,7 @@ func (s *CLITestSuite) TestGetCmdDenomsMetadata() { { "invalid query with denom", func() client.Context { - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Code: 1, }) return s.baseCtx.WithClient(c) @@ -217,7 +218,7 @@ func (s *CLITestSuite) TestGetCmdQueryTotalSupply() { "valid query", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&types.QueryTotalSupplyResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -234,7 +235,7 @@ func (s *CLITestSuite) TestGetCmdQueryTotalSupply() { bz, _ := s.encCfg.Codec.Marshal(&types.QuerySupplyOfResponse{ Amount: sdk.Coin{}, }) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -249,7 +250,7 @@ func (s *CLITestSuite) TestGetCmdQueryTotalSupply() { { "invalid query with denom", func() client.Context { - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Code: 1, }) return s.baseCtx.WithClient(c) @@ -305,7 +306,7 @@ func (s *CLITestSuite) TestGetCmdQuerySendEnabled() { bz, _ := s.encCfg.Codec.Marshal(&types.QuerySendEnabledResponse{ SendEnabled: []*types.SendEnabled{}, }) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -322,7 +323,7 @@ func (s *CLITestSuite) TestGetCmdQuerySendEnabled() { bz, _ := s.encCfg.Codec.Marshal(&types.QuerySendEnabledResponse{ SendEnabled: []*types.SendEnabled{}, }) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) diff --git a/x/bank/client/cli/suite_test.go b/x/bank/client/cli/suite_test.go index 27b01e0d0ec3..9baefdc8ffdc 100644 --- a/x/bank/client/cli/suite_test.go +++ b/x/bank/client/cli/suite_test.go @@ -1,48 +1,19 @@ package cli_test import ( - "context" "io" "testing" "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto/keyring" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/bank" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{Code: 0}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ bytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - type CLITestSuite struct { suite.Suite @@ -62,7 +33,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard) } diff --git a/x/crisis/client/cli/tx_test.go b/x/crisis/client/cli/tx_test.go index c8b23bf40278..d8b92433fd74 100644 --- a/x/crisis/client/cli/tx_test.go +++ b/x/crisis/client/cli/tx_test.go @@ -6,10 +6,9 @@ import ( "io" "testing" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/stretchr/testify/require" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -22,16 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/crisis/client/cli" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client -} - -func (mockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{}, nil -} - func TestNewMsgVerifyInvariantTxCmd(t *testing.T) { encCfg := testutilmod.MakeTestEncodingConfig(crisis.AppModuleBasic{}) kr := keyring.NewInMemory(encCfg.Codec) @@ -39,7 +28,7 @@ func TestNewMsgVerifyInvariantTxCmd(t *testing.T) { WithKeyring(kr). WithTxConfig(encCfg.TxConfig). WithCodec(encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") diff --git a/x/distribution/client/cli/suite_test.go b/x/distribution/client/cli/suite_test.go index 48fff7a96925..6aa3f5181ed9 100644 --- a/x/distribution/client/cli/suite_test.go +++ b/x/distribution/client/cli/suite_test.go @@ -2,7 +2,6 @@ package cli_test import ( "bytes" - "context" "fmt" "io" "strings" @@ -11,12 +10,8 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmbytes "github.com/tendermint/tendermint/libs/bytes" tmcli "github.com/tendermint/tendermint/libs/cli" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -34,30 +29,6 @@ import ( minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{Code: 0}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmbytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - type CLITestSuite struct { suite.Suite @@ -78,7 +49,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -86,7 +57,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) diff --git a/x/evidence/client/cli/tx_test.go b/x/evidence/client/cli/tx_test.go index a7d626bf0e24..bbb162564c60 100644 --- a/x/evidence/client/cli/tx_test.go +++ b/x/evidence/client/cli/tx_test.go @@ -10,17 +10,12 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" - - "github.com/cosmos/cosmos-sdk/client/flags" - svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" + svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -28,30 +23,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/evidence/client/cli" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(_ context.Context, _ tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmbytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - func TestGetQueryCmd(t *testing.T) { cmd := cli.GetQueryCmd() cmd.SetOut(io.Discard) @@ -63,7 +34,7 @@ func TestGetQueryCmd(t *testing.T) { WithKeyring(kr). WithTxConfig(encCfg.TxConfig). WithCodec(encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -79,7 +50,7 @@ func TestGetQueryCmd(t *testing.T) { []string{"DF0C23E8634E480F84B9D5674A7CDC9816466DEC28A3358F73260F68D28D7660"}, func() client.Context { bz, _ := encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return baseCtx.WithClient(c) @@ -92,7 +63,7 @@ func TestGetQueryCmd(t *testing.T) { []string{}, func() client.Context { bz, _ := encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return baseCtx.WithClient(c) @@ -107,7 +78,7 @@ func TestGetQueryCmd(t *testing.T) { }, func() client.Context { bz, _ := encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return baseCtx.WithClient(c) diff --git a/x/feegrant/client/cli/tx_test.go b/x/feegrant/client/cli/tx_test.go index beaa0a45f362..021d5819edfa 100644 --- a/x/feegrant/client/cli/tx_test.go +++ b/x/feegrant/client/cli/tx_test.go @@ -2,7 +2,6 @@ package cli_test import ( "bytes" - "context" "fmt" "io" "strings" @@ -12,11 +11,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmlibs "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -55,30 +50,6 @@ type CLITestSuite struct { accounts []sdk.AccAddress } -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmlibs.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - -func (m mockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{Code: 0}, nil -} - func TestCLITestSuite(t *testing.T) { suite.Run(t, new(CLITestSuite)) } @@ -92,7 +63,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -100,7 +71,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) diff --git a/x/genutil/client/cli/gentx_test.go b/x/genutil/client/cli/gentx_test.go index 2ffde26a8484..915cc450f2d0 100644 --- a/x/genutil/client/cli/gentx_test.go +++ b/x/genutil/client/cli/gentx_test.go @@ -10,16 +10,13 @@ import ( "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -29,30 +26,6 @@ import ( stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(_ context.Context, _ tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmbytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - type CLITestSuite struct { suite.Suite @@ -73,7 +46,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -81,7 +54,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) diff --git a/x/gov/client/cli/tx_test.go b/x/gov/client/cli/tx_test.go index 1b881c3762ab..cae55f6a00d5 100644 --- a/x/gov/client/cli/tx_test.go +++ b/x/gov/client/cli/tx_test.go @@ -2,7 +2,6 @@ package cli_test import ( "bytes" - "context" "encoding/base64" "fmt" "io" @@ -11,11 +10,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -33,30 +28,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{Code: 0}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmbytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - type CLITestSuite struct { suite.Suite @@ -77,7 +48,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -85,7 +56,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index 5c37759f47e3..58106dba2c73 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -13,11 +13,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -25,7 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/testutil/cli" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/group" @@ -37,30 +33,6 @@ const validMetadata = "metadata" var tooLongMetadata = strings.Repeat("A", 256) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(_ context.Context, _ tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmbytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - type CLITestSuite struct { suite.Suite @@ -83,7 +55,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -100,7 +72,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -115,7 +87,7 @@ func (s *CLITestSuite) SetupSuite() { s.Require().NoError(err) account := sdk.AccAddress(pk.Address()) - _, err = cli.MsgSendExec( + _, err = clitestutil.MsgSendExec( clientCtx, val.Address, account, @@ -138,7 +110,7 @@ func (s *CLITestSuite) SetupSuite() { ] }`, val.Address.String(), memberWeight, validMetadata) validMembersFile := testutil.WriteToNewTempFile(s.T(), validMembers) - out, err := cli.ExecTestCLICmd(clientCtx, groupcli.MsgCreateGroupCmd(), + out, err := clitestutil.ExecTestCLICmd(clientCtx, groupcli.MsgCreateGroupCmd(), append( []string{ val.Address.String(), @@ -195,7 +167,7 @@ func (s *CLITestSuite) TestTxCreateGroup() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -217,7 +189,7 @@ func (s *CLITestSuite) TestTxCreateGroup() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -240,7 +212,7 @@ func (s *CLITestSuite) TestTxCreateGroup() { "invalid members address", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -262,7 +234,7 @@ func (s *CLITestSuite) TestTxCreateGroup() { "invalid members weight", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -300,7 +272,7 @@ func (s *CLITestSuite) TestTxCreateGroup() { s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput) } - out, err := cli.ExecTestCLICmd(clientCtx, cmd, tc.args) + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { s.Require().Error(err) s.Require().Contains(out.String(), tc.expectErrMsg) @@ -322,7 +294,7 @@ func (s *CLITestSuite) TestTxUpdateGroupAdmin() { ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -342,7 +314,7 @@ func (s *CLITestSuite) TestTxUpdateGroupAdmin() { "metadata": "%s" }]}`, accounts[0].Address.String(), validMetadata) validMembersFile := testutil.WriteToNewTempFile(s.T(), validMembers) - out, err := cli.ExecTestCLICmd(clientCtx, groupcli.MsgCreateGroupCmd(), + out, err := clitestutil.ExecTestCLICmd(clientCtx, groupcli.MsgCreateGroupCmd(), append( []string{ accounts[0].Address.String(), @@ -369,7 +341,7 @@ func (s *CLITestSuite) TestTxUpdateGroupAdmin() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -391,7 +363,7 @@ func (s *CLITestSuite) TestTxUpdateGroupAdmin() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -414,7 +386,7 @@ func (s *CLITestSuite) TestTxUpdateGroupAdmin() { "group id invalid", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -452,7 +424,7 @@ func (s *CLITestSuite) TestTxUpdateGroupAdmin() { s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput) } - out, err := cli.ExecTestCLICmd(clientCtx, cmd, tc.args) + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { s.Require().Error(err) s.Require().Contains(out.String(), tc.expectErrMsg) @@ -480,7 +452,7 @@ func (s *CLITestSuite) TestTxUpdateGroupMetadata() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -499,7 +471,7 @@ func (s *CLITestSuite) TestTxUpdateGroupMetadata() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -519,7 +491,7 @@ func (s *CLITestSuite) TestTxUpdateGroupMetadata() { "group metadata too long", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -593,7 +565,7 @@ func (s *CLITestSuite) TestTxUpdateGroupMembers() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -612,7 +584,7 @@ func (s *CLITestSuite) TestTxUpdateGroupMembers() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -632,7 +604,7 @@ func (s *CLITestSuite) TestTxUpdateGroupMembers() { "group member metadata too long", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -651,7 +623,7 @@ func (s *CLITestSuite) TestTxUpdateGroupMembers() { "group doesn't exist", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -729,7 +701,7 @@ func (s *CLITestSuite) TestTxCreateGroupWithPolicy() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -754,7 +726,7 @@ func (s *CLITestSuite) TestTxCreateGroupWithPolicy() { "group-policy-as-admin is true", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -779,7 +751,7 @@ func (s *CLITestSuite) TestTxCreateGroupWithPolicy() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -805,7 +777,7 @@ func (s *CLITestSuite) TestTxCreateGroupWithPolicy() { "invalid members address", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -830,7 +802,7 @@ func (s *CLITestSuite) TestTxCreateGroupWithPolicy() { "invalid members weight", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -870,7 +842,7 @@ func (s *CLITestSuite) TestTxCreateGroupWithPolicy() { s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput) } - out, err := cli.ExecTestCLICmd(clientCtx, cmd, tc.args) + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { s.Require().Error(err) s.Require().Contains(out.String(), tc.expectErrMsg) @@ -910,7 +882,7 @@ func (s *CLITestSuite) TestTxCreateGroupPolicy() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -933,7 +905,7 @@ func (s *CLITestSuite) TestTxCreateGroupPolicy() { "correct data with percentage decision policy", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -956,7 +928,7 @@ func (s *CLITestSuite) TestTxCreateGroupPolicy() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -980,7 +952,7 @@ func (s *CLITestSuite) TestTxCreateGroupPolicy() { "wrong admin", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1003,7 +975,7 @@ func (s *CLITestSuite) TestTxCreateGroupPolicy() { "invalid percentage decision policy with negative value", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1026,7 +998,7 @@ func (s *CLITestSuite) TestTxCreateGroupPolicy() { "invalid percentage decision policy with value greater than 1", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1065,7 +1037,7 @@ func (s *CLITestSuite) TestTxCreateGroupPolicy() { s.Require().Contains(fmt.Sprint(cmd), tc.expCmdOutput) } - out, err := cli.ExecTestCLICmd(clientCtx, cmd, tc.args) + out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { s.Require().Error(err) s.Require().Contains(out.String(), tc.expectErrMsg) @@ -1099,7 +1071,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyAdmin() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1118,7 +1090,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyAdmin() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1138,7 +1110,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyAdmin() { "wrong admin", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1157,7 +1129,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyAdmin() { "wrong group policy", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1222,7 +1194,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1241,7 +1213,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { "correct data with percentage decision policy", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1260,7 +1232,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1280,7 +1252,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { "wrong admin", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1299,7 +1271,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { "wrong group policy", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1318,7 +1290,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { "invalid percentage decision policy with negative value", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1337,7 +1309,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { "invalid percentage decision policy with value greater than 1", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1396,7 +1368,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyMetadata() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1415,7 +1387,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyMetadata() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1435,7 +1407,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyMetadata() { "long metadata", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1454,7 +1426,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyMetadata() { "wrong admin", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1473,7 +1445,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyMetadata() { "wrong group policy", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1538,7 +1510,7 @@ func (s *CLITestSuite) TestTxSubmitProposal() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1555,7 +1527,7 @@ func (s *CLITestSuite) TestTxSubmitProposal() { "with try exec", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1573,7 +1545,7 @@ func (s *CLITestSuite) TestTxSubmitProposal() { "with try exec, not enough yes votes for proposal to pass", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1591,7 +1563,7 @@ func (s *CLITestSuite) TestTxSubmitProposal() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1649,7 +1621,7 @@ func (s *CLITestSuite) TestTxVote() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1669,7 +1641,7 @@ func (s *CLITestSuite) TestTxVote() { "with try exec", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1690,7 +1662,7 @@ func (s *CLITestSuite) TestTxVote() { "with amino-json", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1711,7 +1683,7 @@ func (s *CLITestSuite) TestTxVote() { "metadata too long", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1770,7 +1742,7 @@ func (s *CLITestSuite) TestTxWithdrawProposal() { "correct data", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) @@ -1788,7 +1760,7 @@ func (s *CLITestSuite) TestTxWithdrawProposal() { "wrong admin", func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) diff --git a/x/mint/client/cli/query_test.go b/x/mint/client/cli/query_test.go index 72e794964999..445aac432907 100644 --- a/x/mint/client/cli/query_test.go +++ b/x/mint/client/cli/query_test.go @@ -8,12 +8,7 @@ import ( "testing" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -27,26 +22,6 @@ import ( tmcli "github.com/tendermint/tendermint/libs/cli" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func (mockTendermintRPC) BroadcastTxSync(_ context.Context, _ tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ bytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - func TestGetCmdQueryParams(t *testing.T) { encCfg := testutilmod.MakeTestEncodingConfig(mint.AppModuleBasic{}) kr := keyring.NewInMemory(encCfg.Codec) @@ -54,7 +29,7 @@ func TestGetCmdQueryParams(t *testing.T) { WithKeyring(kr). WithTxConfig(encCfg.TxConfig). WithCodec(encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -119,7 +94,7 @@ func TestGetCmdQueryInflation(t *testing.T) { WithKeyring(kr). WithTxConfig(encCfg.TxConfig). WithCodec(encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -179,7 +154,7 @@ func TestGetCmdQueryAnnualProvisions(t *testing.T) { WithKeyring(kr). WithTxConfig(encCfg.TxConfig). WithCodec(encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") diff --git a/x/nft/client/cli/tx_test.go b/x/nft/client/cli/tx_test.go index ea0fb41caef5..7ef91278291f 100644 --- a/x/nft/client/cli/tx_test.go +++ b/x/nft/client/cli/tx_test.go @@ -9,11 +9,7 @@ import ( "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -69,30 +65,6 @@ var ( } ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{Code: 0}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmbytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - type CLITestSuite struct { suite.Suite @@ -116,7 +88,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -125,7 +97,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) diff --git a/x/slashing/client/cli/query_test.go b/x/slashing/client/cli/query_test.go index cbadc7e81cad..6f2bf13c9929 100644 --- a/x/slashing/client/cli/query_test.go +++ b/x/slashing/client/cli/query_test.go @@ -2,19 +2,14 @@ package cli_test import ( "bytes" - "context" "fmt" "io" "testing" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmlibs "github.com/tendermint/tendermint/libs/bytes" tmcli "github.com/tendermint/tendermint/libs/cli" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -40,30 +35,6 @@ type CLITestSuite struct { addr sdk.AccAddress } -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (m mockTendermintRPC) BroadcastTxSync(context.Context, tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{Code: 0}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmlibs.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - func TestCLITestSuite(t *testing.T) { suite.Run(t, new(CLITestSuite)) } @@ -77,7 +48,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -85,7 +56,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) diff --git a/x/staking/client/cli/tx_test.go b/x/staking/client/cli/tx_test.go index cb71d1595c29..0f6564b2b3ca 100644 --- a/x/staking/client/cli/tx_test.go +++ b/x/staking/client/cli/tx_test.go @@ -2,7 +2,6 @@ package cli_test import ( "bytes" - "context" "fmt" "io" "testing" @@ -12,11 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -31,30 +26,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/client/cli" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func newMockTendermintRPC(respQuery abci.ResponseQuery) mockTendermintRPC { - return mockTendermintRPC{responseQuery: respQuery} -} - -func (mockTendermintRPC) BroadcastTxSync(_ context.Context, _ tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ tmbytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - var PKs = simtestutil.CreateTestPubKeys(500) type CLITestSuite struct { @@ -74,7 +45,7 @@ func (s *CLITestSuite) SetupSuite() { WithKeyring(s.kr). WithTxConfig(s.encCfg.TxConfig). WithCodec(s.encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain") @@ -82,7 +53,7 @@ func (s *CLITestSuite) SetupSuite() { var outBuf bytes.Buffer ctxGen := func() client.Context { bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{}) - c := newMockTendermintRPC(abci.ResponseQuery{ + c := clitestutil.NewMockTendermintRPC(abci.ResponseQuery{ Value: bz, }) return s.baseCtx.WithClient(c) diff --git a/x/upgrade/client/cli/tx_test.go b/x/upgrade/client/cli/tx_test.go index 76036c7505e6..b42d936fe923 100644 --- a/x/upgrade/client/cli/tx_test.go +++ b/x/upgrade/client/cli/tx_test.go @@ -7,44 +7,19 @@ import ( "testing" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/bytes" tmcli "github.com/tendermint/tendermint/libs/cli" - rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclientmock "github.com/tendermint/tendermint/rpc/client/mock" - coretypes "github.com/tendermint/tendermint/rpc/core/types" - tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradecli "github.com/cosmos/cosmos-sdk/x/upgrade/client/cli" ) -var _ client.TendermintRPC = (*mockTendermintRPC)(nil) - -type mockTendermintRPC struct { - rpcclientmock.Client - - responseQuery abci.ResponseQuery -} - -func (mockTendermintRPC) BroadcastTxSync(_ context.Context, _ tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { - return &coretypes.ResultBroadcastTx{}, nil -} - -func (m mockTendermintRPC) ABCIQueryWithOptions( - _ context.Context, - _ string, _ bytes.HexBytes, - _ rpcclient.ABCIQueryOptions, -) (*coretypes.ResultABCIQuery, error) { - return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil -} - func TestModuleVersionsCLI(t *testing.T) { cmd := upgradecli.GetModuleVersionsCmd() cmd.SetOut(io.Discard) @@ -56,7 +31,7 @@ func TestModuleVersionsCLI(t *testing.T) { WithKeyring(kr). WithTxConfig(encCfg.TxConfig). WithCodec(encCfg.Codec). - WithClient(mockTendermintRPC{Client: rpcclientmock.Client{}}). + WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). WithAccountRetriever(client.MockAccountRetriever{}). WithOutput(io.Discard). WithChainID("test-chain")