From 202146e4cef2575af665869e15ee7b3069bab7a0 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 23 Feb 2017 13:50:05 +0100 Subject: [PATCH] Fix up checktx/delivertx in broadcastTx(A)sync --- rpc/client/mock/abci.go | 16 ++++++++++++---- rpc/client/mock/abci_test.go | 6 ++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/rpc/client/mock/abci.go b/rpc/client/mock/abci.go index 95d6fc0a2..13e187412 100644 --- a/rpc/client/mock/abci.go +++ b/rpc/client/mock/abci.go @@ -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, diff --git a/rpc/client/mock/abci_test.go b/rpc/client/mock/abci_test.go index 77ad496b9..823752caf 100644 --- a/rpc/client/mock/abci_test.go +++ b/rpc/client/mock/abci_test.go @@ -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)