Skip to content

Commit

Permalink
Refactor TestGaiadCollectGentxs
Browse files Browse the repository at this point in the history
  • Loading branch information
jackzampolin committed Jan 8, 2019
1 parent 0e94043 commit 3e547a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
39 changes: 22 additions & 17 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,33 +625,38 @@ trust-node = true

func TestGaiadCollectGentxs(t *testing.T) {
t.Parallel()
f := NewFixtures(t)

// Initialise temporary directories
gaiadHome, gaiacliHome := getTestingHomeDirs(t.Name())
gentxDir, err := ioutil.TempDir("", "")
gentxDoc := filepath.Join(gentxDir, "gentx.json")
require.NoError(t, err)

tests.ExecuteT(t, fmt.Sprintf("gaiad --home=%s unsafe-reset-all", gaiadHome), "")
os.RemoveAll(filepath.Join(gaiadHome, "config", "gentx"))
executeWrite(t, fmt.Sprintf("gaiacli keys delete --home=%s foo", gaiacliHome), app.DefaultKeyPass)
executeWrite(t, fmt.Sprintf("gaiacli keys delete --home=%s bar", gaiacliHome), app.DefaultKeyPass)
executeWriteCheckErr(t, fmt.Sprintf("gaiacli keys add --home=%s foo", gaiacliHome), app.DefaultKeyPass)
executeWriteCheckErr(t, fmt.Sprintf("gaiacli keys add --home=%s bar", gaiacliHome), app.DefaultKeyPass)
executeWriteCheckErr(t, fmt.Sprintf("gaiacli config --home=%s output json", gaiacliHome))
fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show foo --home=%s", gaiacliHome))
// Reset testing path
f.UnsafeResetAll()

// Initialize keys
f.KeysDelete(keyFoo)
f.KeysDelete(keyBar)
f.KeysAdd(keyFoo)
f.KeysAdd(keyBar)

// Configure json output
f.CLIConfig("output", "json")

// Run init
_ = executeInit(t, fmt.Sprintf("gaiad init -o --moniker=foo --home=%s", gaiadHome))
f.GDInit(keyFoo)

// Add account to genesis.json
executeWriteCheckErr(t, fmt.Sprintf(
"gaiad add-genesis-account %s 150%s,1000footoken --home=%s", fooAddr, stakeTypes.DefaultBondDenom, gaiadHome))
executeWrite(t, fmt.Sprintf("cat %s%sconfig%sgenesis.json", gaiadHome, string(os.PathSeparator), string(os.PathSeparator)))
f.AddGenesisAccount(f.KeyAddress(keyFoo), startCoins)

// Write gentx file
executeWriteCheckErr(t, fmt.Sprintf(
"gaiad gentx --name=foo --home=%s --home-client=%s --output-document=%s", gaiadHome, gaiacliHome, gentxDoc), app.DefaultKeyPass)
f.GenTx(keyFoo, fmt.Sprintf("--output-document=%s", gentxDoc))

// Collect gentxs from a custom directory
executeWriteCheckErr(t, fmt.Sprintf("gaiad collect-gentxs --home=%s --gentx-dir=%s", gaiadHome, gentxDir), app.DefaultKeyPass)
cleanupDirs(gaiadHome, gaiacliHome, gentxDir)
f.CollectGenTxs(fmt.Sprintf("--gentx-dir=%s", gentxDir))

f.Cleanup(gentxDir)
}

// ---------------------------------------------------------------------------
Expand Down
12 changes: 3 additions & 9 deletions cmd/gaia/cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,16 @@ func NewFixtures(t *testing.T) *Fixtures {
}

// Cleanup is meant to be run at the end of a test to clean up an remaining test state
func (f *Fixtures) Cleanup() {
cleanupDirs(f.GDHome, f.GCLIHome)
func (f *Fixtures) Cleanup(dirs ...string) {
clean := append(dirs, f.GDHome, f.GCLIHome)
cleanupDirs(clean...)
}

// Flags returns the flags necessary for making most CLI calls
func (f *Fixtures) Flags() string {
return fmt.Sprintf("--home=%s --node=%s --chain-id=%s", f.GCLIHome, f.RPCAddr, f.ChainID)
}

func getTestingHomeDirs(name string) (string, string) {
tmpDir := os.TempDir()
gaiadHome := fmt.Sprintf("%s%s%s%s.test_gaiad", tmpDir, string(os.PathSeparator), name, string(os.PathSeparator))
gaiacliHome := fmt.Sprintf("%s%s%s%s.test_gaiacli", tmpDir, string(os.PathSeparator), name, string(os.PathSeparator))
return gaiadHome, gaiacliHome
}

// UnsafeResetAll is gaiad unsafe-reset-all
func (f *Fixtures) UnsafeResetAll(flags ...string) {
cmd := fmt.Sprintf("gaiad --home=%s unsafe-reset-all", f.GDHome)
Expand Down

0 comments on commit 3e547a5

Please sign in to comment.