init refactor

This commit is contained in:
rigelrozanski
2018-04-26 14:26:39 -04:00
parent 6748aa7bc6
commit 55c1e1dcfc
13 changed files with 187 additions and 145 deletions
+7 -7
View File
@@ -14,11 +14,11 @@ import (
bam "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
)
// NewApp creates a simple mock kvstore app for testing.
// It should work similar to a real app.
// Make sure rootDir is empty before running the test,
// NewApp creates a simple mock kvstore app for testing. It should work
// similar to a real app. Make sure rootDir is empty before running the test,
// in order to guarantee consistent results
func NewApp(rootDir string, logger log.Logger) (abci.Application, error) {
db, err := dbm.NewGoLevelDB("mock", filepath.Join(rootDir, "data"))
@@ -108,16 +108,16 @@ func InitChainer(key sdk.StoreKey) func(sdk.Context, abci.RequestInitChain) abci
// GenAppState can be passed into InitCmd, returns a static string of a few
// key-values that can be parsed by InitChainer
func GenAppState(pubKey crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState json.RawMessage, err error) {
func GenAppState(_ *wire.Codec, pubKey crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, message json.RawMessage, err error) {
chainID = cmn.Fmt("test-chain-%v", cmn.RandStr(6))
chainID = fmt.Sprintf("test-chain-%v", cmn.RandStr(6))
validators = []tmtypes.GenesisValidator{{
PubKey: pubKey,
Power: 10,
}}
appState = json.RawMessage(fmt.Sprintf(`{
appState = json.RawMessage(`{
"values": [
{
"key": "hello",
@@ -128,6 +128,6 @@ func GenAppState(pubKey crypto.PubKey) (chainID string, validators []tmtypes.Gen
"value": "bar"
}
]
}`))
}`)
return
}
+7 -2
View File
@@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/abci/types"
crypto "github.com/tendermint/go-crypto"
)
// TestInitApp makes sure we can initialize this thing without an error
@@ -21,9 +22,13 @@ func TestInitApp(t *testing.T) {
require.NoError(t, err)
// initialize it future-way
opts, err := GenInitOptions(nil, nil, "")
pubKey := crypto.GenPrivKeyEd25519().PubKey()
_, _, appState, _, err := GenAppState(nil, pubKey)
require.NoError(t, err)
req := abci.RequestInitChain{AppStateBytes: opts}
//TODO test validators in the init chain?
req := abci.RequestInitChain{
AppStateBytes: appState,
}
app.InitChain(req)
app.Commit()