refactor(distribution): move ValidateBasic logic to msgServer (#15755)
This commit is contained in:
parent
f8e2d984b2
commit
ee53930fc1
@ -5549,7 +5549,7 @@ func (x *_MsgDepositValidatorRewardsPool_3_list) IsValid() bool {
|
||||
|
||||
var (
|
||||
md_MsgDepositValidatorRewardsPool protoreflect.MessageDescriptor
|
||||
fd_MsgDepositValidatorRewardsPool_authority protoreflect.FieldDescriptor
|
||||
fd_MsgDepositValidatorRewardsPool_depositor protoreflect.FieldDescriptor
|
||||
fd_MsgDepositValidatorRewardsPool_validator_address protoreflect.FieldDescriptor
|
||||
fd_MsgDepositValidatorRewardsPool_amount protoreflect.FieldDescriptor
|
||||
)
|
||||
@ -5557,7 +5557,7 @@ var (
|
||||
func init() {
|
||||
file_cosmos_distribution_v1beta1_tx_proto_init()
|
||||
md_MsgDepositValidatorRewardsPool = File_cosmos_distribution_v1beta1_tx_proto.Messages().ByName("MsgDepositValidatorRewardsPool")
|
||||
fd_MsgDepositValidatorRewardsPool_authority = md_MsgDepositValidatorRewardsPool.Fields().ByName("authority")
|
||||
fd_MsgDepositValidatorRewardsPool_depositor = md_MsgDepositValidatorRewardsPool.Fields().ByName("depositor")
|
||||
fd_MsgDepositValidatorRewardsPool_validator_address = md_MsgDepositValidatorRewardsPool.Fields().ByName("validator_address")
|
||||
fd_MsgDepositValidatorRewardsPool_amount = md_MsgDepositValidatorRewardsPool.Fields().ByName("amount")
|
||||
}
|
||||
@ -5627,9 +5627,9 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) Interface() protoreflect
|
||||
// While iterating, mutating operations may only be performed
|
||||
// on the current field descriptor.
|
||||
func (x *fastReflection_MsgDepositValidatorRewardsPool) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
|
||||
if x.Authority != "" {
|
||||
value := protoreflect.ValueOfString(x.Authority)
|
||||
if !f(fd_MsgDepositValidatorRewardsPool_authority, value) {
|
||||
if x.Depositor != "" {
|
||||
value := protoreflect.ValueOfString(x.Depositor)
|
||||
if !f(fd_MsgDepositValidatorRewardsPool_depositor, value) {
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -5660,8 +5660,8 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) Range(f func(protoreflec
|
||||
// a repeated field is populated if it is non-empty.
|
||||
func (x *fastReflection_MsgDepositValidatorRewardsPool) Has(fd protoreflect.FieldDescriptor) bool {
|
||||
switch fd.FullName() {
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.authority":
|
||||
return x.Authority != ""
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.depositor":
|
||||
return x.Depositor != ""
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.validator_address":
|
||||
return x.ValidatorAddress != ""
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.amount":
|
||||
@ -5682,8 +5682,8 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) Has(fd protoreflect.Fiel
|
||||
// Clear is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_MsgDepositValidatorRewardsPool) Clear(fd protoreflect.FieldDescriptor) {
|
||||
switch fd.FullName() {
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.authority":
|
||||
x.Authority = ""
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.depositor":
|
||||
x.Depositor = ""
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.validator_address":
|
||||
x.ValidatorAddress = ""
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.amount":
|
||||
@ -5704,8 +5704,8 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) Clear(fd protoreflect.Fi
|
||||
// of the value; to obtain a mutable reference, use Mutable.
|
||||
func (x *fastReflection_MsgDepositValidatorRewardsPool) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value {
|
||||
switch descriptor.FullName() {
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.authority":
|
||||
value := x.Authority
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.depositor":
|
||||
value := x.Depositor
|
||||
return protoreflect.ValueOfString(value)
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.validator_address":
|
||||
value := x.ValidatorAddress
|
||||
@ -5736,8 +5736,8 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) Get(descriptor protorefl
|
||||
// Set is a mutating operation and unsafe for concurrent use.
|
||||
func (x *fastReflection_MsgDepositValidatorRewardsPool) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) {
|
||||
switch fd.FullName() {
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.authority":
|
||||
x.Authority = value.Interface().(string)
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.depositor":
|
||||
x.Depositor = value.Interface().(string)
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.validator_address":
|
||||
x.ValidatorAddress = value.Interface().(string)
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.amount":
|
||||
@ -5770,8 +5770,8 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) Mutable(fd protoreflect.
|
||||
}
|
||||
value := &_MsgDepositValidatorRewardsPool_3_list{list: &x.Amount}
|
||||
return protoreflect.ValueOfList(value)
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.authority":
|
||||
panic(fmt.Errorf("field authority of message cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool is not mutable"))
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.depositor":
|
||||
panic(fmt.Errorf("field depositor of message cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool is not mutable"))
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.validator_address":
|
||||
panic(fmt.Errorf("field validator_address of message cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool is not mutable"))
|
||||
default:
|
||||
@ -5787,7 +5787,7 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) Mutable(fd protoreflect.
|
||||
// For lists, maps, and messages, this returns a new, empty, mutable value.
|
||||
func (x *fastReflection_MsgDepositValidatorRewardsPool) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
|
||||
switch fd.FullName() {
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.authority":
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.depositor":
|
||||
return protoreflect.ValueOfString("")
|
||||
case "cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool.validator_address":
|
||||
return protoreflect.ValueOfString("")
|
||||
@ -5863,7 +5863,7 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) ProtoMethods() *protoifa
|
||||
var n int
|
||||
var l int
|
||||
_ = l
|
||||
l = len(x.Authority)
|
||||
l = len(x.Depositor)
|
||||
if l > 0 {
|
||||
n += 1 + l + runtime.Sov(uint64(l))
|
||||
}
|
||||
@ -5929,10 +5929,10 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) ProtoMethods() *protoifa
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
if len(x.Authority) > 0 {
|
||||
i -= len(x.Authority)
|
||||
copy(dAtA[i:], x.Authority)
|
||||
i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Authority)))
|
||||
if len(x.Depositor) > 0 {
|
||||
i -= len(x.Depositor)
|
||||
copy(dAtA[i:], x.Depositor)
|
||||
i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Depositor)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
@ -5987,7 +5987,7 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) ProtoMethods() *protoifa
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType)
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Depositor", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
@ -6015,7 +6015,7 @@ func (x *fastReflection_MsgDepositValidatorRewardsPool) ProtoMethods() *protoifa
|
||||
if postIndex > l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
x.Authority = string(dAtA[iNdEx:postIndex])
|
||||
x.Depositor = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
@ -6966,7 +6966,7 @@ type MsgDepositValidatorRewardsPool struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"`
|
||||
Depositor string `protobuf:"bytes,1,opt,name=depositor,proto3" json:"depositor,omitempty"`
|
||||
ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"`
|
||||
Amount []*v1beta1.Coin `protobuf:"bytes,3,rep,name=amount,proto3" json:"amount,omitempty"`
|
||||
}
|
||||
@ -6991,9 +6991,9 @@ func (*MsgDepositValidatorRewardsPool) Descriptor() ([]byte, []int) {
|
||||
return file_cosmos_distribution_v1beta1_tx_proto_rawDescGZIP(), []int{12}
|
||||
}
|
||||
|
||||
func (x *MsgDepositValidatorRewardsPool) GetAuthority() string {
|
||||
func (x *MsgDepositValidatorRewardsPool) GetDepositor() string {
|
||||
if x != nil {
|
||||
return x.Authority
|
||||
return x.Depositor
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@ -7180,10 +7180,10 @@ var file_cosmos_distribution_v1beta1_tx_proto_rawDesc = []byte{
|
||||
0x65, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xdc, 0x02, 0x0a, 0x1e,
|
||||
0x4d, 0x73, 0x67, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61,
|
||||
0x74, 0x6f, 0x72, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x36,
|
||||
0x0a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x0a, 0x09, 0x64, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x64,
|
||||
0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x09, 0x61, 0x75, 0x74,
|
||||
0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x12, 0x45, 0x0a, 0x11, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61,
|
||||
0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x09, 0x64, 0x65, 0x70,
|
||||
0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x12, 0x45, 0x0a, 0x11, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61,
|
||||
0x74, 0x6f, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x64,
|
||||
0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x10, 0x76, 0x61, 0x6c,
|
||||
@ -7196,7 +7196,7 @@ var file_cosmos_distribution_v1beta1_tx_proto_rawDesc = []byte{
|
||||
0x79, 0x70, 0x65, 0x73, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x73, 0x9a, 0xe7, 0xb0, 0x2a, 0x0c, 0x6c,
|
||||
0x65, 0x67, 0x61, 0x63, 0x79, 0x5f, 0x63, 0x6f, 0x69, 0x6e, 0x73, 0xa8, 0xe7, 0xb0, 0x2a, 0x01,
|
||||
0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x3a, 0x40, 0x88, 0xa0, 0x1f, 0x00, 0xe8, 0xa0,
|
||||
0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x09, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79,
|
||||
0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x09, 0x64, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72,
|
||||
0x8a, 0xe7, 0xb0, 0x2a, 0x25, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f,
|
||||
0x64, 0x69, 0x73, 0x74, 0x72, 0x2f, 0x4d, 0x73, 0x67, 0x44, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74,
|
||||
0x56, 0x61, 0x6c, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x73, 0x22, 0x28, 0x0a, 0x26, 0x4d, 0x73,
|
||||
|
||||
@ -193,12 +193,12 @@ message MsgCommunityPoolSpendResponse {}
|
||||
// Since: cosmos-sdk 0.48
|
||||
message MsgDepositValidatorRewardsPool {
|
||||
option (amino.name) = "cosmos-sdk/distr/MsgDepositValRewards";
|
||||
option (cosmos.msg.v1.signer) = "authority";
|
||||
option (cosmos.msg.v1.signer) = "depositor";
|
||||
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
string depositor = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
repeated cosmos.base.v1beta1.Coin amount = 3 [
|
||||
(gogoproto.nullable) = false,
|
||||
|
||||
@ -191,6 +191,7 @@ require (
|
||||
// Replace here are pending PRs, or version to be tagged.
|
||||
// It must be in sync with SimApp temporary replaces
|
||||
replace (
|
||||
cosmossdk.io/api => ../api
|
||||
// TODO tag all extracted modules after SDK refactor
|
||||
cosmossdk.io/store => ../store
|
||||
cosmossdk.io/x/evidence => ../x/evidence
|
||||
|
||||
@ -188,8 +188,6 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX
|
||||
cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg=
|
||||
cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
|
||||
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
|
||||
cosmossdk.io/api v0.4.0 h1:x90DmdidP6EhzktAa/6/IofSHidDnPjahdlrUvyQZQw=
|
||||
cosmossdk.io/api v0.4.0/go.mod h1:TWDzBhUBhI1LhSf2XSYpfIBf6D4mbLu/fvzvDfhcaYM=
|
||||
cosmossdk.io/client/v2 v2.0.0-20230309163709-87da587416ba h1:LuPHCncU2KLMNPItFECs709uo46I9wSu2fAWYVCx+/U=
|
||||
cosmossdk.io/client/v2 v2.0.0-20230309163709-87da587416ba/go.mod h1:SXdwqO7cN5htalh/lhXWP8V4zKtBrhhcSTU+ytuEtmM=
|
||||
cosmossdk.io/collections v0.0.0-20230309163709-87da587416ba h1:S4PYij/tX3Op/hwenVEN9D+M27JRcwSwVqE3UA0BnwM=
|
||||
|
||||
@ -11,8 +11,204 @@ import (
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
emptyDelAddr sdk.AccAddress
|
||||
emptyValAddr sdk.ValAddress
|
||||
)
|
||||
|
||||
func TestMsgSetWithdrawAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
delegatorAddr sdk.AccAddress
|
||||
withdrawAddr sdk.AccAddress
|
||||
expErr bool
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "valid case",
|
||||
delegatorAddr: f.addrs[0],
|
||||
withdrawAddr: f.addrs[1],
|
||||
expErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid case, same delegator and withdraw address",
|
||||
delegatorAddr: f.addrs[0],
|
||||
withdrawAddr: f.addrs[0],
|
||||
expErr: false,
|
||||
},
|
||||
{
|
||||
name: "empty delegator address",
|
||||
delegatorAddr: emptyDelAddr,
|
||||
withdrawAddr: f.addrs[0],
|
||||
expErr: true,
|
||||
expErrMsg: "invalid delegator address",
|
||||
},
|
||||
{
|
||||
name: "empty withdraw address",
|
||||
delegatorAddr: f.addrs[0],
|
||||
withdrawAddr: emptyDelAddr,
|
||||
expErr: true,
|
||||
expErrMsg: "invalid withdraw address",
|
||||
},
|
||||
{
|
||||
name: "both empty addresses",
|
||||
delegatorAddr: emptyDelAddr,
|
||||
withdrawAddr: emptyDelAddr,
|
||||
expErr: true,
|
||||
expErrMsg: "invalid delegator address",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
msg := types.NewMsgSetWithdrawAddress(tc.delegatorAddr, tc.withdrawAddr)
|
||||
_, err := f.msgServer.SetWithdrawAddress(f.ctx, msg)
|
||||
if tc.expErr {
|
||||
require.ErrorContains(t, err, tc.expErrMsg)
|
||||
} else {
|
||||
require.Nil(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMsgWithdrawDelegatorReward(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
delegatorAddr sdk.AccAddress
|
||||
validatorAddr sdk.ValAddress
|
||||
expErr bool
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "empty delegator address",
|
||||
delegatorAddr: emptyDelAddr,
|
||||
validatorAddr: f.valAddrs[0],
|
||||
expErr: true,
|
||||
expErrMsg: "invalid delegator address",
|
||||
},
|
||||
{
|
||||
name: "empty validator address",
|
||||
delegatorAddr: f.addrs[0],
|
||||
validatorAddr: emptyValAddr,
|
||||
expErr: true,
|
||||
expErrMsg: "invalid validator address",
|
||||
},
|
||||
{
|
||||
name: "both empty addresses",
|
||||
delegatorAddr: emptyDelAddr,
|
||||
validatorAddr: emptyValAddr,
|
||||
expErr: true,
|
||||
expErrMsg: "invalid validator address",
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
msg := types.NewMsgWithdrawDelegatorReward(tc.delegatorAddr, tc.validatorAddr)
|
||||
_, err := f.msgServer.WithdrawDelegatorReward(f.ctx, msg)
|
||||
if tc.expErr {
|
||||
require.ErrorContains(t, err, tc.expErrMsg)
|
||||
} else {
|
||||
require.Nil(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMsgWithdrawValidatorCommission(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
validatorAddr sdk.ValAddress
|
||||
expErr bool
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "valid withdraw (but validator has no commission)",
|
||||
validatorAddr: f.valAddrs[0],
|
||||
expErr: true,
|
||||
expErrMsg: "no validator commission to withdraw",
|
||||
},
|
||||
{
|
||||
name: "empty validator address",
|
||||
validatorAddr: emptyValAddr,
|
||||
expErr: true,
|
||||
expErrMsg: "invalid validator address",
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
msg := types.NewMsgWithdrawValidatorCommission(tc.validatorAddr)
|
||||
_, err := f.msgServer.WithdrawValidatorCommission(f.ctx, msg)
|
||||
if tc.expErr {
|
||||
require.ErrorContains(t, err, tc.expErrMsg)
|
||||
} else {
|
||||
require.Nil(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMsgFundCommunityPool(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
amount sdk.Coins
|
||||
depositor sdk.AccAddress
|
||||
expErr bool
|
||||
expErrMsg string
|
||||
}{
|
||||
{
|
||||
name: "no depositor",
|
||||
amount: sdk.NewCoins(sdk.NewInt64Coin("stake", 10000)),
|
||||
depositor: sdk.AccAddress{},
|
||||
expErr: true,
|
||||
expErrMsg: "invalid depositor address",
|
||||
},
|
||||
{
|
||||
name: "invalid coin",
|
||||
amount: sdk.Coins{sdk.NewInt64Coin("stake", 10), sdk.NewInt64Coin("stake", 10)},
|
||||
depositor: f.addrs[0],
|
||||
expErr: true,
|
||||
expErrMsg: "10stake,10stake: invalid coins",
|
||||
},
|
||||
{
|
||||
name: "valid deposit",
|
||||
amount: sdk.NewCoins(sdk.NewInt64Coin("stake", 1000)),
|
||||
depositor: f.addrs[0],
|
||||
expErr: false,
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
msg := types.NewMsgFundCommunityPool(tc.amount, tc.depositor)
|
||||
_, err := f.msgServer.FundCommunityPool(f.ctx, msg)
|
||||
if tc.expErr {
|
||||
require.ErrorContains(t, err, tc.expErrMsg)
|
||||
} else {
|
||||
require.Nil(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMsgUpdateParams(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := initFixture(t)
|
||||
@ -116,7 +312,6 @@ func TestMsgUpdateParams(t *testing.T) {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, err := f.msgServer.UpdateParams(f.ctx, tc.input)
|
||||
|
||||
if tc.expErr {
|
||||
assert.ErrorContains(t, err, tc.expErrMsg)
|
||||
} else {
|
||||
@ -211,7 +406,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
|
||||
{
|
||||
name: "happy path (staking token)",
|
||||
input: &types.MsgDepositValidatorRewardsPool{
|
||||
Authority: f.addrs[0].String(),
|
||||
Depositor: f.addrs[0].String(),
|
||||
ValidatorAddress: f.valAddrs[1].String(),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.ctx), sdk.NewInt(100))),
|
||||
},
|
||||
@ -219,7 +414,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
|
||||
{
|
||||
name: "happy path (non-staking token)",
|
||||
input: &types.MsgDepositValidatorRewardsPool{
|
||||
Authority: f.addrs[0].String(),
|
||||
Depositor: f.addrs[0].String(),
|
||||
ValidatorAddress: f.valAddrs[1].String(),
|
||||
Amount: amt,
|
||||
},
|
||||
@ -227,7 +422,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
|
||||
{
|
||||
name: "invalid validator",
|
||||
input: &types.MsgDepositValidatorRewardsPool{
|
||||
Authority: f.addrs[0].String(),
|
||||
Depositor: f.addrs[0].String(),
|
||||
ValidatorAddress: sdk.ValAddress([]byte("addr1_______________")).String(),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(f.ctx), sdk.NewInt(100))),
|
||||
},
|
||||
|
||||
@ -3,13 +3,12 @@ package keeper
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/errors"
|
||||
"github.com/armon/go-metrics"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
)
|
||||
@ -27,16 +26,17 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
|
||||
}
|
||||
|
||||
func (k msgServer) SetWithdrawAddress(goCtx context.Context, msg *types.MsgSetWithdrawAddress) (*types.MsgSetWithdrawAddressResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
delegatorAddress, err := k.authKeeper.StringToBytes(msg.DelegatorAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid delegator address: %s", err)
|
||||
}
|
||||
|
||||
withdrawAddress, err := k.authKeeper.StringToBytes(msg.WithdrawAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid withdraw address: %s", err)
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
err = k.SetWithdrawAddr(ctx, delegatorAddress, withdrawAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -46,16 +46,17 @@ func (k msgServer) SetWithdrawAddress(goCtx context.Context, msg *types.MsgSetWi
|
||||
}
|
||||
|
||||
func (k msgServer) WithdrawDelegatorReward(goCtx context.Context, msg *types.MsgWithdrawDelegatorReward) (*types.MsgWithdrawDelegatorRewardResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err)
|
||||
}
|
||||
|
||||
delegatorAddress, err := k.authKeeper.StringToBytes(msg.DelegatorAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid delegator address: %s", err)
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
amount, err := k.WithdrawDelegationRewards(ctx, delegatorAddress, valAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -77,12 +78,12 @@ func (k msgServer) WithdrawDelegatorReward(goCtx context.Context, msg *types.Msg
|
||||
}
|
||||
|
||||
func (k msgServer) WithdrawValidatorCommission(goCtx context.Context, msg *types.MsgWithdrawValidatorCommission) (*types.MsgWithdrawValidatorCommissionResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err)
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
amount, err := k.Keeper.WithdrawValidatorCommission(ctx, valAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -104,98 +105,132 @@ func (k msgServer) WithdrawValidatorCommission(goCtx context.Context, msg *types
|
||||
}
|
||||
|
||||
func (k msgServer) FundCommunityPool(goCtx context.Context, msg *types.MsgFundCommunityPool) (*types.MsgFundCommunityPoolResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
depositer, err := k.authKeeper.StringToBytes(msg.Depositor)
|
||||
depositor, err := k.authKeeper.StringToBytes(msg.Depositor)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid depositor address: %s", err)
|
||||
}
|
||||
|
||||
if err := validateAmount(msg.Amount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := k.Keeper.FundCommunityPool(ctx, msg.Amount, depositer); err != nil {
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
if err := k.Keeper.FundCommunityPool(ctx, msg.Amount, depositor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.MsgFundCommunityPoolResponse{}, nil
|
||||
}
|
||||
|
||||
func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
|
||||
if k.authority != req.Authority {
|
||||
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority)
|
||||
func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
|
||||
if err := k.validateAuthority(msg.Authority); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if (!req.Params.BaseProposerReward.IsNil() && !req.Params.BaseProposerReward.IsZero()) || //nolint:staticcheck // deprecated but kept for backwards compatibility
|
||||
(!req.Params.BonusProposerReward.IsNil() && !req.Params.BonusProposerReward.IsZero()) { //nolint:staticcheck // deprecated but kept for backwards compatibility
|
||||
return nil, errorsmod.Wrapf(errors.ErrInvalidRequest, "cannot update base or bonus proposer reward because these are deprecated fields")
|
||||
if (!msg.Params.BaseProposerReward.IsNil() && !msg.Params.BaseProposerReward.IsZero()) || //nolint:staticcheck // deprecated but kept for backwards compatibility
|
||||
(!msg.Params.BonusProposerReward.IsNil() && !msg.Params.BonusProposerReward.IsZero()) { //nolint:staticcheck // deprecated but kept for backwards compatibility
|
||||
return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "cannot update base or bonus proposer reward because these are deprecated fields")
|
||||
}
|
||||
|
||||
if err := msg.Params.ValidateBasic(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
if err := k.SetParams(ctx, req.Params); err != nil {
|
||||
if err := k.SetParams(ctx, msg.Params); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.MsgUpdateParamsResponse{}, nil
|
||||
}
|
||||
|
||||
func (k msgServer) CommunityPoolSpend(goCtx context.Context, req *types.MsgCommunityPoolSpend) (*types.MsgCommunityPoolSpendResponse, error) {
|
||||
if k.authority != req.Authority {
|
||||
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority)
|
||||
func (k msgServer) CommunityPoolSpend(goCtx context.Context, msg *types.MsgCommunityPoolSpend) (*types.MsgCommunityPoolSpendResponse, error) {
|
||||
if err := k.validateAuthority(msg.Authority); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
if err := validateAmount(msg.Amount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
recipient, err := k.authKeeper.StringToBytes(req.Recipient)
|
||||
recipient, err := k.authKeeper.StringToBytes(msg.Recipient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if k.bankKeeper.BlockedAddr(recipient) {
|
||||
return nil, errorsmod.Wrapf(errors.ErrUnauthorized, "%s is not allowed to receive external funds", req.Recipient)
|
||||
return nil, errors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", msg.Recipient)
|
||||
}
|
||||
|
||||
if err := k.DistributeFromFeePool(ctx, req.Amount, recipient); err != nil {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
if err := k.DistributeFromFeePool(ctx, msg.Amount, recipient); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logger := k.Logger(ctx)
|
||||
logger.Info("transferred from the community pool to recipient", "amount", req.Amount.String(), "recipient", req.Recipient)
|
||||
logger.Info("transferred from the community pool to recipient", "amount", msg.Amount.String(), "recipient", msg.Recipient)
|
||||
|
||||
return &types.MsgCommunityPoolSpendResponse{}, nil
|
||||
}
|
||||
|
||||
func (k msgServer) DepositValidatorRewardsPool(goCtx context.Context, req *types.MsgDepositValidatorRewardsPool) (*types.MsgDepositValidatorRewardsPoolResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
|
||||
authority, err := k.authKeeper.StringToBytes(req.Authority)
|
||||
func (k msgServer) DepositValidatorRewardsPool(goCtx context.Context, msg *types.MsgDepositValidatorRewardsPool) (*types.MsgDepositValidatorRewardsPoolResponse, error) {
|
||||
depositor, err := k.authKeeper.StringToBytes(msg.Depositor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// deposit coins from sender's account to the distribution module
|
||||
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, authority, types.ModuleName, req.Amount); err != nil {
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
// deposit coins from depositor's account to the distribution module
|
||||
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, depositor, types.ModuleName, msg.Amount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
valAddr, err := sdk.ValAddressFromBech32(req.ValidatorAddress)
|
||||
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
validator := k.stakingKeeper.Validator(ctx, valAddr)
|
||||
if validator == nil {
|
||||
return nil, errorsmod.Wrapf(types.ErrNoValidatorExists, valAddr.String())
|
||||
return nil, errors.Wrapf(types.ErrNoValidatorExists, valAddr.String())
|
||||
}
|
||||
|
||||
// Allocate tokens from the distribution module to the validator, which are
|
||||
// then distributed to the validator's delegators.
|
||||
reward := sdk.NewDecCoinsFromCoins(req.Amount...)
|
||||
reward := sdk.NewDecCoinsFromCoins(msg.Amount...)
|
||||
k.AllocateTokensToValidator(ctx, validator, reward)
|
||||
|
||||
logger := k.Logger(ctx)
|
||||
logger.Info(
|
||||
"transferred from rewards to validator rewards pool",
|
||||
"authority", req.Authority,
|
||||
"amount", req.Amount.String(),
|
||||
"validator", req.ValidatorAddress,
|
||||
"depositor", msg.Depositor,
|
||||
"amount", msg.Amount.String(),
|
||||
"validator", msg.ValidatorAddress,
|
||||
)
|
||||
|
||||
return &types.MsgDepositValidatorRewardsPoolResponse{}, nil
|
||||
}
|
||||
|
||||
func (k *Keeper) validateAuthority(authority string) error {
|
||||
if _, err := k.authKeeper.StringToBytes(authority); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err)
|
||||
}
|
||||
|
||||
if k.authority != authority {
|
||||
return errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, authority)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateAmount(amount sdk.Coins) error {
|
||||
if amount == nil {
|
||||
return errors.Wrap(sdkerrors.ErrInvalidCoins, "amount cannot be nil")
|
||||
}
|
||||
|
||||
if err := amount.Validate(); err != nil {
|
||||
return errors.Wrap(sdkerrors.ErrInvalidCoins, amount.String())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var (
|
||||
delPk1 = ed25519.GenPrivKey().PubKey()
|
||||
delPk2 = ed25519.GenPrivKey().PubKey()
|
||||
delAddr1 = sdk.AccAddress(delPk1.Address())
|
||||
delAddr2 = sdk.AccAddress(delPk2.Address())
|
||||
emptyDelAddr sdk.AccAddress
|
||||
|
||||
valPk1 = ed25519.GenPrivKey().PubKey()
|
||||
valAddr1 = sdk.ValAddress(valPk1.Address())
|
||||
emptyValAddr sdk.ValAddress
|
||||
)
|
||||
@ -1,12 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
||||
)
|
||||
|
||||
@ -46,18 +41,6 @@ func (msg MsgSetWithdrawAddress) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// quick validity check
|
||||
func (msg MsgSetWithdrawAddress) ValidateBasic() error {
|
||||
if _, err := sdk.AccAddressFromBech32(msg.DelegatorAddress); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid delegator address: %s", err)
|
||||
}
|
||||
if _, err := sdk.AccAddressFromBech32(msg.WithdrawAddress); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid withdraw address: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) *MsgWithdrawDelegatorReward {
|
||||
return &MsgWithdrawDelegatorReward{
|
||||
DelegatorAddress: delAddr.String(),
|
||||
@ -77,17 +60,6 @@ func (msg MsgWithdrawDelegatorReward) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// quick validity check
|
||||
func (msg MsgWithdrawDelegatorReward) ValidateBasic() error {
|
||||
if _, err := sdk.AccAddressFromBech32(msg.DelegatorAddress); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid delegator address: %s", err)
|
||||
}
|
||||
if _, err := sdk.ValAddressFromBech32(msg.ValidatorAddress); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) *MsgWithdrawValidatorCommission {
|
||||
return &MsgWithdrawValidatorCommission{
|
||||
ValidatorAddress: valAddr.String(),
|
||||
@ -106,14 +78,6 @@ func (msg MsgWithdrawValidatorCommission) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// quick validity check
|
||||
func (msg MsgWithdrawValidatorCommission) ValidateBasic() error {
|
||||
if _, err := sdk.ValAddressFromBech32(msg.ValidatorAddress); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewMsgFundCommunityPool returns a new MsgFundCommunityPool with a sender and
|
||||
// a funding amount.
|
||||
func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) *MsgFundCommunityPool {
|
||||
@ -137,17 +101,6 @@ func (msg MsgFundCommunityPool) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic MsgFundCommunityPool message validation.
|
||||
func (msg MsgFundCommunityPool) ValidateBasic() error {
|
||||
if !msg.Amount.IsValid() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String())
|
||||
}
|
||||
if _, err := sdk.AccAddressFromBech32(msg.Depositor); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid depositor address: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSigners returns the signer addresses that are expected to sign the result
|
||||
// of GetSignBytes.
|
||||
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
|
||||
@ -162,20 +115,6 @@ func (msg MsgUpdateParams) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic MsgUpdateParams message validation.
|
||||
func (msg MsgUpdateParams) ValidateBasic() error {
|
||||
if (!msg.Params.BaseProposerReward.IsNil() && !msg.Params.BaseProposerReward.IsZero()) ||
|
||||
(!msg.Params.BonusProposerReward.IsNil() && !msg.Params.BonusProposerReward.IsZero()) {
|
||||
return errors.New("base and bonus proposer reward are deprecated fields and should not be used")
|
||||
}
|
||||
|
||||
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err)
|
||||
}
|
||||
|
||||
return msg.Params.ValidateBasic()
|
||||
}
|
||||
|
||||
// GetSigners returns the signer addresses that are expected to sign the result
|
||||
// of GetSignBytes, which is the authority.
|
||||
func (msg MsgCommunityPoolSpend) GetSigners() []sdk.AccAddress {
|
||||
@ -190,30 +129,21 @@ func (msg MsgCommunityPoolSpend) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic MsgCommunityPoolSpend message validation.
|
||||
func (msg MsgCommunityPoolSpend) ValidateBasic() error {
|
||||
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err)
|
||||
}
|
||||
|
||||
return msg.Amount.Validate()
|
||||
}
|
||||
|
||||
// NewMsgDepositValidatorRewardsPool returns a new MsgDepositValidatorRewardsPool
|
||||
// with a sender and a funding amount.
|
||||
// with a depositor and a funding amount.
|
||||
func NewMsgDepositValidatorRewardsPool(depositor sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coins) *MsgDepositValidatorRewardsPool {
|
||||
return &MsgDepositValidatorRewardsPool{
|
||||
Amount: amount,
|
||||
Authority: depositor.String(),
|
||||
Depositor: depositor.String(),
|
||||
ValidatorAddress: valAddr.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// GetSigners returns the signer addresses that are expected to sign the result
|
||||
// of GetSignBytes, which is the authority.
|
||||
// of GetSignBytes, which is the depositor.
|
||||
func (msg MsgDepositValidatorRewardsPool) GetSigners() []sdk.AccAddress {
|
||||
authority, _ := sdk.AccAddressFromBech32(msg.Authority)
|
||||
return []sdk.AccAddress{authority}
|
||||
depositor, _ := sdk.AccAddressFromBech32(msg.Depositor)
|
||||
return []sdk.AccAddress{depositor}
|
||||
}
|
||||
|
||||
// GetSignBytes returns the raw bytes for a MsgDepositValidatorRewardsPool message
|
||||
@ -222,12 +152,3 @@ func (msg MsgDepositValidatorRewardsPool) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic MsgDepositValidatorRewardsPool message validation.
|
||||
func (msg MsgDepositValidatorRewardsPool) ValidateBasic() error {
|
||||
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err)
|
||||
}
|
||||
|
||||
return msg.Amount.Validate()
|
||||
}
|
||||
|
||||
@ -1,95 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// test ValidateBasic for MsgSetWithdrawAddress
|
||||
func TestMsgSetWithdrawAddress(t *testing.T) {
|
||||
tests := []struct {
|
||||
delegatorAddr sdk.AccAddress
|
||||
withdrawAddr sdk.AccAddress
|
||||
expectPass bool
|
||||
}{
|
||||
{delAddr1, delAddr2, true},
|
||||
{delAddr1, delAddr1, true},
|
||||
{emptyDelAddr, delAddr1, false},
|
||||
{delAddr1, emptyDelAddr, false},
|
||||
{emptyDelAddr, emptyDelAddr, false},
|
||||
}
|
||||
|
||||
for i, tc := range tests {
|
||||
msg := NewMsgSetWithdrawAddress(tc.delegatorAddr, tc.withdrawAddr)
|
||||
if tc.expectPass {
|
||||
require.Nil(t, msg.ValidateBasic(), "test index: %v", i)
|
||||
} else {
|
||||
require.NotNil(t, msg.ValidateBasic(), "test index: %v", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test ValidateBasic for MsgWithdrawDelegatorReward
|
||||
func TestMsgWithdrawDelegatorReward(t *testing.T) {
|
||||
tests := []struct {
|
||||
delegatorAddr sdk.AccAddress
|
||||
validatorAddr sdk.ValAddress
|
||||
expectPass bool
|
||||
}{
|
||||
{delAddr1, valAddr1, true},
|
||||
{emptyDelAddr, valAddr1, false},
|
||||
{delAddr1, emptyValAddr, false},
|
||||
{emptyDelAddr, emptyValAddr, false},
|
||||
}
|
||||
for i, tc := range tests {
|
||||
msg := NewMsgWithdrawDelegatorReward(tc.delegatorAddr, tc.validatorAddr)
|
||||
if tc.expectPass {
|
||||
require.Nil(t, msg.ValidateBasic(), "test index: %v", i)
|
||||
} else {
|
||||
require.NotNil(t, msg.ValidateBasic(), "test index: %v", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test ValidateBasic for MsgWithdrawValidatorCommission
|
||||
func TestMsgWithdrawValidatorCommission(t *testing.T) {
|
||||
tests := []struct {
|
||||
validatorAddr sdk.ValAddress
|
||||
expectPass bool
|
||||
}{
|
||||
{valAddr1, true},
|
||||
{emptyValAddr, false},
|
||||
}
|
||||
for i, tc := range tests {
|
||||
msg := NewMsgWithdrawValidatorCommission(tc.validatorAddr)
|
||||
if tc.expectPass {
|
||||
require.Nil(t, msg.ValidateBasic(), "test index: %v", i)
|
||||
} else {
|
||||
require.NotNil(t, msg.ValidateBasic(), "test index: %v", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test ValidateBasic for MsgDepositIntoCommunityPool
|
||||
func TestMsgDepositIntoCommunityPool(t *testing.T) {
|
||||
tests := []struct {
|
||||
amount sdk.Coins
|
||||
depositor sdk.AccAddress
|
||||
expectPass bool
|
||||
}{
|
||||
{sdk.NewCoins(sdk.NewInt64Coin("uatom", 10000)), sdk.AccAddress{}, false},
|
||||
{sdk.Coins{sdk.NewInt64Coin("uatom", 10), sdk.NewInt64Coin("uatom", 10)}, delAddr1, false},
|
||||
{sdk.NewCoins(sdk.NewInt64Coin("uatom", 1000)), delAddr1, true},
|
||||
}
|
||||
for i, tc := range tests {
|
||||
msg := NewMsgFundCommunityPool(tc.amount, tc.depositor)
|
||||
if tc.expectPass {
|
||||
require.Nil(t, msg.ValidateBasic(), "test index: %v", i)
|
||||
} else {
|
||||
require.NotNil(t, msg.ValidateBasic(), "test index: %v", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -573,7 +573,7 @@ var xxx_messageInfo_MsgCommunityPoolSpendResponse proto.InternalMessageInfo
|
||||
//
|
||||
// Since: cosmos-sdk 0.48
|
||||
type MsgDepositValidatorRewardsPool struct {
|
||||
Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"`
|
||||
Depositor string `protobuf:"bytes,1,opt,name=depositor,proto3" json:"depositor,omitempty"`
|
||||
ValidatorAddress string `protobuf:"bytes,2,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"`
|
||||
Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"`
|
||||
}
|
||||
@ -675,7 +675,7 @@ func init() {
|
||||
}
|
||||
|
||||
var fileDescriptor_ed4f433d965e58ca = []byte{
|
||||
// 912 bytes of a gzipped FileDescriptorProto
|
||||
// 913 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x57, 0xb1, 0x6f, 0xf3, 0x44,
|
||||
0x14, 0xcf, 0xa5, 0xa2, 0x28, 0xf7, 0x7d, 0xd2, 0xd7, 0x44, 0x45, 0x6d, 0xfd, 0x15, 0xa7, 0x72,
|
||||
0xa1, 0x44, 0x11, 0xb5, 0x95, 0x80, 0x40, 0x0d, 0x03, 0x90, 0xb4, 0x91, 0x18, 0x22, 0xaa, 0x54,
|
||||
@ -719,20 +719,21 @@ var fileDescriptor_ed4f433d965e58ca = []byte{
|
||||
0x05, 0xaf, 0xc3, 0x9c, 0xa5, 0x76, 0x91, 0x89, 0x54, 0x83, 0xba, 0x17, 0xda, 0x9e, 0x2c, 0x04,
|
||||
0x9c, 0xb6, 0xf0, 0x1f, 0x3b, 0xad, 0xb6, 0x13, 0x55, 0x70, 0x6b, 0x5a, 0x41, 0x29, 0x56, 0x0b,
|
||||
0x36, 0x4b, 0xa2, 0x1b, 0xbe, 0x8c, 0xbf, 0x64, 0x9d, 0x8e, 0xb5, 0xeb, 0xda, 0xd0, 0x7f, 0xfe,
|
||||
0x6e, 0x4b, 0x25, 0xce, 0x1b, 0xbb, 0xab, 0x9e, 0xf7, 0x33, 0x40, 0x1e, 0x52, 0xf8, 0xb7, 0x42,
|
||||
0x4f, 0x35, 0x74, 0x01, 0x2f, 0xc6, 0x5d, 0xc0, 0x44, 0x45, 0xa6, 0x9f, 0x50, 0x72, 0xba, 0x6b,
|
||||
0x82, 0xba, 0xde, 0x45, 0x54, 0xff, 0x7a, 0x16, 0x2e, 0xb4, 0x88, 0x56, 0xf8, 0x1c, 0xc0, 0x42,
|
||||
0xcc, 0x87, 0x4e, 0x35, 0xf1, 0xf5, 0xc5, 0x7e, 0x2f, 0x70, 0xb5, 0xf9, 0x31, 0x7e, 0xb3, 0xff,
|
||||
0x06, 0xc0, 0x95, 0x59, 0x1f, 0x18, 0xaf, 0xa7, 0xe5, 0x9d, 0x01, 0xe4, 0xde, 0xbc, 0x23, 0xd0,
|
||||
0x67, 0x75, 0x06, 0xe0, 0xd3, 0xa4, 0xe1, 0xfa, 0xc6, 0x6d, 0x0f, 0x88, 0x01, 0x73, 0x8d, 0x7f,
|
||||
0x01, 0xf6, 0x19, 0x7e, 0x0a, 0x60, 0x3e, 0x3a, 0xa6, 0x2a, 0x69, 0xa9, 0x23, 0x10, 0x6e, 0x67,
|
||||
0x6e, 0x88, 0xcf, 0xc1, 0x82, 0x8f, 0x43, 0x13, 0xe0, 0xe5, 0xb4, 0x54, 0xc1, 0x68, 0xee, 0xd5,
|
||||
0x79, 0xa2, 0xfd, 0x33, 0x6d, 0xdb, 0xc6, 0xf4, 0xe2, 0x54, 0xdb, 0x46, 0x31, 0xe9, 0xb6, 0x9d,
|
||||
0xdd, 0xce, 0x1c, 0x83, 0x24, 0xf5, 0xb2, 0x54, 0x83, 0x24, 0x80, 0xd3, 0x0d, 0x72, 0x8b, 0x77,
|
||||
0xce, 0x3d, 0xf3, 0x89, 0xdd, 0x62, 0xea, 0xef, 0x5e, 0x8e, 0x78, 0x70, 0x35, 0xe2, 0xc1, 0xf5,
|
||||
0x88, 0x07, 0xbf, 0x8f, 0x78, 0xf0, 0xf5, 0x0d, 0x9f, 0xb9, 0xbe, 0xe1, 0x33, 0x3f, 0xdf, 0xf0,
|
||||
0x99, 0x0f, 0x2b, 0x89, 0x0d, 0xec, 0x34, 0x3c, 0x34, 0x9d, 0x7e, 0xd6, 0x59, 0x74, 0xfe, 0x55,
|
||||
0x7a, 0xe5, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0d, 0xb6, 0xd1, 0xb4, 0x1c, 0x0e, 0x00, 0x00,
|
||||
0x6e, 0x4b, 0x25, 0xce, 0x1b, 0x0b, 0x19, 0x1d, 0xdc, 0xda, 0xe8, 0xf7, 0x34, 0x40, 0x1e, 0x52,
|
||||
0xf8, 0xb7, 0x66, 0x3f, 0xd5, 0x17, 0xe3, 0x2e, 0x60, 0xa2, 0x22, 0xd3, 0x4f, 0x28, 0x39, 0xdd,
|
||||
0x35, 0x41, 0x5d, 0xef, 0x22, 0xaa, 0x7f, 0x3d, 0x0b, 0x17, 0x5a, 0x44, 0x2b, 0x7c, 0x0e, 0x60,
|
||||
0x21, 0xe6, 0x43, 0xa7, 0x9a, 0xf8, 0xfa, 0x62, 0xbf, 0x17, 0xb8, 0xda, 0xfc, 0x18, 0xbf, 0xd9,
|
||||
0x7f, 0x03, 0xe0, 0xca, 0xac, 0x0f, 0x8c, 0xd7, 0xd3, 0xf2, 0xce, 0x00, 0x72, 0x6f, 0xde, 0x11,
|
||||
0xe8, 0xb3, 0x3a, 0x03, 0xf0, 0x69, 0xd2, 0x70, 0x7d, 0xe3, 0xb6, 0x07, 0xc4, 0x80, 0xb9, 0xc6,
|
||||
0xbf, 0x00, 0xfb, 0x0c, 0x3f, 0x05, 0x30, 0x1f, 0x1d, 0x53, 0x95, 0xb4, 0xd4, 0x11, 0x08, 0xb7,
|
||||
0x33, 0x37, 0xc4, 0xe7, 0x60, 0xc1, 0xc7, 0xa1, 0x09, 0xf0, 0x72, 0x5a, 0xaa, 0x60, 0x34, 0xf7,
|
||||
0xea, 0x3c, 0xd1, 0xfe, 0x99, 0xb6, 0x6d, 0x63, 0x7a, 0x71, 0xaa, 0x6d, 0xa3, 0x98, 0x74, 0xdb,
|
||||
0xce, 0x6e, 0x67, 0x8e, 0x41, 0x92, 0x7a, 0x59, 0xaa, 0x41, 0x12, 0xc0, 0xe9, 0x06, 0xb9, 0xc5,
|
||||
0x3b, 0xe7, 0x9e, 0xf9, 0xc4, 0x6e, 0x31, 0xf5, 0x77, 0x2f, 0x47, 0x3c, 0xb8, 0x1a, 0xf1, 0xe0,
|
||||
0x7a, 0xc4, 0x83, 0xdf, 0x47, 0x3c, 0xf8, 0xfa, 0x86, 0xcf, 0x5c, 0xdf, 0xf0, 0x99, 0x9f, 0x6f,
|
||||
0xf8, 0xcc, 0x87, 0x95, 0xc4, 0x06, 0x76, 0x1a, 0x1e, 0x9a, 0x4e, 0x3f, 0xeb, 0x2c, 0x3a, 0xff,
|
||||
0x2a, 0xbd, 0xf2, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd7, 0x20, 0xf3, 0xc2, 0x1c, 0x0e, 0x00,
|
||||
0x00,
|
||||
}
|
||||
|
||||
func (this *MsgSetWithdrawAddressResponse) Equal(that interface{}) bool {
|
||||
@ -1747,10 +1748,10 @@ func (m *MsgDepositValidatorRewardsPool) MarshalToSizedBuffer(dAtA []byte) (int,
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
if len(m.Authority) > 0 {
|
||||
i -= len(m.Authority)
|
||||
copy(dAtA[i:], m.Authority)
|
||||
i = encodeVarintTx(dAtA, i, uint64(len(m.Authority)))
|
||||
if len(m.Depositor) > 0 {
|
||||
i -= len(m.Depositor)
|
||||
copy(dAtA[i:], m.Depositor)
|
||||
i = encodeVarintTx(dAtA, i, uint64(len(m.Depositor)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
@ -1967,7 +1968,7 @@ func (m *MsgDepositValidatorRewardsPool) Size() (n int) {
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Authority)
|
||||
l = len(m.Depositor)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovTx(uint64(l))
|
||||
}
|
||||
@ -3087,7 +3088,7 @@ func (m *MsgDepositValidatorRewardsPool) Unmarshal(dAtA []byte) error {
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType)
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Depositor", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
@ -3115,7 +3116,7 @@ func (m *MsgDepositValidatorRewardsPool) Unmarshal(dAtA []byte) error {
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Authority = string(dAtA[iNdEx:postIndex])
|
||||
m.Depositor = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user