Skip to content

Commit 3e547a5

Browse files
committed
Refactor TestGaiadCollectGentxs
1 parent 0e94043 commit 3e547a5

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

cmd/gaia/cli_test/cli_test.go

+22-17
Original file line numberDiff line numberDiff line change
@@ -625,33 +625,38 @@ trust-node = true
625625

626626
func TestGaiadCollectGentxs(t *testing.T) {
627627
t.Parallel()
628+
f := NewFixtures(t)
629+
628630
// Initialise temporary directories
629-
gaiadHome, gaiacliHome := getTestingHomeDirs(t.Name())
630631
gentxDir, err := ioutil.TempDir("", "")
631632
gentxDoc := filepath.Join(gentxDir, "gentx.json")
632633
require.NoError(t, err)
633634

634-
tests.ExecuteT(t, fmt.Sprintf("gaiad --home=%s unsafe-reset-all", gaiadHome), "")
635-
os.RemoveAll(filepath.Join(gaiadHome, "config", "gentx"))
636-
executeWrite(t, fmt.Sprintf("gaiacli keys delete --home=%s foo", gaiacliHome), app.DefaultKeyPass)
637-
executeWrite(t, fmt.Sprintf("gaiacli keys delete --home=%s bar", gaiacliHome), app.DefaultKeyPass)
638-
executeWriteCheckErr(t, fmt.Sprintf("gaiacli keys add --home=%s foo", gaiacliHome), app.DefaultKeyPass)
639-
executeWriteCheckErr(t, fmt.Sprintf("gaiacli keys add --home=%s bar", gaiacliHome), app.DefaultKeyPass)
640-
executeWriteCheckErr(t, fmt.Sprintf("gaiacli config --home=%s output json", gaiacliHome))
641-
fooAddr, _ := executeGetAddrPK(t, fmt.Sprintf("gaiacli keys show foo --home=%s", gaiacliHome))
635+
// Reset testing path
636+
f.UnsafeResetAll()
637+
638+
// Initialize keys
639+
f.KeysDelete(keyFoo)
640+
f.KeysDelete(keyBar)
641+
f.KeysAdd(keyFoo)
642+
f.KeysAdd(keyBar)
643+
644+
// Configure json output
645+
f.CLIConfig("output", "json")
642646

643647
// Run init
644-
_ = executeInit(t, fmt.Sprintf("gaiad init -o --moniker=foo --home=%s", gaiadHome))
648+
f.GDInit(keyFoo)
649+
645650
// Add account to genesis.json
646-
executeWriteCheckErr(t, fmt.Sprintf(
647-
"gaiad add-genesis-account %s 150%s,1000footoken --home=%s", fooAddr, stakeTypes.DefaultBondDenom, gaiadHome))
648-
executeWrite(t, fmt.Sprintf("cat %s%sconfig%sgenesis.json", gaiadHome, string(os.PathSeparator), string(os.PathSeparator)))
651+
f.AddGenesisAccount(f.KeyAddress(keyFoo), startCoins)
652+
649653
// Write gentx file
650-
executeWriteCheckErr(t, fmt.Sprintf(
651-
"gaiad gentx --name=foo --home=%s --home-client=%s --output-document=%s", gaiadHome, gaiacliHome, gentxDoc), app.DefaultKeyPass)
654+
f.GenTx(keyFoo, fmt.Sprintf("--output-document=%s", gentxDoc))
655+
652656
// Collect gentxs from a custom directory
653-
executeWriteCheckErr(t, fmt.Sprintf("gaiad collect-gentxs --home=%s --gentx-dir=%s", gaiadHome, gentxDir), app.DefaultKeyPass)
654-
cleanupDirs(gaiadHome, gaiacliHome, gentxDir)
657+
f.CollectGenTxs(fmt.Sprintf("--gentx-dir=%s", gentxDir))
658+
659+
f.Cleanup(gentxDir)
655660
}
656661

657662
// ---------------------------------------------------------------------------

cmd/gaia/cli_test/test_helpers.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,16 @@ func NewFixtures(t *testing.T) *Fixtures {
7373
}
7474

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

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

85-
func getTestingHomeDirs(name string) (string, string) {
86-
tmpDir := os.TempDir()
87-
gaiadHome := fmt.Sprintf("%s%s%s%s.test_gaiad", tmpDir, string(os.PathSeparator), name, string(os.PathSeparator))
88-
gaiacliHome := fmt.Sprintf("%s%s%s%s.test_gaiacli", tmpDir, string(os.PathSeparator), name, string(os.PathSeparator))
89-
return gaiadHome, gaiacliHome
90-
}
91-
9286
// UnsafeResetAll is gaiad unsafe-reset-all
9387
func (f *Fixtures) UnsafeResetAll(flags ...string) {
9488
cmd := fmt.Sprintf("gaiad --home=%s unsafe-reset-all", f.GDHome)

0 commit comments

Comments
 (0)