rpc: fix tests

This commit is contained in:
Ethan Buchman 2017-04-27 19:51:18 -04:00
parent a518d08839
commit c930f43cbe
6 changed files with 28 additions and 43 deletions

View File

@ -25,18 +25,16 @@ func (a ABCIApp) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
func (a ABCIApp) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) { func (a ABCIApp) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuery, error) {
q := a.App.Query(abci.RequestQuery{data, path, 0, prove}) q := a.App.Query(abci.RequestQuery{data, path, 0, prove})
return &ctypes.ResultABCIQuery{q}, nil return &ctypes.ResultABCIQuery{q.Result()}, nil
} }
func (a ABCIApp) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { func (a ABCIApp) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
res := ctypes.ResultBroadcastTxCommit{} res := ctypes.ResultBroadcastTxCommit{}
c := a.App.CheckTx(tx) res.CheckTx = a.App.CheckTx(tx)
res.CheckTx = &abci.ResponseCheckTx{c.Code, c.Data, c.Log} if !res.CheckTx.IsOK() {
if !c.IsOK() {
return &res, nil return &res, nil
} }
d := a.App.DeliverTx(tx) res.DeliverTx = a.App.DeliverTx(tx)
res.DeliverTx = &abci.ResponseDeliverTx{d.Code, d.Data, d.Log}
return &res, nil return &res, nil
} }
@ -85,7 +83,8 @@ func (m ABCIMock) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.R
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &ctypes.ResultABCIQuery{res.(abci.ResponseQuery)}, nil resQuery := res.(abci.ResponseQuery)
return &ctypes.ResultABCIQuery{resQuery.Result()}, nil
} }
func (m ABCIMock) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { func (m ABCIMock) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {

View File

@ -36,8 +36,8 @@ func TestABCIMock(t *testing.T) {
BroadcastCommit: mock.Call{ BroadcastCommit: mock.Call{
Args: goodTx, Args: goodTx,
Response: &ctypes.ResultBroadcastTxCommit{ Response: &ctypes.ResultBroadcastTxCommit{
CheckTx: &abci.ResponseCheckTx{Data: data.Bytes("stand")}, CheckTx: abci.Result{Data: data.Bytes("stand")},
DeliverTx: &abci.ResponseDeliverTx{Data: data.Bytes("deliver")}, DeliverTx: abci.Result{Data: data.Bytes("deliver")},
}, },
Error: errors.New("bad tx"), Error: errors.New("bad tx"),
}, },
@ -53,9 +53,9 @@ func TestABCIMock(t *testing.T) {
query, err := m.ABCIQuery("/", nil, false) query, err := m.ABCIQuery("/", nil, false)
require.Nil(err) require.Nil(err)
require.NotNil(query) require.NotNil(query)
assert.Equal(key, query.Response.GetKey()) assert.EqualValues(key, query.Key)
assert.Equal(value, query.Response.GetValue()) assert.EqualValues(value, query.Value)
assert.Equal(height, query.Response.GetHeight()) assert.Equal(height, query.Height)
// non-commit calls always return errors // non-commit calls always return errors
_, err = m.BroadcastTxSync(goodTx) _, err = m.BroadcastTxSync(goodTx)
@ -166,5 +166,5 @@ func TestABCIApp(t *testing.T) {
// check the key // check the key
qres, err := m.ABCIQuery("/key", data.Bytes(key), false) qres, err := m.ABCIQuery("/key", data.Bytes(key), false)
require.Nil(err) require.Nil(err)
assert.EqualValues(value, qres.Response.Value) assert.EqualValues(value, qres.Value)
} }

View File

@ -10,7 +10,6 @@ import (
merktest "github.com/tendermint/merkleeyes/testutil" merktest "github.com/tendermint/merkleeyes/testutil"
"github.com/tendermint/tendermint/rpc/client" "github.com/tendermint/tendermint/rpc/client"
rpctest "github.com/tendermint/tendermint/rpc/test" rpctest "github.com/tendermint/tendermint/rpc/test"
"github.com/tendermint/tendermint/types"
) )
func getHTTPClient() *client.HTTP { func getHTTPClient() *client.HTTP {
@ -119,17 +118,16 @@ func TestAppCalls(t *testing.T) {
k, v, tx := merktest.MakeTxKV() k, v, tx := merktest.MakeTxKV()
bres, err := c.BroadcastTxCommit(tx) bres, err := c.BroadcastTxCommit(tx)
require.Nil(err, "%d: %+v", i, err) require.Nil(err, "%d: %+v", i, err)
require.True(bres.DeliverTx.GetCode().IsOK()) require.True(bres.DeliverTx.Code.IsOK())
txh := bres.Height txh := bres.Height
apph := txh + 1 // this is where the tx will be applied to the state apph := txh + 1 // this is where the tx will be applied to the state
// wait before querying // wait before querying
client.WaitForHeight(c, apph, nil) client.WaitForHeight(c, apph, nil)
qres, err := c.ABCIQuery("/key", k, false) qres, err := c.ABCIQuery("/key", k, false)
if assert.Nil(err) && assert.True(qres.Response.Code.IsOK()) { if assert.Nil(err) && assert.True(qres.Code.IsOK()) {
data := qres.Response
// assert.Equal(k, data.GetKey()) // only returned for proofs // assert.Equal(k, data.GetKey()) // only returned for proofs
assert.Equal(v, data.GetValue()) assert.EqualValues(v, qres.Value)
} }
// make sure we can lookup the tx with proof // make sure we can lookup the tx with proof
@ -137,7 +135,7 @@ func TestAppCalls(t *testing.T) {
ptx, err := c.Tx(bres.Hash, true) ptx, err := c.Tx(bres.Hash, true)
require.Nil(err, "%d: %+v", i, err) require.Nil(err, "%d: %+v", i, err)
assert.Equal(txh, ptx.Height) assert.Equal(txh, ptx.Height)
assert.Equal(types.Tx(tx), ptx.Tx) assert.EqualValues(tx, ptx.Tx)
// and we can even check the block is added // and we can even check the block is added
block, err := c.Block(apph) block, err := c.Block(apph)
@ -174,12 +172,12 @@ func TestAppCalls(t *testing.T) {
// and we got a proof that works! // and we got a proof that works!
pres, err := c.ABCIQuery("/key", k, true) pres, err := c.ABCIQuery("/key", k, true)
if assert.Nil(err) && assert.True(pres.Response.Code.IsOK()) { if assert.Nil(err) && assert.True(pres.Code.IsOK()) {
proof, err := iavl.ReadProof(pres.Response.GetProof()) proof, err := iavl.ReadProof(pres.Proof)
if assert.Nil(err) { if assert.Nil(err) {
key := pres.Response.GetKey() key := pres.Key
value := pres.Response.GetValue() value := pres.Value
assert.Equal(appHash, proof.RootHash) assert.EqualValues(appHash, proof.RootHash)
valid := proof.Verify(key, value, appHash) valid := proof.Verify(key, value, appHash)
assert.True(valid) assert.True(valid)
} }

View File

@ -19,13 +19,7 @@ func ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.ResultABCIQuer
} }
log.Info("ABCIQuery", "path", path, "data", data, "result", resQuery) log.Info("ABCIQuery", "path", path, "data", data, "result", resQuery)
return &ctypes.ResultABCIQuery{ return &ctypes.ResultABCIQuery{
Code: resQuery.Code, resQuery.Result(),
Index: resQuery.Index,
Key: resQuery.Key,
Value: resQuery.Value,
Proof: resQuery.Proof,
Height: resQuery.Height,
Log: resQuery.Log,
}, nil }, nil
} }

View File

@ -113,13 +113,7 @@ type ResultABCIInfo struct {
} }
type ResultABCIQuery struct { type ResultABCIQuery struct {
Code abci.CodeType `json:"code"` *abci.ResultQuery `json:"response"`
Index int64 `json:"index"`
Key []byte `json:"key"`
Value []byte `json:"value"`
Proof []byte `json:"proof"`
Height uint64 `json:"height"`
Log string `json:"log"`
} }
type ResultUnsafeFlushMempool struct{} type ResultUnsafeFlushMempool struct{}

View File

@ -12,9 +12,9 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
rpc "github.com/tendermint/tendermint/rpc/lib/client"
"github.com/tendermint/tendermint/rpc/core" "github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpc "github.com/tendermint/tendermint/rpc/lib/client"
"github.com/tendermint/tendermint/state/txindex/null" "github.com/tendermint/tendermint/state/txindex/null"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
. "github.com/tendermint/tmlibs/common" . "github.com/tendermint/tmlibs/common"
@ -98,8 +98,8 @@ func sendTx(t *testing.T, client rpc.HTTPClient) ([]byte, []byte) {
require.Nil(t, err) require.Nil(t, err)
bres := (*tmResult).(*ctypes.ResultBroadcastTxCommit) bres := (*tmResult).(*ctypes.ResultBroadcastTxCommit)
require.NotNil(t, 0, bres.DeliverTx, "%#v", bres) require.NotNil(t, 0, bres.DeliverTx, "%#v", bres)
require.EqualValues(t, 0, bres.CheckTx.GetCode(), "%#v", bres) require.EqualValues(t, 0, bres.CheckTx.Code, "%#v", bres)
require.EqualValues(t, 0, bres.DeliverTx.GetCode(), "%#v", bres) require.EqualValues(t, 0, bres.DeliverTx.Code, "%#v", bres)
return k, v return k, v
} }
@ -120,10 +120,10 @@ func testABCIQuery(t *testing.T, client rpc.HTTPClient) {
require.Nil(t, err) require.Nil(t, err)
resQuery := (*tmResult).(*ctypes.ResultABCIQuery) resQuery := (*tmResult).(*ctypes.ResultABCIQuery)
require.EqualValues(t, 0, resQuery.Response.Code) require.EqualValues(t, 0, resQuery.Code)
// XXX: specific to value returned by the dummy // XXX: specific to value returned by the dummy
require.NotEqual(t, 0, len(resQuery.Response.Value)) require.NotEqual(t, 0, len(resQuery.Value))
} }
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------