Merge PR #4511: Fix YAML encoding of staking.Validator
* Fix YAML encoding of staking.Validator Closes: #4508 * Address fede's comment
This commit is contained in:
parent
db6cb238ab
commit
b4eb4a9e64
|
@ -9,6 +9,7 @@ import (
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
@ -48,6 +49,39 @@ type Validator struct {
|
||||||
MinSelfDelegation sdk.Int `json:"min_self_delegation"` // validator's self declared minimum self delegation
|
MinSelfDelegation sdk.Int `json:"min_self_delegation"` // validator's self declared minimum self delegation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v Validator) MarshalYAML() (interface{}, error) {
|
||||||
|
bs, err := yaml.Marshal(struct {
|
||||||
|
OperatorAddress sdk.ValAddress
|
||||||
|
ConsPubKey string
|
||||||
|
Jailed bool
|
||||||
|
Status sdk.BondStatus
|
||||||
|
Tokens sdk.Int
|
||||||
|
DelegatorShares sdk.Dec
|
||||||
|
Description Description
|
||||||
|
UnbondingHeight int64
|
||||||
|
UnbondingCompletionTime time.Time
|
||||||
|
Commission Commission
|
||||||
|
MinSelfDelegation sdk.Int
|
||||||
|
}{
|
||||||
|
OperatorAddress: v.OperatorAddress,
|
||||||
|
ConsPubKey: sdk.MustBech32ifyConsPub(v.ConsPubKey),
|
||||||
|
Jailed: v.Jailed,
|
||||||
|
Status: v.Status,
|
||||||
|
Tokens: v.Tokens,
|
||||||
|
DelegatorShares: v.DelegatorShares,
|
||||||
|
Description: v.Description,
|
||||||
|
UnbondingHeight: v.UnbondingHeight,
|
||||||
|
UnbondingCompletionTime: v.UnbondingCompletionTime,
|
||||||
|
Commission: v.Commission,
|
||||||
|
MinSelfDelegation: v.MinSelfDelegation,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(bs), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Validators is a collection of Validator
|
// Validators is a collection of Validator
|
||||||
type Validators []Validator
|
type Validators []Validator
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidatorTestEquivalent(t *testing.T) {
|
func TestValidatorTestEquivalent(t *testing.T) {
|
||||||
|
@ -317,3 +319,34 @@ func TestValidatorSetInitialCommission(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidatorMarshalYAML(t *testing.T) {
|
||||||
|
validator := NewValidator(valAddr1, pk1, Description{})
|
||||||
|
bechifiedPub, err := sdk.Bech32ifyConsPub(validator.ConsPubKey)
|
||||||
|
require.NoError(t, err)
|
||||||
|
bs, err := yaml.Marshal(validator)
|
||||||
|
require.NoError(t, err)
|
||||||
|
want := fmt.Sprintf(`|
|
||||||
|
operatoraddress: %s
|
||||||
|
conspubkey: %s
|
||||||
|
jailed: false
|
||||||
|
status: 0
|
||||||
|
tokens: {}
|
||||||
|
delegatorshares: "0"
|
||||||
|
description:
|
||||||
|
moniker: ""
|
||||||
|
identity: ""
|
||||||
|
website: ""
|
||||||
|
details: ""
|
||||||
|
unbondingheight: 0
|
||||||
|
unbondingcompletiontime: 1970-01-01T00:00:00Z
|
||||||
|
commission:
|
||||||
|
commissionrates:
|
||||||
|
rate: "0"
|
||||||
|
maxrate: "0"
|
||||||
|
maxchangerate: "0"
|
||||||
|
updatetime: 1970-01-01T00:00:00Z
|
||||||
|
minselfdelegation: {}
|
||||||
|
`, validator.OperatorAddress.String(), bechifiedPub)
|
||||||
|
require.Equal(t, want, string(bs))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue