From e52ff8651e27eb9744f455806006cd6109c0553a Mon Sep 17 00:00:00 2001 From: Marc Puig Date: Tue, 23 Jan 2024 14:03:19 +0100 Subject: [PATCH] fix: Invariant fix (#740) * invariant fix * fix test --- x/liquidstakeibc/keeper/invariants.go | 12 ++++++++---- x/liquidstakeibc/keeper/invariants_test.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/x/liquidstakeibc/keeper/invariants.go b/x/liquidstakeibc/keeper/invariants.go index b606badd7..a44be7de9 100644 --- a/x/liquidstakeibc/keeper/invariants.go +++ b/x/liquidstakeibc/keeper/invariants.go @@ -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 } } diff --git a/x/liquidstakeibc/keeper/invariants_test.go b/x/liquidstakeibc/keeper/invariants_test.go index 788a03270..c841fdace 100644 --- a/x/liquidstakeibc/keeper/invariants_test.go +++ b/x/liquidstakeibc/keeper/invariants_test.go @@ -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) }