Skip to content

Commit

Permalink
linter and coverage fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed May 1, 2024
1 parent 40ae91b commit dcc0c79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))

Check warning on line 121 in app/setup_handlers.go

View check run for this annotation

Codecov / codecov/patch

app/setup_handlers.go#L121

Added line #L121 was not covered by tests
}
Expand Down Expand Up @@ -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()

Check warning on line 146 in app/setup_handlers.go

View check run for this annotation

Codecov / codecov/patch

app/setup_handlers.go#L144-L146

Added lines #L144 - L146 were not covered by tests
} else {
return t.mergeAllUpgrades()
}
return t.mergeAllUpgrades()

Check warning on line 148 in app/setup_handlers.go

View check run for this annotation

Codecov / codecov/patch

app/setup_handlers.go#L148

Added line #L148 was not covered by tests
}
23 changes: 19 additions & 4 deletions app/setup_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

0 comments on commit dcc0c79

Please sign in to comment.