Skip to content

Commit

Permalink
fix: fixed crash in CosmovisorUpgradesGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Sep 13, 2024
1 parent 6d9bed8 commit 10297e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/generators/cosmovisor_upgrades_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (g *CosmovisorUpgradesGenerator) Get(state fetchers.State) []metrics.Metric
panic("expected the state entry to be types.UpgradesPresent")
}

if upgradePlan == nil {
return []metrics.MetricInfo{}
}

// From cosmovisor docs:
// The name variable in upgrades/<name> is the lowercase URI-encoded name
// of the upgrade as specified in the upgrade module plan.
Expand Down
17 changes: 15 additions & 2 deletions pkg/generators/cosmovisor_upgrades_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ func TestCosmovisorUpgradesGeneratorEmptyInvalidUpgrades(t *testing.T) {
}

generator := NewCosmovisorUpgradesGenerator()
metrics := generator.Get(state)
assert.Empty(t, metrics)
generator.Get(state)
}

func TestCosmovisorUpgradesGeneratorEmptyInvalidCosmovisorUpgrades(t *testing.T) {
Expand All @@ -75,6 +74,20 @@ func TestCosmovisorUpgradesGeneratorEmptyInvalidCosmovisorUpgrades(t *testing.T)
constants.FetcherNameCosmovisorUpgrades: 3,
}

generator := NewCosmovisorUpgradesGenerator()
generator.Get(state)
}

func TestCosmovisorUpgradesGeneratorEmptyUpgradePlan(t *testing.T) {
t.Parallel()

var upgradePlan *upgradeTypes.Plan

state := fetchers.State{
constants.FetcherNameUpgrades: upgradePlan,
constants.FetcherNameCosmovisorUpgrades: types.UpgradesPresent{},
}

generator := NewCosmovisorUpgradesGenerator()
metrics := generator.Get(state)
assert.Empty(t, metrics)
Expand Down

0 comments on commit 10297e7

Please sign in to comment.