diff --git a/proto/sge/reward/tx.proto b/proto/sge/reward/tx.proto index 807152bb..739b8551 100644 --- a/proto/sge/reward/tx.proto +++ b/proto/sge/reward/tx.proto @@ -49,8 +49,7 @@ message MsgDeleteCampaignResponse {} message MsgApplyReward { string creator = 1; string campaign_uid = 2; - uint64 ts = 3; - string ticket = 4; + string ticket = 3; } // MsgApplyRewardResponse apply reward message response type. diff --git a/x/reward/types/messages_reward.go b/x/reward/types/messages_reward.go index 9750956b..69e51c14 100644 --- a/x/reward/types/messages_reward.go +++ b/x/reward/types/messages_reward.go @@ -4,6 +4,9 @@ import ( sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" ) const ( @@ -50,5 +53,14 @@ func (msg *MsgApplyReward) ValidateBasic() error { if err != nil { return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid creator address (%s)", err) } + + if !utils.IsValidUID(msg.CampaignUid) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid campaign uid") + } + + if msg.Ticket == "" { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid ticket") + } + return nil } diff --git a/x/reward/types/messages_reward_test.go b/x/reward/types/messages_reward_test.go new file mode 100644 index 00000000..88ce6d8c --- /dev/null +++ b/x/reward/types/messages_reward_test.go @@ -0,0 +1,62 @@ +package types_test + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/google/uuid" + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/reward/types" + "github.com/stretchr/testify/require" +) + +func TestMsgApplyReward_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgApplyReward + err error + }{ + { + name: "invalid address", + msg: types.MsgApplyReward{ + Creator: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "invalid uid", + msg: types.MsgApplyReward{ + Creator: sample.AccAddress(), + CampaignUid: "bad uid", + Ticket: "ticket", + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "invalid ticket", + msg: types.MsgApplyReward{ + Creator: sample.AccAddress(), + CampaignUid: uuid.NewString(), + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "valid address", + msg: types.MsgApplyReward{ + Creator: sample.AccAddress(), + CampaignUid: uuid.NewString(), + Ticket: "ticket", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/reward/types/tx.pb.go b/x/reward/types/tx.pb.go index d1749cf9..a019f044 100644 --- a/x/reward/types/tx.pb.go +++ b/x/reward/types/tx.pb.go @@ -317,8 +317,7 @@ var xxx_messageInfo_MsgDeleteCampaignResponse proto.InternalMessageInfo type MsgApplyReward struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` CampaignUid string `protobuf:"bytes,2,opt,name=campaign_uid,json=campaignUid,proto3" json:"campaign_uid,omitempty"` - Ts uint64 `protobuf:"varint,3,opt,name=ts,proto3" json:"ts,omitempty"` - Ticket string `protobuf:"bytes,4,opt,name=ticket,proto3" json:"ticket,omitempty"` + Ticket string `protobuf:"bytes,3,opt,name=ticket,proto3" json:"ticket,omitempty"` } func (m *MsgApplyReward) Reset() { *m = MsgApplyReward{} } @@ -368,13 +367,6 @@ func (m *MsgApplyReward) GetCampaignUid() string { return "" } -func (m *MsgApplyReward) GetTs() uint64 { - if m != nil { - return m.Ts - } - return 0 -} - func (m *MsgApplyReward) GetTicket() string { if m != nil { return m.Ticket @@ -433,31 +425,29 @@ func init() { func init() { proto.RegisterFile("sge/reward/tx.proto", fileDescriptor_ad69e28332238e66) } var fileDescriptor_ad69e28332238e66 = []byte{ - // 369 bytes of a gzipped FileDescriptorProto - 0x1f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 0x7a, 0x8f, 0x03, 0xfc, 0x1d, 0x35, 0x4e, 0x4f, 0x07, - 0xac, 0xd2, 0xc7, 0x50, 0xed, 0x10, 0xbf, 0x15, 0x62, 0x30, 0xb3, 0xa2, 0x7f, 0x9b, 0x13, 0x7d, - 0x06, 0x7b, 0x4e, 0xfc, 0xfe, 0xd3, 0x37, 0xa3, 0x92, 0x68, 0x5d, 0xcf, 0x65, 0x55, 0x28, 0x4a, - 0x8a, 0xa6, 0x2b, 0x59, 0x45, 0x49, 0x6b, 0x13, 0x97, 0x52, 0x13, 0x6b, 0x50, 0x4b, 0x63, 0x93, - 0x0f, 0xba, 0x7a, 0x55, 0x41, 0xed, 0x10, 0x67, 0x03, 0xa8, 0x6e, 0xf4, 0xdb, 0x34, 0x32, 0x0f, - 0x83, 0xb1, 0x55, 0x58, 0xfd, 0x72, 0x57, 0x67, 0x42, 0x0d, 0x69, 0x1b, 0xbd, 0xe6, 0xd0, 0xd2, - 0xce, 0x3c, 0x5a, 0x76, 0xa5, 0x21, 0x6d, 0xa3, 0xcf, 0x1c, 0x5a, 0xda, 0x99, 0x47, 0xcb, 0xae, - 0x98, 0x39, 0x50, 0x59, 0xef, 0xf7, 0xfc, 0xe7, 0x80, 0x35, 0x5b, 0xbd, 0xb5, 0x93, 0x2d, 0x81, - 0xdc, 0xb5, 0xdf, 0x16, 0xba, 0x32, 0x5f, 0xe8, 0xca, 0xc7, 0x42, 0x57, 0x5e, 0x96, 0x7a, 0x61, - 0xbe, 0xd4, 0x0b, 0xef, 0x4b, 0xbd, 0xf0, 0x78, 0xc1, 0x3d, 0xf9, 0x3c, 0xee, 0x19, 0x8e, 0x3f, - 0x34, 0x89, 0x63, 0x2b, 0xce, 0x0c, 0xd7, 0xe6, 0x74, 0x75, 0xe1, 0x67, 0x02, 0xa9, 0x57, 0x8e, - 0x2e, 0xfd, 0xf5, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x42, 0xe5, 0x16, 0x04, 0x0b, 0x04, 0x00, - 0x00, + // 351 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xcf, 0x4a, 0xc3, 0x30, + 0x1c, 0xc7, 0x57, 0x0b, 0x13, 0x7f, 0x93, 0xa1, 0x15, 0x47, 0x9d, 0x10, 0x74, 0x20, 0xcc, 0xc3, + 0x52, 0xd1, 0x07, 0x10, 0x9d, 0xd7, 0x5d, 0x06, 0x43, 0xf0, 0x22, 0x5d, 0xf7, 0x23, 0x96, 0xfd, + 0x49, 0x48, 0x32, 0xb6, 0xbd, 0x85, 0x0f, 0xe3, 0x43, 0x78, 0xdc, 0xd1, 0xa3, 0x6c, 0x2f, 0x22, + 0xad, 0xed, 0x5c, 0xb7, 0x19, 0x86, 0xe0, 0x2d, 0xf9, 0xf5, 0xdb, 0xef, 0xa7, 0xcd, 0x87, 0xc0, + 0x91, 0x62, 0xe8, 0x49, 0x1c, 0xf9, 0xb2, 0xe3, 0xe9, 0x31, 0x15, 0x92, 0x6b, 0xee, 0x1c, 0x2b, + 0x86, 0x03, 0xd4, 0x23, 0x2e, 0xbb, 0x54, 0x31, 0xa4, 0xdf, 0xcf, 0x2b, 0x8f, 0x70, 0xd8, 0x50, + 0xac, 0x2e, 0xd1, 0xd7, 0x58, 0xf7, 0xfb, 0xc2, 0x0f, 0xd9, 0xc0, 0x71, 0x61, 0x37, 0x88, 0x26, + 0x5c, 0xba, 0xd6, 0x99, 0x55, 0xdd, 0x6b, 0xa6, 0x5b, 0xe7, 0x00, 0xec, 0x61, 0xd8, 0x71, 0x77, + 0xe2, 0x69, 0xb4, 0x74, 0x4a, 0x90, 0xd7, 0x61, 0xd0, 0x45, 0xed, 0xda, 0xf1, 0x30, 0xd9, 0x55, + 0x4e, 0xe1, 0x64, 0xad, 0xb8, 0x89, 0x4a, 0xf0, 0x81, 0xc2, 0x84, 0xda, 0x12, 0x9d, 0xff, 0xa1, + 0x66, 0x8b, 0x17, 0xd4, 0xdb, 0x98, 0xfa, 0x80, 0x3d, 0xfc, 0x1b, 0x35, 0x69, 0xcf, 0x16, 0x2c, + 0xda, 0x11, 0x8a, 0x0d, 0xc5, 0xee, 0x84, 0xe8, 0x4d, 0x9a, 0xf1, 0xd9, 0x1a, 0xaa, 0xcf, 0x61, + 0x3f, 0x48, 0xde, 0x7f, 0xfe, 0x61, 0x14, 0xd2, 0x59, 0xcb, 0xf0, 0x87, 0x2e, 0x94, 0xb2, 0x98, + 0xf4, 0x03, 0xae, 0xdf, 0x6c, 0xb0, 0x1b, 0x8a, 0x39, 0x3d, 0x28, 0xae, 0xf8, 0xac, 0xd2, 0x8d, + 0xf2, 0xe9, 0x9a, 0xa0, 0xf2, 0xd5, 0xb6, 0xc9, 0x94, 0x1a, 0xd1, 0x56, 0x3c, 0x1a, 0x68, 0xd9, + 0xa4, 0x89, 0xb6, 0x59, 0x61, 0x44, 0x5b, 0xf1, 0x67, 0xa0, 0x65, 0x93, 0x26, 0xda, 0x66, 0xa5, + 0x4e, 0x00, 0x85, 0x65, 0x9f, 0x17, 0xbf, 0x17, 0x2c, 0xc5, 0xca, 0xb5, 0xad, 0x62, 0x29, 0xe4, + 0xbe, 0xfe, 0x3e, 0x23, 0xd6, 0x74, 0x46, 0xac, 0xcf, 0x19, 0xb1, 0x5e, 0xe7, 0x24, 0x37, 0x9d, + 0x93, 0xdc, 0xc7, 0x9c, 0xe4, 0x9e, 0x2e, 0x59, 0xa8, 0x5f, 0x86, 0x6d, 0x1a, 0xf0, 0xbe, 0xa7, + 0x18, 0xd6, 0x92, 0xce, 0x68, 0xed, 0x8d, 0x17, 0x17, 0x7c, 0x22, 0x50, 0xb5, 0xf3, 0xf1, 0x25, + 0xbf, 0xf9, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x7f, 0xdd, 0xe2, 0xc1, 0xfb, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -875,12 +865,7 @@ func (m *MsgApplyReward) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Ticket) i = encodeVarintTx(dAtA, i, uint64(len(m.Ticket))) i-- - dAtA[i] = 0x22 - } - if m.Ts != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Ts)) - i-- - dAtA[i] = 0x18 + dAtA[i] = 0x1a } if len(m.CampaignUid) > 0 { i -= len(m.CampaignUid) @@ -1033,9 +1018,6 @@ func (m *MsgApplyReward) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.Ts != 0 { - n += 1 + sovTx(uint64(m.Ts)) - } l = len(m.Ticket) if l > 0 { n += 1 + l + sovTx(uint64(l)) @@ -1708,25 +1690,6 @@ func (m *MsgApplyReward) Unmarshal(dAtA []byte) error { m.CampaignUid = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Ts", wireType) - } - m.Ts = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Ts |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Ticket", wireType) }