Skip to content

Commit

Permalink
fix: remove ts from apply reward
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Sep 26, 2023
1 parent e61c72b commit c806f34
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 64 deletions.
3 changes: 1 addition & 2 deletions proto/sge/reward/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions x/reward/types/messages_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"

Check failure on line 6 in x/reward/types/messages_reward.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

ST1019: package "github.com/cosmos/cosmos-sdk/types/errors" is being imported more than once (stylecheck)
sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors"

Check failure on line 7 in x/reward/types/messages_reward.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

ST1019(related information): other import of "github.com/cosmos/cosmos-sdk/types/errors" (stylecheck)

"github.com/sge-network/sge/utils"
)

const (
Expand Down Expand Up @@ -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
}
62 changes: 62 additions & 0 deletions x/reward/types/messages_reward_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
87 changes: 25 additions & 62 deletions x/reward/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c806f34

Please sign in to comment.