Merge PR #4806: Converted balance from sdk.Int to sdk.Coin inside DelegationResponse

This commit is contained in:
Riccardo Montagnin 2019-08-02 18:37:35 +02:00 committed by Alexander Bezobchuk
parent 451535bd79
commit f218de8141
6 changed files with 14 additions and 11 deletions

View File

@ -0,0 +1 @@
#4783 The balance field in the DelegationResponse type is now sdk.Coin instead of sdk.Int

View File

@ -2381,8 +2381,8 @@ definitions:
type: string type: string
shares: shares:
type: string type: string
height: balance:
type: integer $ref: "#/definitions/Coin"
UnbondingDelegationPair: UnbondingDelegationPair:
type: object type: object
properties: properties:

View File

@ -350,7 +350,7 @@ func delegationToDelegationResponse(ctx sdk.Context, k Keeper, del types.Delegat
del.DelegatorAddress, del.DelegatorAddress,
del.ValidatorAddress, del.ValidatorAddress,
del.Shares, del.Shares,
val.TokensFromShares(del.Shares).TruncateInt(), sdk.NewCoin(k.BondDenom(ctx), val.TokensFromShares(del.Shares).TruncateInt()),
), nil ), nil
} }

View File

@ -91,7 +91,7 @@ func TestNewQuerier(t *testing.T) {
func TestQueryParametersPool(t *testing.T) { func TestQueryParametersPool(t *testing.T) {
cdc := codec.New() cdc := codec.New()
ctx, _, keeper, _ := CreateTestInput(t, false, 1000) ctx, _, keeper, _ := CreateTestInput(t, false, 1000)
bondDenom := keeper.BondDenom(ctx) bondDenom := sdk.DefaultBondDenom
res, err := queryParameters(ctx, keeper) res, err := queryParameters(ctx, keeper)
require.Nil(t, err) require.Nil(t, err)
@ -268,7 +268,7 @@ func TestQueryDelegation(t *testing.T) {
require.Equal(t, delegation.ValidatorAddress, delegationRes.ValidatorAddress) require.Equal(t, delegation.ValidatorAddress, delegationRes.ValidatorAddress)
require.Equal(t, delegation.DelegatorAddress, delegationRes.DelegatorAddress) require.Equal(t, delegation.DelegatorAddress, delegationRes.DelegatorAddress)
require.Equal(t, delegation.Shares.TruncateInt(), delegationRes.Balance) require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegationRes.Balance)
// Query Delegator Delegations // Query Delegator Delegations
query = abci.RequestQuery{ query = abci.RequestQuery{
@ -285,7 +285,7 @@ func TestQueryDelegation(t *testing.T) {
require.Len(t, delegatorDelegations, 1) require.Len(t, delegatorDelegations, 1)
require.Equal(t, delegation.ValidatorAddress, delegatorDelegations[0].ValidatorAddress) require.Equal(t, delegation.ValidatorAddress, delegatorDelegations[0].ValidatorAddress)
require.Equal(t, delegation.DelegatorAddress, delegatorDelegations[0].DelegatorAddress) require.Equal(t, delegation.DelegatorAddress, delegatorDelegations[0].DelegatorAddress)
require.Equal(t, delegation.Shares.TruncateInt(), delegatorDelegations[0].Balance) require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegatorDelegations[0].Balance)
// error unknown request // error unknown request
query.Data = bz[:len(bz)-1] query.Data = bz[:len(bz)-1]
@ -312,7 +312,7 @@ func TestQueryDelegation(t *testing.T) {
require.Len(t, delegatorDelegations, 1) require.Len(t, delegatorDelegations, 1)
require.Equal(t, delegation.ValidatorAddress, delegationsRes[0].ValidatorAddress) require.Equal(t, delegation.ValidatorAddress, delegationsRes[0].ValidatorAddress)
require.Equal(t, delegation.DelegatorAddress, delegationsRes[0].DelegatorAddress) require.Equal(t, delegation.DelegatorAddress, delegationsRes[0].DelegatorAddress)
require.Equal(t, delegation.Shares.TruncateInt(), delegationsRes[0].Balance) require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegationsRes[0].Balance)
// Query unbonging delegation // Query unbonging delegation
unbondingTokens := sdk.TokensFromConsensusPower(10) unbondingTokens := sdk.TokensFromConsensusPower(10)

View File

@ -352,10 +352,10 @@ func (d Redelegations) String() (out string) {
// in addition to shares which is more suitable for client responses. // in addition to shares which is more suitable for client responses.
type DelegationResponse struct { type DelegationResponse struct {
Delegation Delegation
Balance sdk.Int `json:"balance" yaml:"balance"` Balance sdk.Coin `json:"balance" yaml:"balance"`
} }
func NewDelegationResp(d sdk.AccAddress, v sdk.ValAddress, s sdk.Dec, b sdk.Int) DelegationResponse { func NewDelegationResp(d sdk.AccAddress, v sdk.ValAddress, s sdk.Dec, b sdk.Coin) DelegationResponse {
return DelegationResponse{NewDelegation(d, v, s), b} return DelegationResponse{NewDelegation(d, v, s), b}
} }

View File

@ -80,8 +80,10 @@ func TestRedelegationString(t *testing.T) {
func TestDelegationResponses(t *testing.T) { func TestDelegationResponses(t *testing.T) {
cdc := codec.New() cdc := codec.New()
dr1 := NewDelegationResp(sdk.AccAddress(valAddr1), valAddr2, sdk.NewDec(5), sdk.NewInt(5)) dr1 := NewDelegationResp(sdk.AccAddress(valAddr1), valAddr2, sdk.NewDec(5),
dr2 := NewDelegationResp(sdk.AccAddress(valAddr1), valAddr3, sdk.NewDec(5), sdk.NewInt(5)) sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(5)))
dr2 := NewDelegationResp(sdk.AccAddress(valAddr1), valAddr3, sdk.NewDec(5),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(5)))
drs := DelegationResponses{dr1, dr2} drs := DelegationResponses{dr1, dr2}
bz1, err := json.Marshal(dr1) bz1, err := json.Marshal(dr1)