Skip to content

Commit

Permalink
Merge pull request #547 from anandrgitnirman/addon
Browse files Browse the repository at this point in the history
#546 - Add on for License
  • Loading branch information
anandrgitnirman authored Sep 3, 2021
2 parents 74a2abf + 3ebbac3 commit 7949bdd
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 76 deletions.
14 changes: 10 additions & 4 deletions blockchain/serviceMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"group_id": "EoFmN3nvaXpf6ew8jJbIPVghE5NXfYupFF7PkRmVyGQ=",
{
"licenses": {
"tiers": [{
"type": "Tier",
"planName": "Tier AAA",
Expand Down Expand Up @@ -159,15 +160,19 @@ type ServiceMetadata struct {
type Tiers struct {
Tiers Tier `json:"tier"`
}

type AddOns struct {
DiscountInPercentage float64 `json:"discountInPercentage"`
AddOnCostInAGIX int `json:"addOnCostInAGIX"`
Name string `json:"name"`
}
type TierRange struct {
High int `json:"high"`
DiscountInPercentage int `json:"DiscountInPercentage"`
High int `json:"high"`
DiscountInPercentage float64 `json:"DiscountInPercentage"`
}

type Subscription struct {
PeriodInDays int `json:"periodInDays"`
DiscountInPercentage int `json:"discountInPercentage"`
DiscountInPercentage float64 `json:"discountInPercentage"`
PlanName string `json:"planName"`
LicenseCost big.Int `json:"licenseCost"`
GrpcServiceName string `json:"grpcServiceName,omitempty"`
Expand Down Expand Up @@ -202,6 +207,7 @@ type OrganizationGroup struct {
FreeCalls int `json:"free_calls"`
FreeCallSigner string `json:"free_call_signer_address"`
Licenses Licenses `json:"licenses,omitempty"`
AddOns []AddOns `json:"addOns,omitempty"`
}
type Pricing struct {
PriceModel string `json:"price_model"`
Expand Down
13 changes: 10 additions & 3 deletions blockchain/serviceMetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
)

var testLicenseJsonData = "\n \"licenses\": { \"tiers\": [{\n \"type\": \"Tier\",\n \"planName\": \"Tier AAA\",\n \"grpcServiceName\": \"ServiceA\",\n \"grpcMethodName\": \"MethodA\",\n \"range\": [\n {\n \"high\": 100,\n \"DiscountInPercentage\": 1\n },\n {\n \"high\": 200,\n \"discountInPercentage\": 20\n },\n {\n \"high\": 300,\n \"discountInPercentage\": 100000\n }\n ],\n \"detailsUrl\": \"http://abc.org/licenses/Tier.html\",\n \"isActive\": \"true/false\"\n},\n {\n \"type\": \"Tier\",\n \"planName\": \"Tier BBB Applicable for All service.methods\",\n \"range\": [\n {\n \"high\": 100,\n \"discountInPercentage\": 1\n },\n {\n \"high\": 200,\n \"discountInPercentage\": 200\n },\n {\n \"high\": 300,\n \"DiscountInPercentage\": 100000\n }\n ],\n \"detailsUrl\": \"http://abc.org/licenses/Tier.html\",\n \"isActive\": \"true/false\"\n}], " +
var testLicenseJsonData = "\n \"licenses\": { \"tiers\": [{\n \"type\": \"Tier\",\n \"planName\": \"Tier AAA\",\n \"grpcServiceName\": \"ServiceA\",\n \"grpcMethodName\": \"MethodA\",\n \"range\": [\n {\n \"high\": 100,\n \"discountInPercentage\": 1\n },\n {\n \"high\": 200,\n \"discountInPercentage\": 20\n },\n {\n \"high\": 300,\n \"discountInPercentage\": 100000\n }\n ],\n \"detailsUrl\": \"http://abc.org/licenses/Tier.html\",\n \"isActive\": \"true/false\"\n},\n {\n \"type\": \"Tier\",\n \"planName\": \"Tier BBB Applicable for All service.methods\",\n \"range\": [\n {\n \"high\": 100,\n \"discountInPercentage\": 1\n },\n {\n \"high\": 200,\n \"discountInPercentage\": 200\n },\n {\n \"high\": 300,\n \"discountInPercentage\": 100000\n }\n ],\n \"detailsUrl\": \"http://abc.org/licenses/Tier.html\",\n \"isActive\": \"true/false\"\n}], " +
"\"subscriptions\": {\n \"subscription\": [\n {\n \"periodInDays\": 30,\n \"discountInPercentage\": 120,\n \"planName\": \"Monthly For ServiceA/MethodA\",\n \"LicenseCost\": 90,\n \"grpcServiceName\": \"ServiceA\",\n \"grpcMethodName\": \"MethodA\"\n },\n {\n \"periodInDays\": 30,\n \"discountInPercentage\": 123,\n \"planName\": \"Monthly\",\n \"LicenseCost\": 93\n },\n {\n \"periodInDays\": 120,\n \"discountInPercentage\": 160,\n \"LicenseCost\": 120,\n \"planName\": \"Quarterly\"\n },\n {\n \"periodInDays\": 365,\n \"discountInPercentage\": 430,\n \"LicenseCost\": 390,\n \"planName\": \"Yearly\"\n }\n], \"type\": \"Subscription\",\n \"detailsUrl\": \"http://abc.org/licenses/Subscription.html\",\n \"isActive\": \"true/false\"\n }\n }"
var testJsonData = "{ \"version\": 1, \"display_name\": \"Example1\", \"encoding\": \"grpc\", \"service_type\": \"grpc\", \"payment_expiration_threshold\": 40320, \"model_ipfs_hash\": \"Qmdiq8Hu6dYiwp712GtnbBxagyfYyvUY1HYqkH7iN76UCc\", " +
" \"mpe_address\": \"0x7E6366Fbe3bdfCE3C906667911FC5237Cc96BD08\", \"groups\": [ { \"free_calls\": 12, \"free_call_signer_address\": \"0x7DF35C98f41F3Af0df1dc4c7F7D4C19a71Dd059F\", \"endpoints\": [\"http://34.344.33.1:2379\",\"http://34.344.33.1:2389\"], \"group_id\": \"88ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\",\"group_name\": \"default_group\", " + testLicenseJsonData + " , \"pricing\": [ { \"price_model\": \"fixed_price\", \"price_in_cogs\": 2 }, { \"package_name\": \"example_service\", \"price_model\": \"fixed_price_per_method\", \"default\":true, \"details\": [ { \"service_name\": \"Calculator\", \"method_pricing\": [ { \"method_name\": \"add\", \"price_in_cogs\": 2 }, { \"method_name\": \"sub\", \"price_in_cogs\": 1 }, { \"method_name\": \"div\", \"price_in_cogs\": 2 }, { \"method_name\": \"mul\", \"price_in_cogs\": 3 } ] }, { \"service_name\": \"Calculator2\", \"method_pricing\": [ { \"method_name\": \"add\", \"price_in_cogs\": 2 }, { \"method_name\": \"sub\", \"price_in_cogs\": 1 }, { \"method_name\": \"div\", \"price_in_cogs\": 3 }, { \"method_name\": \"mul\", \"price_in_cogs\": 2 } ] } ] }] }, { \"endpoints\": [\"http://97.344.33.1:2379\",\"http://67.344.33.1:2389\"], \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"pricing\": [ { \"package_name\": \"example_service\", \"price_model\": \"fixed_price_per_method\", \"details\": [ { \"service_name\": \"Calculator\", \"method_pricing\": [ { \"method_name\": \"add\", \"price_in_cogs\": 2 }, { \"method_name\": \"sub\", \"price_in_cogs\": 1 }, { \"method_name\": \"div\", \"price_in_cogs\": 2 }, { \"method_name\": \"mul\", \"price_in_cogs\": 3 } ] }, { \"service_name\": \"Calculator2\", \"method_pricing\": [ { \"method_name\": \"add\", \"price_in_cogs\": 2 }, { \"method_name\": \"sub\", \"price_in_cogs\": 1 }, { \"method_name\": \"div\", \"price_in_cogs\": 3 }, { \"method_name\": \"mul\", \"price_in_cogs\": 2 } ] } ] }] } ] } "
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestSubscription(t *testing.T) {
assert.Equal(t, metaData.GetLicenses().Subscriptions.Subscription[0].PlanName, "Monthly For ServiceA/MethodA")
assert.Equal(t, metaData.GetLicenses().Subscriptions.Subscription[0].GrpcMethodName, "MethodA")
assert.Equal(t, metaData.GetLicenses().Subscriptions.Subscription[0].GrpcServiceName, "ServiceA")
assert.Equal(t, metaData.GetLicenses().Subscriptions.Subscription[0].DiscountInPercentage, 120)
assert.Equal(t, metaData.GetLicenses().Subscriptions.Subscription[0].DiscountInPercentage, 120.00)
}

func TestTiers(t *testing.T) {
Expand All @@ -55,7 +55,8 @@ func TestTiers(t *testing.T) {

assert.Equal(t, metaData.GetLicenses().Tiers[0].Type, "Tier")
assert.Equal(t, metaData.GetLicenses().Tiers[0].Range[0].High, 100)
assert.Equal(t, metaData.GetLicenses().Tiers[0].Range[0].DiscountInPercentage, 1)
assert.Equal(t, metaData.GetLicenses().Tiers[0].Range[0].DiscountInPercentage,
1.0)
}
func TestInitServiceMetaDataFromJson(t *testing.T) {
//Parse Bad JSON
Expand Down Expand Up @@ -115,3 +116,9 @@ func TestServiceMetadata_parseServiceProto(t *testing.T) {
assert.Equal(t, dynamicPriceMethod, "/example_service.Calculator/estimate_add")
assert.True(t, ok)
}

func TestServiceMetadata_addOns(t *testing.T) {
metadata, err := ReadServiceMetaDataFromLocalFile("../service_metadata.json")
assert.Equal(t, err, nil)
assert.Equal(t, metadata.Groups[0].AddOns[0].DiscountInPercentage, 4.0)
}
Loading

0 comments on commit 7949bdd

Please sign in to comment.