From 8fe12743231ee909ea7dac0eeaedfe07cb3cc121 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 1 Apr 2015 05:12:38 -0700 Subject: [PATCH] rpc: myriad little fixes --- rpc/client.go | 2 -- rpc/core/accounts.go | 4 ++-- rpc/http_server.go | 4 ++-- rpc/test/test.go | 27 +++++++++++++++++++++++++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index 7b9e55410..31e3334d3 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -2,7 +2,6 @@ package rpc import ( "bytes" - "encoding/hex" "encoding/json" "fmt" "github.com/tendermint/tendermint2/binary" @@ -10,7 +9,6 @@ import ( "net/http" "net/url" "reflect" - "strconv" ) type Response struct { diff --git a/rpc/core/accounts.go b/rpc/core/accounts.go index 55c9b38e2..89179f442 100644 --- a/rpc/core/accounts.go +++ b/rpc/core/accounts.go @@ -10,9 +10,9 @@ func GenPrivAccount() (*ResponseGenPrivAccount, error) { return &ResponseGenPrivAccount{account.GenPrivAccount()}, nil } -func GetAccount(addr []byte) (*ResponseGetAccount, error) { +func GetAccount(address []byte) (*ResponseGetAccount, error) { cache := mempoolReactor.Mempool.GetCache() - return &ResponseGetAccount{cache.GetAccount(addr)}, nil + return &ResponseGetAccount{cache.GetAccount(address)}, nil } func GetStorage(address, slot []byte) (*ResponseGetStorage, error) { diff --git a/rpc/http_server.go b/rpc/http_server.go index 8551e2bb9..4bf345ba9 100644 --- a/rpc/http_server.go +++ b/rpc/http_server.go @@ -27,7 +27,7 @@ type RPCResponse struct { Result interface{} `json:"result"` Error string `json:"error"` Id string `json:"id"` - JSONRPC int `json:"jsonrpc"` + JSONRPC string `json:"jsonrpc"` } func NewRPCResponse(res interface{}, err string) RPCResponse { @@ -38,7 +38,7 @@ func NewRPCResponse(res interface{}, err string) RPCResponse { Result: res, Error: err, Id: "", - JSONRPC: 2, + JSONRPC: "2.0", } } diff --git a/rpc/test/test.go b/rpc/test/test.go index 8d87fde33..3921f8ec6 100644 --- a/rpc/test/test.go +++ b/rpc/test/test.go @@ -3,7 +3,6 @@ package rpc import ( "bytes" "encoding/hex" - "encoding/json" "github.com/tendermint/tendermint2/account" "github.com/tendermint/tendermint2/binary" "github.com/tendermint/tendermint2/config" @@ -12,6 +11,7 @@ import ( "github.com/tendermint/tendermint2/p2p" "github.com/tendermint/tendermint2/rpc" "github.com/tendermint/tendermint2/rpc/core" + "github.com/tendermint/tendermint2/state" "github.com/tendermint/tendermint2/types" "io/ioutil" "net/http" @@ -61,12 +61,35 @@ func init() { app.Set("Log.Stdout.Level", "debug") config.SetApp(app) logger.Reset() + + priv := state.LoadPrivValidator(rootDir + "/priv_validator.json") + priv.LastHeight = 0 + priv.LastRound = 0 + priv.LastStep = 0 + priv.Save() + // start a node ready := make(chan struct{}) go newNode(ready) <-ready } +func getAccount(t *testing.T, typ string, addr []byte) *account.Account { + var client rpc.Client + switch typ { + case "JSONRPC": + client = rpc.NewClient(requestAddr, "JSONRPC") + case "HTTP": + client = rpc.NewClient(requestAddr, "HTTP") + } + ac, err := client.GetAccount(addr) + if err != nil { + t.Fatal(err) + } + return ac.Account +} + +/* func getAccount(t *testing.T, typ string, addr []byte) *account.Account { var resp *http.Response var err error @@ -107,7 +130,7 @@ func getAccount(t *testing.T, typ string, addr []byte) *account.Account { t.Fatal(err) } return response.Result.Account -} +}*/ func makeSendTx(t *testing.T, typ string, from, to []byte, amt uint64) *types.SendTx { acc := getAccount(t, typ, from)