mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00

* [linter] Remove unused exclusions Linter `nosnakecase` was removed in 1e1138d0268a9896a1bd058e9b65b808eb20666e. * [linter] Add tool for code clone detection * [linter] Add `errorlint` Find code that will cause problems with the error wrapping scheme introduced in Go 1.13. * [linter] Add `exhaustive` Check exhaustiveness of enum switch statements. * [linter] Add `forcetypeassert` Finds type assertions which did forcely such as below: ``` func f() { var a interface{} _ = a.(int) // type assertion must be checked } ``` * [linter] Add `gocritic` Provides diagnostics that check for bugs, performance and style issues. Signed-off-by: Julian Strobl <jmastr@mailbox.org>
102 lines
3.2 KiB
Go
102 lines
3.2 KiB
Go
package network
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
tmdb "github.com/cometbft/cometbft-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"
|
|
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
|
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
|
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/planetmint/planetmint-go/app"
|
|
"github.com/planetmint/planetmint-go/config"
|
|
)
|
|
|
|
type (
|
|
Network = network.Network
|
|
Config = network.Config
|
|
)
|
|
|
|
// New creates instance with fully configured cosmos network.
|
|
// Accepts optional config, that will be used in place of the DefaultConfig() if provided.
|
|
func New(t *testing.T, configs ...Config) *Network {
|
|
if len(configs) > 1 {
|
|
panic("at most one config should be provided")
|
|
}
|
|
var cfg network.Config
|
|
if len(configs) == 0 {
|
|
cfg = DefaultConfig()
|
|
} else {
|
|
cfg = configs[0]
|
|
}
|
|
validatorTmpDir := t.TempDir()
|
|
|
|
// set the proper root dir for the test environment so that the abci.go logic works
|
|
appConfig := config.GetConfig()
|
|
appConfig.SetRoot(validatorTmpDir + "/node0/simd")
|
|
|
|
net, err := network.New(t, validatorTmpDir, cfg)
|
|
|
|
appConfig.ValidatorAddress = net.Validators[0].Address.String()
|
|
|
|
require.NoError(t, err)
|
|
_, err = net.WaitForHeight(1)
|
|
require.NoError(t, err)
|
|
t.Cleanup(net.Cleanup)
|
|
return net
|
|
}
|
|
|
|
// DefaultConfig will initialize config for the network with custom application,
|
|
// genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig
|
|
func DefaultConfig() network.Config {
|
|
var (
|
|
encoding = app.MakeEncodingConfig()
|
|
chainID = "chain-foobarbaz"
|
|
)
|
|
return network.Config{
|
|
Codec: encoding.Marshaler,
|
|
TxConfig: encoding.TxConfig,
|
|
LegacyAmino: encoding.Amino,
|
|
InterfaceRegistry: encoding.InterfaceRegistry,
|
|
AccountRetriever: authtypes.AccountRetriever{},
|
|
AppConstructor: func(val network.ValidatorI) servertypes.Application {
|
|
return app.New(
|
|
val.GetCtx().Logger,
|
|
tmdb.NewMemDB(),
|
|
nil,
|
|
true,
|
|
map[int64]bool{},
|
|
val.GetCtx().Config.RootDir,
|
|
0,
|
|
encoding,
|
|
simtestutil.EmptyAppOptions{},
|
|
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)),
|
|
baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices),
|
|
baseapp.SetChainID(chainID),
|
|
)
|
|
},
|
|
GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler),
|
|
TimeoutCommit: 2 * time.Second,
|
|
ChainID: chainID,
|
|
NumValidators: 1,
|
|
BondDenom: sdk.DefaultBondDenom,
|
|
MinGasPrices: fmt.Sprintf("0.000003%s", sdk.DefaultBondDenom),
|
|
AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction),
|
|
StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction),
|
|
BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction),
|
|
PruningStrategy: pruningtypes.PruningOptionNothing,
|
|
CleanupDir: true,
|
|
SigningAlgo: string(hd.Secp256k1Type),
|
|
KeyringOptions: []keyring.Option{},
|
|
}
|
|
}
|