namereg event

This commit is contained in:
Ethan Buchman
2015-07-30 17:34:38 -04:00
parent bff06ac657
commit 9b69894180
6 changed files with 67 additions and 9 deletions

View File

@ -9,11 +9,11 @@ import (
"time"
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket"
"github.com/tendermint/tendermint/wire"
_ "github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/rpc/server"
"github.com/tendermint/tendermint/rpc/types"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/wire"
)
//--------------------------------------------------------------------------------
@ -58,6 +58,7 @@ func unsubscribe(t *testing.T, con *websocket.Conn, eventid string) {
}
// wait for an event; do things that might trigger events, and check them when they are received
// the check function takes an event id and the byte slice read off the ws
func waitForEvent(t *testing.T, con *websocket.Conn, eventid string, dieOnTimeout bool, f func(), check func(string, []byte) error) {
// go routine to wait for webscoket msg
goodCh := make(chan []byte)
@ -160,6 +161,29 @@ func unmarshalResponseNewBlock(b []byte) (*types.Block, error) {
return block, nil
}
func unmarshalResponseNameReg(b []byte) (*types.NameTx, error) {
// unmarshall and assert somethings
var response struct {
JSONRPC string `json:"jsonrpc"`
Id string `json:"id"`
Result struct {
Event string `json:"event"`
Data *types.NameTx `json:"data"`
} `json:"result"`
Error string `json:"error"`
}
var err error
wire.ReadJSON(&response, b, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
tx := response.Result.Data
return tx, nil
}
func unmarshalValidateBlockchain(t *testing.T, con *websocket.Conn, eid string) {
var initBlockN int
for i := 0; i < 2; i++ {