refactor: extract MockTendermintRPC to testutil/cli
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user