forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
297 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.