Browse Source

rpc: fix tests

pull/484/head
Ethan Buchman 8 years ago
parent
commit
6afee8f117
6 changed files with 27 additions and 28 deletions
  1. +6
    -6
      config/tendermint/config.go
  2. +1
    -0
      config/tendermint_test/config.go
  3. +2
    -2
      consensus/state.go
  4. +3
    -5
      rpc/client/rpc_test.go
  5. +2
    -3
      rpc/test/client_test.go
  6. +13
    -12
      rpc/test/helpers.go

+ 6
- 6
config/tendermint/config.go View File

@ -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("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_file", rootDir+"/data/cs.wal/wal")
config.SetDefault("consensus.wal_light", false) config.SetDefault("consensus.wal_light", false)


+ 1
- 0
config/tendermint_test/config.go View File

@ -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


+ 2
- 2
consensus/state.go View File

@ -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"`
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 // 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


+ 3
- 5
rpc/client/rpc_test.go View File

@ -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]


+ 2
- 3
rpc/test/client_test.go View File

@ -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, chainID, result.NodeInfo.Network)
assert.Equal(t, moniker, status.NodeInfo.Moniker)
} }
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------


+ 13
- 12
rpc/test/helpers.go View File

@ -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)
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 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)


Loading…
Cancel
Save