From 9abb176a8dc1c3793efebb7a24bacb2c16e50903 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 03:07:00 +0700 Subject: [PATCH 01/20] add emit event & test --- x/superfluid/keeper/internal/events/emit.go | 133 +++++++ .../keeper/internal/events/emit_test.go | 346 ++++++++++++++++++ 2 files changed, 479 insertions(+) create mode 100644 x/superfluid/keeper/internal/events/emit.go create mode 100644 x/superfluid/keeper/internal/events/emit_test.go diff --git a/x/superfluid/keeper/internal/events/emit.go b/x/superfluid/keeper/internal/events/emit.go new file mode 100644 index 00000000000..42c58fd490c --- /dev/null +++ b/x/superfluid/keeper/internal/events/emit.go @@ -0,0 +1,133 @@ +package events + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" +) + +func EmitSetSuperfluidAssetEvent(ctx sdk.Context, denom string, assetType types.SuperfluidAssetType) { + if ctx.EventManager() == nil { + return + } + + ctx.EventManager().EmitEvents(sdk.Events{ + newSetSuperfluidAssetEvent(denom, assetType), + }) +} + +func newSetSuperfluidAssetEvent(denom string, assetType types.SuperfluidAssetType) sdk.Event { + return sdk.NewEvent( + types.TypeEvtSetSuperfluidAsset, + sdk.NewAttribute(types.AttributeDenom, denom), + sdk.NewAttribute(types.AttributeSuperfluidAssetType, assetType.String()), + ) +} + +func EmitRemoveSuperfluidAsset(ctx sdk.Context, denom string) { + if ctx.EventManager() == nil { + return + } + + ctx.EventManager().EmitEvents(sdk.Events{ + newRemoveSuperfluidAssetEvent(denom), + }) +} + +func newRemoveSuperfluidAssetEvent(denom string) sdk.Event { + return sdk.NewEvent( + types.TypeEvtRemoveSuperfluidAsset, + sdk.NewAttribute(types.AttributeDenom, denom), + ) +} + +func EmitSuperfluidDelegateEvent(ctx sdk.Context, lockId uint64, valAddress string) { + if ctx.EventManager() == nil { + return + } + + ctx.EventManager().EmitEvents(sdk.Events{ + newSuperfluidDelegateEvent(lockId, valAddress), + }) +} + +func newSuperfluidDelegateEvent(lockId uint64, valAddress string) sdk.Event { + return sdk.NewEvent( + types.TypeEvtSuperfluidDelegate, + sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", lockId)), + sdk.NewAttribute(types.AttributeValidator, valAddress), + ) +} + +func EmitSuperfluidIncreaseDelegationEvent(ctx sdk.Context, lockId uint64, amount sdk.Coins) { + if ctx.EventManager() == nil { + return + } + + ctx.EventManager().EmitEvents(sdk.Events{ + newSuperfluidIncreaseDelegationEvent(lockId, amount), + }) +} + +func newSuperfluidIncreaseDelegationEvent(lockId uint64, amount sdk.Coins) sdk.Event { + return sdk.NewEvent( + types.TypeEvtSuperfluidIncreaseDelegation, + sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", lockId)), + sdk.NewAttribute(types.AttributeAmount, amount.String()), + ) +} + +func EmitSuperfluidUndelegateEvent(ctx sdk.Context, lockId uint64) { + if ctx.EventManager() == nil { + return + } + + ctx.EventManager().EmitEvents(sdk.Events{ + newSuperfluidUndelegateEvent(lockId), + }) +} + +func newSuperfluidUndelegateEvent(lockId uint64) sdk.Event { + return sdk.NewEvent( + types.TypeEvtSuperfluidUndelegate, + sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", lockId)), + ) +} + +func EmitSuperfluidUnbondLockEvent(ctx sdk.Context, lockId uint64) { + if ctx.EventManager() == nil { + return + } + + ctx.EventManager().EmitEvents(sdk.Events{ + newSuperfluidUnbondLockEvent(lockId), + }) +} + +func newSuperfluidUnbondLockEvent(lockId uint64) sdk.Event { + return sdk.NewEvent( + types.TypeEvtSuperfluidUnbondLock, + sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", lockId)), + ) +} + +func EmitUnpoolIdEvent(ctx sdk.Context, sender string, lpShareDenom string, allExitedLockIDsSerialized []byte) { + if ctx.EventManager() == nil { + return + } + + ctx.EventManager().EmitEvents(sdk.Events{ + newUnpoolIdEvent(sender, lpShareDenom, allExitedLockIDsSerialized), + }) +} + +func newUnpoolIdEvent(sender string, lpShareDenom string, allExitedLockIDsSerialized []byte) sdk.Event { + return sdk.NewEvent( + types.TypeEvtUnpoolId, + sdk.NewAttribute(sdk.AttributeKeySender, sender), + sdk.NewAttribute(types.AttributeDenom, lpShareDenom), + sdk.NewAttribute(types.AttributeNewLockIds, string(allExitedLockIDsSerialized)), + ) +} diff --git a/x/superfluid/keeper/internal/events/emit_test.go b/x/superfluid/keeper/internal/events/emit_test.go new file mode 100644 index 00000000000..68b83d8453b --- /dev/null +++ b/x/superfluid/keeper/internal/events/emit_test.go @@ -0,0 +1,346 @@ +package events_test + +import ( + "encoding/json" + "fmt" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/suite" + + "github.com/osmosis-labs/osmosis/v10/app/apptesting" + "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper/internal/events" + "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" +) + +type SuperfluidEventsTestSuite struct { + apptesting.KeeperTestHelper +} + +const ( + addressString = "addr1---------------" + testDenomA = "denoma" + testDenomB = "denomb" + testDenomC = "denomc" + testDenomD = "denomd" +) + +func TestSuperfluidEventsTestSuite(t *testing.T) { + suite.Run(t, new(SuperfluidEventsTestSuite)) +} + +func (suite *SuperfluidEventsTestSuite) TestEmitSetSuperfluidAssetEvent() { + testcases := map[string]struct { + ctx sdk.Context + denom string + assetType types.SuperfluidAssetType + }{ + "basic valid": { + ctx: suite.CreateTestContext(), + denom: testDenomA, + assetType: types.SuperfluidAssetTypeNative, + + }, + "context with no event manager": { + ctx: sdk.Context{}, + }, + } + + for name, tc := range testcases { + suite.Run(name, func() { + expectedEvents := sdk.Events{ + sdk.NewEvent( + types.TypeEvtSetSuperfluidAsset, + sdk.NewAttribute(types.AttributeDenom, tc.denom), + sdk.NewAttribute(types.AttributeSuperfluidAssetType, tc.assetType.String()), + ), + } + + hasNoEventManager := tc.ctx.EventManager() == nil + + // System under test. + events.EmitSetSuperfluidAssetEvent(tc.ctx, tc.denom, tc.assetType) + + // Assertions + if hasNoEventManager { + // If there is no event manager on context, this is a no-op. + return + } + + eventManager := tc.ctx.EventManager() + actualEvents := eventManager.Events() + suite.Equal(expectedEvents, actualEvents) + }) + } +} + +func (suite *SuperfluidEventsTestSuite) TestEmitRemoveSuperfluidAsset() { + testcases := map[string]struct { + ctx sdk.Context + denom string + }{ + "basic valid": { + ctx: suite.CreateTestContext(), + denom: testDenomA, + + }, + "context with no event manager": { + ctx: sdk.Context{}, + }, + } + + for name, tc := range testcases { + suite.Run(name, func() { + expectedEvents := sdk.Events{ + sdk.NewEvent( + types.TypeEvtRemoveSuperfluidAsset, + sdk.NewAttribute(types.AttributeDenom, tc.denom), + ), + } + + hasNoEventManager := tc.ctx.EventManager() == nil + + // System under test. + events.EmitRemoveSuperfluidAsset(tc.ctx, tc.denom) + + // Assertions + if hasNoEventManager { + // If there is no event manager on context, this is a no-op. + return + } + + eventManager := tc.ctx.EventManager() + actualEvents := eventManager.Events() + suite.Equal(expectedEvents, actualEvents) + }) + } +} + +func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidDelegateEvent() { + testcases := map[string]struct { + ctx sdk.Context + lockID uint64 + valAddr string + }{ + "basic valid": { + ctx: suite.CreateTestContext(), + lockID: 1, + valAddr: sdk.AccAddress([]byte(addressString)).String(), + }, + "context with no event manager": { + ctx: sdk.Context{}, + }, + } + + for name, tc := range testcases { + suite.Run(name, func() { + expectedEvents := sdk.Events{ + sdk.NewEvent( + types.TypeEvtSuperfluidDelegate, + sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", tc.lockID)), + sdk.NewAttribute(types.AttributeValidator, tc.valAddr), + ), + } + + hasNoEventManager := tc.ctx.EventManager() == nil + + // System under test. + events.EmitSuperfluidDelegateEvent(tc.ctx, tc.lockID, tc.valAddr) + + // Assertions + if hasNoEventManager { + // If there is no event manager on context, this is a no-op. + return + } + + eventManager := tc.ctx.EventManager() + actualEvents := eventManager.Events() + suite.Equal(expectedEvents, actualEvents) + }) + } +} + +func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidIncreaseDelegationEvent() { + testcases := map[string]struct { + ctx sdk.Context + lockID uint64 + amount sdk.Coins + }{ + "basic valid": { + ctx: suite.CreateTestContext(), + lockID: 1, + amount: sdk.NewCoins(sdk.NewCoin(testDenomA, sdk.NewInt(100))), + }, + "context with no event manager": { + ctx: sdk.Context{}, + }, + "valid with multiple tokens in and out": { + ctx: suite.CreateTestContext(), + lockID: 1, + amount: sdk.NewCoins(sdk.NewCoin(testDenomA, sdk.NewInt(100)), sdk.NewCoin(testDenomB, sdk.NewInt(10))), + }, + } + + for name, tc := range testcases { + suite.Run(name, func() { + expectedEvents := sdk.Events{ + sdk.NewEvent( + types.TypeEvtSuperfluidIncreaseDelegation, + sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", tc.lockID)), + sdk.NewAttribute(types.AttributeAmount, tc.amount.String()), + ), + } + + hasNoEventManager := tc.ctx.EventManager() == nil + + // System under test. + events.EmitSuperfluidIncreaseDelegationEvent(tc.ctx, tc.lockID, tc.amount) + + // Assertions + if hasNoEventManager { + // If there is no event manager on context, this is a no-op. + return + } + + eventManager := tc.ctx.EventManager() + actualEvents := eventManager.Events() + suite.Equal(expectedEvents, actualEvents) + }) + } +} + +func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidUndelegateEvent() { + testcases := map[string]struct { + ctx sdk.Context + lockID uint64 + }{ + "basic valid": { + ctx: suite.CreateTestContext(), + lockID: 1, + }, + "context with no event manager": { + ctx: sdk.Context{}, + }, + + } + + for name, tc := range testcases { + suite.Run(name, func() { + expectedEvents := sdk.Events{ + sdk.NewEvent( + types.TypeEvtSuperfluidUndelegate, + sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", tc.lockID)), + ), + } + + hasNoEventManager := tc.ctx.EventManager() == nil + + // System under test. + events.EmitSuperfluidUndelegateEvent(tc.ctx, tc.lockID) + + // Assertions + if hasNoEventManager { + // If there is no event manager on context, this is a no-op. + return + } + + eventManager := tc.ctx.EventManager() + actualEvents := eventManager.Events() + suite.Equal(expectedEvents, actualEvents) + }) + } +} + +func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidUnbondLockEvent() { + testcases := map[string]struct { + ctx sdk.Context + lockID uint64 + }{ + "basic valid": { + ctx: suite.CreateTestContext(), + lockID: 1, + }, + "context with no event manager": { + ctx: sdk.Context{}, + }, + + } + + for name, tc := range testcases { + suite.Run(name, func() { + expectedEvents := sdk.Events{ + sdk.NewEvent( + types.TypeEvtSuperfluidUnbondLock, + sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", tc.lockID)), + ), + } + + hasNoEventManager := tc.ctx.EventManager() == nil + + // System under test. + events.EmitSuperfluidUnbondLockEvent(tc.ctx, tc.lockID) + + // Assertions + if hasNoEventManager { + // If there is no event manager on context, this is a no-op. + return + } + + eventManager := tc.ctx.EventManager() + actualEvents := eventManager.Events() + suite.Equal(expectedEvents, actualEvents) + }) + } +} + +func (suite *SuperfluidEventsTestSuite) TestEmitUnpoolIdEvent() { + testAllExitedLockIDsSerialized, _ := json.Marshal([]uint64{1}) + + testcases := map[string]struct { + ctx sdk.Context + sender string + lpShareDenom string + allExitedLockIDsSerialized []byte + }{ + "basic valid": { + ctx: suite.CreateTestContext(), + sender: sdk.AccAddress([]byte(addressString)).String(), + lpShareDenom: "pool1", + allExitedLockIDsSerialized: testAllExitedLockIDsSerialized, + }, + "context with no event manager": { + ctx: sdk.Context{}, + }, + } + + for name, tc := range testcases { + suite.Run(name, func() { + expectedEvents := sdk.Events{ + sdk.NewEvent( + types.TypeEvtUnpoolId, + sdk.NewAttribute(sdk.AttributeKeySender, tc.sender), + sdk.NewAttribute(types.AttributeDenom, tc.lpShareDenom), + sdk.NewAttribute(types.AttributeNewLockIds, string(tc.allExitedLockIDsSerialized)), + ), + } + + hasNoEventManager := tc.ctx.EventManager() == nil + + // System under test. + events.EmitUnpoolIdEvent(tc.ctx, tc.sender, tc.lpShareDenom, tc.allExitedLockIDsSerialized) + + // Assertions + if hasNoEventManager { + // If there is no event manager on context, this is a no-op. + return + } + + eventManager := tc.ctx.EventManager() + actualEvents := eventManager.Events() + suite.Equal(expectedEvents, actualEvents) + }) + } +} + + + From cd82fe73423aafb912b443555c4b75543395c706 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 03:07:20 +0700 Subject: [PATCH 02/20] add test for emit event --- x/superfluid/keeper/gov/gov.go | 14 +-- x/superfluid/keeper/gov/gov_test.go | 10 +- x/superfluid/keeper/gov/suite_test.go | 12 ++ x/superfluid/keeper/hooks.go | 9 +- x/superfluid/keeper/msg_server.go | 33 ++--- x/superfluid/keeper/msg_server_test.go | 162 +++++++++++++++++++++++++ 6 files changed, 193 insertions(+), 47 deletions(-) diff --git a/x/superfluid/keeper/gov/gov.go b/x/superfluid/keeper/gov/gov.go index 1799e6197f2..d5934a66db3 100644 --- a/x/superfluid/keeper/gov/gov.go +++ b/x/superfluid/keeper/gov/gov.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper" + "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper/internal/events" "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,12 +13,7 @@ import ( func HandleSetSuperfluidAssetsProposal(ctx sdk.Context, k keeper.Keeper, ek types.EpochKeeper, p *types.SetSuperfluidAssetsProposal) error { for _, asset := range p.Assets { k.AddNewSuperfluidAsset(ctx, asset) - event := sdk.NewEvent( - types.TypeEvtSetSuperfluidAsset, - sdk.NewAttribute(types.AttributeDenom, asset.Denom), - sdk.NewAttribute(types.AttributeSuperfluidAssetType, asset.AssetType.String()), - ) - ctx.EventManager().EmitEvent(event) + events.EmitSetSuperfluidAssetEvent(ctx, asset.Denom, asset.AssetType) } return nil } @@ -30,11 +26,7 @@ func HandleRemoveSuperfluidAssetsProposal(ctx sdk.Context, k keeper.Keeper, p *t return fmt.Errorf("superfluid asset %s doesn't exist", denom) } k.BeginUnwindSuperfluidAsset(ctx, 0, asset) - event := sdk.NewEvent( - types.TypeEvtRemoveSuperfluidAsset, - sdk.NewAttribute(types.AttributeDenom, denom), - ) - ctx.EventManager().EmitEvent(event) + events.EmitRemoveSuperfluidAsset(ctx, denom) } return nil } diff --git a/x/superfluid/keeper/gov/gov_test.go b/x/superfluid/keeper/gov/gov_test.go index 38022941ea1..bb8263521b3 100644 --- a/x/superfluid/keeper/gov/gov_test.go +++ b/x/superfluid/keeper/gov/gov_test.go @@ -59,6 +59,7 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() { assets []types.SuperfluidAsset expectedAssets []types.SuperfluidAsset expectErr bool + expectedEvent string } testCases := []struct { name string @@ -68,10 +69,10 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() { "happy path flow", []Action{ { - true, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{asset1}, false, + true, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{asset1}, false, types.TypeEvtSetSuperfluidAsset, }, { - false, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{}, false, + false, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{}, false, types.TypeEvtRemoveSuperfluidAsset, }, }, }, @@ -79,10 +80,10 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() { "token does not exist", []Action{ { - true, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{asset1}, false, + true, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{asset1}, false, types.TypeEvtSetSuperfluidAsset, }, { - false, []types.SuperfluidAsset{asset2}, []types.SuperfluidAsset{asset1}, true, + false, []types.SuperfluidAsset{asset2}, []types.SuperfluidAsset{asset1}, true, types.TypeEvtSetSuperfluidAsset, }, }, }, @@ -132,6 +133,7 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() { suite.Require().Error(err) } else { suite.Require().NoError(err) + assertEventEmitted(suite, suite.ctx, action.expectedEvent, 1) } // check assets individually diff --git a/x/superfluid/keeper/gov/suite_test.go b/x/superfluid/keeper/gov/suite_test.go index efd571759f2..6df091ec54e 100644 --- a/x/superfluid/keeper/gov/suite_test.go +++ b/x/superfluid/keeper/gov/suite_test.go @@ -30,3 +30,15 @@ func (suite *KeeperTestSuite) SetupTest() { func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } + +func assertEventEmitted(suite *KeeperTestSuite, ctx sdk.Context, eventTypeExpected string, numEventsExpected int) { + allEvents := ctx.EventManager().Events() + // filter out other events + actualEvents := make([]sdk.Event, 0, 1) + for _, event := range allEvents { + if event.Type == eventTypeExpected { + actualEvents = append(actualEvents, event) + } + } + suite.Require().Equal(numEventsExpected, len(actualEvents)) +} diff --git a/x/superfluid/keeper/hooks.go b/x/superfluid/keeper/hooks.go index 7310854aab0..c8b8270de00 100644 --- a/x/superfluid/keeper/hooks.go +++ b/x/superfluid/keeper/hooks.go @@ -1,11 +1,10 @@ package keeper import ( - "fmt" "time" epochstypes "github.com/osmosis-labs/osmosis/v10/x/epochs/types" - "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" + "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper/internal/events" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -43,11 +42,7 @@ func (h Hooks) AfterAddTokensToLock(ctx sdk.Context, address sdk.AccAddress, loc if err != nil { h.k.Logger(ctx).Error(err.Error()) } else { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.TypeEvtSuperfluidIncreaseDelegation, - sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", lockID)), - sdk.NewAttribute(types.AttributeAmount, amount.String()), - )) + events.EmitSuperfluidIncreaseDelegationEvent(ctx, lockID, amount) } } } diff --git a/x/superfluid/keeper/msg_server.go b/x/superfluid/keeper/msg_server.go index 514541539a2..932b73d0cfc 100644 --- a/x/superfluid/keeper/msg_server.go +++ b/x/superfluid/keeper/msg_server.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "errors" - "fmt" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,6 +13,7 @@ import ( lockuptypes "github.com/osmosis-labs/osmosis/v10/x/lockup/types" "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" + "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper/internal/events" ) type msgServer struct { @@ -46,12 +46,8 @@ func (server msgServer) SuperfluidDelegate(goCtx context.Context, msg *types.Msg ctx := sdk.UnwrapSDKContext(goCtx) err := server.keeper.SuperfluidDelegate(ctx, msg.Sender, msg.LockId, msg.ValAddr) - if err != nil { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.TypeEvtSuperfluidDelegate, - sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", msg.LockId)), - sdk.NewAttribute(types.AttributeValidator, msg.ValAddr), - )) + if err == nil { + events.EmitSuperfluidDelegateEvent(ctx, msg.LockId, msg.ValAddr) } return &types.MsgSuperfluidDelegateResponse{}, err } @@ -65,11 +61,8 @@ func (server msgServer) SuperfluidUndelegate(goCtx context.Context, msg *types.M ctx := sdk.UnwrapSDKContext(goCtx) err := server.keeper.SuperfluidUndelegate(ctx, msg.Sender, msg.LockId) - if err != nil { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.TypeEvtSuperfluidUndelegate, - sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", msg.LockId)), - )) + if err == nil { + events.EmitSuperfluidUndelegateEvent(ctx, msg.LockId) } return &types.MsgSuperfluidUndelegateResponse{}, err } @@ -92,11 +85,8 @@ func (server msgServer) SuperfluidUnbondLock(goCtx context.Context, msg *types.M ctx := sdk.UnwrapSDKContext(goCtx) err := server.keeper.SuperfluidUnbondLock(ctx, msg.LockId, msg.Sender) - if err != nil { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.TypeEvtSuperfluidUnbondLock, - sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", msg.LockId)), - )) + if err == nil { + events.EmitSuperfluidUnbondLockEvent(ctx, msg.LockId) } return &types.MsgSuperfluidUnbondLockResponse{}, err } @@ -157,14 +147,7 @@ func (server msgServer) UnPoolWhitelistedPool(goCtx context.Context, msg *types. } allExitedLockIDsSerialized, _ := json.Marshal(allExitedLockIDs) - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.TypeEvtUnpoolId, - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - sdk.NewAttribute(types.AttributeDenom, lpShareDenom), - sdk.NewAttribute(types.AttributeNewLockIds, string(allExitedLockIDsSerialized)), - ), - }) + events.EmitUnpoolIdEvent(ctx, msg.Sender, lpShareDenom, allExitedLockIDsSerialized) return &types.MsgUnPoolWhitelistedPoolResponse{ExitedLockIds: allExitedLockIDs}, nil } diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index bdfbfa4ba92..0b203a809fe 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -59,6 +59,62 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { } } +// TestMsgSuperfluidDelegate_Event tests that events are correctly emitted +// when calling SuperfluidDelegate. +func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate_Event() { + type param struct { + lockOwner sdk.AccAddress + duration time.Duration + } + + tests := []struct { + name string + param param + expectPass bool + }{ + { + name: "basic valid", + param: param{ + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Hour * 504, + }, + expectPass: true, + }, + { + name: "invalid", + param: param{ + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Second, + }, + expectPass: false, + }, + } + + for _, test := range tests { + suite.SetupTest() + + denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20), sdk.NewDec(20)}) + coinsToLock := sdk.NewCoins(sdk.NewCoin(denoms[0], sdk.NewInt(20))) + suite.FundAcc(test.param.lockOwner, coinsToLock) + + lockupMsgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) + c := sdk.WrapSDKContext(suite.Ctx) + resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, coinsToLock)) + + valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) + + msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) + _, err = msgServer.SuperfluidDelegate(c, types.NewMsgSuperfluidDelegate(test.param.lockOwner, resp.ID, valAddrs[0])) + + if test.expectPass { + suite.Require().NoError(err) + assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidDelegate, 1) + } else { + suite.Require().Error(err) + } + } +} + func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate() { type param struct { coinsToLock sdk.Coins @@ -104,6 +160,65 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate() { } } +// TestMsgSuperfluidUndelegate_Event tests that events are correctly emitted +// when calling SuperfluidUndelegate. +func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate_Event() { + testCases := []struct { + name string + validatorStats []stakingtypes.BondStatus + superDelegations []superfluidDelegation + superUnbondingLockIds []uint64 + expSuperUnbondingErr []bool + // expected amount of delegation to intermediary account + }{ + { + "with single validator and single superfluid delegation and single undelegation", + []stakingtypes.BondStatus{stakingtypes.Bonded}, + []superfluidDelegation{{0, 0, 0, 1000000}}, + []uint64{1}, + []bool{false}, + }, + { + "undelegating not available lock id", + []stakingtypes.BondStatus{stakingtypes.Bonded}, + []superfluidDelegation{{0, 0, 0, 1000000}}, + []uint64{2}, + []bool{true}, + }, + } + + for _, test := range testCases { + suite.SetupTest() + msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) + c := sdk.WrapSDKContext(suite.Ctx) + + // setup validators + valAddrs := suite.SetupValidators(test.validatorStats) + + denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20)}) + + // setup superfluid delegations + suite.setupSuperfluidDelegations(valAddrs, test.superDelegations, denoms) + for index, lockId := range test.superUnbondingLockIds { + lock, err := suite.App.LockupKeeper.GetLockByID(suite.Ctx, lockId) + if err != nil { + lock = &lockuptypes.PeriodLock{} + } + + // superfluid undelegate + sender, _ := sdk.AccAddressFromBech32(lock.Owner) + _, err = msgServer.SuperfluidUndelegate(c, types.NewMsgSuperfluidUndelegate(sender, lockId)) + if test.expSuperUnbondingErr[index] { + suite.Require().Error(err) + continue + } else { + suite.Require().NoError(err) + assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidUndelegate, 1) + } + } + } +} + func (suite *KeeperTestSuite) TestMsgSuperfluidUnbondLock() { type param struct { coinsToLock sdk.Coins @@ -149,6 +264,41 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidUnbondLock() { } } +// TestMsgSuperfluidUnbondLock_Event tests that events are correctly emitted +// when calling SuperfluidUnbondLock. +func (suite *KeeperTestSuite) TestMsgSuperfluidUnbondLock_Event() { + suite.SetupTest() + msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) + + // setup validators + valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) + + denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20), sdk.NewDec(20)}) + + // setup superfluid delegations + _, _, locks := suite.setupSuperfluidDelegations(valAddrs, []superfluidDelegation{{0, 0, 0, 1000000}}, denoms) + + for _, lock := range locks { + startTime := time.Now() + sender, _ := sdk.AccAddressFromBech32(lock.Owner) + + // first we test that SuperfluidUnbondLock would cause error before undelegating + _, err := msgServer.SuperfluidUnbondLock(sdk.WrapSDKContext(suite.Ctx), types.NewMsgSuperfluidUnbondLock(sender, lock.ID)) + suite.Require().Error(err) + + // undelegation needs to happen prior to SuperfluidUnbondLock + err = suite.App.SuperfluidKeeper.SuperfluidUndelegate(suite.Ctx, lock.Owner, lock.ID) + suite.Require().NoError(err) + + // test SuperfluidUnbondLock + unbondLockStartTime := startTime.Add(time.Hour) + suite.Ctx = suite.Ctx.WithBlockTime(unbondLockStartTime) + _, err = msgServer.SuperfluidUnbondLock(sdk.WrapSDKContext(suite.Ctx), types.NewMsgSuperfluidUnbondLock(sender, lock.ID)) + suite.Require().NoError(err) + assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidUnbondLock, 1) + } +} + func (suite *KeeperTestSuite) TestMsgLockAndSuperfluidDelegate() { type param struct { coinsToLock sdk.Coins @@ -192,3 +342,15 @@ func (suite *KeeperTestSuite) TestMsgLockAndSuperfluidDelegate() { } } } + +func assertEventEmitted(suite *KeeperTestSuite, ctx sdk.Context, eventTypeExpected string, numEventsExpected int) { + allEvents := ctx.EventManager().Events() + // filter out other events + actualEvents := make([]sdk.Event, 0, 1) + for _, event := range allEvents { + if event.Type == eventTypeExpected { + actualEvents = append(actualEvents, event) + } + } + suite.Require().Equal(numEventsExpected, len(actualEvents)) +} From c0dd4b101724a1a1b0ff8947168b2b7fb18e3594 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 03:08:50 +0700 Subject: [PATCH 03/20] format --- .../keeper/internal/events/emit_test.go | 75 +++++++++---------- x/superfluid/keeper/msg_server.go | 2 +- x/superfluid/keeper/msg_server_test.go | 12 +-- 3 files changed, 41 insertions(+), 48 deletions(-) diff --git a/x/superfluid/keeper/internal/events/emit_test.go b/x/superfluid/keeper/internal/events/emit_test.go index 68b83d8453b..8ecc8c8d524 100644 --- a/x/superfluid/keeper/internal/events/emit_test.go +++ b/x/superfluid/keeper/internal/events/emit_test.go @@ -32,14 +32,13 @@ func TestSuperfluidEventsTestSuite(t *testing.T) { func (suite *SuperfluidEventsTestSuite) TestEmitSetSuperfluidAssetEvent() { testcases := map[string]struct { ctx sdk.Context - denom string + denom string assetType types.SuperfluidAssetType }{ "basic valid": { - ctx: suite.CreateTestContext(), - denom: testDenomA, - assetType: types.SuperfluidAssetTypeNative, - + ctx: suite.CreateTestContext(), + denom: testDenomA, + assetType: types.SuperfluidAssetTypeNative, }, "context with no event manager": { ctx: sdk.Context{}, @@ -76,13 +75,12 @@ func (suite *SuperfluidEventsTestSuite) TestEmitSetSuperfluidAssetEvent() { func (suite *SuperfluidEventsTestSuite) TestEmitRemoveSuperfluidAsset() { testcases := map[string]struct { - ctx sdk.Context - denom string + ctx sdk.Context + denom string }{ "basic valid": { - ctx: suite.CreateTestContext(), - denom: testDenomA, - + ctx: suite.CreateTestContext(), + denom: testDenomA, }, "context with no event manager": { ctx: sdk.Context{}, @@ -118,13 +116,13 @@ func (suite *SuperfluidEventsTestSuite) TestEmitRemoveSuperfluidAsset() { func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidDelegateEvent() { testcases := map[string]struct { - ctx sdk.Context - lockID uint64 - valAddr string + ctx sdk.Context + lockID uint64 + valAddr string }{ "basic valid": { - ctx: suite.CreateTestContext(), - lockID: 1, + ctx: suite.CreateTestContext(), + lockID: 1, valAddr: sdk.AccAddress([]byte(addressString)).String(), }, "context with no event manager": { @@ -162,21 +160,21 @@ func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidDelegateEvent() { func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidIncreaseDelegationEvent() { testcases := map[string]struct { - ctx sdk.Context - lockID uint64 - amount sdk.Coins + ctx sdk.Context + lockID uint64 + amount sdk.Coins }{ "basic valid": { - ctx: suite.CreateTestContext(), - lockID: 1, + ctx: suite.CreateTestContext(), + lockID: 1, amount: sdk.NewCoins(sdk.NewCoin(testDenomA, sdk.NewInt(100))), }, "context with no event manager": { ctx: sdk.Context{}, }, "valid with multiple tokens in and out": { - ctx: suite.CreateTestContext(), - lockID: 1, + ctx: suite.CreateTestContext(), + lockID: 1, amount: sdk.NewCoins(sdk.NewCoin(testDenomA, sdk.NewInt(100)), sdk.NewCoin(testDenomB, sdk.NewInt(10))), }, } @@ -211,17 +209,16 @@ func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidIncreaseDelegationEven func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidUndelegateEvent() { testcases := map[string]struct { - ctx sdk.Context - lockID uint64 + ctx sdk.Context + lockID uint64 }{ "basic valid": { - ctx: suite.CreateTestContext(), - lockID: 1, + ctx: suite.CreateTestContext(), + lockID: 1, }, "context with no event manager": { ctx: sdk.Context{}, }, - } for name, tc := range testcases { @@ -253,17 +250,16 @@ func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidUndelegateEvent() { func (suite *SuperfluidEventsTestSuite) TestEmitSuperfluidUnbondLockEvent() { testcases := map[string]struct { - ctx sdk.Context - lockID uint64 + ctx sdk.Context + lockID uint64 }{ "basic valid": { - ctx: suite.CreateTestContext(), - lockID: 1, + ctx: suite.CreateTestContext(), + lockID: 1, }, "context with no event manager": { ctx: sdk.Context{}, }, - } for name, tc := range testcases { @@ -297,15 +293,15 @@ func (suite *SuperfluidEventsTestSuite) TestEmitUnpoolIdEvent() { testAllExitedLockIDsSerialized, _ := json.Marshal([]uint64{1}) testcases := map[string]struct { - ctx sdk.Context - sender string - lpShareDenom string + ctx sdk.Context + sender string + lpShareDenom string allExitedLockIDsSerialized []byte }{ "basic valid": { - ctx: suite.CreateTestContext(), - sender: sdk.AccAddress([]byte(addressString)).String(), - lpShareDenom: "pool1", + ctx: suite.CreateTestContext(), + sender: sdk.AccAddress([]byte(addressString)).String(), + lpShareDenom: "pool1", allExitedLockIDsSerialized: testAllExitedLockIDsSerialized, }, "context with no event manager": { @@ -341,6 +337,3 @@ func (suite *SuperfluidEventsTestSuite) TestEmitUnpoolIdEvent() { }) } } - - - diff --git a/x/superfluid/keeper/msg_server.go b/x/superfluid/keeper/msg_server.go index 932b73d0cfc..e4946ec7a75 100644 --- a/x/superfluid/keeper/msg_server.go +++ b/x/superfluid/keeper/msg_server.go @@ -12,8 +12,8 @@ import ( gammtypes "github.com/osmosis-labs/osmosis/v10/x/gamm/types" lockuptypes "github.com/osmosis-labs/osmosis/v10/x/lockup/types" - "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper/internal/events" + "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" ) type msgServer struct { diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index 0b203a809fe..fb7492baae8 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -63,8 +63,8 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { // when calling SuperfluidDelegate. func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate_Event() { type param struct { - lockOwner sdk.AccAddress - duration time.Duration + lockOwner sdk.AccAddress + duration time.Duration } tests := []struct { @@ -75,16 +75,16 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate_Event() { { name: "basic valid", param: param{ - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Hour * 504, + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Hour * 504, }, expectPass: true, }, { name: "invalid", param: param{ - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Second, + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Second, }, expectPass: false, }, From 20cba08858a0c65682e3d75c8a1b2d00d51e4680 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 15:23:00 +0700 Subject: [PATCH 04/20] add event test for hook --- x/superfluid/keeper/gov/gov_test.go | 2 +- x/superfluid/keeper/hooks_test.go | 34 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/x/superfluid/keeper/gov/gov_test.go b/x/superfluid/keeper/gov/gov_test.go index bb8263521b3..cf9755c4aea 100644 --- a/x/superfluid/keeper/gov/gov_test.go +++ b/x/superfluid/keeper/gov/gov_test.go @@ -83,7 +83,7 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() { true, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{asset1}, false, types.TypeEvtSetSuperfluidAsset, }, { - false, []types.SuperfluidAsset{asset2}, []types.SuperfluidAsset{asset1}, true, types.TypeEvtSetSuperfluidAsset, + false, []types.SuperfluidAsset{asset2}, []types.SuperfluidAsset{asset1}, true, types.TypeEvtRemoveSuperfluidAsset, }, }, }, diff --git a/x/superfluid/keeper/hooks_test.go b/x/superfluid/keeper/hooks_test.go index 9017467354d..1078d635ca4 100644 --- a/x/superfluid/keeper/hooks_test.go +++ b/x/superfluid/keeper/hooks_test.go @@ -1,8 +1,14 @@ package keeper_test import ( + "time" + sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + lockupkeeper "github.com/osmosis-labs/osmosis/v10/x/lockup/keeper" + lockuptypes "github.com/osmosis-labs/osmosis/v10/x/lockup/types" + "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" ) func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() { @@ -303,3 +309,31 @@ func (suite *KeeperTestSuite) TestBeforeSlashingUnbondingDelegationHook() { }) } } + +// TestAfterAddTokensToLock_Event tests that events are correctly emitted +// when calling AfterAddTokensToLock. +func (suite *KeeperTestSuite) TestAfterAddTokensToLock_Event() { + suite.SetupTest() + + valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded},) + + denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20)}) + + // setup superfluid delegations + _, intermediaryAccs, locks := suite.setupSuperfluidDelegations(valAddrs, []superfluidDelegation{{0, 0, 0, 1000000}}, denoms) + suite.checkIntermediaryAccountDelegations(intermediaryAccs) + + for index, lock := range locks { + lockupMsgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) + c := sdk.WrapSDKContext(suite.Ctx) + coinsToLock := sdk.NewCoins(sdk.NewCoin(denoms[index], sdk.NewInt(100))) + sender, _ := sdk.AccAddressFromBech32(lock.Owner) + suite.FundAcc(sender, coinsToLock) + + _, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(sender, time.Hour * 504, coinsToLock)) + suite.Require().NoError(err) + + // should call AfterAddTokensToLock hook and emit event here + assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidIncreaseDelegation, 1) + } +} From 3dbe40c1d93fd088dd329e5795ce3f3a9df5a3e6 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 16:07:14 +0700 Subject: [PATCH 05/20] add event test for unpool --- x/superfluid/keeper/msg_server_test.go | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index fb7492baae8..74391e79147 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -10,6 +10,7 @@ import ( lockuptypes "github.com/osmosis-labs/osmosis/v10/x/lockup/types" "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper" "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" + v8constants "github.com/osmosis-labs/osmosis/v10/app/upgrades/v8/constants" ) func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { @@ -299,6 +300,32 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidUnbondLock_Event() { } } +// TestMsgUnPoolWhitelistedPool_Event tests that events are correctly emitted +// when calling UnPoolWhitelistedPool. +func (suite *KeeperTestSuite) TestMsgUnPoolWhitelistedPool_Event() { + suite.SetupTest() + msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) + + // setup validators + valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) + + denoms, poolIds := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20)}) + + // whitelist designated pools + suite.App.SuperfluidKeeper.SetUnpoolAllowedPools(suite.Ctx, poolIds) + + // setup superfluid delegations + _, _, locks := suite.setupSuperfluidDelegations(valAddrs, []superfluidDelegation{{0, 0, 0, 1000000}}, denoms) + + for index, poolId := range poolIds { + sender, _ := sdk.AccAddressFromBech32(locks[index].Owner) + suite.Ctx = suite.Ctx.WithBlockHeight(v8constants.UpgradeHeight) + _, err := msgServer.UnPoolWhitelistedPool(sdk.WrapSDKContext(suite.Ctx), types.NewMsgUnPoolWhitelistedPool(sender, poolId)) + suite.Require().NoError(err) + assertEventEmitted(suite, suite.Ctx, types.TypeEvtUnpoolId, 1) + } +} + func (suite *KeeperTestSuite) TestMsgLockAndSuperfluidDelegate() { type param struct { coinsToLock sdk.Coins From e8b4fca9398c0806df978bdcae16304ff933303e Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 16:10:28 +0700 Subject: [PATCH 06/20] refactor --- x/superfluid/keeper/msg_server_test.go | 226 ++++++++++++------------- 1 file changed, 113 insertions(+), 113 deletions(-) diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index 74391e79147..8cb18c4bd12 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -60,12 +60,12 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { } } -// TestMsgSuperfluidDelegate_Event tests that events are correctly emitted -// when calling SuperfluidDelegate. -func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate_Event() { +func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate() { type param struct { - lockOwner sdk.AccAddress - duration time.Duration + coinsToLock sdk.Coins + lockOwner sdk.AccAddress + duration time.Duration + coinsInOwnerAddress sdk.Coins } tests := []struct { @@ -74,18 +74,57 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate_Event() { expectPass bool }{ { - name: "basic valid", + name: "superfluid undelegation for not superfluid delegated lockup", param: param{ - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Hour * 504, + coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Second, + coinsInOwnerAddress: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, }, - expectPass: true, + expectPass: false, }, + } + + for _, test := range tests { + suite.SetupTest() + + suite.FundAcc(test.param.lockOwner, test.param.coinsInOwnerAddress) + + lockupMsgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) + c := sdk.WrapSDKContext(suite.Ctx) + resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, test.param.coinsToLock)) + + msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) + _, err = msgServer.SuperfluidUndelegate(c, types.NewMsgSuperfluidUndelegate(test.param.lockOwner, resp.ID)) + + if test.expectPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + } +} + +func (suite *KeeperTestSuite) TestMsgSuperfluidUnbondLock() { + type param struct { + coinsToLock sdk.Coins + lockOwner sdk.AccAddress + duration time.Duration + coinsInOwnerAddress sdk.Coins + } + + tests := []struct { + name string + param param + expectPass bool + }{ { - name: "invalid", + name: "superfluid unbond lock that is not superfluid lockup", param: param{ - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Second, + coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Second, + coinsInOwnerAddress: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, }, expectPass: false, }, @@ -94,29 +133,24 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate_Event() { for _, test := range tests { suite.SetupTest() - denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20), sdk.NewDec(20)}) - coinsToLock := sdk.NewCoins(sdk.NewCoin(denoms[0], sdk.NewInt(20))) - suite.FundAcc(test.param.lockOwner, coinsToLock) + suite.FundAcc(test.param.lockOwner, test.param.coinsInOwnerAddress) lockupMsgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) c := sdk.WrapSDKContext(suite.Ctx) - resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, coinsToLock)) - - valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) + resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, test.param.coinsToLock)) msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) - _, err = msgServer.SuperfluidDelegate(c, types.NewMsgSuperfluidDelegate(test.param.lockOwner, resp.ID, valAddrs[0])) + _, err = msgServer.SuperfluidUnbondLock(c, types.NewMsgSuperfluidUnbondLock(test.param.lockOwner, resp.ID)) if test.expectPass { suite.Require().NoError(err) - assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidDelegate, 1) } else { suite.Require().Error(err) } } } -func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate() { +func (suite *KeeperTestSuite) TestMsgLockAndSuperfluidDelegate() { type param struct { coinsToLock sdk.Coins lockOwner sdk.AccAddress @@ -130,7 +164,7 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate() { expectPass bool }{ { - name: "superfluid undelegation for not superfluid delegated lockup", + name: "superfluid lock and superfluid delegate for not allowed asset", param: param{ coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet @@ -146,15 +180,70 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate() { suite.FundAcc(test.param.lockOwner, test.param.coinsInOwnerAddress) + c := sdk.WrapSDKContext(suite.Ctx) + valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) + + msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) + _, err := msgServer.LockAndSuperfluidDelegate(c, types.NewMsgLockAndSuperfluidDelegate(test.param.lockOwner, test.param.coinsToLock, valAddrs[0])) + + if test.expectPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + } +} + +// TestMsgSuperfluidDelegate_Event tests that events are correctly emitted +// when calling SuperfluidDelegate. +func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate_Event() { + type param struct { + lockOwner sdk.AccAddress + duration time.Duration + } + + tests := []struct { + name string + param param + expectPass bool + }{ + { + name: "basic valid", + param: param{ + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Hour * 504, + }, + expectPass: true, + }, + { + name: "invalid", + param: param{ + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Second, + }, + expectPass: false, + }, + } + + for _, test := range tests { + suite.SetupTest() + + denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20), sdk.NewDec(20)}) + coinsToLock := sdk.NewCoins(sdk.NewCoin(denoms[0], sdk.NewInt(20))) + suite.FundAcc(test.param.lockOwner, coinsToLock) + lockupMsgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) c := sdk.WrapSDKContext(suite.Ctx) - resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, test.param.coinsToLock)) + resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, coinsToLock)) + + valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) - _, err = msgServer.SuperfluidUndelegate(c, types.NewMsgSuperfluidUndelegate(test.param.lockOwner, resp.ID)) + _, err = msgServer.SuperfluidDelegate(c, types.NewMsgSuperfluidDelegate(test.param.lockOwner, resp.ID, valAddrs[0])) if test.expectPass { suite.Require().NoError(err) + assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidDelegate, 1) } else { suite.Require().Error(err) } @@ -220,51 +309,6 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate_Event() { } } -func (suite *KeeperTestSuite) TestMsgSuperfluidUnbondLock() { - type param struct { - coinsToLock sdk.Coins - lockOwner sdk.AccAddress - duration time.Duration - coinsInOwnerAddress sdk.Coins - } - - tests := []struct { - name string - param param - expectPass bool - }{ - { - name: "superfluid unbond lock that is not superfluid lockup", - param: param{ - coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Second, - coinsInOwnerAddress: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, - }, - expectPass: false, - }, - } - - for _, test := range tests { - suite.SetupTest() - - suite.FundAcc(test.param.lockOwner, test.param.coinsInOwnerAddress) - - lockupMsgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) - c := sdk.WrapSDKContext(suite.Ctx) - resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, test.param.coinsToLock)) - - msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) - _, err = msgServer.SuperfluidUnbondLock(c, types.NewMsgSuperfluidUnbondLock(test.param.lockOwner, resp.ID)) - - if test.expectPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - } -} - // TestMsgSuperfluidUnbondLock_Event tests that events are correctly emitted // when calling SuperfluidUnbondLock. func (suite *KeeperTestSuite) TestMsgSuperfluidUnbondLock_Event() { @@ -326,50 +370,6 @@ func (suite *KeeperTestSuite) TestMsgUnPoolWhitelistedPool_Event() { } } -func (suite *KeeperTestSuite) TestMsgLockAndSuperfluidDelegate() { - type param struct { - coinsToLock sdk.Coins - lockOwner sdk.AccAddress - duration time.Duration - coinsInOwnerAddress sdk.Coins - } - - tests := []struct { - name string - param param - expectPass bool - }{ - { - name: "superfluid lock and superfluid delegate for not allowed asset", - param: param{ - coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Second, - coinsInOwnerAddress: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, - }, - expectPass: false, - }, - } - - for _, test := range tests { - suite.SetupTest() - - suite.FundAcc(test.param.lockOwner, test.param.coinsInOwnerAddress) - - c := sdk.WrapSDKContext(suite.Ctx) - valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) - - msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) - _, err := msgServer.LockAndSuperfluidDelegate(c, types.NewMsgLockAndSuperfluidDelegate(test.param.lockOwner, test.param.coinsToLock, valAddrs[0])) - - if test.expectPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - } -} - func assertEventEmitted(suite *KeeperTestSuite, ctx sdk.Context, eventTypeExpected string, numEventsExpected int) { allEvents := ctx.EventManager().Events() // filter out other events From f357e10453686b1fbeeeebd692cf0c5aaa41099d Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 19:25:24 +0700 Subject: [PATCH 07/20] update readme --- x/superfluid/README.md | 87 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/x/superfluid/README.md b/x/superfluid/README.md index 5bcf8d1542e..a7018aea28e 100644 --- a/x/superfluid/README.md +++ b/x/superfluid/README.md @@ -455,7 +455,92 @@ Disable multiple assets from being used for superfluid staking. ## Events ------; +There are 7 types of events that exist in Superfluid module: + +* `types.TypeEvtSetSuperfluidAsset` - "set_superfluid_asset" +* `types.TypeEvtRemoveSuperfluidAsset` - "remove_superfluid_asset" +* `types.TypeEvtSuperfluidDelegate` - "superfluid_delegate" +* `types.TypeEvtSuperfluidIncreaseDelegation` - "superfluid_increase_delegation" +* `types.TypeEvtSuperfluidUndelegate` - "superfluid_undelegate" +* `types.TypeEvtSuperfluidUnbondLock` - "superfluid_unbond_lock" +* `types.TypeEvtUnpoolId` - "unpool_pool_id" + +### `types.TypeEvtSetSuperfluidAsset` + +This event is emitted in the proposal which set new superfluid asset + +It consists of the following attributes: + +* `types.AttributeDenom` + * The value is the asset denom. +* `types.AttributeSuperfluidAssetType` + * The value is the type of asset. + +### `types.TypeEvtRemoveSuperfluidAsset` + +This event is emitted in the proposal which remove superfluid asset + +It consists of the following attributes: + +* `types.AttributeDenom` + * The value is the asset denom. + +### `types.TypeEvtSuperfluidDelegate` + +This event is emitted in the message server after succesfully create a delegation for the given lock ID and the validator to delegate to. + +It consists of the following attributes: + +* `types.AttributeLockId` + * The value is the given lock ID. +* `types.AttributeValidator` + * The value is the validator address to delegate to. + +### `types.TypeEvtSuperfluidIncreaseDelegation` + +This event is emitted in the hook after adding more token to the existing lock + +It consists of the following attributes: + +* `types.AttributeLockId` + * The value is the given lock ID. +* `types.AttributeAmount` + * The value is the token amount added to the lock. + +### `types.TypeEvtSuperfluidUndelegate` + +This event is emitted in the message server after undelegating currently superfluid delegated position given by lock ID. + +It consists of the following attributes: + +* `types.AttributeLockId` + * The value is the given lock ID. + +### `types.TypeEvtSuperfluidUnbondLock` + +This event is emitted in the message server after starting unbonding for currently superfluid undelegating lock. + +It consists of the following attributes: + +* `types.AttributeLockId` + * The value is the given lock ID. + +### `types.TypeEvtUnpoolId` + +This event is emitted in the message server `UnPoolWhitelistedPool` + +It consists of the following attributes: + +* `types.AttributeKeySender` + * The value is the msg sender address. +* `types.AttributeLockId` + * The value is the pool lpShareDenom. +* `types.AttributeNewLockIds` + * The value is the exited lock ids in byte[]. + +sdk.NewAttribute(sdk.AttributeKeySender, sender), + sdk.NewAttribute(types.AttributeDenom, lpShareDenom), + sdk.NewAttribute(types.AttributeNewLockIds, string(allExitedLockIDsSerialized)), ### Messages From 41f8b78418bae0dc510890093a60cc7f0c375bc7 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 20:03:25 +0700 Subject: [PATCH 08/20] format codes --- x/superfluid/keeper/hooks_test.go | 6 +++--- x/superfluid/keeper/msg_server_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/superfluid/keeper/hooks_test.go b/x/superfluid/keeper/hooks_test.go index 1078d635ca4..dcdde59ffc3 100644 --- a/x/superfluid/keeper/hooks_test.go +++ b/x/superfluid/keeper/hooks_test.go @@ -315,7 +315,7 @@ func (suite *KeeperTestSuite) TestBeforeSlashingUnbondingDelegationHook() { func (suite *KeeperTestSuite) TestAfterAddTokensToLock_Event() { suite.SetupTest() - valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded},) + valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20)}) @@ -329,8 +329,8 @@ func (suite *KeeperTestSuite) TestAfterAddTokensToLock_Event() { coinsToLock := sdk.NewCoins(sdk.NewCoin(denoms[index], sdk.NewInt(100))) sender, _ := sdk.AccAddressFromBech32(lock.Owner) suite.FundAcc(sender, coinsToLock) - - _, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(sender, time.Hour * 504, coinsToLock)) + + _, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(sender, time.Hour*504, coinsToLock)) suite.Require().NoError(err) // should call AfterAddTokensToLock hook and emit event here diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index 8cb18c4bd12..a119336d14b 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -6,11 +6,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + v8constants "github.com/osmosis-labs/osmosis/v10/app/upgrades/v8/constants" lockupkeeper "github.com/osmosis-labs/osmosis/v10/x/lockup/keeper" lockuptypes "github.com/osmosis-labs/osmosis/v10/x/lockup/types" "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper" "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" - v8constants "github.com/osmosis-labs/osmosis/v10/app/upgrades/v8/constants" ) func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { From 8390a5aa2beb1adaf603f1eaf85337c9fcfd11e0 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 21:50:29 +0700 Subject: [PATCH 09/20] remove unuse --- x/superfluid/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x/superfluid/README.md b/x/superfluid/README.md index a7018aea28e..dd45319d1cf 100644 --- a/x/superfluid/README.md +++ b/x/superfluid/README.md @@ -538,10 +538,6 @@ It consists of the following attributes: * `types.AttributeNewLockIds` * The value is the exited lock ids in byte[]. -sdk.NewAttribute(sdk.AttributeKeySender, sender), - sdk.NewAttribute(types.AttributeDenom, lpShareDenom), - sdk.NewAttribute(types.AttributeNewLockIds, string(allExitedLockIDsSerialized)), - ### Messages ### MsgSuperfluidDelegate From e72df0d1c59b001ebb18955fa56600c410785633 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 29 Jul 2022 22:53:54 +0700 Subject: [PATCH 10/20] fix readme --- x/superfluid/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/superfluid/README.md b/x/superfluid/README.md index dd45319d1cf..657b3c88e99 100644 --- a/x/superfluid/README.md +++ b/x/superfluid/README.md @@ -478,7 +478,7 @@ It consists of the following attributes: ### `types.TypeEvtRemoveSuperfluidAsset` -This event is emitted in the proposal which remove superfluid asset +This event is emitted in the proposal which removes the superfluid asset It consists of the following attributes: @@ -487,7 +487,7 @@ It consists of the following attributes: ### `types.TypeEvtSuperfluidDelegate` -This event is emitted in the message server after succesfully create a delegation for the given lock ID and the validator to delegate to. +This event is emitted in the message server after successfully creating a delegation for the given lock ID and the validator to delegate to. It consists of the following attributes: @@ -509,7 +509,7 @@ It consists of the following attributes: ### `types.TypeEvtSuperfluidUndelegate` -This event is emitted in the message server after undelegating currently superfluid delegated position given by lock ID. +This event is emitted in the message server after undelegating the currently superfluid delegated position given by lock ID. It consists of the following attributes: @@ -518,7 +518,7 @@ It consists of the following attributes: ### `types.TypeEvtSuperfluidUnbondLock` -This event is emitted in the message server after starting unbonding for currently superfluid undelegating lock. +This event is emitted in the message server after starting unbonding for the currently superfluid undelegating lock. It consists of the following attributes: From eddaf55b13bcb18919a66da64e272916ba18a0e9 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Sun, 31 Jul 2022 15:58:53 +0700 Subject: [PATCH 11/20] restruct test --- x/superfluid/keeper/gov/gov_test.go | 14 ++++++++------ x/superfluid/keeper/msg_server_test.go | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/x/superfluid/keeper/gov/gov_test.go b/x/superfluid/keeper/gov/gov_test.go index cf9755c4aea..b502b9e1048 100644 --- a/x/superfluid/keeper/gov/gov_test.go +++ b/x/superfluid/keeper/gov/gov_test.go @@ -59,33 +59,35 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() { assets []types.SuperfluidAsset expectedAssets []types.SuperfluidAsset expectErr bool - expectedEvent string } testCases := []struct { name string actions []Action + expectedEvent []string }{ { "happy path flow", []Action{ { - true, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{asset1}, false, types.TypeEvtSetSuperfluidAsset, + true, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{asset1}, false, }, { - false, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{}, false, types.TypeEvtRemoveSuperfluidAsset, + false, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{}, false, }, }, + []string{types.TypeEvtSetSuperfluidAsset, types.TypeEvtRemoveSuperfluidAsset}, }, { "token does not exist", []Action{ { - true, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{asset1}, false, types.TypeEvtSetSuperfluidAsset, + true, []types.SuperfluidAsset{asset1}, []types.SuperfluidAsset{asset1}, false, }, { - false, []types.SuperfluidAsset{asset2}, []types.SuperfluidAsset{asset1}, true, types.TypeEvtRemoveSuperfluidAsset, + false, []types.SuperfluidAsset{asset2}, []types.SuperfluidAsset{asset1}, true, }, }, + []string{types.TypeEvtSetSuperfluidAsset, types.TypeEvtRemoveSuperfluidAsset}, }, } @@ -133,7 +135,7 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() { suite.Require().Error(err) } else { suite.Require().NoError(err) - assertEventEmitted(suite, suite.ctx, action.expectedEvent, 1) + assertEventEmitted(suite, suite.ctx, tc.expectedEvent[i], 1) } // check assets individually diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index a119336d14b..075291d0edf 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -216,7 +216,7 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate_Event() { expectPass: true, }, { - name: "invalid", + name: "invalid duration", param: param{ lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet duration: time.Second, From 58fbe27114898ae086dbded70fd7f64d218239a9 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 11 Aug 2022 12:57:28 +0700 Subject: [PATCH 12/20] duplicate test --- x/superfluid/keeper/msg_server_test.go | 110 +++++++++---------------- 1 file changed, 39 insertions(+), 71 deletions(-) diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index 075291d0edf..c3de10877b4 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + // "fmt" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,7 +19,6 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { coinsToLock sdk.Coins lockOwner sdk.AccAddress duration time.Duration - coinsInOwnerAddress sdk.Coins } tests := []struct { @@ -30,33 +30,57 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { name: "superfluid delegation for not allowed asset", param: param{ coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Hour * 504, + }, + expectPass: false, + }, + { + name: "invalid duration", + param: param{ lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet duration: time.Second, - coinsInOwnerAddress: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, }, expectPass: false, }, + { + name: "happy case", + param: param{ + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Hour * 504, + }, + expectPass: true, + }, } for _, test := range tests { - suite.SetupTest() + suite.Run(test.name, func() { + suite.SetupTest() + lockupMsgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) + c := sdk.WrapSDKContext(suite.Ctx) - suite.FundAcc(test.param.lockOwner, test.param.coinsInOwnerAddress) + denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20), sdk.NewDec(20)}) - lockupMsgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) - c := sdk.WrapSDKContext(suite.Ctx) - resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, test.param.coinsToLock)) + // If there is no coinsToLock in the param, use pool denom + if(test.param.coinsToLock.Empty()) { + test.param.coinsToLock = sdk.NewCoins(sdk.NewCoin(denoms[0], sdk.NewInt(20))) + } + suite.FundAcc(test.param.lockOwner, test.param.coinsToLock) + resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, test.param.coinsToLock)) - valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) + valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) - msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) - _, err = msgServer.SuperfluidDelegate(c, types.NewMsgSuperfluidDelegate(test.param.lockOwner, resp.ID, valAddrs[0])) + msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) + _, err = msgServer.SuperfluidDelegate(c, types.NewMsgSuperfluidDelegate(test.param.lockOwner, resp.ID, valAddrs[0])) - if test.expectPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } + if test.expectPass { + suite.Require().NoError(err) + suite.AssertEventEmitted(suite.Ctx, types.TypeEvtSuperfluidDelegate, 1) + } else { + suite.Require().Error(err) + } + }) + } } @@ -194,62 +218,6 @@ func (suite *KeeperTestSuite) TestMsgLockAndSuperfluidDelegate() { } } -// TestMsgSuperfluidDelegate_Event tests that events are correctly emitted -// when calling SuperfluidDelegate. -func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate_Event() { - type param struct { - lockOwner sdk.AccAddress - duration time.Duration - } - - tests := []struct { - name string - param param - expectPass bool - }{ - { - name: "basic valid", - param: param{ - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Hour * 504, - }, - expectPass: true, - }, - { - name: "invalid duration", - param: param{ - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Second, - }, - expectPass: false, - }, - } - - for _, test := range tests { - suite.SetupTest() - - denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20), sdk.NewDec(20)}) - coinsToLock := sdk.NewCoins(sdk.NewCoin(denoms[0], sdk.NewInt(20))) - suite.FundAcc(test.param.lockOwner, coinsToLock) - - lockupMsgServer := lockupkeeper.NewMsgServerImpl(suite.App.LockupKeeper) - c := sdk.WrapSDKContext(suite.Ctx) - resp, err := lockupMsgServer.LockTokens(c, lockuptypes.NewMsgLockTokens(test.param.lockOwner, test.param.duration, coinsToLock)) - - valAddrs := suite.SetupValidators([]stakingtypes.BondStatus{stakingtypes.Bonded}) - - msgServer := keeper.NewMsgServerImpl(suite.App.SuperfluidKeeper) - _, err = msgServer.SuperfluidDelegate(c, types.NewMsgSuperfluidDelegate(test.param.lockOwner, resp.ID, valAddrs[0])) - - if test.expectPass { - suite.Require().NoError(err) - assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidDelegate, 1) - } else { - suite.Require().Error(err) - } - } -} - // TestMsgSuperfluidUndelegate_Event tests that events are correctly emitted // when calling SuperfluidUndelegate. func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate_Event() { From 5178a310412f66ab17093bba42ef54f70357cc9c Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 11 Aug 2022 12:59:10 +0700 Subject: [PATCH 13/20] use suite.AssertEventEmitted --- x/superfluid/keeper/msg_server_test.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index c3de10877b4..c8b018007c3 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -271,7 +271,7 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidUndelegate_Event() { continue } else { suite.Require().NoError(err) - assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidUndelegate, 1) + suite.AssertEventEmitted(suite.Ctx, types.TypeEvtSuperfluidUndelegate, 1) } } } @@ -308,7 +308,7 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidUnbondLock_Event() { suite.Ctx = suite.Ctx.WithBlockTime(unbondLockStartTime) _, err = msgServer.SuperfluidUnbondLock(sdk.WrapSDKContext(suite.Ctx), types.NewMsgSuperfluidUnbondLock(sender, lock.ID)) suite.Require().NoError(err) - assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidUnbondLock, 1) + suite.AssertEventEmitted(suite.Ctx, types.TypeEvtSuperfluidUnbondLock, 1) } } @@ -334,18 +334,6 @@ func (suite *KeeperTestSuite) TestMsgUnPoolWhitelistedPool_Event() { suite.Ctx = suite.Ctx.WithBlockHeight(v8constants.UpgradeHeight) _, err := msgServer.UnPoolWhitelistedPool(sdk.WrapSDKContext(suite.Ctx), types.NewMsgUnPoolWhitelistedPool(sender, poolId)) suite.Require().NoError(err) - assertEventEmitted(suite, suite.Ctx, types.TypeEvtUnpoolId, 1) + suite.AssertEventEmitted(suite.Ctx, types.TypeEvtUnpoolId, 1) } } - -func assertEventEmitted(suite *KeeperTestSuite, ctx sdk.Context, eventTypeExpected string, numEventsExpected int) { - allEvents := ctx.EventManager().Events() - // filter out other events - actualEvents := make([]sdk.Event, 0, 1) - for _, event := range allEvents { - if event.Type == eventTypeExpected { - actualEvents = append(actualEvents, event) - } - } - suite.Require().Equal(numEventsExpected, len(actualEvents)) -} From d7102b8802530aa1649225233f4d58fd45a1ec43 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 11 Aug 2022 13:00:26 +0700 Subject: [PATCH 14/20] hooks test --- x/superfluid/keeper/hooks_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/superfluid/keeper/hooks_test.go b/x/superfluid/keeper/hooks_test.go index dcdde59ffc3..a24fdbb2f45 100644 --- a/x/superfluid/keeper/hooks_test.go +++ b/x/superfluid/keeper/hooks_test.go @@ -334,6 +334,6 @@ func (suite *KeeperTestSuite) TestAfterAddTokensToLock_Event() { suite.Require().NoError(err) // should call AfterAddTokensToLock hook and emit event here - assertEventEmitted(suite, suite.Ctx, types.TypeEvtSuperfluidIncreaseDelegation, 1) + suite.AssertEventEmitted(suite.Ctx, types.TypeEvtSuperfluidIncreaseDelegation, 1) } } From f11978452011a73df0d8fd5e79651521880aef05 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 11 Aug 2022 13:02:07 +0700 Subject: [PATCH 15/20] format --- x/superfluid/keeper/msg_server_test.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index c8b018007c3..f1d59419f89 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -16,9 +16,9 @@ import ( func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { type param struct { - coinsToLock sdk.Coins - lockOwner sdk.AccAddress - duration time.Duration + coinsToLock sdk.Coins + lockOwner sdk.AccAddress + duration time.Duration } tests := []struct { @@ -29,25 +29,25 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { { name: "superfluid delegation for not allowed asset", param: param{ - coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Hour * 504, + coinsToLock: sdk.Coins{sdk.NewInt64Coin("stake", 10)}, // setup wallet + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Hour * 504, }, expectPass: false, }, { name: "invalid duration", param: param{ - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Second, + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Second, }, expectPass: false, }, { name: "happy case", param: param{ - lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet - duration: time.Hour * 504, + lockOwner: sdk.AccAddress([]byte("addr1---------------")), // setup wallet + duration: time.Hour * 504, }, expectPass: true, }, @@ -62,7 +62,7 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { denoms, _ := suite.SetupGammPoolsAndSuperfluidAssets([]sdk.Dec{sdk.NewDec(20), sdk.NewDec(20)}) // If there is no coinsToLock in the param, use pool denom - if(test.param.coinsToLock.Empty()) { + if test.param.coinsToLock.Empty() { test.param.coinsToLock = sdk.NewCoins(sdk.NewCoin(denoms[0], sdk.NewInt(20))) } suite.FundAcc(test.param.lockOwner, test.param.coinsToLock) @@ -80,7 +80,6 @@ func (suite *KeeperTestSuite) TestMsgSuperfluidDelegate() { suite.Require().Error(err) } }) - } } From 9506eb1f6d639b5bb0868a010568f286320ac29e Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:04:16 +0700 Subject: [PATCH 16/20] usegov tests use apptesting --- x/superfluid/keeper/gov/gov_test.go | 2 +- x/superfluid/keeper/gov/suite_test.go | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/x/superfluid/keeper/gov/gov_test.go b/x/superfluid/keeper/gov/gov_test.go index b502b9e1048..0a21bc4edfe 100644 --- a/x/superfluid/keeper/gov/gov_test.go +++ b/x/superfluid/keeper/gov/gov_test.go @@ -135,7 +135,7 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() { suite.Require().Error(err) } else { suite.Require().NoError(err) - assertEventEmitted(suite, suite.ctx, tc.expectedEvent[i], 1) + suite.AssertEventEmitted(suite.ctx, tc.expectedEvent[i], 1) } // check assets individually diff --git a/x/superfluid/keeper/gov/suite_test.go b/x/superfluid/keeper/gov/suite_test.go index 6df091ec54e..dd69ec88057 100644 --- a/x/superfluid/keeper/gov/suite_test.go +++ b/x/superfluid/keeper/gov/suite_test.go @@ -11,10 +11,11 @@ import ( "github.com/osmosis-labs/osmosis/v10/app" "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper" + "github.com/osmosis-labs/osmosis/v10/app/apptesting" ) type KeeperTestSuite struct { - suite.Suite + apptesting.KeeperTestHelper ctx sdk.Context querier keeper.Querier @@ -30,15 +31,3 @@ func (suite *KeeperTestSuite) SetupTest() { func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } - -func assertEventEmitted(suite *KeeperTestSuite, ctx sdk.Context, eventTypeExpected string, numEventsExpected int) { - allEvents := ctx.EventManager().Events() - // filter out other events - actualEvents := make([]sdk.Event, 0, 1) - for _, event := range allEvents { - if event.Type == eventTypeExpected { - actualEvents = append(actualEvents, event) - } - } - suite.Require().Equal(numEventsExpected, len(actualEvents)) -} From f42e205aee3c06c2349264c964a31e632e360dd5 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 12 Aug 2022 14:00:47 +0700 Subject: [PATCH 17/20] Update x/superfluid/keeper/internal/events/emit.go Co-authored-by: Sishir Giri --- x/superfluid/keeper/internal/events/emit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/superfluid/keeper/internal/events/emit.go b/x/superfluid/keeper/internal/events/emit.go index 42c58fd490c..d13e7ab7a67 100644 --- a/x/superfluid/keeper/internal/events/emit.go +++ b/x/superfluid/keeper/internal/events/emit.go @@ -56,7 +56,7 @@ func EmitSuperfluidDelegateEvent(ctx sdk.Context, lockId uint64, valAddress stri func newSuperfluidDelegateEvent(lockId uint64, valAddress string) sdk.Event { return sdk.NewEvent( types.TypeEvtSuperfluidDelegate, - sdk.NewAttribute(types.AttributeLockId, fmt.Sprintf("%d", lockId)), + sdk.NewAttribute(types.AttributeLockId, utils.Uint64ToString(lockId)), sdk.NewAttribute(types.AttributeValidator, valAddress), ) } From bc9cbf586972e1560d627c544c4e9cae4184131f Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Fri, 12 Aug 2022 14:06:07 +0700 Subject: [PATCH 18/20] remove unused variables --- x/superfluid/keeper/internal/events/emit.go | 1 + x/superfluid/keeper/internal/events/emit_test.go | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/x/superfluid/keeper/internal/events/emit.go b/x/superfluid/keeper/internal/events/emit.go index d13e7ab7a67..384b1b7aefd 100644 --- a/x/superfluid/keeper/internal/events/emit.go +++ b/x/superfluid/keeper/internal/events/emit.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/osmosis/v10/x/gamm/utils" "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" ) diff --git a/x/superfluid/keeper/internal/events/emit_test.go b/x/superfluid/keeper/internal/events/emit_test.go index 8ecc8c8d524..9fe9e831086 100644 --- a/x/superfluid/keeper/internal/events/emit_test.go +++ b/x/superfluid/keeper/internal/events/emit_test.go @@ -21,8 +21,6 @@ const ( addressString = "addr1---------------" testDenomA = "denoma" testDenomB = "denomb" - testDenomC = "denomc" - testDenomD = "denomd" ) func TestSuperfluidEventsTestSuite(t *testing.T) { From d3dd4881b7d75964856b56eee2334744d291eddf Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 17 Aug 2022 23:03:30 +0700 Subject: [PATCH 19/20] v11 --- x/superfluid/keeper/gov/suite_test.go | 2 +- x/superfluid/keeper/hooks_test.go | 6 +++--- x/superfluid/keeper/internal/events/emit_test.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x/superfluid/keeper/gov/suite_test.go b/x/superfluid/keeper/gov/suite_test.go index 50bf79508d8..4265daca68d 100644 --- a/x/superfluid/keeper/gov/suite_test.go +++ b/x/superfluid/keeper/gov/suite_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/osmosis-labs/osmosis/v10/app/apptesting" + "github.com/osmosis-labs/osmosis/v11/app/apptesting" "github.com/osmosis-labs/osmosis/v11/app" "github.com/osmosis-labs/osmosis/v11/x/superfluid/keeper" ) diff --git a/x/superfluid/keeper/hooks_test.go b/x/superfluid/keeper/hooks_test.go index 267fea0ec3b..76dafa0983d 100644 --- a/x/superfluid/keeper/hooks_test.go +++ b/x/superfluid/keeper/hooks_test.go @@ -6,9 +6,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - lockupkeeper "github.com/osmosis-labs/osmosis/v10/x/lockup/keeper" - lockuptypes "github.com/osmosis-labs/osmosis/v10/x/lockup/types" - "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" + lockupkeeper "github.com/osmosis-labs/osmosis/v11/x/lockup/keeper" + lockuptypes "github.com/osmosis-labs/osmosis/v11/x/lockup/types" + "github.com/osmosis-labs/osmosis/v11/x/superfluid/types" ) func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() { diff --git a/x/superfluid/keeper/internal/events/emit_test.go b/x/superfluid/keeper/internal/events/emit_test.go index 9fe9e831086..8d528963e7d 100644 --- a/x/superfluid/keeper/internal/events/emit_test.go +++ b/x/superfluid/keeper/internal/events/emit_test.go @@ -8,9 +8,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" - "github.com/osmosis-labs/osmosis/v10/app/apptesting" - "github.com/osmosis-labs/osmosis/v10/x/superfluid/keeper/internal/events" - "github.com/osmosis-labs/osmosis/v10/x/superfluid/types" + "github.com/osmosis-labs/osmosis/v11/app/apptesting" + "github.com/osmosis-labs/osmosis/v11/x/superfluid/keeper/internal/events" + "github.com/osmosis-labs/osmosis/v11/x/superfluid/types" ) type SuperfluidEventsTestSuite struct { From 7ec606b4e4e3f81069c2e2909de6d6c9e8b8ab6e Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Wed, 17 Aug 2022 23:15:04 +0700 Subject: [PATCH 20/20] format --- x/superfluid/keeper/gov/gov.go | 2 +- x/superfluid/keeper/gov/gov_test.go | 4 ++-- x/superfluid/keeper/gov/suite_test.go | 2 +- x/superfluid/keeper/msg_server_test.go | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/x/superfluid/keeper/gov/gov.go b/x/superfluid/keeper/gov/gov.go index 489256dacb9..5ac102983f0 100644 --- a/x/superfluid/keeper/gov/gov.go +++ b/x/superfluid/keeper/gov/gov.go @@ -3,8 +3,8 @@ package gov import ( "fmt" - "github.com/osmosis-labs/osmosis/v11/x/superfluid/keeper/internal/events" "github.com/osmosis-labs/osmosis/v11/x/superfluid/keeper" + "github.com/osmosis-labs/osmosis/v11/x/superfluid/keeper/internal/events" "github.com/osmosis-labs/osmosis/v11/x/superfluid/types" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/superfluid/keeper/gov/gov_test.go b/x/superfluid/keeper/gov/gov_test.go index 4ec357cf3ff..3078aca1ecd 100644 --- a/x/superfluid/keeper/gov/gov_test.go +++ b/x/superfluid/keeper/gov/gov_test.go @@ -61,8 +61,8 @@ func (suite *KeeperTestSuite) TestHandleSetSuperfluidAssetsProposal() { expectErr bool } testCases := []struct { - name string - actions []Action + name string + actions []Action expectedEvent []string }{ { diff --git a/x/superfluid/keeper/gov/suite_test.go b/x/superfluid/keeper/gov/suite_test.go index 4265daca68d..efb9f6280df 100644 --- a/x/superfluid/keeper/gov/suite_test.go +++ b/x/superfluid/keeper/gov/suite_test.go @@ -9,8 +9,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/osmosis-labs/osmosis/v11/app/apptesting" "github.com/osmosis-labs/osmosis/v11/app" + "github.com/osmosis-labs/osmosis/v11/app/apptesting" "github.com/osmosis-labs/osmosis/v11/x/superfluid/keeper" ) diff --git a/x/superfluid/keeper/msg_server_test.go b/x/superfluid/keeper/msg_server_test.go index 0c180203876..4a4a5d35104 100644 --- a/x/superfluid/keeper/msg_server_test.go +++ b/x/superfluid/keeper/msg_server_test.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + v8constants "github.com/osmosis-labs/osmosis/v11/app/upgrades/v8/constants" lockupkeeper "github.com/osmosis-labs/osmosis/v11/x/lockup/keeper" lockuptypes "github.com/osmosis-labs/osmosis/v11/x/lockup/types" "github.com/osmosis-labs/osmosis/v11/x/superfluid/keeper"