mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 13:51:21 +00:00
rpc: fix tests
This commit is contained in:
@ -72,12 +72,12 @@ func GetConfig(rootDir string) *viper.Viper {
|
||||
config.SetDefault("grpc_laddr", "")
|
||||
config.SetDefault("tx_index", "kv")
|
||||
|
||||
config.SetDefault("network.listen_addr", "tcp://0.0.0.0:46656")
|
||||
config.SetDefault("network.seeds", "")
|
||||
config.SetDefault("network.skip_upnp", false)
|
||||
config.SetDefault("network.addrbook_file", rootDir+"/addrbook.json")
|
||||
config.SetDefault("network.addrbook_strict", true) // disable to allow connections locally
|
||||
config.SetDefault("network.pex_reactor", false) // enable for peer exchange
|
||||
config.SetDefault("p2p.laddr", "tcp://0.0.0.0:46656")
|
||||
config.SetDefault("p2p.seeds", "")
|
||||
config.SetDefault("p2p.skip_upnp", false)
|
||||
config.SetDefault("p2p.addrbook_file", rootDir+"/addrbook.json")
|
||||
config.SetDefault("p2p.addrbook_strict", true) // disable to allow connections locally
|
||||
config.SetDefault("p2p.pex_reactor", false) // enable for peer exchange
|
||||
|
||||
config.SetDefault("consensus.wal_file", rootDir+"/data/cs.wal/wal")
|
||||
config.SetDefault("consensus.wal_light", false)
|
||||
|
@ -90,6 +90,7 @@ func ResetConfig(localPath string) *viper.Viper {
|
||||
config.SetDefault("filter_peers", false)
|
||||
config.SetDefault("tx_index", "kv")
|
||||
|
||||
config.SetDefault("p2p.laddr", "tcp://0.0.0.0:36656")
|
||||
config.SetDefault("p2p.skip_upnp", true)
|
||||
config.SetDefault("p2p.addrbook_file", rootDir+"/addrbook.json")
|
||||
config.SetDefault("p2p.addrbook_strict", true) // disable to allow connections locally
|
||||
|
@ -40,8 +40,8 @@ type Config struct {
|
||||
SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"`
|
||||
|
||||
// BlockSize
|
||||
MaxBlockSizeTxs int `mapstructure:"block_size_txs"`
|
||||
MaxBlockSizeBytes int `mapstructure:"block_size_bytes"`
|
||||
MaxBlockSizeTxs int `mapstructure:"max_block_size_txs"`
|
||||
MaxBlockSizeBytes int `mapstructure:"max_block_size_bytes"`
|
||||
|
||||
// TODO: This probably shouldn't be exposed but it makes it
|
||||
// easy to write tests for the wal/replay
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func getHTTPClient() *client.HTTP {
|
||||
rpcAddr := rpctest.GetConfig().GetString("rpc_laddr")
|
||||
rpcAddr := rpctest.GetConfig().RPCListenAddress
|
||||
return client.NewHTTP(rpcAddr, "/websocket")
|
||||
}
|
||||
|
||||
@ -32,10 +32,10 @@ func GetClients() []client.Client {
|
||||
// Make sure status is correct (we connect properly)
|
||||
func TestStatus(t *testing.T) {
|
||||
for i, c := range GetClients() {
|
||||
chainID := rpctest.GetConfig().GetString("chain_id")
|
||||
moniker := rpctest.GetConfig().Moniker
|
||||
status, err := c.Status()
|
||||
require.Nil(t, err, "%d: %+v", i, err)
|
||||
assert.Equal(t, chainID, status.NodeInfo.Network)
|
||||
assert.Equal(t, moniker, status.NodeInfo.Moniker)
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,12 +77,10 @@ func TestDumpConsensusState(t *testing.T) {
|
||||
|
||||
func TestGenesisAndValidators(t *testing.T) {
|
||||
for i, c := range GetClients() {
|
||||
chainID := rpctest.GetConfig().GetString("chain_id")
|
||||
|
||||
// make sure this is the right genesis file
|
||||
gen, err := c.Genesis()
|
||||
require.Nil(t, err, "%d: %+v", i, err)
|
||||
assert.Equal(t, chainID, gen.Genesis.ChainID)
|
||||
// get the genesis validator
|
||||
require.Equal(t, 1, len(gen.Genesis.Validators))
|
||||
gval := gen.Genesis.Validators[0]
|
||||
|
@ -39,12 +39,11 @@ func TestJSONStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func testStatus(t *testing.T, client rpc.HTTPClient) {
|
||||
chainID := GetConfig().GetString("chain_id")
|
||||
moniker := GetConfig().Moniker
|
||||
result := new(ctypes.ResultStatus)
|
||||
_, err := client.Call("status", map[string]interface{}{}, result)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, chainID, result.NodeInfo.Network)
|
||||
assert.Equal(t, moniker, status.NodeInfo.Moniker)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
logger "github.com/tendermint/tmlibs/logger"
|
||||
|
||||
@ -24,7 +23,7 @@ import (
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
var config *viper.Viper
|
||||
var config *nm.Config
|
||||
|
||||
const tmLogLevel = "error"
|
||||
|
||||
@ -54,40 +53,42 @@ func makeAddrs() (string, string, string) {
|
||||
}
|
||||
|
||||
// GetConfig returns a config for the test cases as a singleton
|
||||
func GetConfig() *viper.Viper {
|
||||
func GetConfig() *nm.Config {
|
||||
if config == nil {
|
||||
pathname := makePathname()
|
||||
config = tendermint_test.ResetConfig(pathname)
|
||||
viperConfig := tendermint_test.ResetConfig(pathname)
|
||||
// Shut up the logging
|
||||
logger.SetLogLevel(tmLogLevel)
|
||||
// and we use random ports to run in parallel
|
||||
tm, rpc, grpc := makeAddrs()
|
||||
config.Set("node_laddr", tm)
|
||||
config.Set("rpc_laddr", rpc)
|
||||
config.Set("grpc_laddr", grpc)
|
||||
viperConfig.Set("p2p.laddr", tm)
|
||||
viperConfig.Set("rpc_laddr", rpc)
|
||||
viperConfig.Set("grpc_laddr", grpc)
|
||||
|
||||
config = nm.ConfigFromViper(viperConfig)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
// GetURIClient gets a uri client pointing to the test tendermint rpc
|
||||
func GetURIClient() *client.URIClient {
|
||||
rpcAddr := GetConfig().GetString("rpc_laddr")
|
||||
rpcAddr := GetConfig().RPCListenAddress
|
||||
return client.NewURIClient(rpcAddr)
|
||||
}
|
||||
|
||||
// GetJSONClient gets a http/json client pointing to the test tendermint rpc
|
||||
func GetJSONClient() *client.JSONRPCClient {
|
||||
rpcAddr := GetConfig().GetString("rpc_laddr")
|
||||
rpcAddr := GetConfig().RPCListenAddress
|
||||
return client.NewJSONRPCClient(rpcAddr)
|
||||
}
|
||||
|
||||
func GetGRPCClient() core_grpc.BroadcastAPIClient {
|
||||
grpcAddr := config.GetString("grpc_laddr")
|
||||
grpcAddr := config.GRPCListenAddress
|
||||
return core_grpc.StartGRPCClient(grpcAddr)
|
||||
}
|
||||
|
||||
func GetWSClient() *client.WSClient {
|
||||
rpcAddr := GetConfig().GetString("rpc_laddr")
|
||||
rpcAddr := GetConfig().RPCListenAddress
|
||||
wsc := client.NewWSClient(rpcAddr, "/websocket")
|
||||
if _, err := wsc.Start(); err != nil {
|
||||
panic(err)
|
||||
@ -107,7 +108,7 @@ func StartTendermint(app abci.Application) *nm.Node {
|
||||
func NewTendermint(app abci.Application) *nm.Node {
|
||||
// Create & start node
|
||||
config := GetConfig()
|
||||
privValidatorFile := config.GetString("priv_validator_file")
|
||||
privValidatorFile := config.PrivValidatorFile
|
||||
privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
|
||||
papp := proxy.NewLocalClientCreator(app)
|
||||
node := nm.NewNode(config, privValidator, papp)
|
||||
|
Reference in New Issue
Block a user