You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB

  1. package client_test
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/require"
  6. merktest "github.com/tendermint/merkleeyes/testutil"
  7. "github.com/tendermint/tendermint/rpc/client"
  8. "github.com/tendermint/tendermint/types"
  9. )
  10. func TestHeaderEvents(t *testing.T) {
  11. require := require.New(t)
  12. for i, c := range GetClients() {
  13. // start for this test it if it wasn't already running
  14. if !c.IsRunning() {
  15. // if so, then we start it, listen, and stop it.
  16. st, err := c.Start()
  17. require.Nil(err, "%d: %+v", i, err)
  18. require.True(st, "%d", i)
  19. defer c.Stop()
  20. }
  21. evtTyp := types.EventStringNewBlockHeader()
  22. evt, err := client.WaitForOneEvent(c, evtTyp, 1*time.Second)
  23. require.Nil(err, "%d: %+v", i, err)
  24. _, ok := evt.Unwrap().(types.EventDataNewBlockHeader)
  25. require.True(ok, "%d: %#v", i, evt)
  26. // TODO: more checks...
  27. }
  28. }
  29. func TestTxEvents(t *testing.T) {
  30. require := require.New(t)
  31. for i, c := range GetClients() {
  32. // start for this test it if it wasn't already running
  33. if !c.IsRunning() {
  34. // if so, then we start it, listen, and stop it.
  35. st, err := c.Start()
  36. require.Nil(err, "%d: %+v", i, err)
  37. require.True(st, "%d", i)
  38. defer c.Stop()
  39. }
  40. // make the tx
  41. _, _, tx := merktest.MakeTxKV()
  42. evtTyp := types.EventStringTx(types.Tx(tx))
  43. // send async
  44. txres, err := c.BroadcastTxAsync(tx)
  45. require.Nil(err, "%+v", err)
  46. require.True(txres.Code.IsOK())
  47. // and wait for confirmation
  48. evt, err := client.WaitForOneEvent(c, evtTyp, 1*time.Second)
  49. require.Nil(err, "%d: %+v", i, err)
  50. // and make sure it has the proper info
  51. txe, ok := evt.Unwrap().(types.EventDataTx)
  52. require.True(ok, "%d: %#v", i, evt)
  53. // make sure this is the proper tx
  54. require.EqualValues(tx, txe.Tx)
  55. require.True(txe.Code.IsOK())
  56. }
  57. }