Browse Source

Merge pull request #293 from ethanfrey/type-safe-fire-event

Add test for proper tx event
pull/291/head
Ethan Buchman 8 years ago
committed by GitHub
parent
commit
9d331715c0
1 changed files with 34 additions and 0 deletions
  1. +34
    -0
      rpc/test/client_test.go

+ 34
- 0
rpc/test/client_test.go View File

@ -257,6 +257,40 @@ func TestWSBlockchainGrowth(t *testing.T) {
}
}
func TestWSTxEvent(t *testing.T) {
wsc := newWSClient(t)
tx := randBytes()
// listen for the tx I am about to submit
eid := types.EventStringTx(types.Tx(tx))
subscribe(t, wsc, eid)
defer func() {
unsubscribe(t, wsc, eid)
wsc.Stop()
}()
// send an tx
tmResult := new(ctypes.TMResult)
_, err := clientJSON.Call("broadcast_tx_sync", []interface{}{tx}, tmResult)
if err != nil {
t.Fatal("Error submitting event")
}
waitForEvent(t, wsc, eid, true, func() {}, func(eid string, b interface{}) error {
evt, ok := b.(types.EventDataTx)
if !ok {
t.Fatal("Got wrong event type", b)
}
if bytes.Compare([]byte(evt.Tx), tx) != 0 {
t.Error("Event returned different tx")
}
if evt.Code != tmsp.CodeType_OK {
t.Error("Event returned tx error code", evt.Code)
}
return nil
})
}
/* TODO: this with dummy app..
func TestWSDoubleFire(t *testing.T) {
if testing.Short() {


Loading…
Cancel
Save