Skip to content

Commit

Permalink
CNS-817: limit = 0 -> infinite
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Jan 18, 2024
1 parent d8cbc30 commit dd2aede
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
19 changes: 10 additions & 9 deletions x/plans/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ A plan consists of limitations that are associated with a subscription. A consum

```go
type Plan struct {
index string // plan unique index
block uint64 // the epoch that this plan was created
price Coin // plan price (in ulava)
allow_overuse bool // allow CU overuse flag
overuse_rate uint64 // price of CU overuse (higher price per CU)
description string // plan description (for humans)
type string // plan type (currently unused)
annual_discount uint64 // discount for buying a yearly plan (percentage)
plan_policy Policy // plan's policy
Index string // plan unique index
Block uint64 // the epoch that this plan was created
Price Coin // plan price (in ulava)
AllowOveruse bool // allow CU overuse flag
OveruseRate uint64 // price of CU overuse (higher price per CU)
Description string // plan description (for humans)
Type string // plan type (currently unused)
AnnualDiscountPercentage uint64 // discount for buying a yearly plan (percentage)
PlanPolicy Policy // plan's policy
ProjectsLimit uint64 // number of allowed projects
}
```
Note, the `Coin` type is from Cosmos-SDK (`cosmos.base.v1beta1.Coin`).
Expand Down
4 changes: 0 additions & 4 deletions x/plans/types/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ func (p Plan) ValidatePlan() error {
return sdkerrors.Wrap(ErrInvalidPlanAnnualDiscount, "plan's annual discount is invalid (not between 0-100 percent)")
}

if p.GetProjectsLimit() == 0 {
return sdkerrors.Wrap(ErrInvalidPlanProjects, "plan's projects field must be a non-zero positive integer")
}

err := p.PlanPolicy.ValidateBasicPolicy(true)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions x/plans/types/plan_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestDecodeJsonPlan(t *testing.T) {
"annual_discount_percentage": 20,
"allow_overuse": true,
"overuse_rate": 2,
"projects": 10,
"projects_limit": 10,
"plan_policy": {
"chain_policies": [
{
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestDecodePlanAddProposal(t *testing.T) {
"annual_discount_percentage": 20,
"allow_overuse": true,
"overuse_rate": 2,
"projects": 10,
"projects_limit": 10,
"plan_policy": {
"chain_policies": [
{
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestDecodePlanAddProposal(t *testing.T) {
"annual_discount_percentage": 20,
"allow_overuse": true,
"overuse_rate": 2,
"projects": 5,
"projects_limit": 5,
"plan_policy": {
"chain_policies": [
{
Expand Down
2 changes: 1 addition & 1 deletion x/projects/keeper/creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (k Keeper) CreateAdminProject(ctx sdk.Context, subAddr string, plan plantyp
// (takes effect retroactively at the beginning of this epoch)
func (k Keeper) CreateProject(ctx sdk.Context, subAddr string, projectData types.ProjectData, plan plantypes.Plan) error {
projects := k.GetAllProjectsForSubscription(ctx, subAddr)
if len(projects) >= int(plan.ProjectsLimit) {
if len(projects) >= int(plan.ProjectsLimit) && plan.ProjectsLimit != 0 {
return utils.LavaFormatWarning("CreateProject failed", fmt.Errorf("subscription already has max number of projects"),
utils.LogAttr("plan", plan.Index),
utils.LogAttr("plan_projects_limit", plan.ProjectsLimit),
Expand Down

0 comments on commit dd2aede

Please sign in to comment.