Skip to content

Commit

Permalink
Merge pull request #13 from provenance-io/bugfix/cli-test-utils
Browse files Browse the repository at this point in the history
Bugfix/cli test utils
  • Loading branch information
iramiller authored Jan 26, 2021
2 parents 15feeb8 + d621488 commit 9f2c323
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 72 deletions.
62 changes: 62 additions & 0 deletions testutil/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package testutil

import (
"fmt"
"time"

tmrand "github.com/tendermint/tendermint/libs/rand"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdksim "github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"

provenanceapp "github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/app/params"
)

// NewAppConstructor returns a new provenanceapp AppConstructor
func NewAppConstructor(encodingCfg params.EncodingConfig) network.AppConstructor {
return func(val network.Validator) servertypes.Application {
return provenanceapp.New("",
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encodingCfg,
sdksim.EmptyAppOptions{},
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
}

// DefaultTestNetworkConfig creates a network configuration for inproc testing
func DefaultTestNetworkConfig() network.Config {
encCfg := provenanceapp.MakeEncodingConfig()
return network.Config{
Codec: encCfg.Marshaler,
TxConfig: encCfg.TxConfig,
LegacyAmino: encCfg.Amino,
InterfaceRegistry: encCfg.InterfaceRegistry,
AccountRetriever: authtypes.AccountRetriever{},
AppConstructor: NewAppConstructor(encCfg),
GenesisState: provenanceapp.ModuleBasics.DefaultGenesis(encCfg.Marshaler),
TimeoutCommit: 2 * time.Second,
ChainID: "chain-" + tmrand.NewRand().Str(6),
NumValidators: 4,
BondDenom: sdk.DefaultBondDenom, // we use the SDK bond denom here, at least until the entire genesis is rewritten to match bond denom
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
AccountTokens: sdk.TokensFromConsensusPower(1000),
StakingTokens: sdk.TokensFromConsensusPower(500),
BondedTokens: sdk.TokensFromConsensusPower(100),
PruningStrategy: storetypes.PruningOptionNothing,
CleanupDir: true,
SigningAlgo: string(hd.Secp256k1Type),
KeyringOptions: []keyring.Option{},
}
}
25 changes: 2 additions & 23 deletions x/attribute/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@ import (
"github.com/stretchr/testify/suite"

tmcli "github.com/tendermint/tendermint/libs/cli"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/flags"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdksim "github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
testnet "github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"

simapp "github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/testutil"

"github.com/provenance-io/provenance/x/attribute/client/cli"
attributetypes "github.com/provenance-io/provenance/x/attribute/types"
Expand All @@ -51,22 +45,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.accountAddr = addr
s.T().Log("setting up integration test suite")

encCfg := simapp.MakeEncodingConfig()
cfg := testnet.DefaultConfig()
cfg.InterfaceRegistry = encCfg.InterfaceRegistry
cfg.Codec = encCfg.Marshaler
cfg.TxConfig = encCfg.TxConfig
cfg.LegacyAmino = encCfg.Amino

cfg.AppConstructor = func(val network.Validator) servertypes.Application {
return simapp.New("test",
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encCfg,
sdksim.EmptyAppOptions{},
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
cfg := testutil.DefaultTestNetworkConfig()

genesisState := cfg.GenesisState
cfg.NumValidators = 1
Expand Down
30 changes: 4 additions & 26 deletions x/attribute/client/rest/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@ import (

"github.com/stretchr/testify/suite"

dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdksim "github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
testnet "github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

simapp "github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/testutil"

attributetypes "github.com/provenance-io/provenance/x/attribute/types"
nametypes "github.com/provenance-io/provenance/x/name/types"
Expand Down Expand Up @@ -48,22 +41,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.accountAddr = addr
s.T().Log("setting up integration test suite")

encCfg := simapp.MakeEncodingConfig()
cfg := testnet.DefaultConfig()
cfg.InterfaceRegistry = encCfg.InterfaceRegistry
cfg.Codec = encCfg.Marshaler
cfg.TxConfig = encCfg.TxConfig
cfg.LegacyAmino = encCfg.Amino

cfg.AppConstructor = func(val network.Validator) servertypes.Application {
return simapp.New("test",
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encCfg,
sdksim.EmptyAppOptions{},
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
cfg := testutil.DefaultTestNetworkConfig()

genesisState := cfg.GenesisState
cfg.NumValidators = 1
Expand Down Expand Up @@ -222,7 +200,7 @@ func (s *IntegrationTestSuite) TestGRPCQueries() {
tc := tc

s.Run(tc.name, func() {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
resp, err := sdktestutil.GetRequestWithHeaders(tc.url, tc.headers)
s.Require().NoError(err)
err = val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType)

Expand Down
25 changes: 2 additions & 23 deletions x/marker/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@ import (
"github.com/stretchr/testify/suite"

tmcli "github.com/tendermint/tendermint/libs/cli"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdksim "github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
testnet "github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"

simapp "github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/testutil"

markercli "github.com/provenance-io/provenance/x/marker/client/cli"
markertypes "github.com/provenance-io/provenance/x/marker/types"
Expand All @@ -48,22 +42,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.accountAddr = addr
s.T().Log("setting up integration test suite")

encCfg := simapp.MakeEncodingConfig()
cfg := testnet.DefaultConfig()
cfg.InterfaceRegistry = encCfg.InterfaceRegistry
cfg.Codec = encCfg.Marshaler
cfg.TxConfig = encCfg.TxConfig
cfg.LegacyAmino = encCfg.Amino

cfg.AppConstructor = func(val network.Validator) servertypes.Application {
return simapp.New("test",
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encCfg,
sdksim.EmptyAppOptions{},
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
cfg := testutil.DefaultTestNetworkConfig()

genesisState := cfg.GenesisState
cfg.NumValidators = 1
Expand Down

0 comments on commit 9f2c323

Please sign in to comment.