-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #6033: Add setup for cli_test
- Loading branch information
1 parent
5a9d3cf
commit 3b71198
Showing
15 changed files
with
778 additions
and
8 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
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,13 @@ | ||
package helpers | ||
|
||
const ( | ||
Denom = "stake" | ||
KeyFoo = "foo" | ||
KeyBar = "bar" | ||
FooDenom = "footoken" | ||
FeeDenom = "feetoken" | ||
Fee2Denom = "fee2token" | ||
KeyBaz = "baz" | ||
KeyVesting = "vesting" | ||
KeyFooBarBaz = "foobarbaz" | ||
) |
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,49 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/tests" | ||
) | ||
|
||
func ExecuteWriteCheckErr(t *testing.T, cmdStr string, writes ...string) { | ||
require.True(t, ExecuteWrite(t, cmdStr, writes...)) | ||
} | ||
|
||
func ExecuteWrite(t *testing.T, cmdStr string, writes ...string) (exitSuccess bool) { | ||
exitSuccess, _, _ = ExecuteWriteRetStdStreams(t, cmdStr, writes...) | ||
return | ||
} | ||
|
||
func ExecuteWriteRetStdStreams(t *testing.T, cmdStr string, writes ...string) (bool, string, string) { | ||
proc := tests.GoExecuteT(t, cmdStr) | ||
|
||
// Enables use of interactive commands | ||
for _, write := range writes { | ||
_, err := proc.StdinPipe.Write([]byte(write + "\n")) | ||
require.NoError(t, err) | ||
} | ||
|
||
// Read both stdout and stderr from the process | ||
stdout, stderr, err := proc.ReadAll() | ||
if err != nil { | ||
fmt.Println("Err on proc.ReadAll()", err, cmdStr) | ||
} | ||
|
||
// Log output. | ||
if len(stdout) > 0 { | ||
t.Log("Stdout:", string(stdout)) | ||
} | ||
if len(stderr) > 0 { | ||
t.Log("Stderr:", string(stderr)) | ||
} | ||
|
||
// Wait for process to exit | ||
proc.Wait() | ||
|
||
// Return succes, stdout, stderr | ||
return proc.ExitState.Success(), string(stdout), string(stderr) | ||
} |
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,78 @@ | ||
package helpers | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/std" | ||
"github.com/stretchr/testify/require" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
"github.com/cosmos/cosmos-sdk/simapp" | ||
) | ||
|
||
var cdc = std.MakeCodec(simapp.ModuleBasics) | ||
|
||
// Fixtures is used to setup the testing environment | ||
type Fixtures struct { | ||
BuildDir string | ||
RootDir string | ||
SimdBinary string | ||
SimcliBinary string | ||
ChainID string | ||
RPCAddr string | ||
Port string | ||
SimdHome string | ||
SimcliHome string | ||
P2PAddr string | ||
Cdc *codec.Codec | ||
T *testing.T | ||
} | ||
|
||
// NewFixtures creates a new instance of Fixtures with many vars set | ||
func NewFixtures(t *testing.T) *Fixtures { | ||
tmpDir, err := ioutil.TempDir("", "sdk_integration_"+t.Name()+"_") | ||
require.NoError(t, err) | ||
|
||
servAddr, port, err := server.FreeTCPAddr() | ||
require.NoError(t, err) | ||
|
||
p2pAddr, _, err := server.FreeTCPAddr() | ||
require.NoError(t, err) | ||
|
||
buildDir := os.Getenv("BUILDDIR") | ||
require.NotNil(t, buildDir) | ||
|
||
return &Fixtures{ | ||
T: t, | ||
BuildDir: buildDir, | ||
RootDir: tmpDir, | ||
SimdBinary: filepath.Join(buildDir, "simd"), | ||
SimcliBinary: filepath.Join(buildDir, "simcli"), | ||
SimdHome: filepath.Join(tmpDir, ".simd"), | ||
SimcliHome: filepath.Join(tmpDir, ".simcli"), | ||
RPCAddr: servAddr, | ||
P2PAddr: p2pAddr, | ||
Cdc: cdc, | ||
Port: port, | ||
} | ||
} | ||
|
||
// GenesisFile returns the path of the genesis file | ||
func (f Fixtures) GenesisFile() string { | ||
return filepath.Join(f.SimdHome, "config", "genesis.json") | ||
} | ||
|
||
// GenesisFile returns the application's genesis state | ||
func (f Fixtures) GenesisState() simapp.GenesisState { | ||
genDoc, err := tmtypes.GenesisDocFromFile(f.GenesisFile()) | ||
require.NoError(f.T, err) | ||
|
||
var appState simapp.GenesisState | ||
require.NoError(f.T, f.Cdc.UnmarshalJSON(genDoc.AppState, &appState)) | ||
return appState | ||
} |
Oops, something went wrong.