0g-chain/app/app_test.go

66 lines
1.8 KiB
Go
Raw Normal View History

2019-06-20 13:37:57 +00:00
package app
import (
"os"
"testing"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/crisis"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
abci "github.com/tendermint/tendermint/abci/types"
)
2019-06-20 17:28:21 +00:00
func setGenesis(app *App, accs ...*auth.BaseAccount) error {
2019-06-20 13:37:57 +00:00
genaccs := make([]GenesisAccount, len(accs))
for i, acc := range accs {
genaccs[i] = NewGenesisAccount(acc)
}
genesisState := NewGenesisState(
genaccs,
auth.DefaultGenesisState(),
bank.DefaultGenesisState(),
staking.DefaultGenesisState(),
mint.DefaultGenesisState(),
distr.DefaultGenesisState(),
gov.DefaultGenesisState(),
crisis.DefaultGenesisState(),
slashing.DefaultGenesisState(),
)
2019-06-20 17:28:21 +00:00
stateBytes, err := codec.MarshalJSONIndent(app.cdc, genesisState)
2019-06-20 13:37:57 +00:00
if err != nil {
return err
}
// Initialize the chain
vals := []abci.ValidatorUpdate{}
2019-06-20 17:28:21 +00:00
app.InitChain(abci.RequestInitChain{Validators: vals, AppStateBytes: stateBytes})
app.Commit()
2019-06-20 13:37:57 +00:00
return nil
}
2019-06-20 17:08:58 +00:00
func TestExport(t *testing.T) {
2019-06-20 13:37:57 +00:00
db := db.NewMemDB()
2019-06-20 17:28:21 +00:00
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
setGenesis(app)
2019-06-20 13:37:57 +00:00
// Making a new app object with the db, so that initchain hasn't been called
2019-06-20 17:28:21 +00:00
newApp := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
_, _, err := newApp.ExportAppStateAndValidators(false, []string{})
2019-06-20 13:37:57 +00:00
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}