Browse Source

namereg event

pull/123/head
Ethan Buchman 10 years ago
parent
commit
9b69894180
6 changed files with 67 additions and 9 deletions
  1. +29
    -8
      rpc/test/tests.go
  2. +25
    -1
      rpc/test/ws_helpers.go
  3. +5
    -0
      state/execution.go
  4. +4
    -0
      types/events.go
  5. +3
    -0
      types/names.go
  6. +1
    -0
      vm/vm.go

+ 29
- 8
rpc/test/tests.go View File

@ -189,12 +189,6 @@ func testCall(t *testing.T, typ string) {
func testNameReg(t *testing.T, typ string) { func testNameReg(t *testing.T, typ string) {
client := clients[typ] client := clients[typ]
con := newWSCon(t) con := newWSCon(t)
eid := types.EventStringNewBlock()
subscribe(t, con, eid)
defer func() {
unsubscribe(t, con, eid)
con.Close()
}()
types.MinNameRegistrationPeriod = 1 types.MinNameRegistrationPeriod = 1
@ -206,10 +200,26 @@ func testNameReg(t *testing.T, typ string) {
numDesiredBlocks := int64(2) numDesiredBlocks := int64(2)
amt := fee + numDesiredBlocks*types.NameCostPerByte*types.NameCostPerBlock*types.BaseEntryCost(name, data) 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) tx := makeDefaultNameTx(t, typ, name, data, amt, fee)
broadcastTx(t, typ, tx) 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 mempoolCount = 0
entry := getNameRegEntry(t, typ, name) entry := getNameRegEntry(t, typ, name)
if entry.Data != data { 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)) 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 // update the data as the owner, make sure still there
numDesiredBlocks = int64(2) 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" 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"


+ 25
- 1
rpc/test/ws_helpers.go View File

@ -9,11 +9,11 @@ import (
"time" "time"
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket" "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/config/tendermint_test"
"github.com/tendermint/tendermint/rpc/server" "github.com/tendermint/tendermint/rpc/server"
"github.com/tendermint/tendermint/rpc/types" "github.com/tendermint/tendermint/rpc/types"
"github.com/tendermint/tendermint/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 // 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) { 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 // go routine to wait for webscoket msg
goodCh := make(chan []byte) goodCh := make(chan []byte)
@ -160,6 +161,29 @@ func unmarshalResponseNewBlock(b []byte) (*types.Block, error) {
return block, nil 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) { func unmarshalValidateBlockchain(t *testing.T, con *websocket.Conn, eid string) {
var initBlockN int var initBlockN int
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {


+ 5
- 0
state/execution.go View File

@ -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? // 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 return nil
case *types.BondTx: case *types.BondTx:


+ 4
- 0
types/events.go View File

@ -26,6 +26,10 @@ func EventStringPermissions(name string) string {
return fmt.Sprintf("Permissions/%s", name) return fmt.Sprintf("Permissions/%s", name)
} }
func EventStringNameReg(name string) string {
return fmt.Sprintf("NameReg/%s", name)
}
func EventStringBond() string { func EventStringBond() string {
return "Bond" return "Bond"
} }


+ 3
- 0
types/names.go View File

@ -7,6 +7,9 @@ import (
var ( var (
MinNameRegistrationPeriod int = 5 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 // cost for storing a name for a block is
// CostPerBlock*CostPerByte*(len(data) + 32) // CostPerBlock*CostPerByte*(len(data) + 32)
NameCostPerByte int64 = 1 NameCostPerByte int64 = 1


+ 1
- 0
vm/vm.go View File

@ -773,6 +773,7 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
if err != nil { if err != nil {
exception = err.Error() 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) vm.fireCallEvent(&exception, &ret, callee, &Account{Address: addr}, args, value, gas)
} else { } else {
// EVM contract // EVM contract


Loading…
Cancel
Save