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

fix: duplicate value of the name field in plan #150

Merged
merged 6 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/How-To/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This is one of the private plan type messages that anyone can create. A fixed am

Create a file name `private-fixed-plan.json`. This private fixed amount farming plan intends to provide 100ATOM per epoch (measured in day) relative to the rate amount of denoms defined in staking coin weights.

- `name`: is the name of the farming plan. It can be any name you prefer to be stored in a blockchain network; however it cannot overlap with the existing plan names.
- `name`: is the name of the farming plan. It can be any name you prefer to be stored in a blockchain network. It allows duplicate value.
- `staking_coin_weights`: is the distributing amount for each epoch. An amount should be decimal, not an integer. The sum of total weight must be 1.000000000000000000
- `start_time`: is start time of the farming plan
- `end_time`: is end time of the farming plan
Expand Down Expand Up @@ -145,7 +145,7 @@ This is one of the private plan type messages that anyone can create. A ratio pl

Create a file name `private-fixed-plan.json`. This private ratio farming plan intends to provide ratio of all coins that farming pool address has per epoch (measured in day). In this example, epoch ratio is 10 percent and 10 percent of all the coins that the creator of this plan has in balances are used as incentives for the denoms defined in the staking coin weights.

- `name`: is the name of the farming plan. It can be any name you prefer to be stored in a blockchain network; however it cannot overlap with the existing plan names.
- `name`: is the name of the farming plan. It can be any name you prefer to be stored in a blockchain network. It allows duplicate value.
- `staking_coin_weights`: is the distributing amount for each epoch. An amount should be decimal, not an integer. The sum of total weight must be 1.000000000000000000
- `start_time`: is start time of the farming plan
- `end_time`: is end time of the farming plan
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorials/demo/budget_with_farming.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ In this demo, we plan to create a public farming ratio plan that plans to distri

Explanation about each field in the JSON file

- `name`: is the name of the farming plan used for display
- `name`: is the name of the farming plan used for display. It allows duplicate value.
- `farming_pool_address`: is the faucet address for the plan
- `termination_address`: is the address that the remaining coins are transferred to when the plan ends
- `staking_coin_weights`: are the coin weights for the plan. The weights must add up to 1
Expand Down
2 changes: 1 addition & 1 deletion proto/tendermint/farming/v1beta1/farming.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ message BasePlan {
// id specifies index of the farming plan
uint64 id = 1;

// name specifies the name for the base plan
// name specifies the name for the plan
string name = 2;

// type specifies the plan type; type 0 is public and 1 is private
Expand Down
4 changes: 2 additions & 2 deletions proto/tendermint/farming/v1beta1/proposal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ message PublicPlanProposal {

// AddRequestProposal details a proposal for creating a public plan.
message AddRequestProposal {
// name specifies the plan name that describes what plan is for
// name specifies the plan name for diplay
string name = 1;

// farming_pool_address defines the bech32-encoded address of the farming pool
Expand Down Expand Up @@ -84,7 +84,7 @@ message UpdateRequestProposal {
// plan_id specifies index of the farming plan
uint64 plan_id = 1;

// name specifies the plan name that describes what plan is for
// name specifies the plan name for diplay
string name = 2;

// farming_pool_address defines the bech32-encoded address of the farming pool
Expand Down
9 changes: 0 additions & 9 deletions x/farming/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ func (k msgServer) CreateFixedAmountPlan(goCtx context.Context, msg *types.MsgCr
return nil, err
}

plans := k.GetPlans(ctx)
if err := types.ValidatePlanNames(plans); err != nil {
return nil, err
}

return &types.MsgCreateFixedAmountPlanResponse{}, nil
}

Expand All @@ -59,10 +54,6 @@ func (k msgServer) CreateRatioPlan(goCtx context.Context, msg *types.MsgCreateRa
}

plans := k.GetPlans(ctx)
if err := types.ValidatePlanNames(plans); err != nil {
return nil, err
}

if err := types.ValidateTotalEpochRatio(plans); err != nil {
return nil, err
}
Expand Down
4 changes: 0 additions & 4 deletions x/farming/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP
}

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

if err := types.ValidateTotalEpochRatio(plans); err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions x/farming/spec/02_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ A base plan is the simplest and most common plan type, which just stores all req
// type for additional functionality (e.g. fixed amount plan, ratio plan).
type BasePlan struct {
Id uint64 // index of the plan
Name string // name specifies the name for the plan
Type PlanType // type of the plan; public or private
FarmingPoolAddress string // bech32-encoded farming pool address
TerminationAddress string // bech32-encoded termination address
Expand Down Expand Up @@ -186,6 +187,7 @@ An example of `FixedAmountPlan`
{
"base_plan": {
"id": 0,
"name": "testPlan",
"type": 0,
"farmingPoolAddress": "cosmos1...",
"rewardPoolAddress": "cosmos1...",
Expand Down Expand Up @@ -220,6 +222,7 @@ An example of `RatioPlan`
{
"base_plan": {
"id": 0,
"name": "testPlan",
"type": 0,
"farmingPoolAddress": "cosmos1...",
"rewardPoolAddress": "cosmos1...",
Expand Down
4 changes: 3 additions & 1 deletion x/farming/spec/08_proposal.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Note that when requesting `AddRequestProposal` depending on which field is passe
```go
// AddRequestProposal details a proposal for creating a public plan.
type AddRequestProposal struct {
// name specifies the plan name that describes what plan is for
// name specifies the name of the plan
Name string
// farming_pool_address defines the bech32-encoded address of the farming pool
FarmingPoolAddress string
Expand Down Expand Up @@ -59,6 +59,8 @@ type AddRequestProposal struct {
type UpdateRequestProposal struct {
// plan_id specifies index of the farming plan
PlanId uint64
// name specifies the name of the plan
Name string
// farming_pool_address defines the bech32-encoded address of the farming pool
FarmingPoolAddress string
// termination_address defines the bech32-encoded address that terminates plan
Expand Down
2 changes: 1 addition & 1 deletion x/farming/types/farming.pb.go

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

4 changes: 0 additions & 4 deletions x/farming/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ func ValidateGenesis(data GenesisState) error {
id = plan.GetId() + 1
}

if err := ValidatePlanNames(plans); err != nil {
return err
}

if err := ValidateTotalEpochRatio(plans); err != nil {
return err
}
Expand Down
48 changes: 0 additions & 48 deletions x/farming/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,54 +166,6 @@ func TestValidateGenesis(t *testing.T) {
},
"pool records must be sorted",
},
{
"duplicate plan name",
func(genState *types.GenesisState) {
planA := types.NewRatioPlan(
types.NewBasePlan(
1,
"planA",
types.PlanTypePublic,
validAcc.String(),
validAcc.String(),
sdk.NewDecCoins(
sdk.NewInt64DecCoin(validStakingCoinDenom, 1),
),
types.ParseTime("0001-01-01T00:00:00Z"),
types.ParseTime("9999-12-31T00:00:00Z"),
),
sdk.NewDecWithPrec(5, 2),
)
planB := types.NewFixedAmountPlan(
types.NewBasePlan(
2,
"planA",
types.PlanTypePublic,
validAcc.String(),
validAcc.String(),
sdk.NewDecCoins(
sdk.NewInt64DecCoin(validStakingCoinDenom, 1),
),
types.ParseTime("0001-01-01T00:00:00Z"),
types.ParseTime("9999-12-31T00:00:00Z"),
),
sdk.NewCoins(sdk.NewInt64Coin("denom3", 1000000)),
)
planAAny, _ := types.PackPlan(planA)
planBAny, _ := types.PackPlan(planB)
genState.PlanRecords = []types.PlanRecord{
{
Plan: *planAAny,
FarmingPoolCoins: sdk.NewCoins(),
},
{
Plan: *planBAny,
FarmingPoolCoins: sdk.NewCoins(),
},
}
},
"planA: duplicate plan name",
},
{
"invalid plan records - invalid sum of epoch ratio",
func(genState *types.GenesisState) {
Expand Down
19 changes: 0 additions & 19 deletions x/farming/types/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,6 @@ type PlanI interface {
Validate() error
}

// ValidatePlanNames validates duplicate plan name value.
func ValidatePlanNames(i interface{}) error {
plans, ok := i.([]PlanI)
if !ok {
return sdkerrors.Wrapf(ErrInvalidPlanType, "invalid plan type %T", i)
}

names := map[string]struct{}{}

for _, plan := range plans {
if _, ok := names[plan.GetName()]; ok {
return sdkerrors.Wrap(ErrDuplicatePlanName, plan.GetName())
}
names[plan.GetName()] = struct{}{}
}

return nil
}

// ValidateTotalEpochRatio validates a farmer's total epoch ratio that must be equal to 1.
func ValidateTotalEpochRatio(i interface{}) error {
plans, ok := i.([]PlanI)
Expand Down
49 changes: 0 additions & 49 deletions x/farming/types/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,6 @@ import (
"github.com/tendermint/farming/x/farming/types"
)

func TestPlanName(t *testing.T) {
name := "testPlan1"
farmingPoolAddr1 := sdk.AccAddress("farmingPoolAddr1")
terminationAddr1 := sdk.AccAddress("terminationAddr1")
stakingCoinWeights := sdk.NewDecCoins(
sdk.DecCoin{Denom: "testFarmStakingCoinDenom", Amount: sdk.MustNewDecFromStr("1.0")},
)
startTime := time.Now().UTC()
endTime := startTime.AddDate(1, 0, 0)

testCases := []struct {
plans []types.PlanI
expectedErr error
}{
{
[]types.PlanI{
types.NewRatioPlan(
types.NewBasePlan(1, name, 1, farmingPoolAddr1.String(), terminationAddr1.String(), stakingCoinWeights, startTime, endTime),
sdk.NewDec(1),
),
},
nil,
},
{
[]types.PlanI{
types.NewRatioPlan(
types.NewBasePlan(1, name, 1, farmingPoolAddr1.String(), terminationAddr1.String(), stakingCoinWeights, startTime, endTime),
sdk.NewDec(1),
),
types.NewRatioPlan(
types.NewBasePlan(1, name, 1, farmingPoolAddr1.String(), terminationAddr1.String(), stakingCoinWeights, startTime, endTime),
sdk.NewDec(1),
),
},
sdkerrors.Wrap(types.ErrDuplicatePlanName, name),
},
}

for _, tc := range testCases {
err := types.ValidatePlanNames(tc.plans)
if tc.expectedErr == nil {
require.NoError(t, err)
} else {
require.Error(t, err)
require.Equal(t, tc.expectedErr.Error(), err.Error())
}
}
}

func TestTotalEpochRatio(t *testing.T) {
name1 := "testPlan1"
name2 := "testPlan2"
Expand Down
4 changes: 2 additions & 2 deletions x/farming/types/proposal.pb.go

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