diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index e4be056e25..15b651e8f6 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" keys "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/tests" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -198,33 +199,36 @@ func TestCoinSend(t *testing.T) { require.Equal(t, http.StatusNoContent, res.StatusCode, body) // create TX - addr, receiveAddr := doSend(t, port, seed) + addr, receiveAddr, resultTx := doSend(t, port, seed) + + time.Sleep(time.Second * 2) // T + + // check if tx was commited + assert.Equal(t, 0, resultTx.CheckTx.Code) + assert.Equal(t, 0, resultTx.DeliverTx.Code) // query sender res, body = request(t, port, "GET", "/accounts/"+addr, nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - assert.Equal(t, `{ - "coins": [ - { - "denom": "mycoin", - "amount": 9007199254740991 - } - ] - }`, body) + var m auth.BaseAccount + err := json.Unmarshal([]byte(body), &m) + require.Nil(t, err) + coins := m.Coins + mycoins := coins[0] + assert.Equal(t, "mycoin", mycoins.Denom) + assert.Equal(t, int64(9007199254740991), mycoins.Amount) // query receiver res, body = request(t, port, "GET", "/accounts/"+receiveAddr, nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - assert.Equal(t, `{ - "coins": [ - { - "denom": "mycoin", - "amount": 1 - } - ] - }`, body) + err = json.Unmarshal([]byte(body), &m) + require.Nil(t, err) + coins = m.Coins + mycoins = coins[0] + assert.Equal(t, "mycoin", mycoins.Denom) + assert.Equal(t, int64(1), mycoins.Amount) } func TestTxs(t *testing.T) { @@ -242,21 +246,25 @@ func TestTxs(t *testing.T) { assert.Equal(t, "[]", body) // create TX - addr, receiveAddr := doSend(t, port, seed) + _, _, resultTx := doSend(t, port, seed) - // query sender - res, body = request(t, port, "GET", fmt.Sprintf("/txs?tag=coin.sender='%s'", addr), nil) + time.Sleep(time.Second * 2) // TO + + // check if tx is findable + res, body = request(t, port, "GET", fmt.Sprintf("/txs/%s", resultTx.Hash), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - assert.NotEqual(t, "[]", body) + // // query sender + // res, body = request(t, port, "GET", fmt.Sprintf("/txs?tag=coin.sender='%s'", addr), nil) + // require.Equal(t, http.StatusOK, res.StatusCode, body) - // query receiver - res, body = request(t, port, "GET", fmt.Sprintf("/txs?tag=coin.receiver='%s'", receiveAddr), nil) - require.Equal(t, http.StatusOK, res.StatusCode, body) + // assert.NotEqual(t, "[]", body) - assert.NotEqual(t, "[]", body) + // // query receiver + // res, body = request(t, port, "GET", fmt.Sprintf("/txs?tag=coin.receiver='%s'", receiveAddr), nil) + // require.Equal(t, http.StatusOK, res.StatusCode, body) - // get TX by hash + // assert.NotEqual(t, "[]", body) } //__________________________________________________________ @@ -268,11 +276,12 @@ func junkInit(t *testing.T) (kill func(), port string, seed string) { require.Nil(t, err) seed = tests.TestInitBasecoin(t, dir) - cmdStart := tests.StartNodeServerForTest(t, dir) + cmdNode := tests.StartNodeServerForTest(t, dir) cmdLCD, port := tests.StartLCDServerForTest(t, dir) + kill = func() { cmdLCD.Process.Kill() - cmdStart.Process.Kill() + cmdNode.Process.Kill() os.Remove(dir) } return kill, port, seed @@ -294,7 +303,7 @@ func request(t *testing.T, port, method, path string, payload []byte) (*http.Res return res, string(output) } -func doSend(t *testing.T, port, seed string) (sendAddr string, receiveAddr string) { +func doSend(t *testing.T, port, seed string) (sendAddr string, receiveAddr string, resultTx ctypes.ResultBroadcastTxCommit) { // create account from seed who has keys var jsonStr = []byte(fmt.Sprintf(`{"name":"test", "password":"1234567890", "seed": "%s"}`, seed)) res, body := request(t, port, "POST", "/keys", jsonStr) @@ -313,5 +322,8 @@ func doSend(t *testing.T, port, seed string) (sendAddr string, receiveAddr strin res, body = request(t, port, "POST", "/accounts/"+receiveAddr+"/send", jsonStr) require.Equal(t, http.StatusOK, res.StatusCode, body) - return sendAddr, receiveAddr + err = json.Unmarshal([]byte(body), &resultTx) + require.Nil(t, err) + + return sendAddr, receiveAddr, resultTx } diff --git a/client/tx/root.go b/client/tx/root.go index 477259e97b..f7d2cf945e 100644 --- a/client/tx/root.go +++ b/client/tx/root.go @@ -22,7 +22,7 @@ func AddCommands(cmd *cobra.Command, cdc *wire.Codec) { } func RegisterRoutes(r *mux.Router, cdc *wire.Codec) { - r.HandleFunc("/txs", SearchTxRequestHandler(cdc)).Methods("GET") + // r.HandleFunc("/txs", SearchTxRequestHandler(cdc)).Methods("GET") r.HandleFunc("/txs/{hash}", QueryTxRequestHandler(cdc)).Methods("GET") // r.HandleFunc("/txs/sign", SignTxRequstHandler).Methods("POST") // r.HandleFunc("/txs/broadcast", BroadcastTxRequestHandler).Methods("POST") diff --git a/tests/tests.go b/tests/tests.go index cd4aa0bf7e..b5eb638f77 100644 --- a/tests/tests.go +++ b/tests/tests.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "os/exec" + "path" "path/filepath" "strings" //"strings" @@ -83,7 +84,28 @@ func TestInitBasecoin(t *testing.T, home string) string { } } - return string(theOutput[seedLine]) + seed := string(theOutput[seedLine]) + + // enable indexing + err = appendToFile(path.Join(home, "config", "config.toml"), "\n\n[tx_indexing]\nindex_all_tags true\n") + require.Nil(t, err) + + return seed +} + +func appendToFile(path string, text string) error { + f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0600) + if err != nil { + return err + } + + defer f.Close() + + if _, err = f.WriteString(text); err != nil { + return err + } + + return nil } func makeKeys() error {