Skip to content

Commit

Permalink
feat(tests): add pool restaking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoM committed Jun 18, 2024
1 parent cd21618 commit 1f158d7
Show file tree
Hide file tree
Showing 4 changed files with 524 additions and 5 deletions.
46 changes: 45 additions & 1 deletion x/restaking/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,49 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.bk,
suite.pk,
authorityAddr,
)
).SetHooks(newMockHooks())
}

// --------------------------------------------------------------------------------------------------------------------

// fundAccount adds the given amount of coins to the account with the given address
func (suite *KeeperTestSuite) fundAccount(ctx sdk.Context, address string, amount sdk.Coins) {
// Mint the coins
moduleAcc := suite.ak.GetModuleAccount(ctx, authtypes.Minter)

err := suite.bk.MintCoins(ctx, moduleAcc.GetName(), amount)
suite.Require().NoError(err)

// Get the amount to the user
userAddress, err := sdk.AccAddressFromBech32(address)
suite.Require().NoError(err)
err = suite.bk.SendCoinsFromModuleToAccount(ctx, moduleAcc.GetName(), userAddress, amount)
suite.Require().NoError(err)
}

// --------------------------------------------------------------------------------------------------------------------

var _ types.RestakingHooks = &mockHooks{}

type mockHooks struct {
CalledMap map[string]bool
}

func newMockHooks() *mockHooks {
return &mockHooks{CalledMap: make(map[string]bool)}
}

func (m mockHooks) BeforePoolDelegationCreated(ctx sdk.Context, poolID uint32, delegator string) error {
m.CalledMap["BeforePoolDelegationCreated"] = true
return nil
}

func (m mockHooks) BeforePoolDelegationSharesModified(ctx sdk.Context, poolID uint32, delegator string) error {
m.CalledMap["BeforePoolDelegationSharesModified"] = true
return nil
}

func (m mockHooks) AfterPoolDelegationModified(ctx sdk.Context, poolID uint32, delegator string) error {
m.CalledMap["AfterPoolDelegationModified"] = true
return nil
}
2 changes: 1 addition & 1 deletion x/restaking/keeper/pool_restaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (k *Keeper) SavePoolDelegation(ctx sdk.Context, delegation types.PoolDelega
store.Set(types.UserPoolDelegationStoreKey(delegation.UserAddress, delegation.PoolID), delegationBz)

// Store the delegation in the delegations by pool ID store
store.Set(types.DelegationsByPoolIDStoreKey(delegation.PoolID, delegation.UserAddress), []byte{})
store.Set(types.DelegationByPoolIDStoreKey(delegation.PoolID, delegation.UserAddress), []byte{})
}

// GetPoolDelegation retrieves the delegation for the given user and pool
Expand Down
Loading

0 comments on commit 1f158d7

Please sign in to comment.