Skip to content

Commit

Permalink
test: common method for building the app (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code committed Sep 3, 2024
1 parent b97c663 commit f0a831d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
22 changes: 22 additions & 0 deletions app/app_db_test.go
Original file line number Diff line number Diff line change
@@ -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 ...
}
30 changes: 17 additions & 13 deletions app/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f0a831d

Please sign in to comment.