0g-chain/app/app_test.go

46 lines
1.1 KiB
Go
Raw Normal View History

2019-06-20 13:37:57 +00:00
package app
import (
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
abci "github.com/tendermint/tendermint/abci/types"
)
2019-07-18 17:36:31 +00:00
func TestExport(t *testing.T) {
db := db.NewMemDB()
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
setGenesis(app)
2019-06-20 13:37:57 +00:00
2019-07-18 17:36:31 +00:00
// Making a new app object with the db, so that initchain hasn't been called
newApp := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
_, _, err := newApp.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}
func setGenesis(app *App) error {
genesisState := NewDefaultGenesisState()
2019-06-20 13:37:57 +00:00
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
2019-07-18 17:36:31 +00:00
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)
2019-06-20 17:28:21 +00:00
app.Commit()
2019-06-20 13:37:57 +00:00
return nil
}