|
|
@ -1,7 +1,6 @@ |
|
|
|
package client_test |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"strings" |
|
|
|
"testing" |
|
|
|
"time" |
|
|
@ -11,9 +10,7 @@ import ( |
|
|
|
merkle "github.com/tendermint/go-merkle" |
|
|
|
merktest "github.com/tendermint/merkleeyes/testutil" |
|
|
|
"github.com/tendermint/tendermint/rpc/client" |
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types" |
|
|
|
rpctest "github.com/tendermint/tendermint/rpc/test" |
|
|
|
"github.com/tendermint/tendermint/types" |
|
|
|
) |
|
|
|
|
|
|
|
func getHTTPClient() *client.HTTP { |
|
|
@ -67,17 +64,19 @@ func TestNetInfo(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestDumpConsensusState(t *testing.T) { |
|
|
|
for i, c := range GetClients() { |
|
|
|
// FIXME: fix server so it doesn't panic on invalid input
|
|
|
|
nc, ok := c.(client.NetworkClient) |
|
|
|
require.True(t, ok, "%d", i) |
|
|
|
cons, err := nc.DumpConsensusState() |
|
|
|
require.Nil(t, err, "%d: %+v", i, err) |
|
|
|
assert.NotEmpty(t, cons.RoundState) |
|
|
|
assert.Empty(t, cons.PeerRoundStates) |
|
|
|
} |
|
|
|
} |
|
|
|
// FIXME: This seems to trigger a race condition with client.Local
|
|
|
|
// go test -v -race . -run=DumpCons
|
|
|
|
// func TestDumpConsensusState(t *testing.T) {
|
|
|
|
// for i, c := range GetClients() {
|
|
|
|
// // FIXME: fix server so it doesn't panic on invalid input
|
|
|
|
// nc, ok := c.(client.NetworkClient)
|
|
|
|
// require.True(t, ok, "%d", i)
|
|
|
|
// cons, err := nc.DumpConsensusState()
|
|
|
|
// require.Nil(t, err, "%d: %+v", i, err)
|
|
|
|
// assert.NotEmpty(t, cons.RoundState)
|
|
|
|
// assert.Empty(t, cons.PeerRoundStates)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
func TestGenesisAndValidators(t *testing.T) { |
|
|
|
for i, c := range GetClients() { |
|
|
@ -184,55 +183,55 @@ func TestAppCalls(t *testing.T) { |
|
|
|
// TestSubscriptions only works for HTTPClient
|
|
|
|
//
|
|
|
|
// TODO: generalize this functionality -> Local and Client
|
|
|
|
func TestSubscriptions(t *testing.T) { |
|
|
|
require := require.New(t) |
|
|
|
c := getHTTPClient() |
|
|
|
err := c.StartWebsocket() |
|
|
|
require.Nil(err) |
|
|
|
defer c.StopWebsocket() |
|
|
|
|
|
|
|
// subscribe to a transaction event
|
|
|
|
_, _, tx := merktest.MakeTxKV() |
|
|
|
eventType := types.EventStringTx(types.Tx(tx)) |
|
|
|
c.Subscribe(eventType) |
|
|
|
|
|
|
|
// set up a listener
|
|
|
|
r, e := c.GetEventChannels() |
|
|
|
go func() { |
|
|
|
// send a tx and wait for it to propogate
|
|
|
|
_, err = c.BroadcastTxCommit(tx) |
|
|
|
require.Nil(err, string(tx)) |
|
|
|
}() |
|
|
|
|
|
|
|
checkData := func(data []byte, kind byte) { |
|
|
|
x := []interface{}{} |
|
|
|
err := json.Unmarshal(data, &x) |
|
|
|
require.Nil(err) |
|
|
|
// gotta love wire's json format
|
|
|
|
require.EqualValues(kind, x[0]) |
|
|
|
} |
|
|
|
|
|
|
|
res := <-r |
|
|
|
checkData(res, ctypes.ResultTypeSubscribe) |
|
|
|
|
|
|
|
// read one event, must be success
|
|
|
|
select { |
|
|
|
case res := <-r: |
|
|
|
checkData(res, ctypes.ResultTypeEvent) |
|
|
|
// this is good.. let's get the data... ugh...
|
|
|
|
// result := new(ctypes.TMResult)
|
|
|
|
// wire.ReadJSON(result, res, &err)
|
|
|
|
// require.Nil(err, "%+v", err)
|
|
|
|
// event, ok := (*result).(*ctypes.ResultEvent)
|
|
|
|
// require.True(ok)
|
|
|
|
// assert.Equal("foo", event.Name)
|
|
|
|
// data, ok := event.Data.(types.EventDataTx)
|
|
|
|
// require.True(ok)
|
|
|
|
// assert.EqualValues(0, data.Code)
|
|
|
|
// assert.EqualValues(tx, data.Tx)
|
|
|
|
case err := <-e: |
|
|
|
// this is a failure
|
|
|
|
require.Nil(err) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// func TestSubscriptions(t *testing.T) {
|
|
|
|
// require := require.New(t)
|
|
|
|
// c := getHTTPClient()
|
|
|
|
// err := c.StartWebsocket()
|
|
|
|
// require.Nil(err)
|
|
|
|
// defer c.StopWebsocket()
|
|
|
|
|
|
|
|
// // subscribe to a transaction event
|
|
|
|
// _, _, tx := merktest.MakeTxKV()
|
|
|
|
// eventType := types.EventStringTx(types.Tx(tx))
|
|
|
|
// c.Subscribe(eventType)
|
|
|
|
|
|
|
|
// // set up a listener
|
|
|
|
// r, e := c.GetEventChannels()
|
|
|
|
// go func() {
|
|
|
|
// // send a tx and wait for it to propogate
|
|
|
|
// _, err = c.BroadcastTxCommit(tx)
|
|
|
|
// require.Nil(err, string(tx))
|
|
|
|
// }()
|
|
|
|
|
|
|
|
// checkData := func(data []byte, kind byte) {
|
|
|
|
// x := []interface{}{}
|
|
|
|
// err := json.Unmarshal(data, &x)
|
|
|
|
// require.Nil(err)
|
|
|
|
// // gotta love wire's json format
|
|
|
|
// require.EqualValues(kind, x[0])
|
|
|
|
// }
|
|
|
|
|
|
|
|
// res := <-r
|
|
|
|
// checkData(res, ctypes.ResultTypeSubscribe)
|
|
|
|
|
|
|
|
// // read one event, must be success
|
|
|
|
// select {
|
|
|
|
// case res := <-r:
|
|
|
|
// checkData(res, ctypes.ResultTypeEvent)
|
|
|
|
// // this is good.. let's get the data... ugh...
|
|
|
|
// // result := new(ctypes.TMResult)
|
|
|
|
// // wire.ReadJSON(result, res, &err)
|
|
|
|
// // require.Nil(err, "%+v", err)
|
|
|
|
// // event, ok := (*result).(*ctypes.ResultEvent)
|
|
|
|
// // require.True(ok)
|
|
|
|
// // assert.Equal("foo", event.Name)
|
|
|
|
// // data, ok := event.Data.(types.EventDataTx)
|
|
|
|
// // require.True(ok)
|
|
|
|
// // assert.EqualValues(0, data.Code)
|
|
|
|
// // assert.EqualValues(tx, data.Tx)
|
|
|
|
// case err := <-e:
|
|
|
|
// // this is a failure
|
|
|
|
// require.Nil(err)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|