Skip to content

Commit

Permalink
refactor: acc_rec_type consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Sep 29, 2023
1 parent 50a5ac3 commit c618040
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 160 deletions.
6 changes: 3 additions & 3 deletions proto/sge/reward/reward.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ message RewardCommon {
// Definition is the type for reward declaration for a campaign.
message Definition {
ReceiverType rec_type = 1;
string amount = 2 [
ReceiverAccType rec_acc_type = 2;
string amount = 3 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"amount\""
];
ReceiverAccType receiver_acc_type = 3;
uint64 unlock_ts = 4 [
(gogoproto.customname) = "UnlockTS",
(gogoproto.jsontag) = "unlock_ts",
Expand All @@ -49,7 +49,7 @@ message Allocation {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"amount\""
];
ReceiverAccType receiver_acc_type = 2;
ReceiverAccType rec_acc_type = 2;
uint64 unlock_ts = 3 [
(gogoproto.customname) = "UnlockTS",
(gogoproto.jsontag) = "unlock_ts",
Expand Down
6 changes: 3 additions & 3 deletions x/reward/client/cli/query_campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func networkWithCampaignObjects(t *testing.T, n int) (*network.Network, []types.
EndTS: uint64(time.Now().Add(5 * time.Minute).Unix()),
RewardType: types.RewardType_REWARD_TYPE_AFFILIATION,
RewardDefs: []types.Definition{{
RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE,
Amount: sdkmath.NewInt(100),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN,
RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE,
Amount: sdkmath.NewInt(100),
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN,
}},
Pool: types.Pool{Spent: sdkmath.NewInt(100), Total: sdkmath.NewInt(1000)},
}
Expand Down
6 changes: 3 additions & 3 deletions x/reward/keeper/campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func createNCampaign(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Camp
items[i].EndTS = uint64(time.Now().Add(5 * time.Minute).Unix())
items[i].RewardType = types.RewardType_REWARD_TYPE_REFERRAL
items[i].RewardDefs = []types.Definition{{
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
Amount: sdkmath.NewInt(100),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
Amount: sdkmath.NewInt(100),
}}
items[i].Pool = types.Pool{Spent: sdk.ZeroInt(), Total: sdkmath.NewInt(100)}

Expand Down
2 changes: 1 addition & 1 deletion x/reward/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// DistributeRewards distributes the rewards according to the input distribution list.
func (k Keeper) DistributeRewards(ctx sdk.Context, funderAddr string, distributions []types.Distribution) error {
for _, d := range distributions {
switch d.Allocation.ReceiverAccType {
switch d.Allocation.RecAccType {
case types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN:
return k.modFunder.Refund(
types.RewardPoolFunder{}, ctx,
Expand Down
16 changes: 8 additions & 8 deletions x/reward/keeper/msg_server_campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func TestCampaignMsgServerCreate(t *testing.T) {
"type": types.RewardType_REWARD_TYPE_SIGNUP,
"reward_defs": []types.Definition{
{
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
Amount: sdkmath.NewInt(100),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
Amount: sdkmath.NewInt(100),
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
},
},
"pool_amount": sdkmath.NewInt(1000000),
Expand Down Expand Up @@ -111,10 +111,10 @@ func TestCampaignMsgServerUpdate(t *testing.T) {
"type": types.RewardType_REWARD_TYPE_SIGNUP,
"reward_defs": []types.Definition{
{
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
Amount: sdkmath.NewInt(100),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
Amount: sdkmath.NewInt(100),
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
},
},
"pool_amount": sdkmath.NewInt(10000),
Expand Down
56 changes: 28 additions & 28 deletions x/reward/keeper/msg_server_reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func TestMsgApplySignupReward(t *testing.T) {
campClaims["type"] = types.RewardType_REWARD_TYPE_SIGNUP
campClaims["reward_defs"] = []types.Definition{
{
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
Amount: sdkmath.NewInt(100),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
Amount: sdkmath.NewInt(100),
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
},
}

Expand Down Expand Up @@ -150,10 +150,10 @@ func TestMsgApplyAffiliationReward(t *testing.T) {
campClaims["type"] = types.RewardType_REWARD_TYPE_AFFILIATION
campClaims["reward_defs"] = []types.Definition{
{
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
Amount: sdkmath.NewInt(100),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN,
UnlockTS: 0,
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN,
Amount: sdkmath.NewInt(100),
UnlockTS: 0,
},
}

Expand Down Expand Up @@ -245,16 +245,16 @@ func TestMsgApplyReferralReward(t *testing.T) {
campClaims["type"] = types.RewardType_REWARD_TYPE_REFERRAL
campClaims["reward_defs"] = []types.Definition{
{
RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE,
Amount: sdkmath.NewInt(100),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
Amount: sdkmath.NewInt(100),
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
},
{
RecType: types.ReceiverType_RECEIVER_TYPE_REFERRER,
Amount: sdkmath.NewInt(150),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
RecType: types.ReceiverType_RECEIVER_TYPE_REFERRER,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
Amount: sdkmath.NewInt(150),
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
},
}

Expand Down Expand Up @@ -341,10 +341,10 @@ func TestMsgApplyNoLossBetsReward(t *testing.T) {
campClaims["type"] = types.RewardType_REWARD_TYPE_NOLOSS_BETS
campClaims["reward_defs"] = []types.Definition{
{
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
Amount: sdkmath.NewInt(100),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN,
UnlockTS: 0,
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN,
Amount: sdkmath.NewInt(100),
UnlockTS: 0,
},
}

Expand Down Expand Up @@ -433,10 +433,10 @@ func TestMsgApplySignupRewardSubAcc(t *testing.T) {
campClaims["type"] = types.RewardType_REWARD_TYPE_SIGNUP
campClaims["reward_defs"] = []types.Definition{
{
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
Amount: sdkmath.NewInt(100),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
Amount: sdkmath.NewInt(100),
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
},
}

Expand Down Expand Up @@ -533,10 +533,10 @@ func TestMsgApplySubAccFunds(t *testing.T) {
campClaims["type"] = types.RewardType_REWARD_TYPE_SIGNUP
campClaims["reward_defs"] = []types.Definition{
{
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
Amount: sdkmath.NewInt(rewardAmount),
ReceiverAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
Amount: sdkmath.NewInt(rewardAmount),
UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()),
},
}

Expand Down
8 changes: 4 additions & 4 deletions x/reward/types/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func NewDistribution(accAddr string, allocation Allocation) Distribution {
// NewAllocation created allocation object.
func NewAllocation(amount sdkmath.Int, receiverAccType ReceiverAccType, unlockTS uint64) Allocation {
return Allocation{
Amount: amount,
ReceiverAccType: receiverAccType,
UnlockTS: unlockTS,
Amount: amount,
RecAccType: receiverAccType,
UnlockTS: unlockTS,
}
}

// ValidateBasic validates the basic properties of a reward definition.
func (d *Definition) ValidateBasic(blockTime uint64) error {
if d.ReceiverAccType != ReceiverAccType_RECEIVER_ACC_TYPE_SUB {
if d.RecAccType != ReceiverAccType_RECEIVER_ACC_TYPE_SUB {
if d.UnlockTS != 0 {
return sdkerrors.Wrapf(ErrUnlockTSIsSubAccOnly, "%d", d.UnlockTS)
}
Expand Down
Loading

0 comments on commit c618040

Please sign in to comment.