Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lcd test cleanup #625

Merged
merged 3 commits into from
Mar 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func SignAndBuild(name, passphrase string, msg sdk.Msg, cdc *wire.Codec) ([]byte

// sign and build
bz := signMsg.Bytes()

sig, pubkey, err := keybase.Sign(name, passphrase, bz)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions client/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
dbm "github.com/tendermint/tmlibs/db"
)

// TODO explain what the keybase is used for
// GetKeyBase initializes a keybase based on the configuration
// GetKeyBase initializes a keybase based on the given db.
// The KeyBase manages all activity requiring access to a key.
func GetKeyBase(db dbm.DB) keys.Keybase {
keybase := keys.New(
db,
Expand Down
69 changes: 69 additions & 0 deletions client/lcd/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package lcd

// NOTE: COPIED VERBATIM FROM tendermint/tendermint/rpc/test/helpers.go

import (
"fmt"
"os"
"path/filepath"
"strings"

cmn "github.com/tendermint/tmlibs/common"

cfg "github.com/tendermint/tendermint/config"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
)

var globalConfig *cfg.Config

func waitForRPC() {
laddr := GetConfig().RPC.ListenAddress
fmt.Println("LADDR", laddr)
client := rpcclient.NewJSONRPCClient(laddr)
result := new(ctypes.ResultStatus)
for {
_, err := client.Call("status", map[string]interface{}{}, result)
if err == nil {
return
}
}
}

// f**ing long, but unique for each test
func makePathname() string {
// get path
p, err := os.Getwd()
if err != nil {
panic(err)
}
// fmt.Println(p)
sep := string(filepath.Separator)
return strings.Replace(p, sep, "_", -1)
}

func randPort() int {
return int(cmn.RandUint16()/2 + 10000)
}

func makeAddrs() (string, string, string) {
start := randPort()
return fmt.Sprintf("tcp://0.0.0.0:%d", start),
fmt.Sprintf("tcp://0.0.0.0:%d", start+1),
fmt.Sprintf("tcp://0.0.0.0:%d", start+2)
}

// GetConfig returns a config for the test cases as a singleton
func GetConfig() *cfg.Config {
if globalConfig == nil {
pathname := makePathname()
globalConfig = cfg.ResetTestRoot(pathname)

// and we use random ports to run in parallel
tm, rpc, _ := makeAddrs()
globalConfig.P2P.ListenAddress = tm
globalConfig.RPC.ListenAddress = rpc
globalConfig.TxIndex.IndexTags = "app.creator" // see kvstore application
}
return globalConfig
}
Loading