feat(x/staking)!: Add metadata field to validator info (#21315)
This commit is contained in:
@@ -34,7 +34,7 @@ import (
|
||||
var (
|
||||
valTokens = sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction)
|
||||
TestProposal = v1beta1.NewTextProposal("Test", "description")
|
||||
TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z")
|
||||
TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z", stakingtypes.Metadata{})
|
||||
TestCommissionRates = stakingtypes.NewCommissionRates(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec())
|
||||
)
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestSlashingMsgs(t *testing.T) {
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
description := stakingtypes.NewDescription("foo_moniker", "", "", "", "")
|
||||
description := stakingtypes.NewDescription("foo_moniker", "", "", "", "", stakingtypes.Metadata{})
|
||||
commission := stakingtypes.NewCommissionRates(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec())
|
||||
|
||||
addrStrVal, err := valaddrCodec.BytesToString(addr1)
|
||||
|
||||
@@ -2,6 +2,8 @@ package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -214,6 +216,26 @@ func bondTypeGenerator() *rapid.Generator[stakingtypes.BondStatus] {
|
||||
})
|
||||
}
|
||||
|
||||
func metadataGenerator() *rapid.Generator[stakingtypes.Metadata] {
|
||||
return rapid.Custom(func(t *rapid.T) stakingtypes.Metadata {
|
||||
return stakingtypes.Metadata{
|
||||
ProfilePicUri: generateUri(t),
|
||||
SocialHandleUris: []string{generateUri(t), generateUri(t)},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func generateUri(t *rapid.T) string {
|
||||
host := fmt.Sprintf("%s.com", rapid.StringN(5, 250, 255).Draw(t, "host"))
|
||||
path := rapid.StringN(5, 250, 255).Draw(t, "path")
|
||||
uri := url.URL{
|
||||
Scheme: "https",
|
||||
Host: host,
|
||||
Path: path,
|
||||
}
|
||||
return uri.String()
|
||||
}
|
||||
|
||||
// createValidator creates a validator with random values.
|
||||
func createValidator(t *testing.T, rt *rapid.T, _ *deterministicFixture) stakingtypes.Validator {
|
||||
t.Helper()
|
||||
@@ -233,6 +255,7 @@ func createValidator(t *testing.T, rt *rapid.T, _ *deterministicFixture) staking
|
||||
rapid.StringN(5, 250, 255).Draw(rt, "website"),
|
||||
rapid.StringN(5, 250, 255).Draw(rt, "securityContact"),
|
||||
rapid.StringN(5, 250, 255).Draw(rt, "details"),
|
||||
metadataGenerator().Draw(rt, "metadata"),
|
||||
),
|
||||
UnbondingHeight: rapid.Int64Min(1).Draw(rt, "unbonding-height"),
|
||||
UnbondingTime: time.Now().Add(durationGenerator().Draw(rt, "duration")),
|
||||
@@ -308,6 +331,7 @@ func getStaticValidator(t *testing.T, f *deterministicFixture) stakingtypes.Vali
|
||||
"website",
|
||||
"securityContact",
|
||||
"details",
|
||||
stakingtypes.Metadata{},
|
||||
),
|
||||
UnbondingHeight: 10,
|
||||
UnbondingTime: time.Date(2022, 10, 1, 0, 0, 0, 0, time.UTC),
|
||||
@@ -343,6 +367,7 @@ func getStaticValidator2(t *testing.T, f *deterministicFixture) stakingtypes.Val
|
||||
"website",
|
||||
"securityContact",
|
||||
"details",
|
||||
stakingtypes.Metadata{},
|
||||
),
|
||||
UnbondingHeight: 100132,
|
||||
UnbondingTime: time.Date(2025, 10, 1, 0, 0, 0, 0, time.UTC),
|
||||
@@ -408,7 +433,7 @@ func TestGRPCValidator(t *testing.T) {
|
||||
ValidatorAddr: val.OperatorAddress,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Validator, 1915, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Validator, 1921, false)
|
||||
}
|
||||
|
||||
func TestGRPCValidators(t *testing.T) {
|
||||
@@ -434,7 +459,7 @@ func TestGRPCValidators(t *testing.T) {
|
||||
getStaticValidator(t, f)
|
||||
getStaticValidator2(t, f)
|
||||
|
||||
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryValidatorsRequest{}, f.queryClient.Validators, 2862, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryValidatorsRequest{}, f.queryClient.Validators, 2880, false)
|
||||
}
|
||||
|
||||
func TestGRPCValidatorDelegations(t *testing.T) {
|
||||
@@ -479,7 +504,7 @@ func TestGRPCValidatorDelegations(t *testing.T) {
|
||||
ValidatorAddr: validator.OperatorAddress,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorDelegations, 14610, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorDelegations, 14628, false)
|
||||
}
|
||||
|
||||
func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
|
||||
@@ -569,7 +594,7 @@ func TestGRPCDelegation(t *testing.T) {
|
||||
DelegatorAddr: delegator1,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Delegation, 4680, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Delegation, 4686, false)
|
||||
}
|
||||
|
||||
func TestGRPCUnbondingDelegation(t *testing.T) {
|
||||
@@ -652,7 +677,7 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
|
||||
DelegatorAddr: delegator1,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorDelegations, 4283, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorDelegations, 4289, false)
|
||||
}
|
||||
|
||||
func TestGRPCDelegatorValidator(t *testing.T) {
|
||||
@@ -690,7 +715,7 @@ func TestGRPCDelegatorValidator(t *testing.T) {
|
||||
ValidatorAddr: validator.OperatorAddress,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidator, 3563, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidator, 3569, false)
|
||||
}
|
||||
|
||||
func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
|
||||
@@ -772,7 +797,7 @@ func TestGRPCDelegatorValidators(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := &stakingtypes.QueryDelegatorValidatorsRequest{DelegatorAddr: delegator1}
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidators, 3166, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidators, 3172, false)
|
||||
}
|
||||
|
||||
func TestGRPCPool(t *testing.T) {
|
||||
@@ -856,7 +881,7 @@ func TestGRPCRedelegations(t *testing.T) {
|
||||
DstValidatorAddr: validator2,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Redelegations, 3920, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Redelegations, 3926, false)
|
||||
}
|
||||
|
||||
func TestGRPCParams(t *testing.T) {
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestInitGenesis(t *testing.T) {
|
||||
Status: types.Bonded,
|
||||
Tokens: valTokens,
|
||||
DelegatorShares: math.LegacyNewDecFromInt(valTokens),
|
||||
Description: types.NewDescription("hoop", "", "", "", ""),
|
||||
Description: types.NewDescription("hoop", "", "", "", "", types.Metadata{}),
|
||||
}
|
||||
assert.NilError(t, f.stakingKeeper.SetValidator(f.sdkCtx, bondedVal))
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestInitGenesis(t *testing.T) {
|
||||
Status: types.Bonded,
|
||||
Tokens: valTokens,
|
||||
DelegatorShares: math.LegacyNewDecFromInt(valTokens),
|
||||
Description: types.NewDescription("hoop", "", "", "", ""),
|
||||
Description: types.NewDescription("hoop", "", "", "", "", types.Metadata{}),
|
||||
}
|
||||
bondedVal2 := types.Validator{
|
||||
OperatorAddress: sdk.ValAddress(addrs[2]).String(),
|
||||
@@ -75,7 +75,7 @@ func TestInitGenesis(t *testing.T) {
|
||||
Status: types.Bonded,
|
||||
Tokens: valTokens,
|
||||
DelegatorShares: math.LegacyNewDecFromInt(valTokens),
|
||||
Description: types.NewDescription("bloop", "", "", "", ""),
|
||||
Description: types.NewDescription("bloop", "", "", "", "", types.Metadata{}),
|
||||
}
|
||||
|
||||
// append new bonded validators to the list
|
||||
@@ -148,7 +148,7 @@ func TestInitGenesis_PoolsBalanceMismatch(t *testing.T) {
|
||||
Jailed: false,
|
||||
Tokens: math.NewInt(10),
|
||||
DelegatorShares: math.LegacyNewDecFromInt(math.NewInt(10)),
|
||||
Description: types.NewDescription("bloop", "", "", "", ""),
|
||||
Description: types.NewDescription("bloop", "", "", "", "", types.Metadata{}),
|
||||
}
|
||||
|
||||
params := types.Params{
|
||||
@@ -195,7 +195,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
|
||||
validators[i], err = types.NewValidator(
|
||||
sdk.ValAddress(addrs[i]).String(),
|
||||
PKs[i],
|
||||
types.NewDescription(fmt.Sprintf("#%d", i), "", "", "", ""),
|
||||
types.NewDescription(fmt.Sprintf("#%d", i), "", "", "", "", types.Metadata{}),
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
validators[i].Status = types.Bonded
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
|
||||
delegatorAddr := addrs[1]
|
||||
|
||||
// setup a new validator with bonded status
|
||||
validator, err := types.NewValidator(valAddr.String(), PKs[0], types.NewDescription("Validator", "", "", "", ""))
|
||||
validator, err := types.NewValidator(valAddr.String(), PKs[0], types.NewDescription("Validator", "", "", "", "", types.Metadata{}))
|
||||
validator.Status = types.Bonded
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, f.stakingKeeper.SetValidator(ctx, validator))
|
||||
|
||||
@@ -377,10 +377,12 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
|
||||
"staking/create_validator": {
|
||||
gogo: &stakingtypes.MsgCreateValidator{Pubkey: pubkeyAny},
|
||||
pulsar: &stakingapi.MsgCreateValidator{
|
||||
Pubkey: pubkeyAnyPulsar,
|
||||
Description: &stakingapi.Description{},
|
||||
Commission: &stakingapi.CommissionRates{},
|
||||
Value: &v1beta1.Coin{},
|
||||
Pubkey: pubkeyAnyPulsar,
|
||||
Description: &stakingapi.Description{
|
||||
Metadata: &stakingapi.Metadata{},
|
||||
},
|
||||
Commission: &stakingapi.CommissionRates{},
|
||||
Value: &v1beta1.Coin{},
|
||||
},
|
||||
},
|
||||
"staking/msg_cancel_unbonding_delegation_response": {
|
||||
|
||||
Reference in New Issue
Block a user