diff --git a/app/app_db_test.go b/app/app_db_test.go new file mode 100644 index 00000000..6b83014c --- /dev/null +++ b/app/app_db_test.go @@ -0,0 +1,22 @@ +package app_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/functionx/fx-core/v7/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v7/types" +) + +func TestAppDB(t *testing.T) { + helpers.SkipTest(t, "Skipping local test:", t.Name()) + + myApp, chainId := buildApp(t, fxtypes.MainnetChainId) + require.NoError(t, myApp.LoadLatestVersion()) + ctx := newContext(t, myApp, chainId, false) + + _ = ctx + + // do something ... +} diff --git a/app/upgrade_test.go b/app/upgrade_test.go index f6d846df..1239f06e 100644 --- a/app/upgrade_test.go +++ b/app/upgrade_test.go @@ -30,19 +30,7 @@ import ( func Test_UpgradeAndMigrate(t *testing.T) { helpers.SkipTest(t, "Skipping local test:", t.Name()) - fxtypes.SetConfig(true) - - home := filepath.Join(os.Getenv("HOME"), "tmp") - chainId := fxtypes.MainnetChainId - fxtypes.SetChainId(chainId) - - db, err := dbm.NewDB("application", dbm.GoLevelDBBackend, filepath.Join(home, "data")) - require.NoError(t, err) - - makeEncodingConfig := app.MakeEncodingConfig() - myApp := app.New(log.NewFilter(log.NewTMLogger(os.Stdout), log.AllowAll()), - db, nil, false, map[int64]bool{}, home, 0, - makeEncodingConfig, app.EmptyAppOptions{}, baseapp.SetChainID(chainId)) + myApp, chainId := buildApp(t, fxtypes.MainnetChainId) myApp.SetStoreLoader(upgradetypes.UpgradeStoreLoader(myApp.LastBlockHeight()+1, nextversion.Upgrade.StoreUpgrades())) require.NoError(t, myApp.LoadLatestVersion()) @@ -84,6 +72,22 @@ func Test_UpgradeAndMigrate(t *testing.T) { checkProposalPassed(t, ctx, myApp, ingProposalIds) } +func buildApp(t *testing.T, chainId string) (*app.App, string) { + fxtypes.SetConfig(true) + + home := filepath.Join(os.Getenv("HOME"), "tmp") + fxtypes.SetChainId(chainId) + + db, err := dbm.NewDB("application", dbm.GoLevelDBBackend, filepath.Join(home, "data")) + require.NoError(t, err) + + makeEncodingConfig := app.MakeEncodingConfig() + myApp := app.New(log.NewFilter(log.NewTMLogger(os.Stdout), log.AllowAll()), + db, nil, false, map[int64]bool{}, home, 0, + makeEncodingConfig, app.EmptyAppOptions{}, baseapp.SetChainID(chainId)) + return myApp, chainId +} + func newContext(t *testing.T, myApp *app.App, chainId string, deliveState bool) sdk.Context { header := tmproto.Header{ ChainID: chainId,