mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-21 10:41:18 +00:00
rpc/tests: panic dont t.Fatal. use random txs for broadcast
This commit is contained in:
parent
cadb9e8bfe
commit
a43d53ac6e
@ -2,9 +2,11 @@ package rpctest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/tendermint/go-common"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
tmsp "github.com/tendermint/tmsp/types"
|
tmsp "github.com/tendermint/tmsp/types"
|
||||||
@ -21,7 +23,7 @@ func TestURIStatus(t *testing.T) {
|
|||||||
tmResult := new(ctypes.TMResult)
|
tmResult := new(ctypes.TMResult)
|
||||||
_, err := clientURI.Call("status", map[string]interface{}{}, tmResult)
|
_, err := clientURI.Call("status", map[string]interface{}{}, tmResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
testStatus(t, tmResult)
|
testStatus(t, tmResult)
|
||||||
}
|
}
|
||||||
@ -30,7 +32,7 @@ func TestJSONStatus(t *testing.T) {
|
|||||||
tmResult := new(ctypes.TMResult)
|
tmResult := new(ctypes.TMResult)
|
||||||
_, err := clientJSON.Call("status", []interface{}{}, tmResult)
|
_, err := clientJSON.Call("status", []interface{}{}, tmResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
testStatus(t, tmResult)
|
testStatus(t, tmResult)
|
||||||
}
|
}
|
||||||
@ -39,7 +41,7 @@ func testStatus(t *testing.T, statusI interface{}) {
|
|||||||
tmRes := statusI.(*ctypes.TMResult)
|
tmRes := statusI.(*ctypes.TMResult)
|
||||||
status := (*tmRes).(*ctypes.ResultStatus)
|
status := (*tmRes).(*ctypes.ResultStatus)
|
||||||
if status.NodeInfo.Network != chainID {
|
if status.NodeInfo.Network != chainID {
|
||||||
t.Fatal(fmt.Errorf("ChainID mismatch: got %s expected %s",
|
panic(Fmt("ChainID mismatch: got %s expected %s",
|
||||||
status.NodeInfo.Network, chainID))
|
status.NodeInfo.Network, chainID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,44 +49,53 @@ func testStatus(t *testing.T, statusI interface{}) {
|
|||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
// broadcast tx sync
|
// broadcast tx sync
|
||||||
|
|
||||||
var testTx = []byte{0x1, 0x2, 0x3, 0x4, 0x5}
|
func testTx() []byte {
|
||||||
|
buf := make([]byte, 16)
|
||||||
|
_, err := rand.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
func TestURIBroadcastTxSync(t *testing.T) {
|
func TestURIBroadcastTxSync(t *testing.T) {
|
||||||
config.Set("block_size", 0)
|
config.Set("block_size", 0)
|
||||||
defer config.Set("block_size", -1)
|
defer config.Set("block_size", -1)
|
||||||
tmResult := new(ctypes.TMResult)
|
tmResult := new(ctypes.TMResult)
|
||||||
_, err := clientURI.Call("broadcast_tx_sync", map[string]interface{}{"tx": testTx}, tmResult)
|
tx := testTx()
|
||||||
|
_, err := clientURI.Call("broadcast_tx_sync", map[string]interface{}{"tx": tx}, tmResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
testBroadcastTxSync(t, tmResult)
|
testBroadcastTxSync(t, tmResult, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONBroadcastTxSync(t *testing.T) {
|
func TestJSONBroadcastTxSync(t *testing.T) {
|
||||||
config.Set("block_size", 0)
|
config.Set("block_size", 0)
|
||||||
defer config.Set("block_size", -1)
|
defer config.Set("block_size", -1)
|
||||||
tmResult := new(ctypes.TMResult)
|
tmResult := new(ctypes.TMResult)
|
||||||
_, err := clientJSON.Call("broadcast_tx_sync", []interface{}{testTx}, tmResult)
|
tx := testTx()
|
||||||
|
_, err := clientJSON.Call("broadcast_tx_sync", []interface{}{tx}, tmResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
testBroadcastTxSync(t, tmResult)
|
testBroadcastTxSync(t, tmResult, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBroadcastTxSync(t *testing.T, resI interface{}) {
|
func testBroadcastTxSync(t *testing.T, resI interface{}, tx []byte) {
|
||||||
tmRes := resI.(*ctypes.TMResult)
|
tmRes := resI.(*ctypes.TMResult)
|
||||||
res := (*tmRes).(*ctypes.ResultBroadcastTx)
|
res := (*tmRes).(*ctypes.ResultBroadcastTx)
|
||||||
if res.Code != tmsp.CodeType_OK {
|
if res.Code != tmsp.CodeType_OK {
|
||||||
t.Fatalf("BroadcastTxSync got non-zero exit code: %v. %X; %s", res.Code, res.Data, res.Log)
|
panic(Fmt("BroadcastTxSync got non-zero exit code: %v. %X; %s", res.Code, res.Data, res.Log))
|
||||||
}
|
}
|
||||||
mem := node.MempoolReactor().Mempool
|
mem := node.MempoolReactor().Mempool
|
||||||
if mem.Size() != 1 {
|
if mem.Size() != 1 {
|
||||||
t.Fatalf("Mempool size should have been 1. Got %d", mem.Size())
|
panic(Fmt("Mempool size should have been 1. Got %d", mem.Size()))
|
||||||
}
|
}
|
||||||
|
|
||||||
txs := mem.Reap(1)
|
txs := mem.Reap(1)
|
||||||
if !bytes.Equal(txs[0], testTx) {
|
if !bytes.Equal(txs[0], tx) {
|
||||||
t.Fatalf("Tx in mempool does not match test tx. Got %X, expected %X", txs[0], testTx)
|
panic(Fmt("Tx in mempool does not match test tx. Got %X, expected %X", txs[0], testTx))
|
||||||
}
|
}
|
||||||
|
|
||||||
mem.Flush()
|
mem.Flush()
|
||||||
@ -95,32 +106,36 @@ func testBroadcastTxSync(t *testing.T, resI interface{}) {
|
|||||||
|
|
||||||
func TestURIBroadcastTxCommit(t *testing.T) {
|
func TestURIBroadcastTxCommit(t *testing.T) {
|
||||||
tmResult := new(ctypes.TMResult)
|
tmResult := new(ctypes.TMResult)
|
||||||
_, err := clientURI.Call("broadcast_tx_commit", map[string]interface{}{"tx": testTx}, tmResult)
|
tx := testTx()
|
||||||
|
_, err := clientURI.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
testBroadcastTxCommit(t, tmResult)
|
testBroadcastTxCommit(t, tmResult, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONBroadcastTxCommit(t *testing.T) {
|
func TestJSONBroadcastTxCommit(t *testing.T) {
|
||||||
tmResult := new(ctypes.TMResult)
|
tmResult := new(ctypes.TMResult)
|
||||||
_, err := clientJSON.Call("broadcast_tx_commit", []interface{}{testTx}, tmResult)
|
tx := testTx()
|
||||||
|
_, err := clientJSON.Call("broadcast_tx_commit", []interface{}{tx}, tmResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
testBroadcastTxCommit(t, tmResult)
|
testBroadcastTxCommit(t, tmResult, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testBroadcastTxCommit(t *testing.T, resI interface{}) {
|
func testBroadcastTxCommit(t *testing.T, resI interface{}, tx []byte) {
|
||||||
tmRes := resI.(*ctypes.TMResult)
|
tmRes := resI.(*ctypes.TMResult)
|
||||||
res := (*tmRes).(*ctypes.ResultBroadcastTx)
|
res := (*tmRes).(*ctypes.ResultBroadcastTx)
|
||||||
if res.Code != tmsp.CodeType_OK {
|
if res.Code != tmsp.CodeType_OK {
|
||||||
t.Fatalf("BroadcastTxCommit got non-zero exit code: %v. %X; %s", res.Code, res.Data, res.Log)
|
panic(Fmt("BroadcastTxCommit got non-zero exit code: %v. %X; %s", res.Code, res.Data, res.Log))
|
||||||
}
|
}
|
||||||
mem := node.MempoolReactor().Mempool
|
mem := node.MempoolReactor().Mempool
|
||||||
if mem.Size() != 0 {
|
if mem.Size() != 0 {
|
||||||
t.Fatalf("Mempool size should have been 0. Got %d", mem.Size())
|
panic(Fmt("Mempool size should have been 0. Got %d", mem.Size()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: find tx in block
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
@ -232,7 +247,7 @@ func TestURIUnsafeSetConfig(t *testing.T) {
|
|||||||
"value": testCase[2],
|
"value": testCase[2],
|
||||||
}, tmResult)
|
}, tmResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testUnsafeSetConfig(t)
|
testUnsafeSetConfig(t)
|
||||||
@ -243,7 +258,7 @@ func TestJSONUnsafeSetConfig(t *testing.T) {
|
|||||||
tmResult := new(ctypes.TMResult)
|
tmResult := new(ctypes.TMResult)
|
||||||
_, err := clientJSON.Call("unsafe_set_config", []interface{}{testCase[0], testCase[1], testCase[2]}, tmResult)
|
_, err := clientJSON.Call("unsafe_set_config", []interface{}{testCase[0], testCase[1], testCase[2]}, tmResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testUnsafeSetConfig(t)
|
testUnsafeSetConfig(t)
|
||||||
@ -252,16 +267,16 @@ func TestJSONUnsafeSetConfig(t *testing.T) {
|
|||||||
func testUnsafeSetConfig(t *testing.T) {
|
func testUnsafeSetConfig(t *testing.T) {
|
||||||
s := config.GetString("key1")
|
s := config.GetString("key1")
|
||||||
if s != stringVal {
|
if s != stringVal {
|
||||||
t.Fatalf("got %v, expected %v", s, stringVal)
|
panic(Fmt("got %v, expected %v", s, stringVal))
|
||||||
}
|
}
|
||||||
|
|
||||||
i := config.GetInt("key2")
|
i := config.GetInt("key2")
|
||||||
if i != intVal {
|
if i != intVal {
|
||||||
t.Fatalf("got %v, expected %v", i, intVal)
|
panic(Fmt("got %v, expected %v", i, intVal))
|
||||||
}
|
}
|
||||||
|
|
||||||
b := config.GetBool("key3")
|
b := config.GetBool("key3")
|
||||||
if b != boolVal {
|
if b != boolVal {
|
||||||
t.Fatalf("got %v, expected %v", b, boolVal)
|
panic(Fmt("got %v, expected %v", b, boolVal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ func newNode(ready chan struct{}) {
|
|||||||
func newWSClient(t *testing.T) *client.WSClient {
|
func newWSClient(t *testing.T) *client.WSClient {
|
||||||
wsc := client.NewWSClient(websocketAddr, websocketEndpoint)
|
wsc := client.NewWSClient(websocketAddr, websocketEndpoint)
|
||||||
if _, err := wsc.Start(); err != nil {
|
if _, err := wsc.Start(); err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return wsc
|
return wsc
|
||||||
}
|
}
|
||||||
@ -83,14 +83,14 @@ func newWSClient(t *testing.T) *client.WSClient {
|
|||||||
// subscribe to an event
|
// subscribe to an event
|
||||||
func subscribe(t *testing.T, wsc *client.WSClient, eventid string) {
|
func subscribe(t *testing.T, wsc *client.WSClient, eventid string) {
|
||||||
if err := wsc.Subscribe(eventid); err != nil {
|
if err := wsc.Subscribe(eventid); err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// unsubscribe from an event
|
// unsubscribe from an event
|
||||||
func unsubscribe(t *testing.T, wsc *client.WSClient, eventid string) {
|
func unsubscribe(t *testing.T, wsc *client.WSClient, eventid string) {
|
||||||
if err := wsc.Unsubscribe(eventid); err != nil {
|
if err := wsc.Unsubscribe(eventid); err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ func waitForEvent(t *testing.T, wsc *client.WSClient, eventid string, dieOnTimeo
|
|||||||
case <-timeout.C:
|
case <-timeout.C:
|
||||||
if dieOnTimeout {
|
if dieOnTimeout {
|
||||||
wsc.Stop()
|
wsc.Stop()
|
||||||
t.Fatalf("%s event was not received in time", eventid)
|
panic(Fmt("%s event was not received in time", eventid))
|
||||||
}
|
}
|
||||||
// else that's great, we didn't hear the event
|
// else that's great, we didn't hear the event
|
||||||
// and we shouldn't have
|
// and we shouldn't have
|
||||||
@ -146,14 +146,13 @@ func waitForEvent(t *testing.T, wsc *client.WSClient, eventid string, dieOnTimeo
|
|||||||
// message was received and expected
|
// message was received and expected
|
||||||
// run the check
|
// run the check
|
||||||
if err := check(eventid, eventData); err != nil {
|
if err := check(eventid, eventData); err != nil {
|
||||||
t.Fatal(err) // Show the stack trace.
|
panic(err) // Show the stack trace.
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
wsc.Stop()
|
wsc.Stop()
|
||||||
t.Fatalf("%s event was not expected", eventid)
|
panic(Fmt("%s event was not expected", eventid))
|
||||||
}
|
}
|
||||||
case err := <-errCh:
|
case err := <-errCh:
|
||||||
t.Fatal(err)
|
|
||||||
panic(err) // Show the stack trace.
|
panic(err) // Show the stack trace.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user