cosmos-sdk/cmd/gaia/app/app_test.go

55 lines
1.5 KiB
Go
Raw Normal View History

2018-04-06 22:12:00 -07:00
package app
import (
"os"
"testing"
"github.com/cosmos/cosmos-sdk/codec"
2018-04-06 22:12:00 -07:00
"github.com/cosmos/cosmos-sdk/x/auth"
2018-10-15 13:52:39 -07:00
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/slashing"
2018-04-06 22:50:46 -07:00
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
2018-04-06 22:12:00 -07:00
abci "github.com/tendermint/tendermint/abci/types"
2018-04-06 22:12:00 -07:00
)
2018-04-06 22:50:46 -07:00
func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error {
2018-04-06 22:12:00 -07:00
genaccs := make([]GenesisAccount, len(accs))
for i, acc := range accs {
genaccs[i] = NewGenesisAccount(acc)
}
genesisState := GenesisState{
Accounts: genaccs,
StakeData: stake.DefaultGenesisState(),
2018-10-15 13:52:39 -07:00
DistrData: distr.DefaultGenesisState(),
2018-09-10 04:59:05 -07:00
SlashingData: slashing.DefaultGenesisState(),
2018-04-06 22:12:00 -07:00
}
stateBytes, err := codec.MarshalJSONIndent(gapp.cdc, genesisState)
2018-04-06 22:12:00 -07:00
if err != nil {
return err
}
// Initialize the chain
vals := []abci.ValidatorUpdate{}
2018-06-04 16:42:01 -07:00
gapp.InitChain(abci.RequestInitChain{Validators: vals, AppStateBytes: stateBytes})
2018-04-06 22:12:00 -07:00
gapp.Commit()
return nil
}
func TestGaiadExport(t *testing.T) {
db := db.NewMemDB()
gapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil)
setGenesis(gapp)
// Making a new app object with the db, so that initchain hasn't been called
newGapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil)
_, _, err := newGapp.ExportAppStateAndValidators()
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}