Skip to content

Commit

Permalink
fix tests and refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
faboweb authored and ebuchman committed Mar 17, 2018
1 parent fa78893 commit 5ea0663
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
16 changes: 8 additions & 8 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func TestKeys(t *testing.T) {
kill, port, _ := junkInit(t)
kill, port, _ := setupEnvironment(t)
defer kill()

// empty keys
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestKeys(t *testing.T) {
}

func TestVersion(t *testing.T) {
kill, port, _ := junkInit(t)
kill, port, _ := setupEnvironment(t)
defer kill()

// node info
Expand All @@ -104,7 +104,7 @@ func TestVersion(t *testing.T) {
}

func TestNodeStatus(t *testing.T) {
kill, port, _ := junkInit(t)
kill, port, _ := setupEnvironment(t)
defer kill()

// node info
Expand All @@ -127,7 +127,7 @@ func TestNodeStatus(t *testing.T) {
}

func TestBlock(t *testing.T) {
kill, port, _ := junkInit(t)
kill, port, _ := setupEnvironment(t)
defer kill()

time.Sleep(time.Second * 2) // TODO: LOL -> wait for blocks
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestBlock(t *testing.T) {
}

func TestValidators(t *testing.T) {
kill, port, _ := junkInit(t)
kill, port, _ := setupEnvironment(t)
defer kill()

time.Sleep(time.Second * 2) // TODO: LOL -> wait for blocks
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestValidators(t *testing.T) {
}

func TestCoinSend(t *testing.T) {
kill, port, seed := junkInit(t)
kill, port, seed := setupEnvironment(t)
defer kill()

time.Sleep(time.Second * 2) // TO
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestCoinSend(t *testing.T) {
}

func TestTxs(t *testing.T) {
kill, port, seed := junkInit(t)
kill, port, seed := setupEnvironment(t)
defer kill()

// TODO: re-enable once we can get txs by tag
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestTxs(t *testing.T) {
// helpers

// TODO/XXX: We should be spawning what we need in process, not shelling out
func junkInit(t *testing.T) (kill func(), port string, seed string) {
func setupEnvironment(t *testing.T) (kill func(), port string, seed string) {
dir, err := ioutil.TempDir("", "tmp-basecoin-")
require.Nil(t, err)

Expand Down
4 changes: 2 additions & 2 deletions client/tx/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"net/http"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/builder"
)

type BroadcastTxBody struct {
Expand All @@ -22,7 +22,7 @@ func BroadcastTxRequestHandler(w http.ResponseWriter, r *http.Request) {
return
}

res, err := client.BroadcastTx([]byte(m.TxBytes))
res, err := builder.BroadcastTx([]byte(m.TxBytes))
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
Expand Down
2 changes: 1 addition & 1 deletion x/bank/commands/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (c Commander) SignMessage(msg sdk.Msg, kb cryptokeys.Keybase, accountName s
sigs := []sdk.StdSignature{{
PubKey: pubkey,
Signature: sig,
Sequence: viper.GetInt64(flagSequence),
Sequence: viper.GetInt64(client.FlagName),
}}

// marshal bytes
Expand Down
1 change: 1 addition & 0 deletions x/bank/rest/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/gorilla/mux"
)

// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(r *mux.Router, cdc *wire.Codec) {
r.HandleFunc("/accounts/{address}/send", SendRequestHandler(cdc)).Methods("POST")
}
10 changes: 5 additions & 5 deletions x/bank/rest/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ import (

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/builder"
"github.com/cosmos/cosmos-sdk/client/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/bank/commands"
)

type SendBody struct {
type sendBody struct {
// fees is not used currently
// Fees sdk.Coin `json="fees"`
Amount sdk.Coins `json:"amount"`
LocalAccountName string `json:"name"`
Password string `json:"password"`
ChainID string `json:"chain_id"`
Sequence string `json:"sequence"`
Sequence int64 `json:"sequence"`
}

// SendRequestHandler - http request handler to send coins to a address
func SendRequestHandler(cdc *wire.Codec) func(http.ResponseWriter, *http.Request) {
c := commands.Commander{cdc}
return func(w http.ResponseWriter, r *http.Request) {
// collect data
vars := mux.Vars(r)
address := vars["address"]

var m SendBody
var m sendBody
body, err := ioutil.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
Expand Down Expand Up @@ -92,7 +92,7 @@ func SendRequestHandler(cdc *wire.Codec) func(http.ResponseWriter, *http.Request
}

// send
res, err := client.BroadcastTx(txBytes)
res, err := builder.BroadcastTx(txBytes)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
Expand Down

0 comments on commit 5ea0663

Please sign in to comment.