test empty response

This commit is contained in:
Federico Kunze 2018-11-16 13:07:17 +01:00
parent 4de3aee7f1
commit e65d18643e
2 changed files with 12 additions and 5 deletions

View File

@ -401,15 +401,22 @@ func TestTxs(t *testing.T) {
// query wrong
res, body := Request(t, port, "GET", "/txs", nil)
// TODO: test empty array response
require.Equal(t, http.StatusOK, res.StatusCode, body)
require.Equal(t, "\"[]\"", body)
// query empty
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?sender_bech32=%s", "cosmos1jawd35d9aq4u76sr3fjalmcqc8hqygs90d0g0v"), nil)
require.Equal(t, "", body)
require.Equal(t, http.StatusOK, res.StatusCode, body)
require.Equal(t, "\"[]\"", body)
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?action=submit-proposal&proposer=%s", "cosmos1jawd35d9aq4u76sr3fjalmcqc8hqygs90d0g0v"), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
require.Equal(t, "\"[]\"", body)
// also tests url decoding
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?action=submit%%20proposal&proposer=%s", "cosmos1jawd35d9aq4u76sr3fjalmcqc8hqygs90d0g0v"), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
require.Equal(t, "\"[]\"", body)
// create TX
receiveAddr, resultTx := doSend(t, port, seed, name, password, addr)
@ -431,10 +438,9 @@ func TestTxs(t *testing.T) {
// XXX should this move into some other testfile for txs in general?
// test if created TX hash is the correct hash
// assert.Equal(t, resultTx.Hash, indexedTxs[0].Hash)
require.Equal(t, resultTx.Hash, indexedTxs[0].Hash)
// query sender
// also tests url decoding
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?sender_bech32=%s", addr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

View File

@ -146,6 +146,7 @@ func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.
return
}
if len(r.Form) == 0 {
utils.PostProcessResponse(w, cdc, "[]", cliCtx.Indent)
return
}
@ -171,7 +172,6 @@ func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.
tags = append(tags, tag)
}
//
txs, err := searchTxs(cliCtx, cdc, tags)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
@ -179,6 +179,7 @@ func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.
}
if len(txs) == 0 {
utils.PostProcessResponse(w, cdc, "[]", cliCtx.Indent)
return
}