Browse Source

Fix up checktx/delivertx in broadcastTx(A)sync

pull/418/head
Ethan Frey 8 years ago
parent
commit
202146e4ce
2 changed files with 16 additions and 6 deletions
  1. +12
    -4
      rpc/client/mock/abci.go
  2. +4
    -2
      rpc/client/mock/abci_test.go

+ 12
- 4
rpc/client/mock/abci.go View File

@ -40,13 +40,21 @@ func (a ABCIApp) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit
}
func (a ABCIApp) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
d := a.App.DeliverTx(tx)
return &ctypes.ResultBroadcastTx{d.Code, d.Data, d.Log}, nil
c := a.App.CheckTx(tx)
// and this gets writen in a background thread...
if c.IsOK() {
go func() { a.App.DeliverTx(tx) }()
}
return &ctypes.ResultBroadcastTx{c.Code, c.Data, c.Log}, nil
}
func (a ABCIApp) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
d := a.App.DeliverTx(tx)
return &ctypes.ResultBroadcastTx{d.Code, d.Data, d.Log}, nil
c := a.App.CheckTx(tx)
// and this gets writen in a background thread...
if c.IsOK() {
go func() { a.App.DeliverTx(tx) }()
}
return &ctypes.ResultBroadcastTx{c.Code, c.Data, c.Log}, nil
}
// ABCIMock will send all abci related request to the named app,


+ 4
- 2
rpc/client/mock/abci_test.go View File

@ -156,9 +156,11 @@ func TestABCIApp(t *testing.T) {
// add a key
key, value := "foo", "bar"
tx := fmt.Sprintf("%s=%s", key, value)
res, err := m.BroadcastTxSync(types.Tx(tx))
res, err := m.BroadcastTxCommit(types.Tx(tx))
require.Nil(err)
assert.True(res.Code.IsOK())
assert.True(res.CheckTx.Code.IsOK())
require.NotNil(res.DeliverTx)
assert.True(res.DeliverTx.Code.IsOK())
// check the key
qres, err := m.ABCIQuery("/key", []byte(key), false)


Loading…
Cancel
Save