Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for duplicate name value when creating private plans #101

Closed
4 tasks done
jaybxyz opened this issue Sep 8, 2021 · 0 comments
Closed
4 tasks done

Add check for duplicate name value when creating private plans #101

jaybxyz opened this issue Sep 8, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@jaybxyz
Copy link
Contributor

jaybxyz commented Sep 8, 2021

Summary of Bug

There is no check for duplicate name value when creating private plans. This bug is found during simulation test.

Version

master branch

Steps to Reproduce

  1. Send MsgCreateFixedAmountPlan transaction to the network with the plan name simulation.
  2. Send MsgCreateRatioPlan transaction to the network with the same plan name simulation.
  3. Send PublicPlanProposal to the network with any plan name.
  4. You will encounter an error: duplicate plan name: invalid proposal content

Proposal

ValidateRatioPlans checks duplicate name value; however, we can't use the function for private plans since private plans have two different messages to handle and the function handles total epoch ratio and name checks. Therefore, I suggest to have the function broken down into two different functions; ValidateTotalEpochRatio and ValidateName.

plans := k.GetAllPlans(ctx)
if err := types.ValidateRatioPlans(plans); err != nil {
return err
}

func ValidateRatioPlans(i interface{}) error {
plans, ok := i.([]PlanI)
if !ok {
return sdkerrors.Wrapf(ErrInvalidPlanType, "invalid plan type %T", i)
}
totalEpochRatio := make(map[string]sdk.Dec)
names := make(map[string]bool)
for _, plan := range plans {
farmingPoolAddr := plan.GetFarmingPoolAddress().String()
if plan, ok := plan.(*RatioPlan); ok {
if err := plan.Validate(); err != nil {
return err
}
if epochRatio, ok := totalEpochRatio[farmingPoolAddr]; ok {
totalEpochRatio[farmingPoolAddr] = epochRatio.Add(plan.EpochRatio)
} else {
totalEpochRatio[farmingPoolAddr] = plan.EpochRatio
}
if _, ok := names[plan.Name]; ok {
return sdkerrors.Wrap(ErrDuplicatePlanName, plan.Name)
}
names[plan.Name] = true
}
}
for _, farmerRatio := range totalEpochRatio {
if farmerRatio.GT(sdk.NewDec(1)) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "total epoch ratio must be lower than 1")
}
}
return nil
}


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@jaybxyz jaybxyz self-assigned this Sep 8, 2021
@jaybxyz jaybxyz added the bug Something isn't working label Sep 8, 2021
@jaybxyz jaybxyz changed the title Add check for duplicate name value when creating public plans Add check for duplicate name value when creating private plans Sep 8, 2021
dongsam added a commit that referenced this issue Sep 14, 2021
* test: add sim_test

* test: add decoder and its unit tests

* test: add randomized genesis params

* test: add params and unit tests

* chore: adding operations

* test: add operations and tests

* fix: lint checks

* fix: nolint check for interBlockCacheOpt

* test: nolint unused code

* lint: last test

* chore: fix broken test and add todo for public plan proposal

* chore: fix param changes, randomize epoch days, add farming fee collector, add workflow

* fix: broken test

* docs: fix backticks location

* chore: add migration tests, sort imports, fix db to newDB, update Makefile

* chore: fix simulation logic, add minter permission to module account, work in progress to solve harvest issue

* feat: adding public plan proposals

* chore: adding simulation for public plan proposals work in progress

* fix: add check for duplicate name value when creating private plans #101

* test: fix broken tests

* chore: remove comments, refactor logic, fixing harvest

* build: update github workflow to split simulation jobs

* chore: add public plans, remove unused test codes and clean up logics
- add request public plan proposal
- update request public plan proposal
- delete request public plan proposal
- comment TODO to improve public plans logic

* chore: debugging export and import simulation

* fix: update simulation logics for f1 spec

* fix: fix test plan dates and expected codes, lint

* fix: lint and validation logic of simulation

* fix: revert test plan and add validation logic for unstake

* chore: remove unused test functions

* fix: apply suggested reviews

* chore: fix lint

Co-authored-by: dongsam <dongsamb@gmail.com>
@jaybxyz jaybxyz closed this as completed Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant