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