fixed some tests
This commit is contained in:
parent
b44690563a
commit
579bd56127
|
@ -1 +1 @@
|
|||
keys.db
|
||||
tmp-base*
|
|
@ -28,7 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestKeys(t *testing.T) {
|
||||
kill, port := junkInit(t)
|
||||
kill, port, _ := junkInit(t)
|
||||
defer kill()
|
||||
|
||||
// empty keys
|
||||
|
@ -96,19 +96,19 @@ func TestKeys(t *testing.T) {
|
|||
}
|
||||
|
||||
// TODO/XXX: We should be spawning what we need in process, not shelling out
|
||||
func junkInit(t *testing.T) (kill func(), port string) {
|
||||
tests.TestInitBasecoin(t)
|
||||
func junkInit(t *testing.T) (kill func(), port string, seed string) {
|
||||
seed = tests.TestInitBasecoin(t)
|
||||
cmdStart := tests.StartNodeServerForTest(t)
|
||||
cmdLCD, port := tests.StartLCDServerForTest(t)
|
||||
kill = func() {
|
||||
cmdLCD.Process.Kill()
|
||||
cmdStart.Process.Kill()
|
||||
}
|
||||
return kill, port
|
||||
return kill, port, seed
|
||||
}
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
kill, port := junkInit(t)
|
||||
kill, port, _ := junkInit(t)
|
||||
defer kill()
|
||||
|
||||
// node info
|
||||
|
@ -122,7 +122,7 @@ func TestVersion(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNodeStatus(t *testing.T) {
|
||||
kill, port := junkInit(t)
|
||||
kill, port, _ := junkInit(t)
|
||||
defer kill()
|
||||
|
||||
// node info
|
||||
|
@ -143,25 +143,14 @@ func TestNodeStatus(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBlock(t *testing.T) {
|
||||
kill, port := junkInit(t)
|
||||
kill, port, _ := junkInit(t)
|
||||
defer kill()
|
||||
|
||||
// res, body := request(t, port, "GET", "/blocks/latest", nil)
|
||||
// require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
var resultBlock ctypes.ResultBlock
|
||||
|
||||
// var m ctypes.ResultBlock
|
||||
// decoder := json.NewDecoder(res.Body)
|
||||
// err := decoder.Decode(&m)
|
||||
// require.Nil(t, err, "Couldn't parse block")
|
||||
|
||||
// assert.NotEqual(t, ctypes.ResultBlock{}, m)
|
||||
|
||||
// --
|
||||
|
||||
res, body := request(t, port, "GET", "/blocks/1", nil)
|
||||
res, body := request(t, port, "GET", "/blocks/latest", nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
var resultBlock ctypes.ResultBlock
|
||||
err := json.Unmarshal([]byte(body), &resultBlock)
|
||||
require.Nil(t, err, "Couldn't parse block")
|
||||
|
||||
|
@ -169,30 +158,29 @@ func TestBlock(t *testing.T) {
|
|||
|
||||
// --
|
||||
|
||||
res, body = request(t, port, "GET", "/blocks/2", nil)
|
||||
res, body = request(t, port, "GET", "/blocks/1", nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
err = json.Unmarshal([]byte(body), &resultBlock)
|
||||
require.Nil(t, err, "Couldn't parse block")
|
||||
|
||||
assert.NotEqual(t, ctypes.ResultBlock{}, resultBlock)
|
||||
|
||||
// --
|
||||
|
||||
res, body = request(t, port, "GET", "/blocks/1000000000", nil)
|
||||
require.Equal(t, http.StatusNotFound, res.StatusCode, body)
|
||||
}
|
||||
|
||||
func TestValidators(t *testing.T) {
|
||||
kill, port := junkInit(t)
|
||||
kill, port, _ := junkInit(t)
|
||||
defer kill()
|
||||
|
||||
// res, body := request(t, port, "GET", "/validatorsets/latest", nil)
|
||||
// require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
var resultVals ctypes.ResultValidators
|
||||
|
||||
// var m ctypes.ResultValidators
|
||||
// decoder := json.NewDecoder(res.Body)
|
||||
// err := decoder.Decode(&m)
|
||||
// require.Nil(t, err, "Couldn't parse validatorset")
|
||||
|
||||
// assert.NotEqual(t, ctypes.ResultValidators{}, m)
|
||||
|
||||
// --
|
||||
|
||||
res, body := request(t, port, "GET", "/validatorsets/1", nil)
|
||||
res, body := request(t, port, "GET", "/validatorsets/latest", nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
var resultVals ctypes.ResultValidators
|
||||
err := json.Unmarshal([]byte(body), &resultVals)
|
||||
require.Nil(t, err, "Couldn't parse validatorset")
|
||||
|
||||
|
@ -200,12 +188,22 @@ func TestValidators(t *testing.T) {
|
|||
|
||||
// --
|
||||
|
||||
res, body = request(t, port, "GET", "/validatorsets/2", nil)
|
||||
res, body = request(t, port, "GET", "/validatorsets/1", nil)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
err = json.Unmarshal([]byte(body), &resultVals)
|
||||
require.Nil(t, err, "Couldn't parse validatorset")
|
||||
|
||||
assert.NotEqual(t, ctypes.ResultValidators{}, resultVals)
|
||||
|
||||
// --
|
||||
|
||||
res, body = request(t, port, "GET", "/validatorsets/1000000000", nil)
|
||||
require.Equal(t, http.StatusNotFound, res.StatusCode)
|
||||
}
|
||||
|
||||
func TestCoinSend(t *testing.T) {
|
||||
kill, port := junkInit(t)
|
||||
kill, port, _ := junkInit(t)
|
||||
defer kill()
|
||||
|
||||
// TODO make that account has coins
|
||||
|
|
|
@ -101,12 +101,12 @@ func BlockRequestHandler(w http.ResponseWriter, r *http.Request) {
|
|||
w.Write([]byte("ERROR: Couldn't parse block height. Assumed format is '/block/{height}'."))
|
||||
return
|
||||
}
|
||||
// chainHeight, err := GetChainHeight()
|
||||
// if height > chainHeight {
|
||||
// w.WriteHeader(404)
|
||||
// w.Write([]byte("ERROR: Requested block height is bigger then the chain length."))
|
||||
// return
|
||||
// }
|
||||
chainHeight, err := GetChainHeight()
|
||||
if height > chainHeight {
|
||||
w.WriteHeader(404)
|
||||
w.Write([]byte("ERROR: Requested block height is bigger then the chain length."))
|
||||
return
|
||||
}
|
||||
output, err := getBlock(&height)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
|
|
|
@ -47,8 +47,8 @@ func initClientCommand() *cobra.Command {
|
|||
func RegisterRoutes(r *mux.Router) {
|
||||
r.HandleFunc("/node_info", NodeInfoRequestHandler).Methods("GET")
|
||||
r.HandleFunc("/syncing", NodeSyncingRequestHandler).Methods("GET")
|
||||
// r.HandleFunc("/blocks/latest", LatestBlockRequestHandler).Methods("GET")
|
||||
r.HandleFunc("/blocks/latest", LatestBlockRequestHandler).Methods("GET")
|
||||
r.HandleFunc("/blocks/{height}", BlockRequestHandler).Methods("GET")
|
||||
// r.HandleFunc("/validatorsets/latest", LatestValidatorsetRequestHandler).Methods("GET")
|
||||
r.HandleFunc("/validatorsets/latest", LatestValidatorsetRequestHandler).Methods("GET")
|
||||
r.HandleFunc("/validatorsets/{height}", ValidatorsetRequestHandler).Methods("GET")
|
||||
}
|
||||
|
|
|
@ -78,12 +78,12 @@ func ValidatorsetRequestHandler(w http.ResponseWriter, r *http.Request) {
|
|||
w.Write([]byte("ERROR: Couldn't parse block height. Assumed format is '/validatorsets/{height}'."))
|
||||
return
|
||||
}
|
||||
// chainHeight, err := GetChainHeight()
|
||||
// if height > chainHeight {
|
||||
// w.WriteHeader(404)
|
||||
// w.Write([]byte("ERROR: Requested block height is bigger then the chain length."))
|
||||
// return
|
||||
// }
|
||||
chainHeight, err := GetChainHeight()
|
||||
if height > chainHeight {
|
||||
w.WriteHeader(404)
|
||||
w.Write([]byte("ERROR: Requested block height is bigger then the chain length."))
|
||||
return
|
||||
}
|
||||
output, err := getValidators(&height)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
|
|
|
@ -49,20 +49,16 @@ func whereIsBasecli() string {
|
|||
}
|
||||
|
||||
// Init Basecoin Test
|
||||
func TestInitBasecoin(t *testing.T) {
|
||||
func TestInitBasecoin(t *testing.T) string {
|
||||
Clean()
|
||||
|
||||
var err error
|
||||
|
||||
password := "some-random-password"
|
||||
usePassword := exec.Command("echo", password)
|
||||
|
||||
initBasecoind := exec.Command(whereIsBasecoind(), "init", "--home", basecoindDir)
|
||||
|
||||
initBasecoind.Stdin, err = usePassword.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cmdWriter, err := initBasecoind.StdinPipe()
|
||||
require.Nil(t, err)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
initBasecoind.Stdout = buf
|
||||
|
@ -70,32 +66,32 @@ func TestInitBasecoin(t *testing.T) {
|
|||
if err := initBasecoind.Start(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := usePassword.Run(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = cmdWriter.Write([]byte(password))
|
||||
require.Nil(t, err)
|
||||
cmdWriter.Close()
|
||||
|
||||
if err := initBasecoind.Wait(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err := makeKeys(); err != nil {
|
||||
t.Error(err)
|
||||
// get seed from initialization
|
||||
theOutput := strings.Split(buf.String(), "\n")
|
||||
var seedLine int
|
||||
for seedLine, o := range theOutput {
|
||||
if strings.HasPrefix(string(o), "Secret phrase") {
|
||||
seedLine++
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("-----------------")
|
||||
theOutput := strings.Split(buf.String(), "\n")
|
||||
for i, o := range theOutput {
|
||||
fmt.Println(i, o)
|
||||
}
|
||||
fmt.Println("-----------------")
|
||||
return string(theOutput[seedLine])
|
||||
}
|
||||
|
||||
func makeKeys() error {
|
||||
var err error
|
||||
for _, acc := range ACCOUNTS {
|
||||
pass := exec.Command("echo", "1234567890")
|
||||
makeKeys := exec.Command(whereIsBasecli(), "keys", "add", acc, "--home", basecliDir)
|
||||
|
||||
makeKeys.Stdin, err = pass.StdoutPipe()
|
||||
cmdWriter, err := makeKeys.StdinPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -104,9 +100,11 @@ func makeKeys() error {
|
|||
if err := makeKeys.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := pass.Run(); err != nil {
|
||||
cmdWriter.Write([]byte("1234567890"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmdWriter.Close()
|
||||
|
||||
if err := makeKeys.Wait(); err != nil {
|
||||
return err
|
||||
|
@ -176,6 +174,7 @@ func StartServer() error {
|
|||
|
||||
// Init Basecoin Test
|
||||
func InitServerForTest(t *testing.T) {
|
||||
// TODO cleanup doesn't work -> keys are still there in each iteration
|
||||
Clean()
|
||||
|
||||
var err error
|
||||
|
|
|
@ -40,7 +40,7 @@ func QueryAccountRequestHandler(storeName string, cdc *wire.Codec, parser sdk.Pa
|
|||
}
|
||||
|
||||
// the query will return empty if there is no data for this account
|
||||
if len(res) == 0 {
|
||||
if res == nil {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue