fix tests and refactored
This commit is contained in:
parent
fa78893f40
commit
5ea06639f9
|
@ -24,7 +24,7 @@ import (
|
|||
)
|
||||
|
||||
func TestKeys(t *testing.T) {
|
||||
kill, port, _ := junkInit(t)
|
||||
kill, port, _ := setupEnvironment(t)
|
||||
defer kill()
|
||||
|
||||
// empty keys
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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()))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ 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"
|
||||
|
@ -16,16 +15,17 @@ import (
|
|||
"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) {
|
||||
|
@ -33,7 +33,7 @@ func SendRequestHandler(cdc *wire.Codec) func(http.ResponseWriter, *http.Request
|
|||
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)
|
||||
|
@ -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()))
|
||||
|
|
Loading…
Reference in New Issue