Skip to content

Commit

Permalink
fix tests...
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Sep 4, 2021
1 parent 0072778 commit a61cedd
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 25 deletions.
14 changes: 7 additions & 7 deletions pkgs/bft/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func DefaultConfig() *Config {

// LoadOrMakeDefaultConfig() loads configuration or saves a default one.
func LoadOrMakeDefaultConfig(root string) (cfg *Config) {
configPath := rootify(defaultConfigFilePath, root)
configPath := join(root, defaultConfigFilePath)
if osm.FileExists(configPath) {
cfg = LoadConfigFile(configPath)
cfg.SetRootDir(root)
Expand Down Expand Up @@ -238,7 +238,7 @@ func DefaultBaseConfig() BaseConfig {
func TestBaseConfig() BaseConfig {
cfg := DefaultBaseConfig()
cfg.chainID = "tendermint_test"
cfg.ProxyApp = "kvstore"
cfg.ProxyApp = "mock://kvstore"
cfg.FastSyncMode = false
cfg.DBBackend = "memdb"
return cfg
Expand All @@ -250,27 +250,27 @@ func (cfg BaseConfig) ChainID() string {

// GenesisFile returns the full path to the genesis.json file
func (cfg BaseConfig) GenesisFile() string {
return rootify(cfg.Genesis, cfg.RootDir)
return join(cfg.RootDir, cfg.Genesis)
}

// PrivValidatorKeyFile returns the full path to the priv_validator_key.json file
func (cfg BaseConfig) PrivValidatorKeyFile() string {
return rootify(cfg.PrivValidatorKey, cfg.RootDir)
return join(cfg.RootDir, cfg.PrivValidatorKey)
}

// PrivValidatorFile returns the full path to the priv_validator_state.json file
func (cfg BaseConfig) PrivValidatorStateFile() string {
return rootify(cfg.PrivValidatorState, cfg.RootDir)
return join(cfg.RootDir, cfg.PrivValidatorState)
}

// NodeKeyFile returns the full path to the node_key.json file
func (cfg BaseConfig) NodeKeyFile() string {
return rootify(cfg.NodeKey, cfg.RootDir)
return join(cfg.RootDir, cfg.NodeKey)
}

// DBDir returns the full path to the database directory
func (cfg BaseConfig) DBDir() string {
return rootify(cfg.DBPath, cfg.RootDir)
return join(cfg.RootDir, cfg.DBPath)
}

// ValidateBasic performs basic validation (checking param bounds, etc.) and
Expand Down
13 changes: 8 additions & 5 deletions pkgs/bft/config/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package config
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

Expand All @@ -13,7 +12,7 @@ import (

func ensureFiles(t *testing.T, rootDir string, files ...string) {
for _, f := range files {
p := rootify(rootDir, f)
p := join(f, rootDir)
_, err := os.Stat(p)
assert.Nil(t, err, p)
}
Expand All @@ -28,10 +27,14 @@ func TestEnsureRoot(t *testing.T) {
defer os.RemoveAll(tmpDir) // nolint: errcheck

// create root dir
EnsureRoot(tmpDir)
throwaway := DefaultConfig()
throwaway.SetRootDir(tmpDir)
throwaway.EnsureDirs()
configPath := join(tmpDir, defaultConfigFilePath)
WriteConfigFile(configPath, throwaway)

// make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath))
data, err := ioutil.ReadFile(join(tmpDir, defaultConfigFilePath))
require.Nil(err)

if !checkConfig(string(data)) {
Expand All @@ -52,7 +55,7 @@ func TestEnsureTestRoot(t *testing.T) {
rootDir := cfg.RootDir

// make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(rootDir, defaultConfigFilePath))
data, err := ioutil.ReadFile(join(rootDir, defaultConfigFilePath))
require.Nil(err)

if !checkConfig(string(data)) {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/bft/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import "path/filepath"

// helper function to make config creation independent of root dir
func rootify(path, root string) string {
func join(root, path string) string {
if filepath.IsAbs(path) {
return path
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/bft/consensus/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (cfg *ConsensusConfig) WalFile() string {
if cfg.walFile != "" {
return cfg.walFile
}
return rootify(cfg.WalPath, cfg.RootDir)
return join(cfg.RootDir, cfg.WalPath)
}

// SetWalFile sets the path to the write-ahead log file
Expand Down
4 changes: 2 additions & 2 deletions pkgs/bft/consensus/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package config

import "path/filepath"

// helper function to make config creation independent of root dir
func rootify(path, root string) string {
// join path to root unless path is already absolute.
func join(root, path string) string {
if filepath.IsAbs(path) {
return path
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/bft/mempool/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestMempoolConfig() *MempoolConfig {

// WalDir returns the full path to the mempool's write-ahead log
func (cfg *MempoolConfig) WalDir() string {
return rootify(cfg.WalPath, cfg.RootDir)
return join(cfg.RootDir, cfg.WalPath)
}

// WalEnabled returns true if the WAL is enabled.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/bft/mempool/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import "path/filepath"

// helper function to make config creation independent of root dir
func rootify(path, root string) string {
func join(root, path string) string {
if filepath.IsAbs(path) {
return path
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/bft/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestNodeNewNodeCustomReactors(t *testing.T) {
n, err := NewNode(config,
privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()),
nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
proxy.DefaultClientCreator(nil, config.ProxyApp, config.ABCI, config.DBDir()),
DefaultGenesisDocProviderFunc(config),
DefaultDBProvider,
log.TestingLogger(),
Expand Down
4 changes: 2 additions & 2 deletions pkgs/bft/rpc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ func (cfg RPCConfig) KeyFile() string {
if filepath.IsAbs(path) {
return path
}
return rootify(filepath.Join(defaultConfigDir, path), cfg.RootDir)
return join(cfg.RootDir, filepath.Join(defaultConfigDir, path))
}

func (cfg RPCConfig) CertFile() string {
path := cfg.TLSCertFile
if filepath.IsAbs(path) {
return path
}
return rootify(filepath.Join(defaultConfigDir, path), cfg.RootDir)
return join(cfg.RootDir, filepath.Join(defaultConfigDir, path))
}

func (cfg RPCConfig) IsTLSEnabled() bool {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/bft/rpc/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import "path/filepath"

// helper function to make config creation independent of root dir
func rootify(path, root string) string {
func join(root, path string) string {
if filepath.IsAbs(path) {
return path
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/bft/rpc/lib/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
)

// Stop upon receiving SIGTERM or CTRL-C.
osm.TrapSignal(logger, func() {})
osm.TrapSignal(func() {})

rpcserver.RegisterRPCFuncs(mux, routes, logger)
config := rpcserver.DefaultConfig()
Expand Down
7 changes: 7 additions & 0 deletions pkgs/bft/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ func GenesisDocFromFile(genDocFile string) (*GenesisDoc, error) {
}
return genDoc, nil
}

//----------------------------------------
// Mock AppState (for testing)

type MockAppState struct {
AccountOwner string `json:"account_owner"`
}
2 changes: 1 addition & 1 deletion pkgs/bft/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestGenesisBad(t *testing.T) {

func TestGenesisGood(t *testing.T) {
// test a good one by raw json
genDocBytes := []byte(`{"genesis_time":"0001-01-01T00:00:00Z","chain_id":"test-chain-QDKdJr","consensus_params":null,"validators":[{"pub_key":{"@type":"/tm.PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}],"app_hash":"","app_state":{"account_owner": "Bob"}}`)
genDocBytes := []byte(`{"genesis_time":"0001-01-01T00:00:00Z","chain_id":"test-chain-QDKdJr","consensus_params":null,"validators":[{"pub_key":{"@type":"/tm.PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}],"app_hash":"","app_state":{"@type":"/tm.MockAppState","account_owner":"Bob"}}`)
_, err := GenesisDocFromJSON(genDocBytes)
assert.NoError(t, err, "expected no error for good genDoc json")

Expand Down
1 change: 1 addition & 0 deletions pkgs/bft/types/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ var Package = amino.RegisterPackage(amino.NewPackage(

// Misc.
TxResult{},
MockAppState{},
))
2 changes: 1 addition & 1 deletion pkgs/sdk/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestInitChainer(t *testing.T) {
require.Nil(t, err)
require.Equal(t, int64(0), app.LastBlockHeight())

app.InitChain(abci.RequestInitChain{AppStateBytes: []byte("{}"), ChainID: "test-chain-id"}) // must have valid JSON genesis file, even if empty
app.InitChain(abci.RequestInitChain{AppState: nil, ChainID: "test-chain-id"}) // must have valid JSON genesis file, even if empty

// assert that chainID is set correctly in InitChain
chainID := app.deliverState.ctx.ChainID()
Expand Down

0 comments on commit a61cedd

Please sign in to comment.