From 58c860ba11c8e14f99a2bf8059fecf579e499d23 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 13 Apr 2017 14:18:35 -0400 Subject: [PATCH] rpc/test: /tx --- rpc/test/client_test.go | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/rpc/test/client_test.go b/rpc/test/client_test.go index 43409c723..63a0dbfbf 100644 --- a/rpc/test/client_test.go +++ b/rpc/test/client_test.go @@ -149,6 +149,51 @@ func testBroadcastTxCommit(t *testing.T, client rpc.HTTPClient) { // TODO: find tx in block } +//-------------------------------------------------------------------------------- +// query tx + +func TestURITx(t *testing.T) { + testTx(t, GetURIClient()) +} + +func TestJSONTx(t *testing.T) { + testTx(t, GetJSONClient()) +} + +func testTx(t *testing.T, client rpc.HTTPClient) { + require := require.New(t) + + // first we broadcast a tx + tmResult := new(ctypes.TMResult) + tx := randBytes(t) + _, err := client.Call("broadcast_tx_commit", map[string]interface{}{"tx": tx}, tmResult) + require.Nil(err) + + res := (*tmResult).(*ctypes.ResultBroadcastTxCommit) + checkTx := res.CheckTx + require.Equal(abci.CodeType_OK, checkTx.Code) + deliverTx := res.DeliverTx + require.Equal(abci.CodeType_OK, deliverTx.Code) + mem := node.MempoolReactor().Mempool + require.Equal(0, mem.Size()) + + // now we query for the tx. + // since there's only one tx, we know index=0. + tmResult = new(ctypes.TMResult) + _, err = client.Call("tx", map[string]interface{}{"height": res.Height}, tmResult) + require.Nil(err) + + res2 := (*tmResult).(*ctypes.ResultTx) + require.Equal(res2.Tx, types.Tx(tx), "tx is not correct") + + // TODO: a query with height and hash should fail + + // TODO: a query with just hash should work same way + + // TODO: verify proof + +} + //-------------------------------------------------------------------------------- // Test the websocket service