From dcc0c79631de2620db0f4b6718dffbfd24ccd76e Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Wed, 1 May 2024 11:14:24 -0700 Subject: [PATCH] linter and coverage fixes --- app/setup_handlers.go | 8 ++++---- app/setup_handlers_test.go | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/setup_handlers.go b/app/setup_handlers.go index 2757491c27..fe3e06f055 100644 --- a/app/setup_handlers.go +++ b/app/setup_handlers.go @@ -85,9 +85,10 @@ type upgradeTracker struct { func (t upgradeTracker) getDevelopUpgrades() ([]versionModiferFn, *storetypes.StoreUpgrades) { neededUpgrades := &storetypes.StoreUpgrades{} neededVersionModifiers := []versionModiferFn{} - stateFilePath := path.Join(t.stateFileDir, "storeupgradetracker") + stateFilePath := path.Join(t.stateFileDir, "developupgradetracker") currentIdx := int64(0) + // #nosec G304 stateFilePath is not user controllable if stateFileContents, err := os.ReadFile(stateFilePath); err == nil { currentIdx, err = strconv.ParseInt(string(stateFileContents), 10, 64) if err != nil { @@ -115,7 +116,7 @@ func (t upgradeTracker) getDevelopUpgrades() ([]versionModiferFn, *storetypes.St } maxIdx = idx } - err := os.WriteFile(stateFilePath, []byte(strconv.FormatInt(maxIdx, 10)), 0o660) + err := os.WriteFile(stateFilePath, []byte(strconv.FormatInt(maxIdx, 10)), 0o600) if err != nil { panic(fmt.Sprintf("unable to write upgrade state file: %v", err)) } @@ -143,7 +144,6 @@ func (t upgradeTracker) mergeAllUpgrades() ([]versionModiferFn, *storetypes.Stor func (t upgradeTracker) getUpgrades(isDevelop bool) ([]versionModiferFn, *storetypes.StoreUpgrades) { if isDevelop { return t.getDevelopUpgrades() - } else { - return t.mergeAllUpgrades() } + return t.mergeAllUpgrades() } diff --git a/app/setup_handlers_test.go b/app/setup_handlers_test.go index 9290b42379..573b58b45d 100644 --- a/app/setup_handlers_test.go +++ b/app/setup_handlers_test.go @@ -6,6 +6,8 @@ import ( "time" storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/stretchr/testify/require" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" lightclienttypes "github.com/zeta-chain/zetacore/x/lightclient/types" @@ -33,27 +35,39 @@ func TestStoreUpgradeTracker(t *testing.T) { storeUpgrade: &storetypes.StoreUpgrades{ Added: []string{lightclienttypes.ModuleName}, }, + versionModifier: func(ctx sdk.Context, vm module.VersionMap) (module.VersionMap, error) { + return vm, nil + }, + }, + { + idx: 3000, + versionModifier: func(ctx sdk.Context, vm module.VersionMap) (module.VersionMap, error) { + return vm, nil + }, }, }, stateFileDir: tmpdir, } - _, storeUpgrades := allUpgrades.mergeAllUpgrades() + versionModifierFns, storeUpgrades := allUpgrades.mergeAllUpgrades() r.Len(storeUpgrades.Added, 2) r.Len(storeUpgrades.Renamed, 0) r.Len(storeUpgrades.Deleted, 0) + r.Len(versionModifierFns, 2) // should return all migrations on first call - _, storeUpgrades = allUpgrades.getDevelopUpgrades() + versionModifierFns, storeUpgrades = allUpgrades.getDevelopUpgrades() r.Len(storeUpgrades.Added, 2) r.Len(storeUpgrades.Renamed, 0) r.Len(storeUpgrades.Deleted, 0) + r.Len(versionModifierFns, 2) // should return no upgrades on second call - _, storeUpgrades = allUpgrades.getDevelopUpgrades() + versionModifierFns, storeUpgrades = allUpgrades.getDevelopUpgrades() r.Len(storeUpgrades.Added, 0) r.Len(storeUpgrades.Renamed, 0) r.Len(storeUpgrades.Deleted, 0) + r.Len(versionModifierFns, 0) // now add a upgrade and ensure that it gets run without running // the other upgrades @@ -64,8 +78,9 @@ func TestStoreUpgradeTracker(t *testing.T) { }, }) - _, storeUpgrades = allUpgrades.getDevelopUpgrades() + versionModifierFns, storeUpgrades = allUpgrades.getDevelopUpgrades() r.Len(storeUpgrades.Added, 0) r.Len(storeUpgrades.Renamed, 0) r.Len(storeUpgrades.Deleted, 1) + r.Len(versionModifierFns, 0) }