Skip to content

Commit

Permalink
Fix/delgation amount (#3)
Browse files Browse the repository at this point in the history
* set default delegation amount
  • Loading branch information
MarkCherepovskyi authored Jul 24, 2024
1 parent 234dfc8 commit 6694f7a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func genesisStateWithValSet(t *testing.T,
MinSelfDelegation: sdk.ZeroInt(),
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec(), sdk.OneDec()))

}
// set validators and delegations
Expand Down
4 changes: 2 additions & 2 deletions x/staking/client/testutil/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryValidatorDelegations() {
&types.QueryValidatorDelegationsResponse{},
&types.QueryValidatorDelegationsResponse{
DelegationResponses: types.DelegationResponses{
types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)),
types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)),
},
Pagination: &query.PageResponse{Total: 1},
},
Expand Down Expand Up @@ -398,7 +398,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegatorDelegations() {
&types.QueryDelegatorDelegationsResponse{},
&types.QueryDelegatorDelegationsResponse{
DelegationResponses: types.DelegationResponses{
types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)),
types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)),
},
Pagination: &query.PageResponse{Total: 1},
},
Expand Down
4 changes: 2 additions & 2 deletions x/staking/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryDelegations() {
&types.QueryDelegatorDelegationsResponse{},
&types.QueryDelegatorDelegationsResponse{
DelegationResponses: types.DelegationResponses{
types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)),
types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)),
},
Pagination: &query.PageResponse{},
},
Expand Down Expand Up @@ -476,7 +476,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorDelegations() {
&types.QueryValidatorDelegationsResponse{},
&types.QueryValidatorDelegationsResponse{
DelegationResponses: types.DelegationResponses{
types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)),
types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)),
},
Pagination: &query.PageResponse{},
},
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func (k Keeper) Delegate(
// Get or create the delegation object
delegation, found := k.GetDelegation(ctx, delAddr, validator.GetOperator())
if !found {
delegation = types.NewDelegation(delAddr, validator.GetOperator(), sdk.ZeroDec())
delegation = types.NewDelegation(delAddr, validator.GetOperator(), sdk.ZeroDec(), sdk.ZeroDec())
}

// call the appropriate hook if present
Expand Down
1 change: 1 addition & 0 deletions x/staking/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ func DelegationToDelegationResponse(ctx sdk.Context, k Keeper, del types.Delegat
delegatorAddress,
del.GetValidatorAddr(),
del.Shares,
del.Amount,
sdk.NewCoin(k.BondDenom(ctx), val.TokensFromShares(del.Shares).TruncateInt()),
), nil
}
Expand Down
2 changes: 1 addition & 1 deletion x/staking/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func RandomizedGenState(simState *module.SimulationState) {
validator.DelegatorShares = sdk.NewDecFromInt(simState.InitialStake)
validator.Commission = commission

delegation := types.NewDelegation(simState.Accounts[i].Address, valAddr, sdk.NewDecFromInt(simState.InitialStake))
delegation := types.NewDelegation(simState.Accounts[i].Address, valAddr, sdk.NewDecFromInt(simState.InitialStake), sdk.NewDecFromInt(simState.InitialStake))

validators = append(validators, validator)
delegations = append(delegations, delegation)
Expand Down
7 changes: 4 additions & 3 deletions x/staking/types/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ func (dvv DVVTriplet) String() string {
// NewDelegation creates a new delegation object
//
//nolint:interfacer
func NewDelegation(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, shares sdk.Dec) Delegation {
func NewDelegation(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, shares sdk.Dec, amount sdk.Dec) Delegation {
return Delegation{
DelegatorAddress: delegatorAddr.String(),
ValidatorAddress: validatorAddr.String(),
Shares: shares,
Amount: amount,
}
}

Expand Down Expand Up @@ -296,10 +297,10 @@ func (d Redelegations) String() (out string) {

// NewDelegationResp creates a new DelegationResponse instance
func NewDelegationResp(
delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, shares sdk.Dec, balance sdk.Coin,
delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, shares, amount sdk.Dec, balance sdk.Coin,
) DelegationResponse {
return DelegationResponse{
Delegation: NewDelegation(delegatorAddr, validatorAddr, shares),
Delegation: NewDelegation(delegatorAddr, validatorAddr, shares, amount),
Balance: balance,
}
}
Expand Down

0 comments on commit 6694f7a

Please sign in to comment.