From 2047abc8bc7b1eb2873f93c581b86dcadf3341d2 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 1 Mar 2018 02:00:44 -0500 Subject: [PATCH] add tests to show mounting multiple stores is broken. see #532 --- baseapp/baseapp_test.go | 27 +++++++++++++++++++++++++-- examples/basecoin/app/app_test.go | 12 ++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 1155ca24b40f..d94217c7f2a4 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -145,11 +145,15 @@ func TestInfo(t *testing.T) { } func TestInitChainer(t *testing.T) { - app := newBaseApp(t.Name()) + logger := defaultLogger() + db := dbm.NewMemDB() + name := t.Name() + app := NewBaseApp(name, logger, db) // make a cap key and mount the store capKey := sdk.NewKVStoreKey("main") - app.MountStoresIAVL(capKey) + capKey2 := sdk.NewKVStoreKey("key2") + app.MountStoresIAVL(capKey, capKey2) err := app.LoadLatestVersion(capKey) // needed to make stores non-nil assert.Nil(t, err) @@ -178,6 +182,25 @@ func TestInitChainer(t *testing.T) { app.Commit() res = app.Query(query) assert.Equal(t, value, res.Value) + + // reload app + app = NewBaseApp(name, logger, db) + capKey = sdk.NewKVStoreKey("main") + capKey2 = sdk.NewKVStoreKey("key2") + app.MountStoresIAVL(capKey, capKey2) + err = app.LoadLatestVersion(capKey) // needed to make stores non-nil + assert.Nil(t, err) + app.SetInitChainer(initChainer) + + // ensure we can still query after reloading + res = app.Query(query) + assert.Equal(t, value, res.Value) + + // commit and ensure we can still query + app.BeginBlock(abci.RequestBeginBlock{}) + app.Commit() + res = app.Query(query) + assert.Equal(t, value, res.Value) } // Test that successive CheckTx can see each others' effects diff --git a/examples/basecoin/app/app_test.go b/examples/basecoin/app/app_test.go index e917936b658c..b6ed35b16e21 100644 --- a/examples/basecoin/app/app_test.go +++ b/examples/basecoin/app/app_test.go @@ -71,7 +71,9 @@ func TestSendMsg(t *testing.T) { } func TestGenesis(t *testing.T) { - bapp := newBasecoinApp() + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app") + db := dbm.NewMemDB() + bapp := NewBasecoinApp(logger, db) // Construct some genesis bytes to reflect basecoin/types/AppAccount pk := crypto.GenPrivKeyEd25519().PubKey() @@ -97,9 +99,15 @@ func TestGenesis(t *testing.T) { // A checkTx context ctx := bapp.BaseApp.NewContext(true, abci.Header{}) - res1 := bapp.accountMapper.GetAccount(ctx, baseAcc.Address) assert.Equal(t, acc, res1) + + // reload app and ensure the account is still there + bapp = NewBasecoinApp(logger, db) + ctx = bapp.BaseApp.NewContext(true, abci.Header{}) + res1 = bapp.accountMapper.GetAccount(ctx, baseAcc.Address) + assert.Equal(t, acc, res1) + } func TestSendMsgWithAccounts(t *testing.T) {