Skip to content

Commit

Permalink
CLI/Tests: Remove Fixtures (cosmos#6799)
Browse files Browse the repository at this point in the history
* remove fixtures

* setup tests

* update x/mint

* cli: update x/staking commands

* tests: convert x/staking CLI tests

* tests: fix x/auth CLI tests

* cli updates

* fix buiild

* fix build

* Update x/gov/client/cli/cli_test.go

Co-authored-by: Amaury Martiny <[email protected]>

* remove GenerateOrBroadcastTx

* move TestCLIQueryConn

Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: Amaury Martiny <[email protected]>
  • Loading branch information
3 people authored and chengwenxi committed Jul 22, 2020
1 parent 2ee6807 commit e294d97
Show file tree
Hide file tree
Showing 38 changed files with 638 additions and 2,026 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,3 @@ jobs:
with:
file: ./coverage.txt
if: "env.GIT_DIFF != ''"

integration-tests:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- name: build-simd
run: |
make build-simd
if: "env.GIT_DIFF != ''"
- name: cli-test
run: |
make test-integration
if: "env.GIT_DIFF != ''"
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ test-unit:
test-race:
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)

test-integration: build-simd
BUILDDIR=$(BUILDDIR) go test -mod=readonly -p 4 -tags='ledger test_ledger_mock cli_test' -run ^TestCLI `go list ./.../cli/...`

.PHONY: test test-all test-ledger-mock test-ledger test-unit test-race

test-sim-nondeterminism:
Expand Down Expand Up @@ -239,8 +236,7 @@ test-sim-after-import \
test-sim-custom-genesis-multi-seed \
test-sim-multi-seed-short \
test-sim-multi-seed-long \
test-sim-benchmark-invariants \
test-integration
test-sim-benchmark-invariants

SIM_NUM_BLOCKS ?= 500
SIM_BLOCK_SIZE ?= 200
Expand Down
25 changes: 19 additions & 6 deletions client/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package client_test

import (
"bytes"
"context"
"os"
"testing"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"

"github.com/cosmos/cosmos-sdk/crypto/keyring"

"github.com/spf13/viper"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -100,3 +100,16 @@ value:
x: "10"
`, string(buf.Bytes()))
}

func TestCLIQueryConn(t *testing.T) {
cfg := network.DefaultConfig()
cfg.NumValidators = 1

n := network.New(t, cfg)
defer n.Cleanup()

testClient := testdata.NewTestServiceClient(n.Validators[0].ClientCtx)
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"})
require.NoError(t, err)
require.Equal(t, "hello", res.Message)
}
44 changes: 0 additions & 44 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package tx

import (
"io"

"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -78,47 +75,6 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
return f
}

// TODO: Remove in favor of NewFactoryCLI
func NewFactoryFromDeprecated(input io.Reader) Factory {
kb, err := keyring.New(
sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend),
viper.GetString(flags.FlagHome),
input,
)
if err != nil {
panic(err)
}

signModeStr := viper.GetString(flags.FlagSignMode)
signMode := signing.SignMode_SIGN_MODE_UNSPECIFIED
switch signModeStr {
case signModeDirect:
signMode = signing.SignMode_SIGN_MODE_DIRECT
case signModeAminoJSON:
signMode = signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON
}

gasSetting, _ := flags.ParseGasSetting(viper.GetString(flags.FlagGas))

f := Factory{
keybase: kb,
chainID: viper.GetString(flags.FlagChainID),
accountNumber: viper.GetUint64(flags.FlagAccountNumber),
sequence: viper.GetUint64(flags.FlagSequence),
gas: gasSetting.Gas,
simulateAndExecute: gasSetting.Simulate,
gasAdjustment: viper.GetFloat64(flags.FlagGasAdjustment),
memo: viper.GetString(flags.FlagMemo),
signMode: signMode,
}

f = f.WithFees(viper.GetString(flags.FlagFees))
f = f.WithGasPrices(viper.GetString(flags.FlagGasPrices))

return f
}

func (f Factory) AccountNumber() uint64 { return f.accountNumber }
func (f Factory) Sequence() uint64 { return f.sequence }
func (f Factory) Gas() uint64 { return f.gas }
Expand Down
9 changes: 0 additions & 9 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ func GenerateOrBroadcastTxCLI(clientCtx client.Context, flagSet *pflag.FlagSet,
return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
}

// GenerateOrBroadcastTx will either generate and print and unsigned transaction
// or sign it and broadcast it returning an error upon failure.
//
// TODO: Remove in favor of GenerateOrBroadcastTxCLI
func GenerateOrBroadcastTx(clientCtx client.Context, msgs ...sdk.Msg) error {
txf := NewFactoryFromDeprecated(clientCtx.Input).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)
return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
}

// GenerateOrBroadcastTxWithFactory will either generate and print and unsigned transaction
// or sign it and broadcast it returning an error upon failure.
func GenerateOrBroadcastTxWithFactory(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
Expand Down
2 changes: 1 addition & 1 deletion contrib/test_cover.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

PKGS=$(go list ./... | grep -v '/simapp' | grep -v '/cli_test')
PKGS=$(go list ./... | grep -v '/simapp')

set -e
echo "mode: atomic" > coverage.txt
Expand Down
13 changes: 0 additions & 13 deletions tests/cli/constants.go

This file was deleted.

3 changes: 0 additions & 3 deletions tests/cli/doc.go

This file was deleted.

49 changes: 0 additions & 49 deletions tests/cli/executors.go

This file was deleted.

81 changes: 0 additions & 81 deletions tests/cli/fixtures.go

This file was deleted.

24 changes: 0 additions & 24 deletions tests/cli/grpc_query_test.go

This file was deleted.

Loading

0 comments on commit e294d97

Please sign in to comment.