From 84da7d222f43ddc53e0c0ca8a3476ddb130f0216 Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Thu, 22 Jul 2021 09:28:29 +0530 Subject: [PATCH] #542 Support new structure changes in license --- blockchain/serviceMetadata.go | 44 +++++++++++++++--------------- blockchain/serviceMetadata_test.go | 6 ++-- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/blockchain/serviceMetadata.go b/blockchain/serviceMetadata.go index 6ce82a29..8f70d3e4 100644 --- a/blockchain/serviceMetadata.go +++ b/blockchain/serviceMetadata.go @@ -48,15 +48,15 @@ import ( "range": [ { "high": 100, - "fixedPriceInCogs": 1 + "DiscountInPercentage": 3 }, { "high": 200, - "fixedPriceInCogs": 0.75 + "DiscountInPercentage": 4 }, { "high": 300, - "fixedPriceInCogs": 0.50 + "DiscountInPercentage": 6 } ], "detailsUrl": "http://abc.org/licenses/Tier.html", @@ -68,15 +68,15 @@ import ( "range": [ { "high": 100, - "fixedPriceInCogs": 1 + "DiscountInPercentage": 1 }, { "high": 200, - "fixedPriceInCogs": 0.75 + "DiscountInPercentage": 1.75 }, { "high": 300, - "fixedPriceInCogs": 0.50 + "DiscountInPercentage": 2.50 } ], "detailsUrl": "http://abc.org/licenses/Tier.html", @@ -87,28 +87,28 @@ import ( "subscription": [ { "periodInDays": 30, - "creditsInAGI": 120, + "DiscountInPercentage": 10, "planName": "Monthly For ServiceA/MethodA", - "licenseCost": 90, + "LicenseCost": 90, "grpcServiceName": "ServiceA", "grpcMethodName": "MethodA" }, { "periodInDays": 30, - "creditsInAGI": 123, + "DiscountInPercentage": 12, "planName": "Monthly", - "licenseCost": 93 + "LicenseCost": 93 }, { "periodInDays": 120, - "creditsInAGI": 160, - "licenseCost": 120, + "DiscountInPercentage": 16, + "LicenseCost": 120, "planName": "Quarterly" }, { "periodInDays": 365, - "creditsInAGI": 430, - "licenseCost": 390, + "DiscountInPercentage": 23, + "LicenseCost": 390, "planName": "Yearly" } ], @@ -161,17 +161,17 @@ type Tiers struct { } type TierRange struct { - High int `json:"high"` - FixedPriceInCogs int `json:"fixedPriceInCogs"` + High int `json:"high"` + DiscountInPercentage int `json:"DiscountInPercentage"` } type Subscription struct { - PeriodInDays int `json:"periodInDays"` - CreditsInAGI int `json:"creditsInAGI"` - PlanName string `json:"planName"` - licenseCost big.Int `json:"licenseCost"` - GrpcServiceName string `json:"grpcServiceName,omitempty"` - GrpcMethodName string `json:"grpcMethodName,omitempty"` + PeriodInDays int `json:"periodInDays"` + DiscountInPercentage int `json:"discountInPercentage"` + PlanName string `json:"planName"` + LicenseCost big.Int `json:"licenseCost"` + GrpcServiceName string `json:"grpcServiceName,omitempty"` + GrpcMethodName string `json:"grpcMethodName,omitempty"` } type Subscriptions struct { diff --git a/blockchain/serviceMetadata_test.go b/blockchain/serviceMetadata_test.go index 2205b743..70cd7896 100644 --- a/blockchain/serviceMetadata_test.go +++ b/blockchain/serviceMetadata_test.go @@ -11,8 +11,8 @@ 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 \"fixedPriceInCogs\": 1\n },\n {\n \"high\": 200,\n \"fixedPriceInCogs\": 200000\n },\n {\n \"high\": 300,\n \"fixedPriceInCogs\": 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 \"fixedPriceInCogs\": 1\n },\n {\n \"high\": 200,\n \"fixedPriceInCogs\": 200000\n },\n {\n \"high\": 300,\n \"fixedPriceInCogs\": 100000\n }\n ],\n \"detailsUrl\": \"http://abc.org/licenses/Tier.html\",\n \"isActive\": \"true/false\"\n}], " + - "\"subscriptions\": {\n \"subscription\": [\n {\n \"periodInDays\": 30,\n \"creditsInAGI\": 120,\n \"planName\": \"Monthly For ServiceA/MethodA\",\n \"licenseCost\": 90,\n \"grpcServiceName\": \"ServiceA\",\n \"grpcMethodName\": \"MethodA\"\n },\n {\n \"periodInDays\": 30,\n \"creditsInAGI\": 123,\n \"planName\": \"Monthly\",\n \"licenseCost\": 93\n },\n {\n \"periodInDays\": 120,\n \"creditsInAGI\": 160,\n \"licenseCost\": 120,\n \"planName\": \"Quarterly\"\n },\n {\n \"periodInDays\": 365,\n \"creditsInAGI\": 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 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 } ] } ] }] } ] } " @@ -45,6 +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) } func TestTiers(t *testing.T) { @@ -54,6 +55,7 @@ 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) } func TestInitServiceMetaDataFromJson(t *testing.T) { //Parse Bad JSON