2018-08-23 02:34:59 -07:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2018-08-30 01:24:56 -07:00
|
|
|
"bytes"
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-08-30 01:24:56 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/server/mock"
|
|
|
|
"github.com/stretchr/testify/require"
|
2018-08-23 02:34:59 -07:00
|
|
|
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
2018-08-30 01:24:56 -07:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
2018-08-23 02:34:59 -07:00
|
|
|
"io"
|
2018-08-30 01:24:56 -07:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
2018-08-23 02:34:59 -07:00
|
|
|
|
|
|
|
func TestEmptyState(t *testing.T) {
|
|
|
|
defer setupViper(t)()
|
|
|
|
logger := log.NewNopLogger()
|
|
|
|
cfg, err := tcmd.ParseConfig()
|
|
|
|
require.Nil(t, err)
|
|
|
|
ctx := NewContext(cfg, logger)
|
2018-09-13 11:17:32 -07:00
|
|
|
cdc := codec.New()
|
2018-08-23 02:34:59 -07:00
|
|
|
appInit := AppInit{
|
|
|
|
AppGenTx: mock.AppGenTx,
|
|
|
|
AppGenState: mock.AppGenStateEmpty,
|
|
|
|
}
|
|
|
|
cmd := InitCmd(ctx, cdc, appInit)
|
|
|
|
err = cmd.RunE(nil, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
old := os.Stdout
|
|
|
|
r, w, _ := os.Pipe()
|
|
|
|
os.Stdout = w
|
|
|
|
cmd = ExportCmd(ctx, cdc, nil)
|
|
|
|
err = cmd.RunE(nil, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
outC := make(chan string)
|
|
|
|
go func() {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
io.Copy(&buf, r)
|
|
|
|
outC <- buf.String()
|
|
|
|
}()
|
|
|
|
|
|
|
|
w.Close()
|
|
|
|
os.Stdout = old
|
|
|
|
out := <-outC
|
|
|
|
require.Contains(t, out, "WARNING: State is not initialized")
|
|
|
|
require.Contains(t, out, "genesis_time")
|
|
|
|
require.Contains(t, out, "chain_id")
|
|
|
|
require.Contains(t, out, "consensus_params")
|
|
|
|
require.Contains(t, out, "validators")
|
|
|
|
require.Contains(t, out, "app_hash")
|
|
|
|
}
|