Skip to content

Commit

Permalink
fix: Invariant fix (#740)
Browse files Browse the repository at this point in the history
* invariant fix

* fix test
  • Loading branch information
kruspy authored Jan 23, 2024
1 parent 05cc290 commit e52ff86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions x/liquidstakeibc/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper) {
func CValueLimits(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
hostChains := k.GetAllHostChains(ctx)
str := ""
strs := make([]string, 0)
broken := false
for _, hc := range hostChains {
if !k.CValueWithinLimits(hc) {
str = fmt.Sprintf("chainID: %s, cValue: %s \n", hc.ChainId, hc.CValue)
strs = append(strs, fmt.Sprintf("chainID: %s, cValue: %s \n", hc.ChainId, hc.CValue))
}
}
if str != "" {
invariantStr := ""
if len(strs) != 0 {
broken = true
for _, str := range strs {
invariantStr += fmt.Sprintf("%s\n", str)
}
}
return sdk.FormatInvariant(
types.ModuleName, "cvalue-limits",
fmt.Sprintf("cvalue out of bounds: %v, values as follows \n %s ", broken, str),
fmt.Sprintf("cvalue out of bounds: %v, values as follows \n %s ", broken, invariantStr),
), broken
}
}
2 changes: 1 addition & 1 deletion x/liquidstakeibc/keeper/invariants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ func (suite *IntegrationTestSuite) TestCValueLimits() {
k.SetHostChain(ctx, hc)
str, broken = keeper.CValueLimits(k)(ctx)
suite.True(broken)
suite.Equal("liquidstakeibc: cvalue-limits invariant\ncvalue out of bounds: true, values as follows \n chainID: testchain2-1, cValue: 2.000000000000000000 \n \n", str)
suite.Equal("liquidstakeibc: cvalue-limits invariant\ncvalue out of bounds: true, values as follows \n chainID: testchain2-1, cValue: 2.000000000000000000 \n\n \n", str)
}

0 comments on commit e52ff86

Please sign in to comment.