Skip to content

Commit

Permalink
test(superfluid): unpool when not whitelisted (#3532) (#3534)
Browse files Browse the repository at this point in the history
* test(superfluid): unpool when not whitelisted

* testLockId

(cherry picked from commit 7dd5f4e)

Co-authored-by: Roman <[email protected]>
  • Loading branch information
mergify[bot] and p0mvn authored Nov 27, 2022
1 parent 3412d78 commit b0881ef
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions x/superfluid/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ func (server msgServer) UnPoolWhitelistedPool(goCtx context.Context, msg *types.
return nil, err
}

err = server.keeper.checkUnpoolWhitelisted(ctx, msg.PoolId)
if err != nil {
return nil, err
}

// We get all the lockIDs to unpool
lpShareDenom := gammtypes.GetPoolShareDenom(msg.PoolId)
minimalDuration := time.Millisecond
Expand Down
35 changes: 34 additions & 1 deletion x/superfluid/keeper/unpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

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

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

Expand Down Expand Up @@ -252,3 +251,37 @@ func (suite *KeeperTestSuite) TestUnpool() {
})
}
}

// TestUnpoolAllowedPools_WhiteList tests that unpooling does not work for pools not in a whitelist.
// Should fail immediately if pool is not in whitelist.
func (suite *KeeperTestSuite) TestUnpoolAllowedPools_WhiteList() {
// lock id does not matter in the context of this test.
const (
testLockId = 1
whiteListedPoolId = 1
)
suite.SetupTest()
ctx := suite.Ctx
superfluidKeeper := suite.App.SuperfluidKeeper

// id 1
suite.PrepareBalancerPool()
// id 2
suite.PrepareBalancerPool()

// set id 1 to whitelist
superfluidKeeper.SetUnpoolAllowedPools(ctx, []uint64{whiteListedPoolId})

_, err := superfluidKeeper.UnpoolAllowedPools(ctx, suite.TestAccs[0], whiteListedPoolId, testLockId)

// An error should still occur due to incorrect setup. However, it should be unrelated
// to whitelist.
suite.Error(err)
suite.Require().NotErrorIs(err, types.ErrPoolNotWhitelisted)

_, err = superfluidKeeper.UnpoolAllowedPools(ctx, suite.TestAccs[0], whiteListedPoolId+1, testLockId)

// Here, we used a non-whitelisted pool id so it should fail with the whitelist error.
suite.Error(err)
suite.Require().ErrorIs(err, types.ErrPoolNotWhitelisted)
}

0 comments on commit b0881ef

Please sign in to comment.