Skip to content

Commit

Permalink
CNS-334: Remove duration parameter from Plans
Browse files Browse the repository at this point in the history
Plans are always for 1 month.
The `tx subscription buy` message indicates duration (in months).
  • Loading branch information
orenl-lava committed Mar 9, 2023
1 parent 65042a3 commit e641114
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 142 deletions.
25 changes: 12 additions & 13 deletions proto/plans/plan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import "cosmos/base/v1beta1/coin.proto";

message Plan {
string index = 1;
uint64 duration = 2; // duration of the plan's subscription in months
uint64 block = 3; // the epoch that this plan was created
cosmos.base.v1beta1.Coin price = 4 [(gogoproto.nullable) = false]; // plan price (in ulava)
uint64 compute_units = 5; // max CU for the whole plan duration
uint64 compute_units_per_epoch = 6; // max CU per epoch for the whole plan duration
uint64 servicers_to_pair = 7; // max providers to be paired in an epoch
bool allow_overuse = 8; // allow CU overuse flag
uint64 overuse_rate = 9; // price of CU overuse
string name = 10; // plan name (non-unique "human" name)
string description = 11; // plan description (for humans)
string type = 12; // plan type
uint64 annual_discount_percentage = 13; // discount for buying the plan for a year
}
uint64 block = 2; // the epoch that this plan was created
cosmos.base.v1beta1.Coin price = 3 [(gogoproto.nullable) = false]; // plan price (in ulava)
uint64 compute_units = 4; // max CU for the whole plan duration
uint64 compute_units_per_epoch = 5; // max CU per epoch for the whole plan duration
uint64 servicers_to_pair = 6; // max providers to be paired in an epoch
bool allow_overuse = 7; // allow CU overuse flag
uint64 overuse_rate = 8; // price of CU overuse
string name = 9; // plan name (non-unique "human" name)
string description = 10; // plan description (for humans)
string type = 11; // plan type
uint64 annual_discount_percentage = 12; // discount for buying the plan for a year
}
1 change: 0 additions & 1 deletion testutil/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func CreateMockPlan() plantypes.Plan {
Name: "mock plan",
Description: "plan for testing",
Type: "rpc",
Duration: 200,
Block: 100,
Price: sdk.NewCoin("ulava", sdk.NewInt(100)),
ComputeUnits: 1000,
Expand Down
33 changes: 14 additions & 19 deletions x/plans/keeper/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func CreateTestPlans(planAmount uint64, withSameIndex bool, startIndex uint64) [
Name: "test plan",
Description: "plan to test",
Type: "rpc",
Duration: 200,
Block: 100,
Price: sdk.NewCoin("ulava", sdk.OneInt()),
ComputeUnits: 1000,
Expand Down Expand Up @@ -154,14 +153,13 @@ func TestUpdatePlanInSameEpoch(t *testing.T) {
}

const (
DURATION_FIELD = 1
PRICE_FIELD = 2
OVERUSE_FIELDS = 3
CU_FIELD = 4
SERVICERS_FIELD = 5
NAME_FIELD = 6
DESCRIPTION_FIELD = 7
TYPE_FIELD = 8
PRICE_FIELD = iota+1
OVERUSE_FIELDS
CU_FIELD
SERVICERS_FIELD
NAME_FIELD
DESCRIPTION_FIELD
TYPE_FIELD
)

// Test that the plan verification before adding it to the plan storage is working correctly
Expand All @@ -178,14 +176,13 @@ func TestInvalidPlanAddition(t *testing.T) {
name string
fieldIndex int
}{
{"InvalidDurationTest", 1},
{"InvalidPriceTest", 2},
{"InvalidOveruseTest", 3},
{"InvalidCuTest", 4},
{"InvalidServicersToPairTest", 5},
{"InvalidNameTest", 6},
{"InvalidDescriptionTest", 7},
{"InvalidTypeTest", 8},
{"InvalidPriceTest", 1},
{"InvalidOveruseTest", 2},
{"InvalidCuTest", 3},
{"InvalidServicersToPairTest", 4},
{"InvalidNameTest", 5},
{"InvalidDescriptionTest", 6},
{"InvalidTypeTest", 7},
}

for _, tt := range tests {
Expand All @@ -195,8 +192,6 @@ func TestInvalidPlanAddition(t *testing.T) {

// each test, change one field to an invalid value
switch tt.fieldIndex {
case DURATION_FIELD:
planToTest[0].Duration = 0
case PRICE_FIELD:
planToTest[0].Price = sdk.NewCoin(epochstoragetypes.TokenDenom, sdk.ZeroInt())
case OVERUSE_FIELDS:
Expand Down
1 change: 0 additions & 1 deletion x/plans/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
// x/plan module sentinel errors
var (
ErrEmptyPlans = sdkerrors.Register(ModuleName, 1, "plans list is empty")
ErrInvalidPlanDuration = sdkerrors.Register(ModuleName, 2, "plan's duration field is invalid")
ErrInvalidPlanPrice = sdkerrors.Register(ModuleName, 3, "plan's price field is invalid")
ErrInvalidPlanOveruse = sdkerrors.Register(ModuleName, 4, "plan's CU overuse fields are invalid")
ErrInvalidPlanServicersToPair = sdkerrors.Register(ModuleName, 5, "plan's servicersToPair field is invalid")
Expand Down
5 changes: 0 additions & 5 deletions x/plans/types/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (

// Function to validate a plan object fields
func (p Plan) ValidatePlan() error {
// check that the plan's duration is non-zero
if p.GetDuration() == 0 {
return sdkerrors.Wrap(ErrInvalidPlanDuration, "plan's duration can't be zero")
}

// check that the plan's price is non-zero
if p.GetPrice().IsEqual(sdk.NewCoin(epochstoragetypes.TokenDenom, sdk.ZeroInt())) {
return sdkerrors.Wrap(ErrInvalidPlanPrice, "plan's price can't be zero")
Expand Down
Loading

0 comments on commit e641114

Please sign in to comment.