Skip to content

Commit

Permalink
feat: change module account invariant (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
catShaark authored Jan 25, 2024
1 parent a8d8a36 commit 0168215
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions x/multi-staking/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func (k Keeper) BurnUnbondedCoinAndUnlockedMultiStakingCoin(
if err != nil {
return sdk.Coin{}, err
}
// burn remaining coin in unlock
remaningCoin := unlockEntry.UnlockingCoin.ToCoin().Sub(unlockedCoin)
k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(remaningCoin))

Check failure on line 86 in x/multi-staking/keeper/abci.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `k.bankKeeper.BurnCoins` is not checked (errcheck)

err = k.UnescrowCoinTo(ctx, multiStakerAddr, unlockedCoin)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/multi-staking/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ModuleAccountInvariants(k Keeper) sdk.Invariant {
moduleAccount := authtypes.NewModuleAddress(types.ModuleName)
escrowBalances := k.bankKeeper.GetAllBalances(ctx, moduleAccount)

broken := !escrowBalances.IsAllGTE(totalLockCoinAmount)
broken := !escrowBalances.IsEqual(totalLockCoinAmount)

return sdk.FormatInvariant(
types.ModuleName,
Expand Down
9 changes: 9 additions & 0 deletions x/multi-staking/keeper/invartiants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/realio-tech/multi-staking-module/testutil"
"github.com/realio-tech/multi-staking-module/x/multi-staking/keeper"
"github.com/realio-tech/multi-staking-module/x/multi-staking/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -118,6 +119,14 @@ func (suite *KeeperTestSuite) TestModuleAccountInvariants() {
},
expPass: true,
},
{
name: "Fail invariant",
malleate: func() {
multiStakingLock := types.NewMultiStakingLock(types.MultiStakingLockID(delAddr.String(), valAddr.String()), types.NewMultiStakingCoin(MultiStakingDenomA, sdk.NewInt(200), sdk.OneDec()))
suite.app.MultiStakingKeeper.SetMultiStakingLock(suite.ctx, multiStakingLock)
},
expPass: false,
},
}
for _, tc := range testCases {
suite.SetupTest() // reset
Expand Down

0 comments on commit 0168215

Please sign in to comment.