Skip to content

Commit

Permalink
Add int overflow panic catching test
Browse files Browse the repository at this point in the history
  • Loading branch information
NotJeremyLiu committed Jun 6, 2023
1 parent 22d528e commit ed66bce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion x/protorev/keeper/hooks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"errors"

sdk "github.com/cosmos/cosmos-sdk/types"

gammtypes "github.com/osmosis-labs/osmosis/v16/x/gamm/types"
Expand Down Expand Up @@ -115,7 +117,7 @@ func (k Keeper) GetComparablePoolLiquidity(ctx sdk.Context, poolId uint64) (comp
defer func() {
if r := recover(); r != nil {
comparableLiquidity = sdk.Int{}
err = sdk.ErrIntOverflowAbci
err = errors.New("Int overflow in GetComparablePoolLiquidity")
}
}()

Expand Down
15 changes: 15 additions & 0 deletions x/protorev/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,18 @@ func (s *KeeperTestSuite) TestGetComparablePoolLiquidity() {
},
expectPass: true,
},
{
name: "Catch overflow error on liquidity multiplication",
param: param{
executePoolCreation: func() uint64 {
return s.PrepareBalancerPoolWithCoins(
sdk.NewCoin("uosmo", sdk.Int(sdk.NewUintFromString("999999999999999999999999999999999999999"))),
sdk.NewCoin("juno", sdk.Int(sdk.NewUintFromString("999999999999999999999999999999999999999"))))
},
expectedComparableLiquidity: sdk.Int{},
},
expectPass: false,
},
}

for _, tc := range tests {
Expand All @@ -542,6 +554,9 @@ func (s *KeeperTestSuite) TestGetComparablePoolLiquidity() {
if tc.expectPass {
s.Require().NoError(err)
s.Require().Equal(tc.param.expectedComparableLiquidity, comparableLiquidity)
} else {
s.Require().Error(err)
s.Require().Equal(tc.param.expectedComparableLiquidity, comparableLiquidity)
}
})
}
Expand Down

0 comments on commit ed66bce

Please sign in to comment.