mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-16 17:52:50 +00:00
Compare commits
2 Commits
master
...
callum/sim
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e6e57118e | ||
|
|
27d139cdb9 |
@@ -3,6 +3,7 @@ package debug
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
)
|
||||
|
||||
@@ -12,7 +13,7 @@ const (
|
||||
flagFrequency = "frequency"
|
||||
)
|
||||
|
||||
func GetDebugCommand(logger log.Logger) *cobra.Command {
|
||||
func GetDebugCommand(conf *config.Config, logger log.Logger) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "debug",
|
||||
Short: "A utility to kill or watch a Tendermint process while aggregating debugging data",
|
||||
@@ -25,7 +26,7 @@ func GetDebugCommand(logger log.Logger) *cobra.Command {
|
||||
)
|
||||
|
||||
cmd.AddCommand(getKillCmd(logger))
|
||||
cmd.AddCommand(getDumpCmd(logger))
|
||||
cmd.AddCommand(getDumpCmd(conf, logger))
|
||||
return cmd
|
||||
|
||||
}
|
||||
|
||||
@@ -9,15 +9,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
)
|
||||
|
||||
func getDumpCmd(logger log.Logger) *cobra.Command {
|
||||
func getDumpCmd(conf *config.Config, logger log.Logger) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "dump [output-directory]",
|
||||
Short: "Continuously poll a Tendermint process and dump debugging data into a single location",
|
||||
@@ -63,11 +60,6 @@ if enabled.`,
|
||||
|
||||
ctx := cmd.Context()
|
||||
|
||||
home := viper.GetString(cli.HomeFlag)
|
||||
conf := config.DefaultConfig()
|
||||
conf = conf.SetRoot(home)
|
||||
config.EnsureRoot(conf.RootDir)
|
||||
|
||||
dumpArgs := dumpDebugDataArgs{
|
||||
conf: conf,
|
||||
outDir: outDir,
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
)
|
||||
@@ -52,7 +52,7 @@ $ tendermint debug kill 34255 /path/to/tm-debug.zip`,
|
||||
return fmt.Errorf("failed to create new http client: %w", err)
|
||||
}
|
||||
|
||||
home := viper.GetString(cli.HomeFlag)
|
||||
home := viper.GetString(commands.HomeFlag)
|
||||
conf := config.DefaultConfig()
|
||||
conf = conf.SetRoot(home)
|
||||
config.EnsureRoot(conf.RootDir)
|
||||
|
||||
@@ -65,7 +65,12 @@ either or both arguments.
|
||||
return fmt.Errorf("%s: %w", reindexFailed, err)
|
||||
}
|
||||
|
||||
es, err := loadEventSinks(conf)
|
||||
state, err := ss.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
es, err := loadEventSinks(conf, state.ChainID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", reindexFailed, err)
|
||||
}
|
||||
@@ -91,7 +96,7 @@ either or both arguments.
|
||||
return cmd
|
||||
}
|
||||
|
||||
func loadEventSinks(cfg *tmcfg.Config) ([]indexer.EventSink, error) {
|
||||
func loadEventSinks(cfg *tmcfg.Config, chainID string) ([]indexer.EventSink, error) {
|
||||
// Check duplicated sinks.
|
||||
sinks := map[string]bool{}
|
||||
for _, s := range cfg.TxIndex.Indexer {
|
||||
@@ -119,7 +124,7 @@ func loadEventSinks(cfg *tmcfg.Config) ([]indexer.EventSink, error) {
|
||||
if conn == "" {
|
||||
return nil, errors.New("the psql connection settings cannot be empty")
|
||||
}
|
||||
es, err := psql.NewEventSink(conn, cfg.ChainID())
|
||||
es, err := psql.NewEventSink(conn, chainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -156,7 +161,7 @@ func loadStateAndBlockStore(cfg *tmcfg.Config) (*store.BlockStore, state.Store,
|
||||
blockStore := store.NewBlockStore(blockStoreDB)
|
||||
|
||||
if !os.FileExists(filepath.Join(cfg.DBDir(), "state.db")) {
|
||||
return nil, nil, fmt.Errorf("no blockstore found in %v", cfg.DBDir())
|
||||
return nil, nil, fmt.Errorf("no statestore found in %v", cfg.DBDir())
|
||||
}
|
||||
|
||||
// Get StateStore
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/internal/state/indexer"
|
||||
"github.com/tendermint/tendermint/internal/state/mocks"
|
||||
"github.com/tendermint/tendermint/internal/test/factory"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
||||
@@ -100,7 +101,7 @@ func TestLoadEventSink(t *testing.T) {
|
||||
cfg := config.TestConfig()
|
||||
cfg.TxIndex.Indexer = tc.sinks
|
||||
cfg.TxIndex.PsqlConn = tc.connURL
|
||||
_, err := loadEventSinks(cfg)
|
||||
_, err := loadEventSinks(cfg, factory.DefaultTestChainID)
|
||||
if tc.loadErr {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
||||
@@ -1,69 +1,79 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
)
|
||||
|
||||
const ctxTimeout = 4 * time.Second
|
||||
|
||||
// ParseConfig retrieves the default environment configuration,
|
||||
// sets up the Tendermint root and ensures that the root exists
|
||||
func ParseConfig(conf *config.Config) (*config.Config, error) {
|
||||
if err := viper.Unmarshal(conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conf.SetRoot(conf.RootDir)
|
||||
|
||||
if err := conf.ValidateBasic(); err != nil {
|
||||
return nil, fmt.Errorf("error in config file: %w", err)
|
||||
}
|
||||
return conf, nil
|
||||
}
|
||||
const (
|
||||
ctxTimeout = 4 * time.Second
|
||||
HomeFlag = "home"
|
||||
TraceFlag = "trace"
|
||||
OutputFlag = "output"
|
||||
)
|
||||
|
||||
// RootCommand constructs the root command-line entry point for Tendermint core.
|
||||
func RootCommand(conf *config.Config, logger log.Logger) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "tendermint",
|
||||
Short: "BFT state machine replication for applications in any programming languages",
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if cmd.Name() == VersionCmd.Name() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := cli.BindFlagsLoadViper(cmd, args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pconf, err := ParseConfig(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*conf = *pconf
|
||||
config.EnsureRoot(conf.RootDir)
|
||||
if err := log.OverrideWithNewLogger(logger, conf.LogFormat, conf.LogLevel); err != nil {
|
||||
return err
|
||||
}
|
||||
if warning := pconf.DeprecatedFieldWarning(); warning != nil {
|
||||
logger.Info("WARNING", "deprecated field warning", warning)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
cmd.PersistentFlags().StringP(cli.HomeFlag, "", os.ExpandEnv(filepath.Join("$HOME", config.DefaultTendermintDir)), "directory for config and data")
|
||||
cmd.PersistentFlags().Bool(cli.TraceFlag, false, "print out full stack trace on errors")
|
||||
cmd.PersistentFlags().StringP(HomeFlag, "", os.ExpandEnv(filepath.Join("$HOME", config.DefaultTendermintDir)), "directory for config and data")
|
||||
cmd.PersistentFlags().Bool(TraceFlag, false, "print out full stack trace on errors")
|
||||
cmd.PersistentFlags().String("log-level", conf.LogLevel, "log level")
|
||||
cobra.OnInitialize(func() { cli.InitEnv("TM") })
|
||||
cobra.OnInitialize(func() { initEnv("TM") })
|
||||
return cmd
|
||||
}
|
||||
|
||||
// InitEnv sets to use ENV variables if set.
|
||||
func initEnv(prefix string) {
|
||||
// This copies all variables like TMROOT to TM_ROOT,
|
||||
// so we can support both formats for the user
|
||||
prefix = strings.ToUpper(prefix)
|
||||
ps := prefix + "_"
|
||||
for _, e := range os.Environ() {
|
||||
kv := strings.SplitN(e, "=", 2)
|
||||
if len(kv) == 2 {
|
||||
k, v := kv[0], kv[1]
|
||||
if strings.HasPrefix(k, prefix) && !strings.HasPrefix(k, ps) {
|
||||
k2 := strings.Replace(k, prefix, ps, 1)
|
||||
os.Setenv(k2, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// env variables with TM prefix (eg. TM_ROOT)
|
||||
viper.SetEnvPrefix(prefix)
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
|
||||
viper.AutomaticEnv()
|
||||
}
|
||||
|
||||
func RunWithTrace(ctx context.Context, cmd *cobra.Command) error {
|
||||
cmd.SilenceUsage = true
|
||||
cmd.SilenceErrors = true
|
||||
|
||||
if err := cmd.ExecuteContext(ctx); err != nil {
|
||||
if viper.GetBool(TraceFlag) {
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n%s\n", err, buf)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
)
|
||||
@@ -38,7 +37,8 @@ func clearConfig(t *testing.T, dir string) *cfg.Config {
|
||||
|
||||
viper.Reset()
|
||||
conf := cfg.DefaultConfig()
|
||||
conf.RootDir = dir
|
||||
conf.SetRoot(dir)
|
||||
|
||||
return conf
|
||||
}
|
||||
|
||||
@@ -46,8 +46,6 @@ func clearConfig(t *testing.T, dir string) *cfg.Config {
|
||||
func testRootCmd(conf *cfg.Config) *cobra.Command {
|
||||
logger := log.NewNopLogger()
|
||||
cmd := RootCommand(conf, logger)
|
||||
cmd.RunE = func(cmd *cobra.Command, args []string) error { return nil }
|
||||
|
||||
var l string
|
||||
cmd.PersistentFlags().String("log", l, "Log")
|
||||
return cmd
|
||||
@@ -57,11 +55,11 @@ func testSetup(ctx context.Context, t *testing.T, conf *cfg.Config, args []strin
|
||||
t.Helper()
|
||||
|
||||
cmd := testRootCmd(conf)
|
||||
viper.Set(cli.HomeFlag, conf.RootDir)
|
||||
viper.Set(HomeFlag, conf.RootDir)
|
||||
|
||||
// run with the args and env
|
||||
args = append([]string{cmd.Use}, args...)
|
||||
return cli.RunWithArgs(ctx, cmd, args, env)
|
||||
return RunWithArgs(ctx, cmd, args, env)
|
||||
}
|
||||
|
||||
func TestRootHome(t *testing.T) {
|
||||
@@ -107,11 +105,8 @@ func TestRootFlagsEnv(t *testing.T) {
|
||||
env map[string]string
|
||||
logLevel string
|
||||
}{
|
||||
{[]string{"--log", "debug"}, nil, defaultLogLvl}, // wrong flag
|
||||
{[]string{"--log-level", "debug"}, nil, "debug"}, // right flag
|
||||
{nil, map[string]string{"TM_LOW": "debug"}, defaultLogLvl}, // wrong env flag
|
||||
{nil, map[string]string{"MT_LOG_LEVEL": "debug"}, defaultLogLvl}, // wrong env prefix
|
||||
{nil, map[string]string{"TM_LOG_LEVEL": "debug"}, "debug"}, // right env
|
||||
{[]string{"--log", "debug"}, nil, defaultLogLvl}, // wrong flag
|
||||
{[]string{"--log-level", "debug"}, nil, "debug"}, // right flag
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -145,9 +140,8 @@ func TestRootConfig(t *testing.T) {
|
||||
env map[string]string
|
||||
logLvl string
|
||||
}{
|
||||
{nil, nil, nonDefaultLogLvl}, // should load config
|
||||
{[]string{"--log-level=info"}, nil, "info"}, // flag over rides
|
||||
{nil, map[string]string{"TM_LOG_LEVEL": "info"}, "info"}, // env over rides
|
||||
{nil, nil, nonDefaultLogLvl}, // should load config
|
||||
{[]string{"--log-level=info"}, nil, "info"}, // flag over rides
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
@@ -170,7 +164,7 @@ func TestRootConfig(t *testing.T) {
|
||||
|
||||
// run with the args and env
|
||||
tc.args = append([]string{cmd.Use}, tc.args...)
|
||||
err = cli.RunWithArgs(ctx, cmd, tc.args, tc.env)
|
||||
err = RunWithArgs(ctx, cmd, tc.args, tc.env)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, tc.logLvl, conf.LogLevel)
|
||||
@@ -188,3 +182,31 @@ func WriteConfigVals(dir string, vals map[string]string) error {
|
||||
cfile := filepath.Join(dir, "config.toml")
|
||||
return os.WriteFile(cfile, []byte(data), 0600)
|
||||
}
|
||||
|
||||
// RunWithArgs executes the given command with the specified command line args
|
||||
// and environmental variables set. It returns any error returned from cmd.Execute()
|
||||
func RunWithArgs(ctx context.Context, cmd *cobra.Command, args []string, env map[string]string) error {
|
||||
oargs := os.Args
|
||||
oenv := map[string]string{}
|
||||
// defer returns the environment back to normal
|
||||
defer func() {
|
||||
os.Args = oargs
|
||||
for k, v := range oenv {
|
||||
os.Setenv(k, v)
|
||||
}
|
||||
}()
|
||||
|
||||
// set the args and env how we want them
|
||||
os.Args = args
|
||||
for k, v := range env {
|
||||
// backup old value if there, to restore at end
|
||||
oenv[k] = os.Getenv(k)
|
||||
err := os.Setenv(k, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// and finally run the command
|
||||
return RunWithTrace(ctx, cmd)
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func NewRunNodeCmd(nodeProvider cfg.ServiceProvider, conf *cfg.Config, logger lo
|
||||
return fmt.Errorf("failed to start node: %w", err)
|
||||
}
|
||||
|
||||
logger.Info("started node", "chain", conf.ChainID())
|
||||
logger.Info("started node")
|
||||
|
||||
<-ctx.Done()
|
||||
return nil
|
||||
|
||||
@@ -29,12 +29,24 @@ func MakeShowValidatorCommand(conf *config.Config, logger log.Logger) *cobra.Com
|
||||
)
|
||||
//TODO: remove once gRPC is the only supported protocol
|
||||
protocol, _ := tmnet.ProtocolAndAddress(conf.PrivValidator.ListenAddr)
|
||||
|
||||
switch protocol {
|
||||
case "grpc":
|
||||
// we need to load the chain ID and it's faster to load from state then from genesis
|
||||
_, ss, err := loadStateAndBlockStore(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
state, err := ss.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pvsc, err := tmgrpc.DialRemoteSigner(
|
||||
bctx,
|
||||
conf.PrivValidator,
|
||||
conf.ChainID(),
|
||||
state.ChainID,
|
||||
logger,
|
||||
conf.Instrumentation.Prometheus,
|
||||
)
|
||||
|
||||
@@ -3,10 +3,10 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||
"github.com/tendermint/tendermint/cmd/tendermint/commands/debug"
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/node"
|
||||
)
|
||||
@@ -15,16 +15,25 @@ func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
conf, err := commands.ParseConfig(config.DefaultConfig())
|
||||
homeDir := viper.GetString(commands.HomeFlag)
|
||||
viper.Set(commands.HomeFlag, homeDir)
|
||||
|
||||
conf, err := config.Load(homeDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
config.EnsureRoot(conf.RootDir)
|
||||
|
||||
logger, err := log.NewDefaultLogger(conf.LogFormat, conf.LogLevel)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if warning := conf.DeprecatedFieldWarning(); warning != nil {
|
||||
logger.Info("WARNING", "deprecated field warning", warning)
|
||||
}
|
||||
|
||||
rcmd := commands.RootCommand(conf, logger)
|
||||
rcmd.AddCommand(
|
||||
commands.MakeGenValidatorCommand(),
|
||||
@@ -42,7 +51,7 @@ func main() {
|
||||
commands.MakeInspectCommand(conf, logger),
|
||||
commands.MakeRollbackStateCommand(conf),
|
||||
commands.MakeKeyMigrateCommand(conf, logger),
|
||||
debug.GetDebugCommand(logger),
|
||||
debug.GetDebugCommand(conf, logger),
|
||||
commands.NewCompletionCmd(rcmd, true),
|
||||
commands.MakeCompactDBCommand(conf, logger),
|
||||
)
|
||||
@@ -60,7 +69,7 @@ func main() {
|
||||
// Create & start node
|
||||
rcmd.AddCommand(commands.NewRunNodeCmd(nodeFunc, conf, logger))
|
||||
|
||||
if err := cli.RunWithTrace(ctx, rcmd); err != nil {
|
||||
if err := commands.RunWithTrace(ctx, rcmd); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,9 +155,6 @@ func (cfg *Config) DeprecatedFieldWarning() error {
|
||||
|
||||
// BaseConfig defines the base configuration for a Tendermint node
|
||||
type BaseConfig struct { //nolint: maligned
|
||||
// chainID is unexposed and immutable but here for convenience
|
||||
chainID string
|
||||
|
||||
// The root directory for all data.
|
||||
// This should be set in viper so it can unmarshal into this struct
|
||||
RootDir string `mapstructure:"home"`
|
||||
@@ -247,17 +244,12 @@ func DefaultBaseConfig() BaseConfig {
|
||||
// TestBaseConfig returns a base configuration for testing a Tendermint node
|
||||
func TestBaseConfig() BaseConfig {
|
||||
cfg := DefaultBaseConfig()
|
||||
cfg.chainID = "tendermint_test"
|
||||
cfg.Mode = ModeValidator
|
||||
cfg.ProxyApp = "kvstore"
|
||||
cfg.DBBackend = "memdb"
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (cfg BaseConfig) ChainID() string {
|
||||
return cfg.chainID
|
||||
}
|
||||
|
||||
// GenesisFile returns the full path to the genesis.json file
|
||||
func (cfg BaseConfig) GenesisFile() string {
|
||||
return rootify(cfg.Genesis, cfg.RootDir)
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/internal/test/factory"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
)
|
||||
@@ -49,6 +51,33 @@ func WriteConfigFile(rootDir string, config *Config) error {
|
||||
return config.WriteToTemplate(filepath.Join(rootDir, defaultConfigFilePath))
|
||||
}
|
||||
|
||||
// Load uses viper to attempt to load the tendermint config given the root directory.
|
||||
func Load(rootDir string) (*Config, error) {
|
||||
// name of config file (without extension)
|
||||
viper.SetConfigName("config")
|
||||
// search root directory
|
||||
viper.AddConfigPath(rootDir)
|
||||
// search root directory /config
|
||||
viper.AddConfigPath(filepath.Join(rootDir, defaultConfigDir))
|
||||
|
||||
// If a config file is found, read it in.
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config = DefaultConfig()
|
||||
if err := viper.Unmarshal(config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config.SetRoot(rootDir)
|
||||
|
||||
if err := config.ValidateBasic(); err != nil {
|
||||
return nil, fmt.Errorf("error in config file: %w", err)
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// WriteToTemplate writes the config to the exact file specified by
|
||||
// the path, in the default toml template and does not mangle the path
|
||||
// or filename at all.
|
||||
@@ -579,7 +608,7 @@ func ResetTestRootWithChainID(dir, testName string, chainID string) (*Config, er
|
||||
|
||||
if !tmos.FileExists(genesisFilePath) {
|
||||
if chainID == "" {
|
||||
chainID = "tendermint_test"
|
||||
chainID = factory.DefaultTestChainID
|
||||
}
|
||||
testGenesis := fmt.Sprintf(testGenesisFmt, chainID)
|
||||
if err := writeFile(genesisFilePath, []byte(testGenesis), 0644); err != nil {
|
||||
|
||||
@@ -18,10 +18,13 @@ func ensureFiles(t *testing.T, rootDir string, files ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureRoot(t *testing.T) {
|
||||
func TestWriteAndReadConfig(t *testing.T) {
|
||||
// setup temp dir for test
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
_, err := Load(tmpDir)
|
||||
require.Error(t, err)
|
||||
|
||||
// create root dir
|
||||
EnsureRoot(tmpDir)
|
||||
|
||||
@@ -34,6 +37,11 @@ func TestEnsureRoot(t *testing.T) {
|
||||
checkConfig(t, string(data))
|
||||
|
||||
ensureFiles(t, tmpDir, "data")
|
||||
|
||||
cfg, err := Load(tmpDir)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, cfg)
|
||||
require.Equal(t, tmpDir, cfg.RootDir)
|
||||
}
|
||||
|
||||
func TestEnsureTestRoot(t *testing.T) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package blocksync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -13,7 +12,6 @@ import (
|
||||
|
||||
abciclient "github.com/tendermint/tendermint/abci/client"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/internal/consensus"
|
||||
"github.com/tendermint/tendermint/internal/eventbus"
|
||||
mpmocks "github.com/tendermint/tendermint/internal/mempool/mocks"
|
||||
@@ -253,12 +251,8 @@ func TestReactor_AbruptDisconnect(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
cfg, err := config.ResetTestRoot(t.TempDir(), "block_sync_reactor_test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(cfg.RootDir)
|
||||
|
||||
valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30)
|
||||
genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
maxBlockHeight := int64(64)
|
||||
|
||||
rts := setup(ctx, t, genDoc, privVals[0], []int64{maxBlockHeight, 0})
|
||||
@@ -293,12 +287,8 @@ func TestReactor_SyncTime(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
cfg, err := config.ResetTestRoot(t.TempDir(), "block_sync_reactor_test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(cfg.RootDir)
|
||||
|
||||
valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30)
|
||||
genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
maxBlockHeight := int64(101)
|
||||
|
||||
rts := setup(ctx, t, genDoc, privVals[0], []int64{maxBlockHeight, 0})
|
||||
@@ -321,12 +311,8 @@ func TestReactor_NoBlockResponse(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
cfg, err := config.ResetTestRoot(t.TempDir(), "block_sync_reactor_test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(cfg.RootDir)
|
||||
|
||||
valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30)
|
||||
genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
maxBlockHeight := int64(65)
|
||||
|
||||
rts := setup(ctx, t, genDoc, privVals[0], []int64{maxBlockHeight, 0})
|
||||
@@ -373,13 +359,9 @@ func TestReactor_BadBlockStopsPeer(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
cfg, err := config.ResetTestRoot(t.TempDir(), "block_sync_reactor_test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(cfg.RootDir)
|
||||
|
||||
maxBlockHeight := int64(48)
|
||||
valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30)
|
||||
genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
|
||||
rts := setup(ctx, t, genDoc, privVals[0], []int64{maxBlockHeight, 0, 0, 0, 0})
|
||||
|
||||
@@ -414,7 +396,7 @@ func TestReactor_BadBlockStopsPeer(t *testing.T) {
|
||||
// XXX: This causes a potential race condition.
|
||||
// See: https://github.com/tendermint/tendermint/issues/6005
|
||||
valSet, otherPrivVals := factory.ValidatorSet(ctx, t, 1, 30)
|
||||
otherGenDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
otherGenDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
newNode := rts.network.MakeNode(ctx, t, p2ptest.NodeOptions{
|
||||
MaxPeers: uint16(len(rts.nodes) + 1),
|
||||
MaxConnected: uint16(len(rts.nodes) + 1),
|
||||
@@ -445,35 +427,3 @@ func TestReactor_BadBlockStopsPeer(t *testing.T) {
|
||||
len(rts.reactors[newNode.NodeID].pool.peers),
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
func TestReactorReceivesNoExtendedCommit(t *testing.T) {
|
||||
blockDB := dbm.NewMemDB()
|
||||
stateDB := dbm.NewMemDB()
|
||||
stateStore := sm.NewStore(stateDB)
|
||||
blockStore := store.NewBlockStore(blockDB)
|
||||
blockExec := sm.NewBlockExecutor(
|
||||
stateStore,
|
||||
log.NewNopLogger(),
|
||||
rts.app[nodeID],
|
||||
mp,
|
||||
sm.EmptyEvidencePool{},
|
||||
blockStore,
|
||||
eventbus,
|
||||
sm.NopMetrics(),
|
||||
)
|
||||
NewReactor(
|
||||
log.NewNopLogger(),
|
||||
stateStore,
|
||||
blockExec,
|
||||
blockStore,
|
||||
nil,
|
||||
chCreator,
|
||||
func(ctx context.Context) *p2p.PeerUpdates { return rts.peerUpdates[nodeID] },
|
||||
rts.blockSync,
|
||||
consensus.NopMetrics(),
|
||||
nil, // eventbus, can be nil
|
||||
)
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -40,15 +40,13 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
|
||||
config := configSetup(t)
|
||||
|
||||
nValidators := 4
|
||||
prevoteHeight := int64(2)
|
||||
testName := "consensus_byzantine_test"
|
||||
tickerFunc := newMockTickerFunc(true)
|
||||
|
||||
valSet, privVals := factory.ValidatorSet(ctx, t, nValidators, 30)
|
||||
genDoc := factory.GenesisDoc(config, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
states := make([]*State, nValidators)
|
||||
|
||||
for i := 0; i < nValidators; i++ {
|
||||
|
||||
@@ -557,7 +557,7 @@ func makeState(ctx context.Context, t *testing.T, args makeStateArgs) (*State, [
|
||||
c = args.consensusParams
|
||||
}
|
||||
|
||||
state, privVals := makeGenesisState(ctx, t, args.config, genesisStateArgs{
|
||||
state, privVals := makeGenesisState(ctx, t, genesisStateArgs{
|
||||
Params: c,
|
||||
Validators: validators,
|
||||
})
|
||||
@@ -803,7 +803,7 @@ func makeConsensusState(
|
||||
tempDir := t.TempDir()
|
||||
|
||||
valSet, privVals := factory.ValidatorSet(ctx, t, nValidators, 30)
|
||||
genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
css := make([]*State, nValidators)
|
||||
logger := consensusLogger()
|
||||
|
||||
@@ -863,7 +863,7 @@ func randConsensusNetWithPeers(
|
||||
t.Helper()
|
||||
|
||||
valSet, privVals := factory.ValidatorSet(ctx, t, nValidators, testMinPower)
|
||||
genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
css := make([]*State, nPeers)
|
||||
t.Helper()
|
||||
logger := consensusLogger()
|
||||
@@ -924,7 +924,7 @@ type genesisStateArgs struct {
|
||||
Time time.Time
|
||||
}
|
||||
|
||||
func makeGenesisState(ctx context.Context, t *testing.T, cfg *config.Config, args genesisStateArgs) (sm.State, []types.PrivValidator) {
|
||||
func makeGenesisState(ctx context.Context, t *testing.T, args genesisStateArgs) (sm.State, []types.PrivValidator) {
|
||||
t.Helper()
|
||||
if args.Power == 0 {
|
||||
args.Power = 1
|
||||
@@ -939,7 +939,7 @@ func makeGenesisState(ctx context.Context, t *testing.T, cfg *config.Config, arg
|
||||
if args.Time.IsZero() {
|
||||
args.Time = time.Now()
|
||||
}
|
||||
genDoc := factory.GenesisDoc(cfg, args.Time, valSet.Validators, args.Params)
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, args.Time, valSet.Validators, args.Params)
|
||||
s0, err := sm.MakeGenesisState(genDoc)
|
||||
require.NoError(t, err)
|
||||
return s0, privValidators
|
||||
|
||||
@@ -35,14 +35,12 @@ func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
baseConfig := configSetup(t)
|
||||
|
||||
config, err := ResetConfig(t.TempDir(), "consensus_mempool_txs_available_test")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = os.RemoveAll(config.RootDir) })
|
||||
|
||||
config.Consensus.CreateEmptyBlocks = false
|
||||
state, privVals := makeGenesisState(ctx, t, baseConfig, genesisStateArgs{
|
||||
state, privVals := makeGenesisState(ctx, t, genesisStateArgs{
|
||||
Validators: 1,
|
||||
Power: 10,
|
||||
Params: factory.ConsensusParams()})
|
||||
@@ -61,7 +59,6 @@ func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) {
|
||||
baseConfig := configSetup(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -70,7 +67,7 @@ func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) {
|
||||
t.Cleanup(func() { _ = os.RemoveAll(config.RootDir) })
|
||||
|
||||
config.Consensus.CreateEmptyBlocksInterval = ensureTimeout
|
||||
state, privVals := makeGenesisState(ctx, t, baseConfig, genesisStateArgs{
|
||||
state, privVals := makeGenesisState(ctx, t, genesisStateArgs{
|
||||
Validators: 1,
|
||||
Power: 10,
|
||||
Params: factory.ConsensusParams()})
|
||||
@@ -87,7 +84,6 @@ func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMempoolProgressInHigherRound(t *testing.T) {
|
||||
baseConfig := configSetup(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -96,7 +92,7 @@ func TestMempoolProgressInHigherRound(t *testing.T) {
|
||||
t.Cleanup(func() { _ = os.RemoveAll(config.RootDir) })
|
||||
|
||||
config.Consensus.CreateEmptyBlocks = false
|
||||
state, privVals := makeGenesisState(ctx, t, baseConfig, genesisStateArgs{
|
||||
state, privVals := makeGenesisState(ctx, t, genesisStateArgs{
|
||||
Validators: 1,
|
||||
Power: 10,
|
||||
Params: factory.ConsensusParams()})
|
||||
@@ -150,7 +146,7 @@ func TestMempoolTxConcurrentWithCommit(t *testing.T) {
|
||||
|
||||
config := configSetup(t)
|
||||
logger := log.NewNopLogger()
|
||||
state, privVals := makeGenesisState(ctx, t, config, genesisStateArgs{
|
||||
state, privVals := makeGenesisState(ctx, t, genesisStateArgs{
|
||||
Validators: 1,
|
||||
Power: 10,
|
||||
Params: factory.ConsensusParams(),
|
||||
@@ -188,7 +184,7 @@ func TestMempoolRmBadTx(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
state, privVals := makeGenesisState(ctx, t, config, genesisStateArgs{
|
||||
state, privVals := makeGenesisState(ctx, t, genesisStateArgs{
|
||||
Validators: 1,
|
||||
Power: 10,
|
||||
Params: factory.ConsensusParams()})
|
||||
|
||||
@@ -90,7 +90,6 @@ type pbtsTestConfiguration struct {
|
||||
func newPBTSTestHarness(ctx context.Context, t *testing.T, tc pbtsTestConfiguration) pbtsTestHarness {
|
||||
t.Helper()
|
||||
const validators = 4
|
||||
cfg := configSetup(t)
|
||||
clock := new(tmtimemocks.Source)
|
||||
|
||||
if tc.genesisTime.IsZero() {
|
||||
@@ -110,7 +109,7 @@ func newPBTSTestHarness(ctx context.Context, t *testing.T, tc pbtsTestConfigurat
|
||||
consensusParams.Timeout.Propose = tc.timeoutPropose
|
||||
consensusParams.Synchrony = tc.synchronyParams
|
||||
|
||||
state, privVals := makeGenesisState(ctx, t, cfg, genesisStateArgs{
|
||||
state, privVals := makeGenesisState(ctx, t, genesisStateArgs{
|
||||
Params: consensusParams,
|
||||
Time: tc.genesisTime,
|
||||
Validators: validators,
|
||||
@@ -137,7 +136,7 @@ func newPBTSTestHarness(ctx context.Context, t *testing.T, tc pbtsTestConfigurat
|
||||
otherValidators: vss[1:],
|
||||
validatorClock: clock,
|
||||
currentHeight: 1,
|
||||
chainID: cfg.ChainID(),
|
||||
chainID: factory.DefaultTestChainID,
|
||||
roundCh: subscribe(ctx, t, cs.eventBus, types.EventQueryNewRound),
|
||||
ensureProposalCh: subscribe(ctx, t, cs.eventBus, types.EventQueryCompleteProposal),
|
||||
blockCh: subscribe(ctx, t, cs.eventBus, types.EventQueryNewBlock),
|
||||
|
||||
@@ -444,14 +444,12 @@ func TestReactorWithEvidence(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
|
||||
cfg := configSetup(t)
|
||||
|
||||
n := 2
|
||||
testName := "consensus_reactor_test"
|
||||
tickerFunc := newMockTickerFunc(true)
|
||||
|
||||
valSet, privVals := factory.ValidatorSet(ctx, t, n, 30)
|
||||
genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
states := make([]*State, n)
|
||||
logger := consensusLogger()
|
||||
|
||||
@@ -493,7 +491,7 @@ func TestReactorWithEvidence(t *testing.T) {
|
||||
// everyone includes evidence of another double signing
|
||||
vIdx := (i + 1) % n
|
||||
|
||||
ev, err := types.NewMockDuplicateVoteEvidenceWithValidator(ctx, 1, defaultTestTime, privVals[vIdx], cfg.ChainID())
|
||||
ev, err := types.NewMockDuplicateVoteEvidenceWithValidator(ctx, 1, defaultTestTime, privVals[vIdx], factory.DefaultTestChainID)
|
||||
require.NoError(t, err)
|
||||
evpool := &statemocks.EvidencePool{}
|
||||
evpool.On("CheckEvidence", ctx, mock.AnythingOfType("types.EvidenceList")).Return(nil)
|
||||
|
||||
@@ -364,7 +364,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
ensureNewProposal(t, proposalCh, height, round)
|
||||
rs := css[0].GetRoundState()
|
||||
|
||||
signAddVotes(ctx, t, css[0], tmproto.PrecommitType, sim.Config.ChainID(),
|
||||
signAddVotes(ctx, t, css[0], tmproto.PrecommitType, factory.DefaultTestChainID,
|
||||
types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()},
|
||||
vss[1:nVals]...)
|
||||
|
||||
@@ -388,7 +388,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
|
||||
proposal := types.NewProposal(vss[1].Height, round, -1, blockID, propBlock.Header.Time)
|
||||
p := proposal.ToProto()
|
||||
if err := vss[1].SignProposal(ctx, cfg.ChainID(), p); err != nil {
|
||||
if err := vss[1].SignProposal(ctx, factory.DefaultTestChainID, p); err != nil {
|
||||
t.Fatal("failed to sign bad proposal", err)
|
||||
}
|
||||
proposal.Signature = p.Signature
|
||||
@@ -399,7 +399,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
}
|
||||
ensureNewProposal(t, proposalCh, height, round)
|
||||
rs = css[0].GetRoundState()
|
||||
signAddVotes(ctx, t, css[0], tmproto.PrecommitType, sim.Config.ChainID(),
|
||||
signAddVotes(ctx, t, css[0], tmproto.PrecommitType, factory.DefaultTestChainID,
|
||||
types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()},
|
||||
vss[1:nVals]...)
|
||||
ensureNewRound(t, newRoundCh, height+1, 0)
|
||||
@@ -422,7 +422,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
|
||||
proposal = types.NewProposal(vss[2].Height, round, -1, blockID, propBlock.Header.Time)
|
||||
p = proposal.ToProto()
|
||||
if err := vss[2].SignProposal(ctx, cfg.ChainID(), p); err != nil {
|
||||
if err := vss[2].SignProposal(ctx, factory.DefaultTestChainID, p); err != nil {
|
||||
t.Fatal("failed to sign bad proposal", err)
|
||||
}
|
||||
proposal.Signature = p.Signature
|
||||
@@ -433,7 +433,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
}
|
||||
ensureNewProposal(t, proposalCh, height, round)
|
||||
rs = css[0].GetRoundState()
|
||||
signAddVotes(ctx, t, css[0], tmproto.PrecommitType, sim.Config.ChainID(),
|
||||
signAddVotes(ctx, t, css[0], tmproto.PrecommitType, factory.DefaultTestChainID,
|
||||
types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()},
|
||||
vss[1:nVals]...)
|
||||
ensureNewRound(t, newRoundCh, height+1, 0)
|
||||
@@ -485,7 +485,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
|
||||
proposal = types.NewProposal(vss[3].Height, round, -1, blockID, propBlock.Header.Time)
|
||||
p = proposal.ToProto()
|
||||
if err := vss[3].SignProposal(ctx, cfg.ChainID(), p); err != nil {
|
||||
if err := vss[3].SignProposal(ctx, factory.DefaultTestChainID, p); err != nil {
|
||||
t.Fatal("failed to sign bad proposal", err)
|
||||
}
|
||||
proposal.Signature = p.Signature
|
||||
@@ -506,7 +506,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
continue
|
||||
}
|
||||
signAddVotes(ctx, t, css[0],
|
||||
tmproto.PrecommitType, sim.Config.ChainID(),
|
||||
tmproto.PrecommitType, factory.DefaultTestChainID,
|
||||
types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()},
|
||||
newVss[i])
|
||||
}
|
||||
@@ -531,7 +531,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
continue
|
||||
}
|
||||
signAddVotes(ctx, t, css[0],
|
||||
tmproto.PrecommitType, sim.Config.ChainID(),
|
||||
tmproto.PrecommitType, factory.DefaultTestChainID,
|
||||
types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()},
|
||||
newVss[i])
|
||||
}
|
||||
@@ -556,7 +556,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
require.NotEqual(t, -1, selfIndex)
|
||||
proposal = types.NewProposal(vss[1].Height, round, -1, blockID, propBlock.Header.Time)
|
||||
p = proposal.ToProto()
|
||||
if err := vss[1].SignProposal(ctx, cfg.ChainID(), p); err != nil {
|
||||
if err := vss[1].SignProposal(ctx, factory.DefaultTestChainID, p); err != nil {
|
||||
t.Fatal("failed to sign bad proposal", err)
|
||||
}
|
||||
proposal.Signature = p.Signature
|
||||
@@ -572,7 +572,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite {
|
||||
continue
|
||||
}
|
||||
signAddVotes(ctx, t, css[0],
|
||||
tmproto.PrecommitType, sim.Config.ChainID(),
|
||||
tmproto.PrecommitType, factory.DefaultTestChainID,
|
||||
types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()},
|
||||
newVss[i])
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func TestStateProposerSelection0(t *testing.T) {
|
||||
ensureNewProposal(t, proposalCh, height, round)
|
||||
|
||||
rs := cs1.GetRoundState()
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{
|
||||
Hash: rs.ProposalBlock.Hash(),
|
||||
PartSetHeader: rs.ProposalBlockParts.Header(),
|
||||
}, vss[1:]...)
|
||||
@@ -141,7 +141,7 @@ func TestStateProposerSelection2(t *testing.T) {
|
||||
int(i+2)%len(vss),
|
||||
prop.Address)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vss[1:]...)
|
||||
ensureNewRound(t, newRoundCh, height, i+round+1) // wait for the new round event each round
|
||||
incrementRound(vss[1:]...)
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func TestStateBadProposal(t *testing.T) {
|
||||
blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
|
||||
proposal := types.NewProposal(vs2.Height, round, -1, blockID, propBlock.Header.Time)
|
||||
p := proposal.ToProto()
|
||||
err = vs2.SignProposal(ctx, config.ChainID(), p)
|
||||
err = vs2.SignProposal(ctx, factory.DefaultTestChainID, p)
|
||||
require.NoError(t, err)
|
||||
|
||||
proposal.Signature = p.Signature
|
||||
@@ -258,13 +258,13 @@ func TestStateBadProposal(t *testing.T) {
|
||||
ensurePrevoteMatch(t, voteCh, height, round, nil)
|
||||
|
||||
// add bad prevote from vs2 and wait for it
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2)
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
// wait for precommit
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs2)
|
||||
}
|
||||
|
||||
func TestStateOversizedBlock(t *testing.T) {
|
||||
@@ -296,7 +296,7 @@ func TestStateOversizedBlock(t *testing.T) {
|
||||
blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
|
||||
proposal := types.NewProposal(height, round, -1, blockID, propBlock.Header.Time)
|
||||
p := proposal.ToProto()
|
||||
err = vs2.SignProposal(ctx, config.ChainID(), p)
|
||||
err = vs2.SignProposal(ctx, factory.DefaultTestChainID, p)
|
||||
require.NoError(t, err)
|
||||
proposal.Signature = p.Signature
|
||||
|
||||
@@ -319,11 +319,11 @@ func TestStateOversizedBlock(t *testing.T) {
|
||||
// and then should send nil prevote and precommit regardless of whether other validators prevote and
|
||||
// precommit on it
|
||||
ensurePrevoteMatch(t, voteCh, height, round, nil)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2)
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs2)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -401,7 +401,7 @@ func TestStateFullRound2(t *testing.T) {
|
||||
blockID := types.BlockID{Hash: rs.ProposalBlock.Hash(), PartSetHeader: rs.ProposalBlockParts.Header()}
|
||||
|
||||
// prevote arrives from vs2:
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2)
|
||||
ensurePrevote(t, voteCh, height, round) // prevote
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round) // precommit
|
||||
@@ -411,7 +411,7 @@ func TestStateFullRound2(t *testing.T) {
|
||||
// we should be stuck in limbo waiting for more precommits
|
||||
|
||||
// precommit arrives from vs2:
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs2)
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
|
||||
// wait to finish commit, propose in next height
|
||||
@@ -461,7 +461,7 @@ func TestStateLock_NoPOL(t *testing.T) {
|
||||
|
||||
// we should now be stuck in limbo forever, waiting for more prevotes
|
||||
// prevote arrives from vs2:
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), initialBlockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, initialBlockID, vs2)
|
||||
ensurePrevote(t, voteCh, height, round) // prevote
|
||||
validatePrevote(ctx, t, cs1, round, vss[0], initialBlockID.Hash)
|
||||
|
||||
@@ -474,7 +474,7 @@ func TestStateLock_NoPOL(t *testing.T) {
|
||||
hash := make([]byte, len(initialBlockID.Hash))
|
||||
copy(hash, initialBlockID.Hash)
|
||||
hash[0] = (hash[0] + 1) % 255
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{
|
||||
Hash: hash,
|
||||
PartSetHeader: initialBlockID.PartSetHeader,
|
||||
}, vs2)
|
||||
@@ -509,7 +509,7 @@ func TestStateLock_NoPOL(t *testing.T) {
|
||||
partSet, err := rs.LockedBlock.MakePartSet(partSize)
|
||||
require.NoError(t, err)
|
||||
conflictingBlockID := types.BlockID{Hash: hash, PartSetHeader: partSet.Header()}
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), conflictingBlockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, conflictingBlockID, vs2)
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
// now we're going to enter prevote again, but with invalid args
|
||||
@@ -521,7 +521,7 @@ func TestStateLock_NoPOL(t *testing.T) {
|
||||
validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, initialBlockID.Hash)
|
||||
|
||||
// add conflicting precommit from vs2
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), conflictingBlockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, conflictingBlockID, vs2)
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
|
||||
// (note we're entering precommit for a second time this round, but with invalid args
|
||||
@@ -550,7 +550,7 @@ func TestStateLock_NoPOL(t *testing.T) {
|
||||
partSet, err = rs.ProposalBlock.MakePartSet(partSize)
|
||||
require.NoError(t, err)
|
||||
newBlockID := types.BlockID{Hash: hash, PartSetHeader: partSet.Header()}
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), newBlockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, newBlockID, vs2)
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -563,7 +563,7 @@ func TestStateLock_NoPOL(t *testing.T) {
|
||||
t,
|
||||
cs1,
|
||||
tmproto.PrecommitType,
|
||||
config.ChainID(),
|
||||
factory.DefaultTestChainID,
|
||||
newBlockID,
|
||||
vs2) // NOTE: conflicting precommits at same height
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
@@ -604,7 +604,7 @@ func TestStateLock_NoPOL(t *testing.T) {
|
||||
validatePrevote(ctx, t, cs1, 3, vss[0], nil)
|
||||
|
||||
// prevote for proposed block
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), propBlockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, propBlockID, vs2)
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -616,7 +616,7 @@ func TestStateLock_NoPOL(t *testing.T) {
|
||||
t,
|
||||
cs1,
|
||||
tmproto.PrecommitType,
|
||||
config.ChainID(),
|
||||
factory.DefaultTestChainID,
|
||||
propBlockID,
|
||||
vs2) // NOTE: conflicting precommits at same height
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
@@ -671,7 +671,7 @@ func TestStateLock_POLUpdateLock(t *testing.T) {
|
||||
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), initialBlockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, initialBlockID, vs2, vs3, vs4)
|
||||
|
||||
// check that the validator generates a Lock event.
|
||||
ensureLock(t, lockCh, height, round)
|
||||
@@ -681,7 +681,7 @@ func TestStateLock_POLUpdateLock(t *testing.T) {
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], initialBlockID.Hash, initialBlockID.Hash)
|
||||
|
||||
// add precommits from the rest of the validators.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// timeout to new round.
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -721,7 +721,7 @@ func TestStateLock_POLUpdateLock(t *testing.T) {
|
||||
ensurePrevoteMatch(t, voteCh, height, round, nil)
|
||||
|
||||
// Add prevotes from the remainder of the validators for the new locked block.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), r1BlockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, r1BlockID, vs2, vs3, vs4)
|
||||
|
||||
// Check that we lock on a new block.
|
||||
ensureLock(t, lockCh, height, round)
|
||||
@@ -777,7 +777,7 @@ func TestStateLock_POLRelock(t *testing.T) {
|
||||
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
// check that the validator generates a Lock event.
|
||||
ensureLock(t, lockCh, height, round)
|
||||
@@ -787,7 +787,7 @@ func TestStateLock_POLRelock(t *testing.T) {
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash)
|
||||
|
||||
// add precommits from the rest of the validators.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// timeout to new round.
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -820,7 +820,7 @@ func TestStateLock_POLRelock(t *testing.T) {
|
||||
validatePrevote(ctx, t, cs1, round, vss[0], blockID.Hash)
|
||||
|
||||
// Add prevotes from the remainder of the validators for the locked block.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
// Check that we relock.
|
||||
ensureRelock(t, relockCh, height, round)
|
||||
@@ -872,7 +872,7 @@ func TestStateLock_PrevoteNilWhenLockedAndMissProposal(t *testing.T) {
|
||||
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
// check that the validator generates a Lock event.
|
||||
ensureLock(t, lockCh, height, round)
|
||||
@@ -882,7 +882,7 @@ func TestStateLock_PrevoteNilWhenLockedAndMissProposal(t *testing.T) {
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash)
|
||||
|
||||
// add precommits from the rest of the validators.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// timeout to new round.
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -905,7 +905,7 @@ func TestStateLock_PrevoteNilWhenLockedAndMissProposal(t *testing.T) {
|
||||
validatePrevote(ctx, t, cs1, round, vss[0], nil)
|
||||
|
||||
// Add prevotes from the remainder of the validators nil.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
// We should now be locked on the same block but with an updated locked round.
|
||||
validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, blockID.Hash)
|
||||
@@ -958,7 +958,7 @@ func TestStateLock_PrevoteNilWhenLockedAndDifferentProposal(t *testing.T) {
|
||||
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
// check that the validator generates a Lock event.
|
||||
ensureLock(t, lockCh, height, round)
|
||||
@@ -968,7 +968,7 @@ func TestStateLock_PrevoteNilWhenLockedAndDifferentProposal(t *testing.T) {
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash)
|
||||
|
||||
// add precommits from the rest of the validators.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// timeout to new round.
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -1001,7 +1001,7 @@ func TestStateLock_PrevoteNilWhenLockedAndDifferentProposal(t *testing.T) {
|
||||
validatePrevote(ctx, t, cs1, round, vss[0], nil)
|
||||
|
||||
// Add prevotes from the remainder of the validators for nil.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// We should now be locked on the same block but prevote nil.
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
@@ -1060,7 +1060,7 @@ func TestStateLock_POLDoesNotUnlock(t *testing.T) {
|
||||
|
||||
ensurePrevoteMatch(t, voteCh, height, round, blockID.Hash)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
// the validator should have locked a block in this round.
|
||||
ensureLock(t, lockCh, height, round)
|
||||
@@ -1075,8 +1075,8 @@ func TestStateLock_POLDoesNotUnlock(t *testing.T) {
|
||||
// This ensures that the validator being tested does not commit the block.
|
||||
// We do not want the validator to commit the block because we want the test
|
||||
// test to proceeds to the next consensus round.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs3)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs3)
|
||||
|
||||
// timeout to new round
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -1105,14 +1105,14 @@ func TestStateLock_POLDoesNotUnlock(t *testing.T) {
|
||||
ensurePrevoteMatch(t, voteCh, height, round, nil)
|
||||
|
||||
// add >2/3 prevotes for nil from all other validators
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
|
||||
// verify that we haven't update our locked block since the first round
|
||||
validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, blockID.Hash)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
|
||||
/*
|
||||
@@ -1138,7 +1138,7 @@ func TestStateLock_POLDoesNotUnlock(t *testing.T) {
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
validatePrevote(ctx, t, cs1, round, vss[0], nil)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
|
||||
@@ -1189,14 +1189,14 @@ func TestStateLock_MissingProposalWhenPOLSeenDoesNotUpdateLock(t *testing.T) {
|
||||
|
||||
ensurePrevote(t, voteCh, height, round) // prevote
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), firstBlockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, firstBlockID, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round) // our precommit
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], firstBlockID.Hash, firstBlockID.Hash)
|
||||
|
||||
// add precommits from the rest
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// timeout to new round
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -1229,7 +1229,7 @@ func TestStateLock_MissingProposalWhenPOLSeenDoesNotUpdateLock(t *testing.T) {
|
||||
ensurePrevoteMatch(t, voteCh, height, round, nil)
|
||||
|
||||
// now lets add prevotes from everyone else for the new block
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), secondBlockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, secondBlockID, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
validatePrecommit(ctx, t, cs1, round, 0, vss[0], nil, firstBlockID.Hash)
|
||||
@@ -1275,13 +1275,13 @@ func TestStateLock_DoesNotLockOnOldProposal(t *testing.T) {
|
||||
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// The proposed block should not have been locked.
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
validatePrecommit(ctx, t, cs1, round, -1, vss[0], nil, nil)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
|
||||
@@ -1303,7 +1303,7 @@ func TestStateLock_DoesNotLockOnOldProposal(t *testing.T) {
|
||||
validatePrevote(ctx, t, cs1, round, vss[0], nil) // All validators prevote for the old block.
|
||||
|
||||
// All validators prevote for the old block.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), firstBlockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, firstBlockID, vs2, vs3, vs4)
|
||||
|
||||
// Make sure that cs1 did not lock on the block since it did not receive a proposal for it.
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
@@ -1348,12 +1348,12 @@ func TestStateLock_POLSafety1(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: partSet.Header()}
|
||||
// the others sign a polka but we don't see it
|
||||
prevotes := signVotes(ctx, t, tmproto.PrevoteType, config.ChainID(),
|
||||
prevotes := signVotes(ctx, t, tmproto.PrevoteType, factory.DefaultTestChainID,
|
||||
blockID,
|
||||
vs2, vs3, vs4)
|
||||
|
||||
// we do see them precommit nil
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// cs1 precommit nil
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
@@ -1390,13 +1390,13 @@ func TestStateLock_POLSafety1(t *testing.T) {
|
||||
ensurePrevoteMatch(t, voteCh, height, round, r2BlockID.Hash)
|
||||
|
||||
// now we see the others prevote for it, so we should lock on it
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), r2BlockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, r2BlockID, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
// we should have precommitted
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], r2BlockID.Hash, r2BlockID.Hash)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
|
||||
@@ -1459,7 +1459,7 @@ func TestStateLock_POLSafety2(t *testing.T) {
|
||||
propBlockID0 := types.BlockID{Hash: propBlockHash0, PartSetHeader: propBlockParts0.Header()}
|
||||
|
||||
// the others sign a polka but we don't see it
|
||||
prevotes := signVotes(ctx, t, tmproto.PrevoteType, config.ChainID(), propBlockID0, vs2, vs3, vs4)
|
||||
prevotes := signVotes(ctx, t, tmproto.PrevoteType, factory.DefaultTestChainID, propBlockID0, vs2, vs3, vs4)
|
||||
|
||||
// the block for round 1
|
||||
prop1, propBlock1 := decideProposal(ctx, t, cs1, vs2, vs2.Height, vs2.Round+1)
|
||||
@@ -1481,15 +1481,15 @@ func TestStateLock_POLSafety2(t *testing.T) {
|
||||
|
||||
ensurePrevoteMatch(t, voteCh, height, round, propBlockID1.Hash)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), propBlockID1, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, propBlockID1, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlockID1.Hash, propBlockID1.Hash)
|
||||
|
||||
// add precommits from the rest
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), propBlockID1, vs3)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, propBlockID1, vs3)
|
||||
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
|
||||
@@ -1500,7 +1500,7 @@ func TestStateLock_POLSafety2(t *testing.T) {
|
||||
// in round 2 we see the polkad block from round 0
|
||||
newProp := types.NewProposal(height, round, 0, propBlockID0, propBlock0.Header.Time)
|
||||
p := newProp.ToProto()
|
||||
err = vs3.SignProposal(ctx, config.ChainID(), p)
|
||||
err = vs3.SignProposal(ctx, factory.DefaultTestChainID, p)
|
||||
require.NoError(t, err)
|
||||
|
||||
newProp.Signature = p.Signature
|
||||
@@ -1568,7 +1568,7 @@ func TestState_PrevotePOLFromPreviousRound(t *testing.T) {
|
||||
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), r0BlockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, r0BlockID, vs2, vs3, vs4)
|
||||
|
||||
// check that the validator generates a Lock event.
|
||||
ensureLock(t, lockCh, height, round)
|
||||
@@ -1578,7 +1578,7 @@ func TestState_PrevotePOLFromPreviousRound(t *testing.T) {
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], r0BlockID.Hash, r0BlockID.Hash)
|
||||
|
||||
// add precommits from the rest of the validators.
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// timeout to new round.
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -1612,12 +1612,12 @@ func TestState_PrevotePOLFromPreviousRound(t *testing.T) {
|
||||
|
||||
ensureNewRound(t, newRoundCh, height, round)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), r1BlockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, r1BlockID, vs2, vs3, vs4)
|
||||
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
validatePrevote(ctx, t, cs1, round, vss[0], nil)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
|
||||
@@ -1656,7 +1656,7 @@ func TestState_PrevotePOLFromPreviousRound(t *testing.T) {
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
validatePrevote(ctx, t, cs1, round, vss[0], r1BlockID.Hash)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
// cs1 did not receive a POL within this round, so it should remain locked
|
||||
// on the block from round 0.
|
||||
@@ -1706,14 +1706,14 @@ func TestProposeValidBlock(t *testing.T) {
|
||||
ensurePrevoteMatch(t, voteCh, height, round, blockID.Hash)
|
||||
|
||||
// the others sign a polka
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
// we should have precommitted the proposed block in this round.
|
||||
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
|
||||
@@ -1728,7 +1728,7 @@ func TestProposeValidBlock(t *testing.T) {
|
||||
// We did not see a valid proposal within this round, so prevote nil.
|
||||
ensurePrevoteMatch(t, voteCh, height, round, nil)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
// we should have precommitted nil during this round because we received
|
||||
@@ -1738,7 +1738,7 @@ func TestProposeValidBlock(t *testing.T) {
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
round += 2 // increment by multiple rounds
|
||||
|
||||
@@ -1798,10 +1798,10 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) {
|
||||
ensurePrevoteMatch(t, voteCh, height, round, blockID.Hash)
|
||||
|
||||
// vs2 send prevote for propBlock
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2)
|
||||
|
||||
// vs3 send prevote nil
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs3)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, types.BlockID{}, vs3)
|
||||
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
|
||||
@@ -1816,7 +1816,7 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) {
|
||||
assert.True(t, rs.ValidRound == -1)
|
||||
|
||||
// vs2 send (delayed) prevote for propBlock
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs4)
|
||||
|
||||
ensureNewValidBlock(t, validBlockCh, height, round)
|
||||
|
||||
@@ -1870,7 +1870,7 @@ func TestSetValidBlockOnDelayedProposal(t *testing.T) {
|
||||
}
|
||||
|
||||
// vs2, vs3 and vs4 send prevote for propBlock
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
ensureNewValidBlock(t, validBlockCh, height, round)
|
||||
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -2010,10 +2010,10 @@ func TestFinalizeBlockCalled(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vss[1:]...)
|
||||
ensurePrevoteMatch(t, voteCh, height, round, rs.ProposalBlock.Hash())
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vss[1:]...)
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
|
||||
ensureNewRound(t, newRoundCh, nextHeight, nextRound)
|
||||
@@ -2089,7 +2089,7 @@ func TestExtendVoteCalledWhenEnabled(t *testing.T) {
|
||||
Hash: rs.ProposalBlock.Hash(),
|
||||
PartSetHeader: rs.ProposalBlockParts.Header(),
|
||||
}
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vss[1:]...)
|
||||
ensurePrevoteMatch(t, voteCh, height, round, blockID.Hash)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
@@ -2103,7 +2103,7 @@ func TestExtendVoteCalledWhenEnabled(t *testing.T) {
|
||||
m.AssertNotCalled(t, "ExtendVote", mock.Anything, mock.Anything)
|
||||
}
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vss[1:]...)
|
||||
ensureNewRound(t, newRoundCh, height+1, 0)
|
||||
m.AssertExpectations(t)
|
||||
|
||||
@@ -2166,7 +2166,7 @@ func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) {
|
||||
Hash: rs.ProposalBlock.Hash(),
|
||||
PartSetHeader: rs.ProposalBlockParts.Header(),
|
||||
}
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vss...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vss...)
|
||||
ensurePrevoteMatch(t, voteCh, height, round, blockID.Hash)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
@@ -2177,7 +2177,7 @@ func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) {
|
||||
})
|
||||
|
||||
m.On("Commit", mock.Anything).Return(&abci.ResponseCommit{}, nil).Maybe()
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vss[2:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vss[2:]...)
|
||||
ensureNewRound(t, newRoundCh, height+1, 0)
|
||||
m.AssertExpectations(t)
|
||||
|
||||
@@ -2254,11 +2254,11 @@ func TestPrepareProposalReceivesVoteExtensions(t *testing.T) {
|
||||
Hash: rs.ProposalBlock.Hash(),
|
||||
PartSetHeader: rs.ProposalBlockParts.Header(),
|
||||
}
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vss[1:]...)
|
||||
|
||||
// create a precommit for each validator with the associated vote extension.
|
||||
for i, vs := range vss[1:] {
|
||||
signAddPrecommitWithExtension(ctx, t, cs1, config.ChainID(), blockID, voteExtensions[i+1], vs)
|
||||
signAddPrecommitWithExtension(ctx, t, cs1, factory.DefaultTestChainID, blockID, voteExtensions[i+1], vs)
|
||||
}
|
||||
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
@@ -2275,7 +2275,7 @@ func TestPrepareProposalReceivesVoteExtensions(t *testing.T) {
|
||||
incrementRound(vss[1:]...)
|
||||
round = 3
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vss[1:]...)
|
||||
ensureNewRound(t, newRoundCh, height, round)
|
||||
ensureNewProposal(t, proposalCh, height, round)
|
||||
|
||||
@@ -2387,7 +2387,7 @@ func TestVoteExtensionEnableHeight(t *testing.T) {
|
||||
}
|
||||
|
||||
// sign all of the votes
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vss[1:]...)
|
||||
ensurePrevoteMatch(t, voteCh, height, round, rs.ProposalBlock.Hash())
|
||||
|
||||
var ext []byte
|
||||
@@ -2396,7 +2396,7 @@ func TestVoteExtensionEnableHeight(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, vs := range vss[1:] {
|
||||
vote, err := vs.signVote(ctx, tmproto.PrecommitType, config.ChainID(), blockID, ext)
|
||||
vote, err := vs.signVote(ctx, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, ext)
|
||||
if !testCase.hasExtension {
|
||||
vote.ExtensionSignature = nil
|
||||
}
|
||||
@@ -2435,7 +2435,7 @@ func TestWaitingTimeoutOnNilPolka(t *testing.T) {
|
||||
startTestRound(ctx, cs1, height, round)
|
||||
ensureNewRound(t, newRoundCh, height, round)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
ensureNewTimeout(t, timeoutWaitCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
ensureNewRound(t, newRoundCh, height, round+1)
|
||||
@@ -2467,7 +2467,7 @@ func TestWaitingTimeoutProposeOnNewRound(t *testing.T) {
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
incrementRound(vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
round++ // moving to the next round
|
||||
ensureNewRound(t, newRoundCh, height, round)
|
||||
@@ -2506,7 +2506,7 @@ func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) {
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
incrementRound(vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
round++ // moving to the next round
|
||||
ensureNewRound(t, newRoundCh, height, round)
|
||||
@@ -2544,7 +2544,7 @@ func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) {
|
||||
ensureNewRound(t, newRoundCh, height, round)
|
||||
|
||||
incrementRound(vss[1:]...)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), types.BlockID{}, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, types.BlockID{}, vs2, vs3, vs4)
|
||||
|
||||
ensureNewTimeout(t, timeoutProposeCh, height, round, cs1.proposeTimeout(round).Nanoseconds())
|
||||
|
||||
@@ -2582,7 +2582,7 @@ func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) {
|
||||
ensureNewRound(t, newRoundCh, height, round)
|
||||
|
||||
// vs2, vs3 and vs4 send precommit for propBlock
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
ensureNewValidBlock(t, validBlockCh, height, round)
|
||||
|
||||
rs := cs1.GetRoundState()
|
||||
@@ -2623,7 +2623,7 @@ func TestCommitFromPreviousRound(t *testing.T) {
|
||||
ensureNewRound(t, newRoundCh, height, round)
|
||||
|
||||
// vs2, vs3 and vs4 send precommit for propBlock for the previous round
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
ensureNewValidBlock(t, validBlockCh, height, round)
|
||||
|
||||
@@ -2692,15 +2692,15 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) {
|
||||
|
||||
ensurePrevoteMatch(t, voteCh, height, round, blockID.Hash)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash)
|
||||
|
||||
// add precommits
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs3)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs3)
|
||||
|
||||
// wait till timeout occurs
|
||||
ensureNewTimeout(t, precommitTimeoutCh, height, round, cs1.voteTimeout(round).Nanoseconds())
|
||||
@@ -2708,7 +2708,7 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) {
|
||||
ensureNewRound(t, newRoundCh, height, round+1)
|
||||
|
||||
// majority is now reached
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs4)
|
||||
|
||||
ensureNewBlockHeader(t, newBlockHeader, height, blockID.Hash)
|
||||
|
||||
@@ -2757,15 +2757,15 @@ func TestResetTimeoutPrecommitUponNewHeight(t *testing.T) {
|
||||
|
||||
ensurePrevoteMatch(t, voteCh, height, round, blockID.Hash)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], blockID.Hash, blockID.Hash)
|
||||
|
||||
// add precommits
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs3)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs3)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs4)
|
||||
|
||||
ensureNewBlockHeader(t, newBlockHeader, height, blockID.Hash)
|
||||
|
||||
@@ -2827,17 +2827,17 @@ func TestStateHalt1(t *testing.T) {
|
||||
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(t, voteCh, height, round)
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(ctx, t, cs1, round, round, vss[0], propBlock.Hash(), propBlock.Hash())
|
||||
|
||||
// add precommits from the rest
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), types.BlockID{}, vs2) // didnt receive proposal
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, config.ChainID(), blockID, vs3)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, types.BlockID{}, vs2) // didnt receive proposal
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrecommitType, factory.DefaultTestChainID, blockID, vs3)
|
||||
// we receive this later, but vs3 might receive it earlier and with ours will go to commit!
|
||||
precommit4 := signVote(ctx, t, vs4, tmproto.PrecommitType, config.ChainID(), blockID)
|
||||
precommit4 := signVote(ctx, t, vs4, tmproto.PrecommitType, factory.DefaultTestChainID, blockID)
|
||||
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
|
||||
@@ -2928,7 +2928,7 @@ func TestStateOutputVoteStats(t *testing.T) {
|
||||
Hash: randBytes,
|
||||
}
|
||||
|
||||
vote := signVote(ctx, t, vss[1], tmproto.PrecommitType, config.ChainID(), blockID)
|
||||
vote := signVote(ctx, t, vss[1], tmproto.PrecommitType, factory.DefaultTestChainID, blockID)
|
||||
|
||||
voteMessage := &VoteMessage{vote}
|
||||
cs.handleMsg(ctx, msgInfo{voteMessage, peerID, tmtime.Now()})
|
||||
@@ -2942,7 +2942,7 @@ func TestStateOutputVoteStats(t *testing.T) {
|
||||
|
||||
// sending the vote for the bigger height
|
||||
incrementHeight(vss[1])
|
||||
vote = signVote(ctx, t, vss[1], tmproto.PrecommitType, config.ChainID(), blockID)
|
||||
vote = signVote(ctx, t, vss[1], tmproto.PrecommitType, factory.DefaultTestChainID, blockID)
|
||||
|
||||
cs.handleMsg(ctx, msgInfo{&VoteMessage{vote}, peerID, tmtime.Now()})
|
||||
|
||||
@@ -2968,7 +2968,7 @@ func TestSignSameVoteTwice(t *testing.T) {
|
||||
t,
|
||||
vss[1],
|
||||
tmproto.PrecommitType,
|
||||
config.ChainID(),
|
||||
factory.DefaultTestChainID,
|
||||
|
||||
types.BlockID{
|
||||
Hash: randBytes,
|
||||
@@ -2980,7 +2980,7 @@ func TestSignSameVoteTwice(t *testing.T) {
|
||||
t,
|
||||
vss[1],
|
||||
tmproto.PrecommitType,
|
||||
config.ChainID(),
|
||||
factory.DefaultTestChainID,
|
||||
|
||||
types.BlockID{
|
||||
Hash: randBytes,
|
||||
@@ -3021,7 +3021,7 @@ func TestStateTimestamp_ProposalNotMatch(t *testing.T) {
|
||||
// Create a proposal with a timestamp that does not match the timestamp of the block.
|
||||
proposal := types.NewProposal(vs2.Height, round, -1, blockID, propBlock.Header.Time.Add(time.Millisecond))
|
||||
p := proposal.ToProto()
|
||||
err = vs2.SignProposal(ctx, config.ChainID(), p)
|
||||
err = vs2.SignProposal(ctx, factory.DefaultTestChainID, p)
|
||||
require.NoError(t, err)
|
||||
proposal.Signature = p.Signature
|
||||
require.NoError(t, cs1.SetProposalAndBlock(ctx, proposal, propBlock, propBlockParts, "some peer"))
|
||||
@@ -3029,7 +3029,7 @@ func TestStateTimestamp_ProposalNotMatch(t *testing.T) {
|
||||
startTestRound(ctx, cs1, height, round)
|
||||
ensureProposal(t, proposalCh, height, round, blockID)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
// ensure that the validator prevotes nil.
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
@@ -3069,7 +3069,7 @@ func TestStateTimestamp_ProposalMatch(t *testing.T) {
|
||||
// Create a proposal with a timestamp that matches the timestamp of the block.
|
||||
proposal := types.NewProposal(vs2.Height, round, -1, blockID, propBlock.Header.Time)
|
||||
p := proposal.ToProto()
|
||||
err = vs2.SignProposal(ctx, config.ChainID(), p)
|
||||
err = vs2.SignProposal(ctx, factory.DefaultTestChainID, p)
|
||||
require.NoError(t, err)
|
||||
proposal.Signature = p.Signature
|
||||
require.NoError(t, cs1.SetProposalAndBlock(ctx, proposal, propBlock, propBlockParts, "some peer"))
|
||||
@@ -3077,7 +3077,7 @@ func TestStateTimestamp_ProposalMatch(t *testing.T) {
|
||||
startTestRound(ctx, cs1, height, round)
|
||||
ensureProposal(t, proposalCh, height, round, blockID)
|
||||
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, config.ChainID(), blockID, vs2, vs3, vs4)
|
||||
signAddVotes(ctx, t, cs1, tmproto.PrevoteType, factory.DefaultTestChainID, blockID, vs2, vs3, vs4)
|
||||
|
||||
// ensure that the validator prevotes the block.
|
||||
ensurePrevote(t, voteCh, height, round)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/internal/test/factory"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
@@ -16,17 +15,12 @@ import (
|
||||
)
|
||||
|
||||
func TestPeerCatchupRounds(t *testing.T) {
|
||||
cfg, err := config.ResetTestRoot(t.TempDir(), "consensus_height_vote_set_test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
valSet, privVals := factory.ValidatorSet(ctx, t, 10, 1)
|
||||
|
||||
chainID := cfg.ChainID()
|
||||
chainID := factory.DefaultTestChainID
|
||||
hvs := NewExtendedHeightVoteSet(chainID, 1, valSet)
|
||||
|
||||
vote999_0 := makeVoteHR(ctx, t, 1, 0, 999, privVals, chainID)
|
||||
|
||||
@@ -114,7 +114,7 @@ func TestDispatcherTimeOutWaitingOnLightBlock(t *testing.T) {
|
||||
func TestDispatcherProviders(t *testing.T) {
|
||||
t.Cleanup(leaktest.Check(t))
|
||||
|
||||
chainID := "test-chain"
|
||||
chainID := factory.DefaultTestChainID
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultTestChainID = "test-chain"
|
||||
DefaultTestChainID = "test_chain"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -3,12 +3,11 @@ package factory
|
||||
import (
|
||||
"time"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func GenesisDoc(
|
||||
config *cfg.Config,
|
||||
chainID string,
|
||||
time time.Time,
|
||||
validators []*types.Validator,
|
||||
consensusParams *types.ConsensusParams,
|
||||
@@ -26,7 +25,7 @@ func GenesisDoc(
|
||||
return &types.GenesisDoc{
|
||||
GenesisTime: time,
|
||||
InitialHeight: 1,
|
||||
ChainID: config.ChainID(),
|
||||
ChainID: chainID,
|
||||
Validators: genesisValidators,
|
||||
ConsensusParams: consensusParams,
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// RunWithArgs executes the given command with the specified command line args
|
||||
// and environmental variables set. It returns any error returned from cmd.Execute()
|
||||
//
|
||||
// This is only used in testing.
|
||||
func RunWithArgs(ctx context.Context, cmd *cobra.Command, args []string, env map[string]string) error {
|
||||
oargs := os.Args
|
||||
oenv := map[string]string{}
|
||||
// defer returns the environment back to normal
|
||||
defer func() {
|
||||
os.Args = oargs
|
||||
for k, v := range oenv {
|
||||
os.Setenv(k, v)
|
||||
}
|
||||
}()
|
||||
|
||||
// set the args and env how we want them
|
||||
os.Args = args
|
||||
for k, v := range env {
|
||||
// backup old value if there, to restore at end
|
||||
oenv[k] = os.Getenv(k)
|
||||
err := os.Setenv(k, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// and finally run the command
|
||||
return RunWithTrace(ctx, cmd)
|
||||
}
|
||||
|
||||
func RunWithTrace(ctx context.Context, cmd *cobra.Command) error {
|
||||
cmd.SilenceUsage = true
|
||||
cmd.SilenceErrors = true
|
||||
|
||||
if err := cmd.ExecuteContext(ctx); err != nil {
|
||||
if viper.GetBool(TraceFlag) {
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n%s\n", err, buf)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const (
|
||||
HomeFlag = "home"
|
||||
TraceFlag = "trace"
|
||||
OutputFlag = "output" // used in the cli
|
||||
)
|
||||
|
||||
// PrepareBaseCmd is meant for tendermint and other servers
|
||||
func PrepareBaseCmd(cmd *cobra.Command, envPrefix, defaultHome string) *cobra.Command {
|
||||
// the primary caller of this command is in the SDK and
|
||||
// returning the cobra.Command object avoids breaking that
|
||||
// code. In the long term, the SDK could avoid this entirely.
|
||||
cobra.OnInitialize(func() { InitEnv(envPrefix) })
|
||||
cmd.PersistentFlags().StringP(HomeFlag, "", defaultHome, "directory for config and data")
|
||||
cmd.PersistentFlags().Bool(TraceFlag, false, "print out full stack trace on errors")
|
||||
cmd.PersistentPreRunE = concatCobraCmdFuncs(BindFlagsLoadViper, cmd.PersistentPreRunE)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// InitEnv sets to use ENV variables if set.
|
||||
func InitEnv(prefix string) {
|
||||
// This copies all variables like TMROOT to TM_ROOT,
|
||||
// so we can support both formats for the user
|
||||
prefix = strings.ToUpper(prefix)
|
||||
ps := prefix + "_"
|
||||
for _, e := range os.Environ() {
|
||||
kv := strings.SplitN(e, "=", 2)
|
||||
if len(kv) == 2 {
|
||||
k, v := kv[0], kv[1]
|
||||
if strings.HasPrefix(k, prefix) && !strings.HasPrefix(k, ps) {
|
||||
k2 := strings.Replace(k, prefix, ps, 1)
|
||||
os.Setenv(k2, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// env variables with TM prefix (eg. TM_ROOT)
|
||||
viper.SetEnvPrefix(prefix)
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
|
||||
viper.AutomaticEnv()
|
||||
}
|
||||
|
||||
type cobraCmdFunc func(cmd *cobra.Command, args []string) error
|
||||
|
||||
// Returns a single function that calls each argument function in sequence
|
||||
// RunE, PreRunE, PersistentPreRunE, etc. all have this same signature
|
||||
func concatCobraCmdFuncs(fs ...cobraCmdFunc) cobraCmdFunc {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
for _, f := range fs {
|
||||
if f != nil {
|
||||
if err := f(cmd, args); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Bind all flags and read the config into viper
|
||||
func BindFlagsLoadViper(cmd *cobra.Command, args []string) error {
|
||||
// cmd.Flags() includes flags from this command and all persistent flags from the parent
|
||||
if err := viper.BindPFlags(cmd.Flags()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
homeDir := viper.GetString(HomeFlag)
|
||||
viper.Set(HomeFlag, homeDir)
|
||||
viper.SetConfigName("config") // name of config file (without extension)
|
||||
viper.AddConfigPath(homeDir) // search root directory
|
||||
viper.AddConfigPath(filepath.Join(homeDir, "config")) // search root directory /config
|
||||
|
||||
// If a config file is found, read it in.
|
||||
if err := viper.ReadInConfig(); err == nil {
|
||||
// stderr, so if we redirect output to json file, this doesn't appear
|
||||
// fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
||||
} else if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
||||
// ignore not found error, return other errors
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,293 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSetupEnv(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
cases := []struct {
|
||||
args []string
|
||||
env map[string]string
|
||||
expected string
|
||||
}{
|
||||
{nil, nil, ""},
|
||||
{[]string{"--foobar", "bang!"}, nil, "bang!"},
|
||||
// make sure reset is good
|
||||
{nil, nil, ""},
|
||||
// test both variants of the prefix
|
||||
{nil, map[string]string{"DEMO_FOOBAR": "good"}, "good"},
|
||||
{nil, map[string]string{"DEMOFOOBAR": "silly"}, "silly"},
|
||||
// and that cli overrides env...
|
||||
{[]string{"--foobar", "important"},
|
||||
map[string]string{"DEMO_FOOBAR": "ignored"}, "important"},
|
||||
}
|
||||
|
||||
for idx, tc := range cases {
|
||||
i := strconv.Itoa(idx)
|
||||
// test command that store value of foobar in local variable
|
||||
var foo string
|
||||
demo := &cobra.Command{
|
||||
Use: "demo",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
foo = viper.GetString("foobar")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
demo.Flags().String("foobar", "", "Some test value from config")
|
||||
cmd := PrepareBaseCmd(demo, "DEMO", "/qwerty/asdfgh") // some missing dir..
|
||||
|
||||
viper.Reset()
|
||||
args := append([]string{cmd.Use}, tc.args...)
|
||||
err := RunWithArgs(ctx, cmd, args, tc.env)
|
||||
require.NoError(t, err, i)
|
||||
assert.Equal(t, tc.expected, foo, i)
|
||||
}
|
||||
}
|
||||
|
||||
// writeConfigVals writes a toml file with the given values.
|
||||
// It returns an error if writing was impossible.
|
||||
func writeConfigVals(dir string, vals map[string]string) error {
|
||||
lines := make([]string, 0, len(vals))
|
||||
for k, v := range vals {
|
||||
lines = append(lines, fmt.Sprintf("%s = %q", k, v))
|
||||
}
|
||||
data := strings.Join(lines, "\n")
|
||||
cfile := filepath.Join(dir, "config.toml")
|
||||
return os.WriteFile(cfile, []byte(data), 0600)
|
||||
}
|
||||
|
||||
func TestSetupConfig(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// we pre-create two config files we can refer to in the rest of
|
||||
// the test cases.
|
||||
cval1 := "fubble"
|
||||
conf1 := t.TempDir()
|
||||
err := writeConfigVals(conf1, map[string]string{"boo": cval1})
|
||||
require.NoError(t, err)
|
||||
|
||||
cases := []struct {
|
||||
args []string
|
||||
env map[string]string
|
||||
expected string
|
||||
expectedTwo string
|
||||
}{
|
||||
{nil, nil, "", ""},
|
||||
// setting on the command line
|
||||
{[]string{"--boo", "haha"}, nil, "haha", ""},
|
||||
{[]string{"--two-words", "rocks"}, nil, "", "rocks"},
|
||||
{[]string{"--home", conf1}, nil, cval1, ""},
|
||||
// test both variants of the prefix
|
||||
{nil, map[string]string{"RD_BOO": "bang"}, "bang", ""},
|
||||
{nil, map[string]string{"RD_TWO_WORDS": "fly"}, "", "fly"},
|
||||
{nil, map[string]string{"RDTWO_WORDS": "fly"}, "", "fly"},
|
||||
{nil, map[string]string{"RD_HOME": conf1}, cval1, ""},
|
||||
{nil, map[string]string{"RDHOME": conf1}, cval1, ""},
|
||||
}
|
||||
|
||||
for idx, tc := range cases {
|
||||
i := strconv.Itoa(idx)
|
||||
// test command that store value of foobar in local variable
|
||||
var foo, two string
|
||||
boo := &cobra.Command{
|
||||
Use: "reader",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
foo = viper.GetString("boo")
|
||||
two = viper.GetString("two-words")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
boo.Flags().String("boo", "", "Some test value from config")
|
||||
boo.Flags().String("two-words", "", "Check out env handling -")
|
||||
cmd := PrepareBaseCmd(boo, "RD", "/qwerty/asdfgh") // some missing dir...
|
||||
|
||||
viper.Reset()
|
||||
args := append([]string{cmd.Use}, tc.args...)
|
||||
err := RunWithArgs(ctx, cmd, args, tc.env)
|
||||
require.NoError(t, err, i)
|
||||
assert.Equal(t, tc.expected, foo, i)
|
||||
assert.Equal(t, tc.expectedTwo, two, i)
|
||||
}
|
||||
}
|
||||
|
||||
type DemoConfig struct {
|
||||
Name string `mapstructure:"name"`
|
||||
Age int `mapstructure:"age"`
|
||||
Unused int `mapstructure:"unused"`
|
||||
}
|
||||
|
||||
func TestSetupUnmarshal(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// we pre-create two config files we can refer to in the rest of
|
||||
// the test cases.
|
||||
cval1, cval2 := "someone", "else"
|
||||
conf1 := t.TempDir()
|
||||
err := writeConfigVals(conf1, map[string]string{"name": cval1})
|
||||
require.NoError(t, err)
|
||||
// even with some ignored fields, should be no problem
|
||||
conf2 := t.TempDir()
|
||||
err = writeConfigVals(conf2, map[string]string{"name": cval2, "foo": "bar"})
|
||||
require.NoError(t, err)
|
||||
|
||||
// unused is not declared on a flag and remains from base
|
||||
base := DemoConfig{
|
||||
Name: "default",
|
||||
Age: 42,
|
||||
Unused: -7,
|
||||
}
|
||||
c := func(name string, age int) DemoConfig {
|
||||
r := base
|
||||
// anything set on the flags as a default is used over
|
||||
// the default config object
|
||||
r.Name = "from-flag"
|
||||
if name != "" {
|
||||
r.Name = name
|
||||
}
|
||||
if age != 0 {
|
||||
r.Age = age
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
args []string
|
||||
env map[string]string
|
||||
expected DemoConfig
|
||||
}{
|
||||
{nil, nil, c("", 0)},
|
||||
// setting on the command line
|
||||
{[]string{"--name", "haha"}, nil, c("haha", 0)},
|
||||
{[]string{"--home", conf1}, nil, c(cval1, 0)},
|
||||
// test both variants of the prefix
|
||||
{nil, map[string]string{"MR_AGE": "56"}, c("", 56)},
|
||||
{nil, map[string]string{"MR_HOME": conf1}, c(cval1, 0)},
|
||||
{[]string{"--age", "17"}, map[string]string{"MRHOME": conf2}, c(cval2, 17)},
|
||||
}
|
||||
|
||||
for idx, tc := range cases {
|
||||
i := strconv.Itoa(idx)
|
||||
// test command that store value of foobar in local variable
|
||||
cfg := base
|
||||
marsh := &cobra.Command{
|
||||
Use: "marsh",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return viper.Unmarshal(&cfg)
|
||||
},
|
||||
}
|
||||
marsh.Flags().String("name", "from-flag", "Some test value from config")
|
||||
// if we want a flag to use the proper default, then copy it
|
||||
// from the default config here
|
||||
marsh.Flags().Int("age", base.Age, "Some test value from config")
|
||||
cmd := PrepareBaseCmd(marsh, "MR", "/qwerty/asdfgh") // some missing dir...
|
||||
|
||||
viper.Reset()
|
||||
args := append([]string{cmd.Use}, tc.args...)
|
||||
err := RunWithArgs(ctx, cmd, args, tc.env)
|
||||
require.NoError(t, err, i)
|
||||
assert.Equal(t, tc.expected, cfg, i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupTrace(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
cases := []struct {
|
||||
args []string
|
||||
env map[string]string
|
||||
long bool
|
||||
expected string
|
||||
}{
|
||||
{nil, nil, false, "trace flag = false"},
|
||||
{[]string{"--trace"}, nil, true, "trace flag = true"},
|
||||
{[]string{"--no-such-flag"}, nil, false, "unknown flag: --no-such-flag"},
|
||||
{nil, map[string]string{"DBG_TRACE": "true"}, true, "trace flag = true"},
|
||||
}
|
||||
|
||||
for idx, tc := range cases {
|
||||
i := strconv.Itoa(idx)
|
||||
// test command that store value of foobar in local variable
|
||||
trace := &cobra.Command{
|
||||
Use: "trace",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("trace flag = %t", viper.GetBool(TraceFlag))
|
||||
},
|
||||
}
|
||||
cmd := PrepareBaseCmd(trace, "DBG", "/qwerty/asdfgh") // some missing dir..
|
||||
|
||||
viper.Reset()
|
||||
args := append([]string{cmd.Use}, tc.args...)
|
||||
stdout, stderr, err := runCaptureWithArgs(ctx, cmd, args, tc.env)
|
||||
require.Error(t, err, i)
|
||||
require.Equal(t, "", stdout, i)
|
||||
require.NotEqual(t, "", stderr, i)
|
||||
msg := strings.Split(stderr, "\n")
|
||||
desired := fmt.Sprintf("ERROR: %s", tc.expected)
|
||||
assert.Equal(t, desired, msg[0], i, msg)
|
||||
if tc.long && assert.True(t, len(msg) > 2, i) {
|
||||
// the next line starts the stack trace...
|
||||
assert.Contains(t, stderr, "TestSetupTrace", i)
|
||||
assert.Contains(t, stderr, "setup_test.go", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// runCaptureWithArgs executes the given command with the specified command
|
||||
// line args and environmental variables set. It returns string fields
|
||||
// representing output written to stdout and stderr, additionally any error
|
||||
// from cmd.Execute() is also returned
|
||||
func runCaptureWithArgs(ctx context.Context, cmd *cobra.Command, args []string, env map[string]string) (stdout, stderr string, err error) {
|
||||
oldout, olderr := os.Stdout, os.Stderr // keep backup of the real stdout
|
||||
rOut, wOut, _ := os.Pipe()
|
||||
rErr, wErr, _ := os.Pipe()
|
||||
os.Stdout, os.Stderr = wOut, wErr
|
||||
defer func() {
|
||||
os.Stdout, os.Stderr = oldout, olderr // restoring the real stdout
|
||||
}()
|
||||
|
||||
// copy the output in a separate goroutine so printing can't block indefinitely
|
||||
copyStd := func(reader *os.File) *(chan string) {
|
||||
stdC := make(chan string)
|
||||
go func() {
|
||||
var buf bytes.Buffer
|
||||
// io.Copy will end when we call reader.Close() below
|
||||
io.Copy(&buf, reader) //nolint:errcheck //ignore error
|
||||
select {
|
||||
case <-cmd.Context().Done():
|
||||
case stdC <- buf.String():
|
||||
}
|
||||
}()
|
||||
return &stdC
|
||||
}
|
||||
outC := copyStd(rOut)
|
||||
errC := copyStd(rErr)
|
||||
|
||||
// now run the command
|
||||
err = RunWithArgs(ctx, cmd, args, env)
|
||||
|
||||
// and grab the stdout to return
|
||||
wOut.Close()
|
||||
wErr.Close()
|
||||
stdout = <-*outC
|
||||
stderr = <-*errC
|
||||
return stdout, stderr, err
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
"github.com/tendermint/tendermint/internal/test/factory"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/light"
|
||||
httpp "github.com/tendermint/tendermint/light/provider/http"
|
||||
@@ -39,7 +40,7 @@ func TestExampleClient(t *testing.T) {
|
||||
defer func() { _ = closer(ctx) }()
|
||||
|
||||
dbDir := t.TempDir()
|
||||
chainID := conf.ChainID()
|
||||
chainID := factory.DefaultTestChainID
|
||||
|
||||
primary, err := httpp.New(chainID, conf.RPC.ListenAddress)
|
||||
if err != nil {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
"github.com/tendermint/tendermint/internal/test/factory"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/light"
|
||||
"github.com/tendermint/tendermint/light/provider"
|
||||
@@ -42,7 +43,7 @@ func TestClientIntegration_Update(t *testing.T) {
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
dbDir := t.TempDir()
|
||||
chainID := conf.ChainID()
|
||||
chainID := factory.DefaultTestChainID
|
||||
|
||||
primary, err := httpp.New(chainID, conf.RPC.ListenAddress)
|
||||
require.NoError(t, err)
|
||||
@@ -100,7 +101,7 @@ func TestClientIntegration_VerifyLightBlockAtHeight(t *testing.T) {
|
||||
defer func() { require.NoError(t, closer(ctx)) }()
|
||||
|
||||
dbDir := t.TempDir()
|
||||
chainID := conf.ChainID()
|
||||
chainID := factory.DefaultTestChainID
|
||||
|
||||
primary, err := httpp.New(chainID, conf.RPC.ListenAddress)
|
||||
require.NoError(t, err)
|
||||
@@ -175,7 +176,7 @@ func TestClientStatusRPC(t *testing.T) {
|
||||
defer func() { require.NoError(t, closer(ctx)) }()
|
||||
|
||||
dbDir := t.TempDir()
|
||||
chainID := conf.ChainID()
|
||||
chainID := factory.DefaultTestChainID
|
||||
|
||||
primary, err := httpp.New(chainID, conf.RPC.ListenAddress)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -174,7 +174,7 @@ func TestNodeSetPrivValTCP(t *testing.T) {
|
||||
|
||||
signerServer := privval.NewSignerServer(
|
||||
dialerEndpoint,
|
||||
cfg.ChainID(),
|
||||
factory.DefaultTestChainID,
|
||||
types.NewMockPV(),
|
||||
)
|
||||
|
||||
@@ -238,7 +238,7 @@ func TestNodeSetPrivValIPC(t *testing.T) {
|
||||
|
||||
pvsc := privval.NewSignerServer(
|
||||
dialerEndpoint,
|
||||
cfg.ChainID(),
|
||||
factory.DefaultTestChainID,
|
||||
types.NewMockPV(),
|
||||
)
|
||||
|
||||
@@ -760,15 +760,13 @@ func loadStatefromGenesis(ctx context.Context, t *testing.T) sm.State {
|
||||
|
||||
stateDB := dbm.NewMemDB()
|
||||
stateStore := sm.NewStore(stateDB)
|
||||
cfg, err := config.ResetTestRoot(t.TempDir(), "load_state_from_genesis")
|
||||
require.NoError(t, err)
|
||||
|
||||
loadedState, err := stateStore.Load()
|
||||
require.NoError(t, err)
|
||||
require.True(t, loadedState.IsEmpty())
|
||||
|
||||
valSet, _ := factory.ValidatorSet(ctx, t, 0, 10)
|
||||
genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
genDoc := factory.GenesisDoc(factory.DefaultTestChainID, time.Now(), valSet.Validators, factory.ConsensusParams())
|
||||
|
||||
state, err := loadStateFromDBOrGenesisDocProvider(
|
||||
stateStore,
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/encoding"
|
||||
"github.com/tendermint/tendermint/internal/mempool"
|
||||
rpccore "github.com/tendermint/tendermint/internal/rpc/core"
|
||||
"github.com/tendermint/tendermint/internal/test/factory"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
@@ -518,14 +519,12 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
chainID := conf.ChainID()
|
||||
|
||||
// make sure that the node has produced enough blocks
|
||||
waitForBlock(ctx, t, c, 2)
|
||||
evidenceHeight := int64(1)
|
||||
block, _ := c.Block(ctx, &evidenceHeight)
|
||||
ts := block.Block.Time
|
||||
correct, fakes := makeEvidences(t, pv, chainID, ts)
|
||||
correct, fakes := makeEvidences(t, pv, factory.DefaultTestChainID, ts)
|
||||
|
||||
result, err := c.BroadcastEvidence(ctx, correct)
|
||||
require.NoError(t, err, "BroadcastEvidence(%s) failed", correct)
|
||||
|
||||
@@ -7,11 +7,9 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
abciclient "github.com/tendermint/tendermint/abci/client"
|
||||
@@ -293,23 +291,9 @@ func setupNode() (*config.Config, log.Logger, error) {
|
||||
return nil, nil, errors.New("TMHOME not set")
|
||||
}
|
||||
|
||||
viper.AddConfigPath(filepath.Join(home, "config"))
|
||||
viper.SetConfigName("config")
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
tmcfg = config.DefaultConfig()
|
||||
|
||||
if err := viper.Unmarshal(tmcfg); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
tmcfg.SetRoot(home)
|
||||
|
||||
if err := tmcfg.ValidateBasic(); err != nil {
|
||||
return nil, nil, fmt.Errorf("error in config file: %w", err)
|
||||
tmcfg, err := config.Load(home)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("loading node config: %w", err)
|
||||
}
|
||||
|
||||
nodeLogger, err := log.NewDefaultLogger(tmcfg.LogFormat, tmcfg.LogLevel)
|
||||
|
||||
Reference in New Issue
Block a user