Skip to content

Commit

Permalink
CNS-815: fixed all plan related code + fix plan proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Jan 15, 2024
1 parent 3e41081 commit 88bbddd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions testutil/common/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func CreateMockPlan() plantypes.Plan {
OveruseRate: 10,
AnnualDiscountPercentage: 20,
PlanPolicy: CreateMockPolicy(),
Projects: 10,
}

return plan
Expand Down
5 changes: 5 additions & 0 deletions x/pairing/keeper/pairing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,20 +982,23 @@ func TestGeolocationPairingScores(t *testing.T) {
Index: "free",
Block: ts.BlockHeight(),
Price: sdk.NewCoin(ts.TokenDenom(), sdk.NewInt(1)),
Projects: 3,
PlanPolicy: freePlanPolicy,
}

basicPlan := planstypes.Plan{
Index: "basic",
Block: ts.BlockHeight(),
Price: sdk.NewCoin(ts.TokenDenom(), sdk.NewInt(1)),
Projects: 5,
PlanPolicy: basicPlanPolicy,
}

premiumPlan := planstypes.Plan{
Index: "premium",
Block: ts.BlockHeight(),
Price: sdk.NewCoin(ts.TokenDenom(), sdk.NewInt(1)),
Projects: 7,
PlanPolicy: premiumPlanPolicy,
}

Expand Down Expand Up @@ -1196,6 +1199,7 @@ func TestDuplicateProviders(t *testing.T) {
Index: "basic",
Block: ts.BlockHeight(),
Price: sdk.NewCoin(ts.TokenDenom(), sdk.NewInt(1)),
Projects: 5,
PlanPolicy: basicPlanPolicy,
}

Expand Down Expand Up @@ -1247,6 +1251,7 @@ func TestNoRequiredGeo(t *testing.T) {
Index: "free",
Block: ts.BlockHeight(),
Price: sdk.NewCoin(ts.TokenDenom(), sdk.NewInt(1)),
Projects: 3,
PlanPolicy: freePlanPolicy,
}

Expand Down
1 change: 1 addition & 0 deletions x/plans/keeper/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (ts *tester) createTestPlans(count int, withSameIndex bool, startIndex int)
AllowOveruse: true,
OveruseRate: overuseRate,
AnnualDiscountPercentage: 20,
Projects: 10,
}

plans = append(plans, plan)
Expand Down
1 change: 1 addition & 0 deletions x/plans/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ var (
ErrPolicyInvalidSelectedProvidersConfig = sdkerrors.Register(ModuleName, 15, "plan's selected providers config is invalid")
ErrPolicyGeolocation = sdkerrors.Register(ModuleName, 16, "plan's geolocation is invalid")
ErrInvalidDenom = sdkerrors.Register(ModuleName, 17, commontypes.ErrInvalidDenomMsg)
ErrInvalidPlanProjects = sdkerrors.Register(ModuleName, 18, "plan's projects field is invalid")
)
4 changes: 4 additions & 0 deletions x/plans/types/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (p Plan) ValidatePlan() error {
return sdkerrors.Wrap(ErrInvalidPlanAnnualDiscount, "plan's annual discount is invalid (not between 0-100 percent)")
}

if p.GetProjects() == 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: 6 additions & 0 deletions x/plans/types/plan_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestDecodeJsonPlan(t *testing.T) {
AnnualDiscountPercentage: 20,
AllowOveruse: true,
OveruseRate: 2,
Projects: 10,
PlanPolicy: Policy{
ChainPolicies: []ChainPolicy{
{ChainId: "LAV1", Apis: []string{}},
Expand All @@ -84,6 +85,7 @@ func TestDecodeJsonPlan(t *testing.T) {
"annual_discount_percentage": 20,
"allow_overuse": true,
"overuse_rate": 2,
"projects": 10,
"plan_policy": {
"chain_policies": [
{
Expand Down Expand Up @@ -135,6 +137,7 @@ func TestDecodePlanAddProposal(t *testing.T) {
AnnualDiscountPercentage: 20,
AllowOveruse: true,
OveruseRate: 2,
Projects: 10,
PlanPolicy: Policy{
ChainPolicies: []ChainPolicy{
{ChainId: "LAV1", Apis: []string{}},
Expand All @@ -156,6 +159,7 @@ func TestDecodePlanAddProposal(t *testing.T) {
AnnualDiscountPercentage: 20,
AllowOveruse: true,
OveruseRate: 2,
Projects: 5,
PlanPolicy: Policy{
ChainPolicies: []ChainPolicy{
{ChainId: "LAV1", Apis: []string{}},
Expand Down Expand Up @@ -191,6 +195,7 @@ func TestDecodePlanAddProposal(t *testing.T) {
"annual_discount_percentage": 20,
"allow_overuse": true,
"overuse_rate": 2,
"projects": 10,
"plan_policy": {
"chain_policies": [
{
Expand Down Expand Up @@ -229,6 +234,7 @@ func TestDecodePlanAddProposal(t *testing.T) {
"annual_discount_percentage": 20,
"allow_overuse": true,
"overuse_rate": 2,
"projects": 5,
"plan_policy": {
"chain_policies": [
{
Expand Down
21 changes: 12 additions & 9 deletions x/projects/keeper/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,10 @@ func TestSetPolicyByGeolocation(t *testing.T) {

// propose all plans
freePlan := planstypes.Plan{
Index: "free",
Block: uint64(ctx.BlockHeight()),
Price: sdk.NewCoin(keepers.StakingKeeper.BondDenom(ctx), sdk.NewInt(1)),
Index: "free",
Block: uint64(ctx.BlockHeight()),
Price: sdk.NewCoin(keepers.StakingKeeper.BondDenom(ctx), sdk.NewInt(1)),
Projects: 3,
PlanPolicy: planstypes.Policy{
GeolocationProfile: 4, // USE
TotalCuLimit: 10,
Expand All @@ -1108,9 +1109,10 @@ func TestSetPolicyByGeolocation(t *testing.T) {
}

basicPlan := planstypes.Plan{
Index: "basic",
Block: uint64(ctx.BlockHeight()),
Price: sdk.NewCoin(keepers.StakingKeeper.BondDenom(ctx), sdk.NewInt(1)),
Index: "basic",
Block: uint64(ctx.BlockHeight()),
Price: sdk.NewCoin(keepers.StakingKeeper.BondDenom(ctx), sdk.NewInt(1)),
Projects: 5,
PlanPolicy: planstypes.Policy{
GeolocationProfile: 0, // GLS
TotalCuLimit: 10,
Expand All @@ -1120,9 +1122,10 @@ func TestSetPolicyByGeolocation(t *testing.T) {
}

premiumPlan := planstypes.Plan{
Index: "premium",
Block: uint64(ctx.BlockHeight()),
Price: sdk.NewCoin(keepers.StakingKeeper.BondDenom(ctx), sdk.NewInt(1)),
Index: "premium",
Block: uint64(ctx.BlockHeight()),
Price: sdk.NewCoin(keepers.StakingKeeper.BondDenom(ctx), sdk.NewInt(1)),
Projects: 10,
PlanPolicy: planstypes.Policy{
GeolocationProfile: 65535, // GL
TotalCuLimit: 10,
Expand Down

0 comments on commit 88bbddd

Please sign in to comment.