Skip to content

Commit

Permalink
test: Add CLI, gRPC, MsgServer tests (backport #1405) (#1430)
Browse files Browse the repository at this point in the history
(cherry picked from commit 97219d5)

* Add CHANGELOG

* Resolve ostracon conflicts

---------

Co-authored-by: Jaeseung Lee <41176085+tkxkd0159@users.noreply.github.com>
  • Loading branch information
mergify[bot] and tkxkd0159 authored Jun 26, 2024
1 parent 7d2a15f commit 48480c1
Show file tree
Hide file tree
Showing 20 changed files with 2,159 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features

### Improvements
* (x/fbridge) [\#1430](https://github.com/Finschia/finschia-sdk/pull/1430) Add CLI, gRPC, MsgServer tests

### Bug Fixes

Expand Down
28 changes: 28 additions & 0 deletions client/tendermint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package client

import (
"context"

rpcclient "github.com/Finschia/ostracon/rpc/client"
coretypes "github.com/Finschia/ostracon/rpc/core/types"
)

// TendermintRPC defines the interface of a Tendermint RPC client needed for
// queries and transaction handling.
type TendermintRPC interface {
rpcclient.ABCIClient

Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error)
Status(context.Context) (*coretypes.ResultStatus, error)
Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error)
BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error)
Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error)
Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error)
TxSearch(
ctx context.Context,
query string,
prove bool,
page, perPage *int,
orderBy string,
) (*coretypes.ResultTxSearch, error)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module github.com/Finschia/finschia-sdk

require (
github.com/99designs/keyring v1.1.6
github.com/Finschia/ostracon v1.1.4
github.com/Finschia/ostracon v1.1.5
github.com/VictoriaMetrics/fastcache v1.12.2
github.com/bgentry/speakeasy v0.1.0
github.com/btcsuite/btcd v0.22.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/Finschia/ostracon v1.1.4 h1:untqhChZjktLoMo/b94q6bmeedDfvCV+d+t7yO0I1N8=
github.com/Finschia/ostracon v1.1.4/go.mod h1:kuW9en37Z9+6dGzdoA8+xdCil42wZGZNtrcJe9ugRx8=
github.com/Finschia/ostracon v1.1.5 h1:8nWHh+6v/0+KSx536Aix+P5cn5iqvoAuVvVYn9g1q7c=
github.com/Finschia/ostracon v1.1.5/go.mod h1:kuW9en37Z9+6dGzdoA8+xdCil42wZGZNtrcJe9ugRx8=
github.com/Finschia/r2ishiguro_vrf v0.1.2 h1:lDBz6NQMx1pw5I3End6xFmXpM//7KcmTr3Ka983e7v8=
github.com/Finschia/r2ishiguro_vrf v0.1.2/go.mod h1:OHRtvzcJnfIrcJ0bvPNktJozRFAyZFuv56E9R3/qB+Y=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
Expand Down
Empty file modified init_node.sh
100644 → 100755
Empty file.
41 changes: 41 additions & 0 deletions testutil/cli/tm_mocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cli

import (
"context"

tmbytes "github.com/Finschia/ostracon/libs/bytes"
rpcclient "github.com/Finschia/ostracon/rpc/client"
rpcclientmock "github.com/Finschia/ostracon/rpc/client/mock"
coretypes "github.com/Finschia/ostracon/rpc/core/types"
tmtypes "github.com/Finschia/ostracon/types"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/Finschia/finschia-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
}
78 changes: 78 additions & 0 deletions types/module/testutil/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package testutil

import (
"github.com/Finschia/finschia-sdk/client"
"github.com/Finschia/finschia-sdk/codec"
"github.com/Finschia/finschia-sdk/codec/types"
"github.com/Finschia/finschia-sdk/std"
"github.com/Finschia/finschia-sdk/types/module"
"github.com/Finschia/finschia-sdk/x/auth/tx"
)

// TestEncodingConfig defines an encoding configuration that is used for testing
// purposes. Note, MakeTestEncodingConfig takes a series of AppModuleBasic types
// which should only contain the relevant module being tested and any potential
// dependencies.
type TestEncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

func MakeTestEncodingConfig(modules ...module.AppModuleBasic) TestEncodingConfig {
aminoCdc := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)

encCfg := TestEncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: cdc,
TxConfig: tx.NewTxConfig(cdc, tx.DefaultSignModes),
Amino: aminoCdc,
}

mb := module.NewBasicManager(modules...)

std.RegisterLegacyAminoCodec(encCfg.Amino)
std.RegisterInterfaces(encCfg.InterfaceRegistry)
mb.RegisterLegacyAminoCodec(encCfg.Amino)
mb.RegisterInterfaces(encCfg.InterfaceRegistry)

return encCfg
}

func MakeTestTxConfig() client.TxConfig {
interfaceRegistry := types.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
return tx.NewTxConfig(cdc, tx.DefaultSignModes)
}

type TestBuilderTxConfig struct {
client.TxConfig
TxBuilder *TestTxBuilder
}

func MakeBuilderTestTxConfig() TestBuilderTxConfig {
return TestBuilderTxConfig{
TxConfig: MakeTestTxConfig(),
}
}

func (cfg TestBuilderTxConfig) NewTxBuilder() client.TxBuilder {
if cfg.TxBuilder == nil {
cfg.TxBuilder = &TestTxBuilder{
TxBuilder: cfg.TxConfig.NewTxBuilder(),
}
}
return cfg.TxBuilder
}

type TestTxBuilder struct {
client.TxBuilder
ExtOptions []*types.Any
}

func (b *TestTxBuilder) SetExtensionOptions(extOpts ...*types.Any) {
b.ExtOptions = extOpts
}
6 changes: 3 additions & 3 deletions x/fbridge/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
flagSequences = "sequences"
FlagSequences = "sequences"
)

// NewQueryCmd returns the query commands for fbridge module
Expand Down Expand Up @@ -100,7 +100,7 @@ func NewQuerySeqToBlocknumsCmd() *cobra.Command {
}
qc := types.NewQueryClient(clientCtx)

seqSlice, err := cmd.Flags().GetInt64Slice(flagSequences)
seqSlice, err := cmd.Flags().GetInt64Slice(FlagSequences)
if err != nil {
return err
}
Expand All @@ -119,7 +119,7 @@ func NewQuerySeqToBlocknumsCmd() *cobra.Command {
},
}

cmd.Flags().Int64Slice(flagSequences, []int64{}, "comma separated list of bridge sequnece numbers")
cmd.Flags().Int64Slice(FlagSequences, []int64{}, "comma separated list of bridge sequnece numbers")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
Expand Down
Loading

0 comments on commit 48480c1

Please sign in to comment.