Skip to content

Commit

Permalink
feat: fix update public plan proposal & disable codecov patch (#133)
Browse files Browse the repository at this point in the history
* feat: work in progress

* feat: add logic to change plan type if there is a update request proposal

* test: add more cases

* chore: improve code coverage and update nil check to IsAllPositive

* test: remove nolint comments

* test: disable codecov patch

* test: add codecov.yml and revert the prev commit

* test: update codecov.yml

* chore: apply feedback
  • Loading branch information
jaybxyz authored Sep 27, 2021
1 parent 9c24552 commit 97b297b
Show file tree
Hide file tree
Showing 5 changed files with 444 additions and 358 deletions.
23 changes: 23 additions & 0 deletions .github/.codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# To validate:
# cat codecov.yml | curl --data-binary @- https://codecov.io/validate

codecov:
notify:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "50...80"

status:
project:
default:
target: auto
threshold: 1%
patch:
default:
enabled: no # disable patch since it is noisy and not correct
if_not_found: success

comment: false
43 changes: 22 additions & 21 deletions x/farming/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP
if err := types.ValidateName(plans); err != nil {
return err
}

if err := types.ValidateTotalEpochRatio(plans); err != nil {
return err
}
Expand All @@ -45,12 +46,13 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq
if err != nil {
return err
}

terminationAcc, err := sdk.AccAddressFromBech32(p.GetTerminationAddress())
if err != nil {
return err
}

if !p.EpochAmount.IsZero() && !p.EpochAmount.IsAnyNegative() {
if p.EpochAmount.IsAllPositive() {
msg := types.NewMsgCreateFixedAmountPlan(
p.GetName(),
farmingPoolAddrAcc,
Expand All @@ -68,7 +70,7 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq
logger := k.Logger(ctx)
logger.Info("created public fixed amount plan", "fixed_amount_plan", plan)

} else if !p.EpochRatio.IsZero() && !p.EpochRatio.IsNegative() && !p.EpochRatio.IsNil() {
} else if p.EpochRatio.IsPositive() {
msg := types.NewMsgCreateRatioPlan(
p.GetName(),
farmingPoolAddrAcc,
Expand Down Expand Up @@ -103,8 +105,13 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", p.GetPlanId())
}

switch plan := plan.(type) {
case *types.FixedAmountPlan:
if p.EpochAmount.IsAllPositive() {
if p.GetName() != "" {
if err := plan.SetName(p.GetName()); err != nil {
return err
}
}

if p.GetFarmingPoolAddress() != "" {
farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress())
if err != nil {
Expand Down Expand Up @@ -143,22 +150,21 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd
}
}

if p.GetName() != "" {
plan.Name = p.GetName()
}

if p.GetEpochAmount() != nil {
plan.EpochAmount = p.GetEpochAmount()
// change the plan to fixed amount plan if an epoch amount exists
if p.GetEpochAmount().IsAllPositive() {
plan = types.NewFixedAmountPlan(plan.GetBasePlan(), p.GetEpochAmount())
}

k.SetPlan(ctx, plan)

logger := k.Logger(ctx)
logger.Info("updated public fixed amount plan", "fixed_amount_plan", plan)

case *types.RatioPlan:
if err := plan.Validate(); err != nil {
return err
} else if p.EpochRatio.IsPositive() {
if p.GetName() != "" {
if err := plan.SetName(p.GetName()); err != nil {
return err
}
}

if p.GetFarmingPoolAddress() != "" {
Expand Down Expand Up @@ -199,21 +205,16 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd
}
}

if p.GetName() != "" {
plan.Name = p.GetName()
}

if !p.EpochRatio.IsZero() {
plan.EpochRatio = p.EpochRatio
// change the plan to ratio plan if an epoch ratio exists
if p.EpochRatio.IsPositive() {
plan = types.NewRatioPlan(plan.GetBasePlan(), p.EpochRatio)
}

k.SetPlan(ctx, plan)

logger := k.Logger(ctx)
logger.Info("updated public ratio plan", "ratio_plan", plan)

default:
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized plan type: %T", p)
}
}

Expand Down
Loading

0 comments on commit 97b297b

Please sign in to comment.