diff --git a/rpc/test/tests.go b/rpc/test/tests.go index 9fc41fe54..ba57dc125 100644 --- a/rpc/test/tests.go +++ b/rpc/test/tests.go @@ -189,12 +189,6 @@ func testCall(t *testing.T, typ string) { func testNameReg(t *testing.T, typ string) { client := clients[typ] con := newWSCon(t) - eid := types.EventStringNewBlock() - subscribe(t, con, eid) - defer func() { - unsubscribe(t, con, eid) - con.Close() - }() types.MinNameRegistrationPeriod = 1 @@ -206,10 +200,26 @@ func testNameReg(t *testing.T, typ string) { numDesiredBlocks := int64(2) amt := fee + numDesiredBlocks*types.NameCostPerByte*types.NameCostPerBlock*types.BaseEntryCost(name, data) + eid := types.EventStringNameReg(name) + subscribe(t, con, eid) + tx := makeDefaultNameTx(t, typ, name, data, amt, fee) broadcastTx(t, typ, tx) - // commit block - waitForEvent(t, con, eid, true, func() {}, doNothing) + // verify the name by both using the event and by checking get_name + waitForEvent(t, con, eid, true, func() {}, func(eid string, b []byte) error { + // TODO: unmarshal the response + tx, err := unmarshalResponseNameReg(b) + if err != nil { + return err + } + if tx.Name != name { + t.Fatal(fmt.Sprintf("Err on received event tx.Name: Got %s, expected %s", tx.Name, name)) + } + if tx.Data != data { + t.Fatal(fmt.Sprintf("Err on received event tx.Data: Got %s, expected %s", tx.Data, data)) + } + return nil + }) mempoolCount = 0 entry := getNameRegEntry(t, typ, name) if entry.Data != data { @@ -219,6 +229,17 @@ func testNameReg(t *testing.T, typ string) { t.Fatal(fmt.Sprintf("Err on entry.Owner: Got %s, expected %s", entry.Owner, user[0].Address)) } + unsubscribe(t, con, eid) + + // for the rest we just use new block event + // since we already tested the namereg event + eid = types.EventStringNewBlock() + subscribe(t, con, eid) + defer func() { + unsubscribe(t, con, eid) + con.Close() + }() + // update the data as the owner, make sure still there numDesiredBlocks = int64(2) data = "these are amongst the things I wish to bestow upon the youth of generations come: a safe supply of honey, and a better money. For what else shall they need" diff --git a/rpc/test/ws_helpers.go b/rpc/test/ws_helpers.go index 985ad86b8..db6636892 100644 --- a/rpc/test/ws_helpers.go +++ b/rpc/test/ws_helpers.go @@ -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++ { diff --git a/state/execution.go b/state/execution.go index d935666e0..18f0032ef 100644 --- a/state/execution.go +++ b/state/execution.go @@ -633,6 +633,11 @@ func ExecTx(blockCache *BlockCache, tx types.Tx, runCall bool, evc events.Fireab // TODO: maybe we want to take funds on error and allow txs in that don't do anythingi? + if evc != nil { + evc.FireEvent(types.EventStringAccInput(tx.Input.Address), tx) + evc.FireEvent(types.EventStringNameReg(tx.Name), tx) + } + return nil case *types.BondTx: diff --git a/types/events.go b/types/events.go index e3502a1a5..2e065f5ba 100644 --- a/types/events.go +++ b/types/events.go @@ -26,6 +26,10 @@ func EventStringPermissions(name string) string { return fmt.Sprintf("Permissions/%s", name) } +func EventStringNameReg(name string) string { + return fmt.Sprintf("NameReg/%s", name) +} + func EventStringBond() string { return "Bond" } diff --git a/types/names.go b/types/names.go index 9ce4cc6f4..7eb703ff0 100644 --- a/types/names.go +++ b/types/names.go @@ -7,6 +7,9 @@ import ( var ( MinNameRegistrationPeriod int = 5 + // NOTE: base costs and validity checks are here so clients + // can use them without importing state + // cost for storing a name for a block is // CostPerBlock*CostPerByte*(len(data) + 32) NameCostPerByte int64 = 1 diff --git a/vm/vm.go b/vm/vm.go index ee1298db1..8d252b33f 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -773,6 +773,7 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas if err != nil { exception = err.Error() } + // NOTE: these fire call events and not particular events for eg name reg or permissions vm.fireCallEvent(&exception, &ret, callee, &Account{Address: addr}, args, value, gas) } else { // EVM contract