mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
namereg event
This commit is contained in:
parent
bff06ac657
commit
9b69894180
@ -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"
|
||||
|
@ -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++ {
|
||||
|
@ -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:
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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
|
||||
|
1
vm/vm.go
1
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user