2018-04-06 22:12:00 -07:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2018-07-25 14:10:07 -07:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-04-06 22:12:00 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
2018-04-06 22:50:46 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
2018-07-25 14:10:07 -07:00
|
|
|
"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
|
|
|
|
2018-06-28 17:54:47 -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{
|
2018-04-06 22:50:46 -07:00
|
|
|
Accounts: genaccs,
|
2018-04-30 23:07:06 -07:00
|
|
|
StakeData: stake.DefaultGenesisState(),
|
2018-04-06 22:12:00 -07:00
|
|
|
}
|
|
|
|
|
2018-09-13 11:17:32 -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
|
2018-10-03 08:48:23 -07:00
|
|
|
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
|
|
|
|
}
|
2018-07-25 14:10:07 -07:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|