71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// InitFixtures is called at the beginning of a test and initializes a chain
|
|
// with 1 validator.
|
|
func InitFixtures(t *testing.T) (f *Fixtures) {
|
|
f = NewFixtures(t)
|
|
|
|
// reset test state
|
|
f.UnsafeResetAll()
|
|
|
|
f.CLIConfig("keyring-backend", "test")
|
|
|
|
// ensure keystore has foo and bar keys
|
|
f.KeysDelete(KeyFoo)
|
|
f.KeysDelete(KeyBar)
|
|
f.KeysDelete(KeyBar)
|
|
f.KeysDelete(KeyFooBarBaz)
|
|
f.KeysAdd(KeyFoo)
|
|
f.KeysAdd(KeyBar)
|
|
f.KeysAdd(KeyBaz)
|
|
f.KeysAdd(KeyVesting)
|
|
f.KeysAdd(KeyFooBarBaz, "--multisig-threshold=2", fmt.Sprintf(
|
|
"--multisig=%s,%s,%s", KeyFoo, KeyBar, KeyBaz))
|
|
|
|
// ensure that CLI output is in JSON format
|
|
f.CLIConfig("output", "json")
|
|
|
|
// NOTE: SDInit sets the ChainID
|
|
f.SDInit(KeyFoo)
|
|
|
|
f.CLIConfig("chain-id", f.ChainID)
|
|
f.CLIConfig("broadcast-mode", "block")
|
|
f.CLIConfig("trust-node", "true")
|
|
|
|
// start an account with tokens
|
|
f.AddGenesisAccount(f.KeyAddress(KeyFoo), startCoins)
|
|
f.AddGenesisAccount(
|
|
f.KeyAddress(KeyVesting), startCoins,
|
|
fmt.Sprintf("--vesting-amount=%s", vestingCoins),
|
|
fmt.Sprintf("--vesting-start-time=%d", time.Now().UTC().UnixNano()),
|
|
fmt.Sprintf("--vesting-end-time=%d", time.Now().Add(60*time.Second).UTC().UnixNano()),
|
|
)
|
|
|
|
f.GenTx(KeyFoo)
|
|
f.CollectGenTxs()
|
|
|
|
return f
|
|
}
|
|
|
|
// Cleanup is meant to be run at the end of a test to clean up an remaining test state
|
|
func (f *Fixtures) Cleanup(dirs ...string) {
|
|
clean := append(dirs, f.RootDir)
|
|
for _, d := range clean {
|
|
require.NoError(f.T, os.RemoveAll(d))
|
|
}
|
|
}
|
|
|
|
// Flags returns the flags necessary for making most CLI calls
|
|
func (f *Fixtures) Flags() string {
|
|
return fmt.Sprintf("--home=%s --node=%s", f.SimcliHome, f.RPCAddr)
|
|
}
|