Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app)!: cosmos SDK v0.46 upgrade #1244

Merged
merged 38 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4b3f44e
wip: remove cosmwasm
aleem1314 Jul 7, 2022
e3699aa
wip
aleem1314 Jul 8, 2022
b7a0bb9
refactor: remove experimental config
aleem1314 Jul 12, 2022
848b08d
refactor: fix imports
aleem1314 Jul 12, 2022
f3b165e
wip: migrating regen app
aleem1314 Jul 12, 2022
db76e51
wip: fixing tests
aleem1314 Jul 12, 2022
ba2bf1c
fix: fix imports
aleem1314 Jul 13, 2022
a1f2c5d
Merge branch 'master' of https://github.com/regen-network/regen-ledge…
aleem1314 Jul 18, 2022
3b4a5df
fix: resolve build errors
aleem1314 Jul 18, 2022
dc2c5cb
chore: remove ecocredit migrations
aleem1314 Jul 25, 2022
e30ddf8
Merge branch 'master' into aleem/857-sdk-v0.46
aleem1314 Jul 25, 2022
c600659
chore: cleanup
aleem1314 Jul 25, 2022
fef7838
refactor: bump sdk version to rc3
aleem1314 Jul 25, 2022
a137cf2
chore: update Makefile
aleem1314 Jul 25, 2022
e636cce
fix: fix simulations
aleem1314 Jul 26, 2022
487bc6d
Merge branch 'master' into aleem/857-sdk-v0.46
aleem1314 Jul 26, 2022
664278a
chore: run make tidy
aleem1314 Jul 26, 2022
7f09b82
fix: fix failing tests
aleem1314 Jul 26, 2022
ae8e514
wip: fix integration tests
aleem1314 Jul 26, 2022
14ab5bb
chore: fix failing test
aleem1314 Jul 27, 2022
bc0ccfa
chore: try fixing tests
aleem1314 Jul 27, 2022
c9de3cd
update network.go
aleem1314 Jul 27, 2022
d72698e
try fix cli tests
aleem1314 Jul 27, 2022
5bf06a3
chore: fix tests
aleem1314 Jul 28, 2022
44a1014
chore: fix failing tests
aleem1314 Jul 28, 2022
4083d80
chore: fix failing tests
aleem1314 Jul 28, 2022
2d7ac5e
Merge branch 'master' into aleem/857-sdk-v0.46
aleem1314 Jul 28, 2022
cca7587
chore: cleanup
aleem1314 Jul 29, 2022
1669f61
chore: update test.yml
aleem1314 Jul 29, 2022
a3bfed7
wip
aleem1314 Jul 29, 2022
2ebe49a
chore: update scripts
aleem1314 Jul 30, 2022
1482427
Update app/encoding.go
aleem1314 Aug 2, 2022
c1b86b4
Update app/app.go
aleem1314 Aug 2, 2022
be2e491
chore: review changes
aleem1314 Aug 2, 2022
fdcb556
chore: fix failing tests
aleem1314 Aug 2, 2022
1127910
chore: register data module types with authz
aleem1314 Aug 2, 2022
9aaa8d3
Update app/app.go
aleem1314 Aug 3, 2022
fafe166
Merge branch 'master' into aleem/857-sdk-v0.46
aleem1314 Aug 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
try fix cli tests
  • Loading branch information
aleem1314 committed Jul 27, 2022
commit d72698e6991a2d2053ad3c48f80970d95c6b6db2
23 changes: 12 additions & 11 deletions app/testsuite/network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import (
"github.com/regen-network/regen-ledger/v4/app"
)

func NewRegenAppConstructor(val network.Validator) servertypes.Application {
return app.NewRegenApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
app.MakeEncodingConfig(),
app.EmptyAppOptions{},
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
func NewRegenAppConstructor(encCfg app.EncodingConfig) network.AppConstructor {
return func(val network.Validator) servertypes.Application {
return app.NewRegenApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encCfg,
app.EmptyAppOptions{},
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
}

// DefaultConfig returns a sane default configuration suitable for nearly all
Expand All @@ -39,11 +41,11 @@ func DefaultConfig() network.Config {
LegacyAmino: encCfg.Amino,
InterfaceRegistry: encCfg.InterfaceRegistry,
AccountRetriever: authtypes.AccountRetriever{},
AppConstructor: NewRegenAppConstructor,
AppConstructor: NewRegenAppConstructor(encCfg),
GenesisState: app.ModuleBasics.DefaultGenesis(encCfg.Codec),
TimeoutCommit: 2 * time.Second,
ChainID: "chain-" + tmrand.NewRand().Str(6),
NumValidators: 4,
NumValidators: 2,
BondDenom: sdk.DefaultBondDenom,
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction),
Expand All @@ -54,6 +56,5 @@ func DefaultConfig() network.Config {
SigningAlgo: string(hd.Secp256k1Type),
KeyringOptions: []keyring.Option{},
PrintMnemonic: false,
Mnemonics: []string{""},
}
}
118 changes: 90 additions & 28 deletions types/testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ import (
"testing"
"time"

"github.com/regen-network/regen-ledger/v4/app"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/node"
tmclient "github.com/tendermint/tendermint/rpc/client"
dbm "github.com/tendermint/tm-db"
"google.golang.org/grpc"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
Expand All @@ -31,13 +43,6 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/spf13/cobra"
tmcfg "github.com/tendermint/tendermint/config"
tmflags "github.com/tendermint/tendermint/libs/cli/flags"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/node"
tmclient "github.com/tendermint/tendermint/rpc/client"
"google.golang.org/grpc"
)

// package-wide network lock to only allow one test network at a time
Expand All @@ -47,6 +52,19 @@ var lock = new(sync.Mutex)
// creates an ABCI Application to provide to Tendermint.
type AppConstructor = func(val Validator) servertypes.Application

// NewAppConstructor returns a new regen AppConstructor
func NewAppConstructor(encodingCfg app.EncodingConfig) AppConstructor {
return func(val Validator) servertypes.Application {
return app.NewRegenApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
encodingCfg,
app.EmptyAppOptions{},
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
)
}
}

// Config defines the necessary configuration used to bootstrap and start an
// in-process local testing network.
type Config struct {
Expand All @@ -57,7 +75,7 @@ type Config struct {
TxConfig client.TxConfig
AccountRetriever client.AccountRetriever
AppConstructor AppConstructor // the ABCI application constructor
GenesisState map[string]json.RawMessage // custom gensis state to provide
GenesisState map[string]json.RawMessage // custom genesis state to provide
TimeoutCommit time.Duration // the consensus commitment timeout
ChainID string // the network chain-id
NumValidators int // the total number of validators to create and bond
Expand All @@ -78,6 +96,35 @@ type Config struct {
PrintMnemonic bool // print the mnemonic of first validator as log output for testing
}

// DefaultConfig returns a sane default configuration suitable for nearly all
// testing requirements.
func DefaultConfig() Config {
encCfg := app.MakeEncodingConfig()

return Config{
Codec: encCfg.Codec,
TxConfig: encCfg.TxConfig,
LegacyAmino: encCfg.Amino,
InterfaceRegistry: encCfg.InterfaceRegistry,
AccountRetriever: authtypes.AccountRetriever{},
AppConstructor: NewAppConstructor(encCfg),
GenesisState: app.ModuleBasics.DefaultGenesis(encCfg.Codec),
TimeoutCommit: 2 * time.Second,
ChainID: "chain-" + tmrand.Str(6),
NumValidators: 4,
BondDenom: sdk.DefaultBondDenom,
MinGasPrices: fmt.Sprintf("0.000006%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{},
PrintMnemonic: false,
}
}

type (
// Network defines a local in-process testing network using SimApp. It can be
// configured to start any number of validators, each with its own RPC and API
Expand Down Expand Up @@ -129,26 +176,32 @@ type Logger interface {
Logf(format string, args ...interface{})
}

var _ Logger = (*testing.T)(nil)
var _ Logger = (*CLILogger)(nil)
var (
_ Logger = (*testing.T)(nil)
_ Logger = (*CLILogger)(nil)
)

// CLILogger wraps a cobra.Command and provides command logging methods.
type CLILogger struct {
cmd *cobra.Command
}

// Log logs given args.
func (s CLILogger) Log(args ...interface{}) {
s.cmd.Println(args...)
}

// Logf logs given args according to a format specifier.
func (s CLILogger) Logf(format string, args ...interface{}) {
s.cmd.Printf(format, args...)
}

// NewCLILogger creates a new CLILogger.
func NewCLILogger(cmd *cobra.Command) CLILogger {
return CLILogger{cmd}
}

// New creates Network
// New creates a new Network for integration tests or in-process testnets run via the CLI
func New(l Logger, baseDir string, cfg Config) (*Network, error) {
// only one caller/test can create and use a network at a time
l.Log("acquiring test network lock")
Expand Down Expand Up @@ -205,13 +258,12 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
return nil, err
}
}
appCfg.API.Address = apiListenAddr

appCfg.API.Address = apiListenAddr
apiURL, err := url.Parse(apiListenAddr)
if err != nil {
return nil, err
}

apiAddr = fmt.Sprintf("http://%s:%s", apiURL.Hostname(), apiURL.Port())

if cfg.RPCAddress != "" {
Expand Down Expand Up @@ -243,10 +295,10 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
appCfg.GRPCWeb.Enable = true
}

logger := log.NewNopLogger()
logger := server.ZeroLogWrapper{Logger: zerolog.Nop()}
if cfg.EnableTMLogging {
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
logger, _ = tmflags.ParseLogLevel("info", logger, tmcfg.DefaultLogLevel)
logWriter := zerolog.ConsoleWriter{Out: os.Stderr}
logger = server.ZeroLogWrapper{Logger: zerolog.New(logWriter).Level(zerolog.InfoLevel).With().Timestamp().Logger()}
}

ctx.Logger = logger
Expand All @@ -256,12 +308,12 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
clientDir := filepath.Join(network.BaseDir, nodeDirName, "simcli")
gentxsDir := filepath.Join(network.BaseDir, "gentxs")

err := os.MkdirAll(filepath.Join(nodeDir, "config"), 0755)
err := os.MkdirAll(filepath.Join(nodeDir, "config"), 0o755)
if err != nil {
return nil, err
}

err = os.MkdirAll(clientDir, 0755)
err = os.MkdirAll(clientDir, 0o755)
if err != nil {
return nil, err
}
Expand All @@ -280,6 +332,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
if err != nil {
return nil, err
}

tmCfg.P2P.ListenAddress = p2pAddr
tmCfg.P2P.AddrBookStrict = false
tmCfg.P2P.AllowDuplicateIP = true
Expand All @@ -288,6 +341,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
if err != nil {
return nil, err
}

nodeIDs[i] = nodeID
valPubKeys[i] = pubKey

Expand Down Expand Up @@ -347,7 +401,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
createValMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewCoin(sdk.DefaultBondDenom, cfg.BondedTokens),
sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
Expand Down Expand Up @@ -388,15 +442,15 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
if err != nil {
return nil, err
}

err = writeFile(fmt.Sprintf("%v.json", nodeDirName), gentxsDir, txBz)
if err != nil {
return nil, err
}

srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appCfg)
srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config", "app.toml"), appCfg)

clientCtx := client.Context{}.
WithKeyringDir(clientDir).
WithKeyring(kb).
WithHomeDir(tmCfg.RootDir).
WithChainID(cfg.ChainID).
Expand Down Expand Up @@ -426,20 +480,26 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
if err != nil {
return nil, err
}

err = collectGenFiles(cfg, network.Validators, network.BaseDir)
if err != nil {
return nil, err
}

l.Log("starting test network...")
for _, v := range network.Validators {
if err := startInProcess(cfg, v); err != nil {
for idx, v := range network.Validators {
err := startInProcess(cfg, v)
if err != nil {
return nil, err
}
l.Log("started validator", idx)
}

l.Log("started test network")
height, err := network.LatestHeight()
if err != nil {
return nil, err
}

l.Log("started test network at height:", height)

// Ensure we cleanup incase any test was abruptly halted (e.g. SIGINT) as any
// defer in a test would not be called.
Expand Down Expand Up @@ -474,7 +534,10 @@ func (n *Network) WaitForHeight(h int64) (int64, error) {
// provide a custom timeout.
func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error) {
ticker := time.NewTicker(time.Second)
timeout := time.After(t)
defer ticker.Stop()

timeout := time.NewTimer(t)
defer timeout.Stop()

if len(n.Validators) == 0 {
return 0, errors.New("no validators available")
Expand All @@ -485,8 +548,7 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err

for {
select {
case <-timeout:
ticker.Stop()
case <-timeout.C:
return latestHeight, errors.New("timeout exceeded waiting for block")
case <-ticker.C:
status, err := val.RPCClient.Status(context.Background())
Expand Down
Loading