Skip to content

Commit 84da7d2

Browse files
anandrgitnirmananandrgitnirman
authored andcommitted
Support new structure changes in license
1 parent 095767a commit 84da7d2

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

blockchain/serviceMetadata.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ import (
4848
"range": [
4949
{
5050
"high": 100,
51-
"fixedPriceInCogs": 1
51+
"DiscountInPercentage": 3
5252
},
5353
{
5454
"high": 200,
55-
"fixedPriceInCogs": 0.75
55+
"DiscountInPercentage": 4
5656
},
5757
{
5858
"high": 300,
59-
"fixedPriceInCogs": 0.50
59+
"DiscountInPercentage": 6
6060
}
6161
],
6262
"detailsUrl": "http://abc.org/licenses/Tier.html",
@@ -68,15 +68,15 @@ import (
6868
"range": [
6969
{
7070
"high": 100,
71-
"fixedPriceInCogs": 1
71+
"DiscountInPercentage": 1
7272
},
7373
{
7474
"high": 200,
75-
"fixedPriceInCogs": 0.75
75+
"DiscountInPercentage": 1.75
7676
},
7777
{
7878
"high": 300,
79-
"fixedPriceInCogs": 0.50
79+
"DiscountInPercentage": 2.50
8080
}
8181
],
8282
"detailsUrl": "http://abc.org/licenses/Tier.html",
@@ -87,28 +87,28 @@ import (
8787
"subscription": [
8888
{
8989
"periodInDays": 30,
90-
"creditsInAGI": 120,
90+
"DiscountInPercentage": 10,
9191
"planName": "Monthly For ServiceA/MethodA",
92-
"licenseCost": 90,
92+
"LicenseCost": 90,
9393
"grpcServiceName": "ServiceA",
9494
"grpcMethodName": "MethodA"
9595
},
9696
{
9797
"periodInDays": 30,
98-
"creditsInAGI": 123,
98+
"DiscountInPercentage": 12,
9999
"planName": "Monthly",
100-
"licenseCost": 93
100+
"LicenseCost": 93
101101
},
102102
{
103103
"periodInDays": 120,
104-
"creditsInAGI": 160,
105-
"licenseCost": 120,
104+
"DiscountInPercentage": 16,
105+
"LicenseCost": 120,
106106
"planName": "Quarterly"
107107
},
108108
{
109109
"periodInDays": 365,
110-
"creditsInAGI": 430,
111-
"licenseCost": 390,
110+
"DiscountInPercentage": 23,
111+
"LicenseCost": 390,
112112
"planName": "Yearly"
113113
}
114114
],
@@ -161,17 +161,17 @@ type Tiers struct {
161161
}
162162

163163
type TierRange struct {
164-
High int `json:"high"`
165-
FixedPriceInCogs int `json:"fixedPriceInCogs"`
164+
High int `json:"high"`
165+
DiscountInPercentage int `json:"DiscountInPercentage"`
166166
}
167167

168168
type Subscription struct {
169-
PeriodInDays int `json:"periodInDays"`
170-
CreditsInAGI int `json:"creditsInAGI"`
171-
PlanName string `json:"planName"`
172-
licenseCost big.Int `json:"licenseCost"`
173-
GrpcServiceName string `json:"grpcServiceName,omitempty"`
174-
GrpcMethodName string `json:"grpcMethodName,omitempty"`
169+
PeriodInDays int `json:"periodInDays"`
170+
DiscountInPercentage int `json:"discountInPercentage"`
171+
PlanName string `json:"planName"`
172+
LicenseCost big.Int `json:"licenseCost"`
173+
GrpcServiceName string `json:"grpcServiceName,omitempty"`
174+
GrpcMethodName string `json:"grpcMethodName,omitempty"`
175175
}
176176

177177
type Subscriptions struct {

blockchain/serviceMetadata_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
)
1313

14-
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}], " +
15-
"\"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 }"
14+
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}], " +
15+
"\"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 }"
1616
var testJsonData = "{ \"version\": 1, \"display_name\": \"Example1\", \"encoding\": \"grpc\", \"service_type\": \"grpc\", \"payment_expiration_threshold\": 40320, \"model_ipfs_hash\": \"Qmdiq8Hu6dYiwp712GtnbBxagyfYyvUY1HYqkH7iN76UCc\", " +
1717
" \"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 } ] } ] }] } ] } "
1818

@@ -45,6 +45,7 @@ func TestSubscription(t *testing.T) {
4545
assert.Equal(t, metaData.GetLicenses().Subscriptions.Subscription[0].PlanName, "Monthly For ServiceA/MethodA")
4646
assert.Equal(t, metaData.GetLicenses().Subscriptions.Subscription[0].GrpcMethodName, "MethodA")
4747
assert.Equal(t, metaData.GetLicenses().Subscriptions.Subscription[0].GrpcServiceName, "ServiceA")
48+
assert.Equal(t, metaData.GetLicenses().Subscriptions.Subscription[0].DiscountInPercentage, 120)
4849
}
4950

5051
func TestTiers(t *testing.T) {
@@ -54,6 +55,7 @@ func TestTiers(t *testing.T) {
5455

5556
assert.Equal(t, metaData.GetLicenses().Tiers[0].Type, "Tier")
5657
assert.Equal(t, metaData.GetLicenses().Tiers[0].Range[0].High, 100)
58+
assert.Equal(t, metaData.GetLicenses().Tiers[0].Range[0].DiscountInPercentage, 1)
5759
}
5860
func TestInitServiceMetaDataFromJson(t *testing.T) {
5961
//Parse Bad JSON

0 commit comments

Comments
 (0)