-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: testnode utilities (#3785)
## Motivation I was looking through testnode code while working on a separate PR and these minor renames + moves made the code a little easier to read and understand.
- Loading branch information
Showing
10 changed files
with
179 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package testnode | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
"github.com/tendermint/tendermint/node" | ||
"github.com/tendermint/tendermint/p2p" | ||
"github.com/tendermint/tendermint/privval" | ||
"github.com/tendermint/tendermint/proxy" | ||
tmdb "github.com/tendermint/tm-db" | ||
) | ||
|
||
// NewCometNode creates a ready to use comet node that operates a single | ||
// validator celestia-app network. It expects that all configuration files are | ||
// already initialized and saved to the baseDir. | ||
func NewCometNode(baseDir string, config *UniversalTestingConfig) (*node.Node, servertypes.Application, error) { | ||
logger := NewLogger(config) | ||
dbPath := filepath.Join(config.TmConfig.RootDir, "data") | ||
db, err := tmdb.NewGoLevelDB("application", dbPath) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
config.AppOptions.Set(flags.FlagHome, baseDir) | ||
|
||
app := config.AppCreator(logger, db, nil, config.AppOptions) | ||
|
||
nodeKey, err := p2p.LoadOrGenNodeKey(config.TmConfig.NodeKeyFile()) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
cometNode, err := node.NewNode( | ||
config.TmConfig, | ||
privval.LoadOrGenFilePV(config.TmConfig.PrivValidatorKeyFile(), config.TmConfig.PrivValidatorStateFile()), | ||
nodeKey, | ||
proxy.NewLocalClientCreator(app), | ||
node.DefaultGenesisDocProviderFunc(config.TmConfig), | ||
node.DefaultDBProvider, | ||
node.DefaultMetricsProvider(config.TmConfig.Instrumentation), | ||
logger, | ||
) | ||
|
||
return cometNode, app, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package testnode | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/tendermint/tendermint/libs/log" | ||
) | ||
|
||
func NewLogger(config *UniversalTestingConfig) log.Logger { | ||
if config.SuppressLogs { | ||
return log.NewNopLogger() | ||
} | ||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) | ||
switch config.TmConfig.LogLevel { | ||
case "error": | ||
return log.NewFilter(logger, log.AllowError()) | ||
case "info": | ||
return log.NewFilter(logger, log.AllowInfo()) | ||
case "debug": | ||
return log.NewFilter(logger, log.AllowDebug()) | ||
default: | ||
return logger | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.