Rework the process of loading a genesis.json file to load a starting app state and set of initial transactions to process.
* New function to create genesis account from MsgCreateValidator
* Add arg to PrintUnsignedStdTx() to actually operate in offline mode
* New func processStdTxs()
* Remove gen-tx command
* Cleanup, return validators as they need to be written into genesis.json
* Modify gaiad init to allow auto-create of stdTx
* Remove server/testnet.go
* Don't load node_key.json, which might not be available
* Get the txs through DeliverTx
* Add app.slashingKeeper.AddValidators at the end of genesis
* On InitChain(), Signature's account number must be 0
* Add (tentative?) command to generate {node_key,priv_validator}.json files
* Reintroduce gaiad testnet
* Prompt user for passwords
* Update gaia to work with auth.StdTx
* Remove test_utils, NewTestGaiaAppGenState is now deprecated
* Combine --genesis-format and --generate-only
* Improve sign command's --offline flag documentation
* Moniker must be set
* Call app.slashingKeeper.AddValidators() even if len(txs) == 0
* Refactoring, introduce gaiad init --skip-genesis, code cleanup
* Drop unnecessary workaround to make lcd_tests pass
* Reintroduce gentx
* Simple name changes, GenesisState.Txs -> .GenTxs; OWK -> OverwriteKey; OverwriteKeys -> OverwriteKey
108 lines
2.4 KiB
Go
108 lines
2.4 KiB
Go
package tests
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
|
)
|
|
|
|
// ExecuteT executes the command, pipes any input to STDIN and return STDOUT,
|
|
// logging STDOUT/STDERR to t.
|
|
// nolint: errcheck
|
|
func ExecuteT(t *testing.T, cmd, input string) (stdout, stderr string) {
|
|
t.Log("Running", cmn.Cyan(cmd))
|
|
|
|
// split cmd to name and args
|
|
split := strings.Split(cmd, " ")
|
|
require.True(t, len(split) > 0, "no command provided")
|
|
name, args := split[0], []string(nil)
|
|
if len(split) > 1 {
|
|
args = split[1:]
|
|
}
|
|
|
|
proc, err := StartProcess("", name, args)
|
|
require.NoError(t, err)
|
|
|
|
// if input is provided, pass it to STDIN and close the pipe
|
|
if input != "" {
|
|
_, err = io.WriteString(proc.StdinPipe, input)
|
|
require.NoError(t, err)
|
|
proc.StdinPipe.Close()
|
|
}
|
|
|
|
outbz, errbz, err := proc.ReadAll()
|
|
if err != nil {
|
|
fmt.Println("Err on proc.ReadAll()", err, args)
|
|
}
|
|
|
|
proc.Wait()
|
|
|
|
if len(outbz) > 0 {
|
|
t.Log("Stdout:", cmn.Green(string(outbz)))
|
|
}
|
|
|
|
if len(errbz) > 0 {
|
|
t.Log("Stderr:", cmn.Red(string(errbz)))
|
|
}
|
|
|
|
stdout = strings.Trim(string(outbz), "\n")
|
|
stderr = strings.Trim(string(errbz), "\n")
|
|
|
|
return
|
|
}
|
|
|
|
// Execute the command, launch goroutines to log stdout/err to t.
|
|
// Caller should wait for .Wait() or .Stop() to terminate.
|
|
func GoExecuteT(t *testing.T, cmd string) (proc *Process) {
|
|
t.Log("Running", cmn.Cyan(cmd))
|
|
|
|
// Split cmd to name and args.
|
|
split := strings.Split(cmd, " ")
|
|
require.True(t, len(split) > 0, "no command provided")
|
|
name, args := split[0], []string(nil)
|
|
if len(split) > 1 {
|
|
args = split[1:]
|
|
}
|
|
|
|
// Start process.
|
|
proc, err := StartProcess("", name, args)
|
|
require.NoError(t, err)
|
|
return proc
|
|
}
|
|
|
|
// Same as GoExecuteT but spawns a go routine to ReadAll off stdout.
|
|
func GoExecuteTWithStdout(t *testing.T, cmd string) (proc *Process) {
|
|
t.Log("Running", cmn.Cyan(cmd))
|
|
|
|
// Split cmd to name and args.
|
|
split := strings.Split(cmd, " ")
|
|
require.True(t, len(split) > 0, "no command provided")
|
|
name, args := split[0], []string(nil)
|
|
if len(split) > 1 {
|
|
args = split[1:]
|
|
}
|
|
|
|
// Start process.
|
|
proc, err := CreateProcess("", name, args)
|
|
require.NoError(t, err)
|
|
|
|
// Without this, the test halts ?!
|
|
go func() {
|
|
_, err := ioutil.ReadAll(proc.StdoutPipe)
|
|
if err != nil {
|
|
fmt.Println("-------------ERR-----------------------", err)
|
|
return
|
|
}
|
|
}()
|
|
|
|
err = proc.Cmd.Start()
|
|
require.NoError(t, err)
|
|
proc.Pid = proc.Cmd.Process.Pid
|
|
return proc
|
|
}
|