Browse Source

rpc: fix tests

pull/467/head
Ethan Buchman 8 years ago
parent
commit
c930f43cbe
6 changed files with 28 additions and 43 deletions
  1. +6
    -7
      rpc/client/mock/abci.go
  2. +6
    -6
      rpc/client/mock/abci_test.go
  3. +9
    -11
      rpc/client/rpc_test.go
  4. +1
    -7
      rpc/core/abci.go
  5. +1
    -7
      rpc/core/types/responses.go
  6. +5
    -5
      rpc/test/client_test.go

+ 6
- 7
rpc/client/mock/abci.go 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) {
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) {
res := ctypes.ResultBroadcastTxCommit{}
c := a.App.CheckTx(tx)
res.CheckTx = &abci.ResponseCheckTx{c.Code, c.Data, c.Log}
if !c.IsOK() {
res.CheckTx = a.App.CheckTx(tx)
if !res.CheckTx.IsOK() {
return &res, nil
}
d := a.App.DeliverTx(tx)
res.DeliverTx = &abci.ResponseDeliverTx{d.Code, d.Data, d.Log}
res.DeliverTx = a.App.DeliverTx(tx)
return &res, nil
}
@ -85,7 +83,8 @@ func (m ABCIMock) ABCIQuery(path string, data data.Bytes, prove bool) (*ctypes.R
if err != nil {
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) {


+ 6
- 6
rpc/client/mock/abci_test.go View File

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

+ 9
- 11
rpc/client/rpc_test.go View File

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


+ 1
- 7
rpc/core/abci.go 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)
return &ctypes.ResultABCIQuery{
Code: resQuery.Code,
Index: resQuery.Index,
Key: resQuery.Key,
Value: resQuery.Value,
Proof: resQuery.Proof,
Height: resQuery.Height,
Log: resQuery.Log,
resQuery.Result(),
}, nil
}


+ 1
- 7
rpc/core/types/responses.go View File

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


+ 5
- 5
rpc/test/client_test.go View File

@ -12,9 +12,9 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/abci/types"
rpc "github.com/tendermint/tendermint/rpc/lib/client"
"github.com/tendermint/tendermint/rpc/core"
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/types"
. "github.com/tendermint/tmlibs/common"
@ -98,8 +98,8 @@ func sendTx(t *testing.T, client rpc.HTTPClient) ([]byte, []byte) {
require.Nil(t, err)
bres := (*tmResult).(*ctypes.ResultBroadcastTxCommit)
require.NotNil(t, 0, bres.DeliverTx, "%#v", bres)
require.EqualValues(t, 0, bres.CheckTx.GetCode(), "%#v", bres)
require.EqualValues(t, 0, bres.DeliverTx.GetCode(), "%#v", bres)
require.EqualValues(t, 0, bres.CheckTx.Code, "%#v", bres)
require.EqualValues(t, 0, bres.DeliverTx.Code, "%#v", bres)
return k, v
}
@ -120,10 +120,10 @@ func testABCIQuery(t *testing.T, client rpc.HTTPClient) {
require.Nil(t, err)
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
require.NotEqual(t, 0, len(resQuery.Response.Value))
require.NotEqual(t, 0, len(resQuery.Value))
}
//--------------------------------------------------------------------------------


Loading…
Cancel
Save