From 02fab90eb7ab0c6c0f5b9aea37169d155bcba839 Mon Sep 17 00:00:00 2001 From: Semyon Novikov Date: Tue, 15 Oct 2024 14:56:12 +0300 Subject: [PATCH] fix: tests --- blockchain/orginzationMetadata_test.go | 7 +++---- blockchain/serviceMetadata_test.go | 12 ++++++------ escrow/control_service_test.go | 4 ++-- escrow/free_call_payment_handler_test.go | 4 ++-- escrow/free_call_state_service_test.go | 4 ++-- escrow/free_call_test.go | 2 +- escrow/income_test.go | 2 +- escrow/token_service_test.go | 4 ++-- etcddb/etcddb_conf_test.go | 6 +++--- etcddb/etcddb_test.go | 2 +- license_server/license_service_test.go | 4 ++-- pricing/fixed_method_pricing_test.go | 2 +- pricing/fixed_pricing_test.go | 2 +- pricing/pricing_strategy_test.go | 2 +- training/service_test.go | 4 ++-- 15 files changed, 30 insertions(+), 31 deletions(-) diff --git a/blockchain/orginzationMetadata_test.go b/blockchain/orginzationMetadata_test.go index 3f7abe35..18460499 100644 --- a/blockchain/orginzationMetadata_test.go +++ b/blockchain/orginzationMetadata_test.go @@ -11,7 +11,7 @@ import ( var testJsonOrgGroupData = "{ \"org_name\": \"organization_name\", \"org_id\": \"org_id1\", \"groups\": [ { \"group_name\": \"default_group2\", \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"15s\", \"request_timeout\": \"13s\", \"endpoints\": [ \"http://127.0.0.1:2379\" ] } } }, { \"group_name\": \"default_group\", \"license_server_endpoints\": [\"https://licensendpoint:8082\"], \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"15s\", \"request_timeout\": \"13s\", \"endpoints\": [ \"http://127.0.0.1:2379\" ] } } } ] }" func TestGetOrganizationMetaData(t *testing.T) { - metadata, err := InitOrganizationMetaDataFromJson(testJsonOrgGroupData) + metadata, err := InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)) assert.Nil(t, err) assert.NotNil(t, metadata) assert.Equal(t, "organization_name", metadata.OrgName) @@ -25,16 +25,15 @@ func TestGetOrganizationMetaData(t *testing.T) { assert.Equal(t, 15*time.Second, metadata.GetConnectionTimeOut()) assert.Equal(t, 13*time.Second, metadata.GetRequestTimeOut()) assert.Equal(t, "https://licensendpoint:8082", metadata.GetLicenseEndPoints()[0]) - } func TestGetOrganizationMetaDataForError(t *testing.T) { - metadata, err := InitOrganizationMetaDataFromJson("bad json") + metadata, err := InitOrganizationMetaDataFromJson([]byte("bad json")) assert.Nil(t, metadata) assert.NotNil(t, err) config.Vip().Set(config.DaemonGroupName, "unknow") - if metadata, err = InitOrganizationMetaDataFromJson(testJsonOrgGroupData); err != nil { + if metadata, err = InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)); err != nil { assert.Nil(t, metadata) assert.Equal(t, "group name unknow in config is invalid, there was no group found with this name in the metadata", err.Error()) } diff --git a/blockchain/serviceMetadata_test.go b/blockchain/serviceMetadata_test.go index 4e271190..91cf9fab 100644 --- a/blockchain/serviceMetadata_test.go +++ b/blockchain/serviceMetadata_test.go @@ -18,7 +18,7 @@ var testJsonData = "{ \"version\": 1, \"display_name\": \"Example1\", \"en func TestAllGetterMethods(t *testing.T) { fmt.Println(testJsonData) - metaData, err := InitServiceMetaDataFromJson(testJsonData) + metaData, err := InitServiceMetaDataFromJson([]byte(testJsonData)) assert.Equal(t, err, nil) assert.Equal(t, metaData.GetVersion(), 1) @@ -37,7 +37,7 @@ func TestAllGetterMethods(t *testing.T) { func TestSubscription(t *testing.T) { fmt.Println(testJsonData) - metaData, err := InitServiceMetaDataFromJson(testJsonData) + metaData, err := InitServiceMetaDataFromJson([]byte(testJsonData)) assert.Equal(t, err, nil) assert.Equal(t, 12, metaData.GetFreeCallsAllowed()) assert.Equal(t, metaData.GetLicenses().Subscriptions.Type, "Subscription") @@ -50,7 +50,7 @@ func TestSubscription(t *testing.T) { func TestTiers(t *testing.T) { fmt.Println(testJsonData) - metaData, err := InitServiceMetaDataFromJson(testJsonData) + metaData, err := InitServiceMetaDataFromJson([]byte(testJsonData)) assert.Equal(t, err, nil) assert.Equal(t, metaData.GetLicenses().Tiers[0].Type, "Tier") @@ -60,17 +60,17 @@ func TestTiers(t *testing.T) { } func TestInitServiceMetaDataFromJson(t *testing.T) { //Parse Bad JSON - _, err := InitServiceMetaDataFromJson(strings.Replace(testJsonData, "{", "", 1)) + _, err := InitServiceMetaDataFromJson([]byte(strings.Replace(testJsonData, "{", "", 1))) if err != nil { assert.Equal(t, err.Error(), "invalid character ':' after top-level value") } //Parse Bad JSON - _, err = InitServiceMetaDataFromJson(strings.Replace(testJsonData, "0x7DF35C98f41F3Af0df1dc4c7F7D4C19a71Dd059F", "", 1)) + _, err = InitServiceMetaDataFromJson([]byte(strings.Replace(testJsonData, "0x7DF35C98f41F3Af0df1dc4c7F7D4C19a71Dd059F", "", 1))) if err != nil { assert.Equal(t, err.Error(), "MetaData does not have 'free_call_signer_address defined correctly") } - _, err = InitServiceMetaDataFromJson(strings.Replace(testJsonData, "default_pricing", "dummy", 1)) + _, err = InitServiceMetaDataFromJson([]byte(strings.Replace(testJsonData, "default_pricing", "dummy", 1))) if err != nil { assert.Equal(t, err.Error(), "MetaData does not have the default pricing set ") } diff --git a/escrow/control_service_test.go b/escrow/control_service_test.go index eec5ba39..3fb78872 100644 --- a/escrow/control_service_test.go +++ b/escrow/control_service_test.go @@ -78,8 +78,8 @@ func (suite *ControlServiceTestSuite) SetupSuite() { println(errs) suite.receiverAddress = crypto.PubkeyToAddress(suite.receiverPvtKy.PublicKey) orgJson := strings.Replace(testJsonOrgGroupData, "0x671276c61943A35D5F230d076bDFd91B0c47bF09", suite.receiverAddress.Hex(), -1) - suite.orgMetaData, _ = blockchain.InitOrganizationMetaDataFromJson(orgJson) - suite.serviceMetaData, _ = blockchain.InitServiceMetaDataFromJson(testJsonData) + suite.orgMetaData, _ = blockchain.InitOrganizationMetaDataFromJson([]byte(orgJson)) + suite.serviceMetaData, _ = blockchain.InitServiceMetaDataFromJson([]byte(testJsonData)) println("suite.orgMetaData.GetPaymentAddress().Hex() " + suite.orgMetaData.GetPaymentAddress().Hex()) println("suite.receiverAddress.Hex()" + suite.receiverAddress.Hex()) diff --git a/escrow/free_call_payment_handler_test.go b/escrow/free_call_payment_handler_test.go index ef58f4f7..036fd517 100644 --- a/escrow/free_call_payment_handler_test.go +++ b/escrow/free_call_payment_handler_test.go @@ -43,8 +43,8 @@ func (suite *FreeCallPaymentHandlerTestSuite) SetupSuite() { suite.privateKey = GenerateTestPrivateKey() suite.memoryStorage = storage.NewMemStorage() suite.storage = NewFreeCallUserStorage(suite.memoryStorage) - orgMetadata, _ := blockchain.InitOrganizationMetaDataFromJson(testJsonOrgGroupData) - suite.metadata, _ = blockchain.InitServiceMetaDataFromJson(testJsonData) + orgMetadata, _ := blockchain.InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)) + suite.metadata, _ = blockchain.InitServiceMetaDataFromJson([]byte(testJsonData)) suite.data = &FreeCallUserData{FreeCallsMade: 12, UserId: "user1"} suite.key = suite.getKey("user1") suite.paymentHandler = freeCallPaymentHandler{ diff --git a/escrow/free_call_state_service_test.go b/escrow/free_call_state_service_test.go index 675ad31f..60ed19be 100644 --- a/escrow/free_call_state_service_test.go +++ b/escrow/free_call_state_service_test.go @@ -48,8 +48,8 @@ func (suite *FreeCallStateServiceSuite) SetupSuite() { 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\": \"0x94d04332C4f5273feF69c4a52D24f42a3aF1F207\", \"endpoints\": [\"http://34.344.33.1:2379\",\"http://34.344.33.1:2389\"], \"group_id\": \"88ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\",\"group_name\": \"default_group\", \"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 } ] } ] }] } ] } " - suite.orgMetaData, _ = blockchain.InitOrganizationMetaDataFromJson(testJsonOrgGroupData) - suite.serviceMetaData, _ = blockchain.InitServiceMetaDataFromJson(testJsonData) + suite.orgMetaData, _ = blockchain.InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)) + suite.serviceMetaData, _ = blockchain.InitServiceMetaDataFromJson([]byte(testJsonData)) suite.memoryStorage = storage.NewMemStorage() suite.storage = NewFreeCallUserStorage(suite.memoryStorage) suite.service = NewFreeCallUserService(suite.storage, diff --git a/escrow/free_call_test.go b/escrow/free_call_test.go index c63f6793..e3705559 100644 --- a/escrow/free_call_test.go +++ b/escrow/free_call_test.go @@ -30,7 +30,7 @@ func (suite *FreeCallServiceSuite) FreeCallUserData() *FreeCallUserData { } func (suite *FreeCallServiceSuite) SetupSuite() { - metadata, err := blockchain.InitServiceMetaDataFromJson(testJsonData) + metadata, err := blockchain.InitServiceMetaDataFromJson([]byte(testJsonData)) assert.Nil(suite.T(), err, "Unexpected error: %v", err) suite.metadata = metadata suite.memoryStorage = storage.NewMemStorage() diff --git a/escrow/income_test.go b/escrow/income_test.go index 9668ebab..6b319618 100644 --- a/escrow/income_test.go +++ b/escrow/income_test.go @@ -31,7 +31,7 @@ func (priceType MockPriceType) GetPriceType() string { var testJsonDataFixedPrice = "{ \"version\": 1, \"display_name\": \"Example1\", \"encoding\": \"grpc\", \"service_type\": \"grpc\", \"payment_expiration_threshold\": 40320, \"model_ipfs_hash\": \"Qmdiq8Hu6dYiwp712GtnbBxagyfYyvUY1HYqkH7iN76UCc\", \"mpe_address\": \"0x7E6366Fbe3bdfCE3C906667911FC5237Cc96BD08\", \"groups\": [ { \"endpoints\": [\"http://34.344.33.1:2379\",\"http://34.344.33.1:2389\"], \"group_id\": \"88ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\",\"group_name\": \"default_group\", \"pricing\": [ { \"price_model\": \"fixed_price\", \"default\":true, \"price_in_cogs\": 2 }, { \"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 } ] } ] }] }, { \"endpoints\": [\"http://97.344.33.1:2379\",\"http://67.344.33.1:2389\"], \"group_name\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"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 } ] } ] }] } ] } " -var pricingMetadata, _ = blockchain.InitServiceMetaDataFromJson(testJsonDataFixedPrice) +var pricingMetadata, _ = blockchain.InitServiceMetaDataFromJson([]byte(testJsonDataFixedPrice)) func TestIncomeValidate(t *testing.T) { one := big.NewInt(1) diff --git a/escrow/token_service_test.go b/escrow/token_service_test.go index fe694414..d0aa2047 100644 --- a/escrow/token_service_test.go +++ b/escrow/token_service_test.go @@ -77,8 +77,8 @@ func (suite *TokenServiceTestSuite) SetupSuite() { suite.senderAddress = crypto.PubkeyToAddress(suite.senderPvtKy.PublicKey) suite.receiverAddress = crypto.PubkeyToAddress(suite.receiverPvtKy.PublicKey) orgJson := strings.Replace(testJsonOrgGroupData, "0x671276c61943A35D5F230d076bDFd91B0c47bF09", suite.receiverAddress.Hex(), -1) - suite.orgMetaData, _ = blockchain.InitOrganizationMetaDataFromJson(orgJson) - suite.serviceMetaData, _ = blockchain.InitServiceMetaDataFromJson(testJsonData) + suite.orgMetaData, _ = blockchain.InitOrganizationMetaDataFromJson([]byte(orgJson)) + suite.serviceMetaData, _ = blockchain.InitServiceMetaDataFromJson([]byte(testJsonData)) println("suite.orgMetaData.GetPaymentAddress().Hex() " + suite.orgMetaData.GetPaymentAddress().Hex()) println("suite.receiverAddress.Hex()" + suite.receiverAddress.Hex()) diff --git a/etcddb/etcddb_conf_test.go b/etcddb/etcddb_conf_test.go index e3868101..72d26fb2 100644 --- a/etcddb/etcddb_conf_test.go +++ b/etcddb/etcddb_conf_test.go @@ -15,7 +15,7 @@ import ( func TestDefaultEtcdClientConf(t *testing.T) { var testJsonOrgGroupData = "{ \"org_name\": \"organization_name\", \"org_id\": \"org_id1\", \"groups\": [ { \"group_name\": \"default_group2\", \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"5s\", \"request_timeout\": \"3s\", \"endpoints\": [ \"http://127.0.0.1:2379\" ] } } }, { \"group_name\": \"default_group\", \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"5s\", \"request_timeout\": \"3s\", \"endpoints\": [ \"http://127.0.0.1:2379\" ] } } } ] }" - metadata, err := blockchain.InitOrganizationMetaDataFromJson(testJsonOrgGroupData) + metadata, err := blockchain.InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)) conf, err := GetEtcdClientConf(config.Vip(), metadata) assert.Nil(t, err) @@ -28,7 +28,7 @@ func TestDefaultEtcdClientConf(t *testing.T) { func TestCustomEtcdClientConf(t *testing.T) { var testJsonOrgGroupData = "{ \"org_name\": \"organization_name\", \"org_id\": \"org_id1\", \"groups\": [ { \"group_name\": \"default_group\", \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"15s\", \"request_timeout\": \"5s\", \"endpoints\": [ \"http://127.0.0.1:2479\" ] } } }, { \"group_name\": \"default_group2\", \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"5s\", \"request_timeout\": \"3s\", \"endpoints\": [ \"http://127.0.0.1:2379\" ] } } } ] }" - metadata, err := blockchain.InitOrganizationMetaDataFromJson(testJsonOrgGroupData) + metadata, err := blockchain.InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)) conf, err := GetEtcdClientConf(nil, metadata) @@ -41,7 +41,7 @@ func TestCustomEtcdClientConf(t *testing.T) { func TestCustomEtcdClientConfWithDefault(t *testing.T) { var testJsonOrgGroupData = "{ \"org_name\": \"organization_name\", \"org_id\": \"org_id1\", \"groups\": [ { \"group_name\": \"default_group2\", \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"15s\", \"endpoints\": [ \"http://127.0.0.1:2479\" ] } } }, { \"group_name\": \"default_group\", \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"5s\", \"request_timeout\": \"3s\" } } } ] }" - metadata, err := blockchain.InitOrganizationMetaDataFromJson(testJsonOrgGroupData) + metadata, err := blockchain.InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)) assert.Nil(t, metadata) assert.NotNil(t, err) diff --git a/etcddb/etcddb_test.go b/etcddb/etcddb_test.go index e6344616..14f48e00 100644 --- a/etcddb/etcddb_test.go +++ b/etcddb/etcddb_test.go @@ -30,7 +30,7 @@ func TestEtcdTestSuite(t *testing.T) { func (suite *EtcdTestSuite) BeforeTest(suiteName string, testName string) { var testJsonOrgGroupData = "{ \"org_name\": \"organization_name\", \"org_id\": \"org_id1\", \"groups\": [ { \"group_name\": \"default_group2\", \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"500s\", \"request_timeout\": \"300s\", \"endpoints\": [ \"http://127.0.0.1:2379\" ] } } }, { \"group_name\": \"default_group\", \"group_id\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"payment\": { \"payment_address\": \"0x671276c61943A35D5F230d076bDFd91B0c47bF09\", \"payment_expiration_threshold\": 40320, \"payment_channel_storage_type\": \"etcd\", \"payment_channel_storage_client\": { \"connection_timeout\": \"5s\", \"request_timeout\": \"3s\", \"endpoints\": [ \"http://127.0.0.1:2379\" ] } } } ] }" - suite.metaData, _ = blockchain.InitOrganizationMetaDataFromJson(testJsonOrgGroupData) + suite.metaData, _ = blockchain.InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)) const confJSON = ` { diff --git a/license_server/license_service_test.go b/license_server/license_service_test.go index c88aae87..e5b2bcd7 100644 --- a/license_server/license_service_test.go +++ b/license_server/license_service_test.go @@ -23,13 +23,14 @@ type LicenseServiceTestSuite struct { func (suite *LicenseServiceTestSuite) SetupSuite() { suite.channelID = big.NewInt(1) - suite.orgMetaData, _ = blockchain.InitOrganizationMetaDataFromJson(testJsonOrgGroupData) + suite.orgMetaData, _ = blockchain.InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)) suite.servMetaData, _ = blockchain.ReadServiceMetaDataFromLocalFile("../service_metadata.json") suite.licenseDetailsStorage = NewLicenseDetailsStorage(storage.NewMemStorage()) suite.licenseUsageStorage = NewLicenseUsageTrackerStorage(storage.NewMemStorage()) suite.service = NewLicenseService(suite.licenseDetailsStorage, suite.licenseUsageStorage, suite.orgMetaData, suite.servMetaData) } + func TestTokenServiceTestSuite(t *testing.T) { suite.Run(t, new(LicenseServiceTestSuite)) } @@ -41,5 +42,4 @@ func (suite *LicenseServiceTestSuite) TestCreateLicense() { usage, ok, err := suite.service.GetLicenseUsage(LicenseUsageTrackerKey{ChannelID: suite.channelID, ServiceID: "serviceId1", UsageType: PLANNED}) assert.True(suite.T(), ok) assert.Equal(suite.T(), usage.Usage.GetUsage(), big.NewInt(100)) - } diff --git a/pricing/fixed_method_pricing_test.go b/pricing/fixed_method_pricing_test.go index 3bd985fc..aca7daac 100644 --- a/pricing/fixed_method_pricing_test.go +++ b/pricing/fixed_method_pricing_test.go @@ -14,7 +14,7 @@ import ( var testJsonDataFixedMethodPrice = "{ \"version\": 1, \"display_name\": \"Example1\", \"encoding\": \"grpc\", \"service_type\": \"grpc\", \"payment_expiration_threshold\": 40320, \"model_ipfs_hash\": \"Qmdiq8Hu6dYiwp712GtnbBxagyfYyvUY1HYqkH7iN76UCc\", \"mpe_address\": \"0x7E6366Fbe3bdfCE3C906667911FC5237Cc96BD08\", \"groups\": [ { \"endpoints\": [\"http://34.344.33.1:2379\",\"http://34.344.33.1:2389\"], \"group_id\": \"88ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\",\"group_name\": \"default_group\", \"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 } ] } ] }] } ] } " func TestFixedMethodPrice_initPricingData(t *testing.T) { - metadata, _ := blockchain.InitServiceMetaDataFromJson(testJsonDataFixedMethodPrice) + metadata, _ := blockchain.InitServiceMetaDataFromJson([]byte(testJsonDataFixedMethodPrice)) grpcCtx := &handler.GrpcStreamContext{Info: &grpc.StreamServerInfo{FullMethod: "/example_service.Calculator/add"}} pricing, _ := InitPricingStrategy(metadata) price, err := pricing.GetPrice(grpcCtx) diff --git a/pricing/fixed_pricing_test.go b/pricing/fixed_pricing_test.go index c9f18876..6671c2aa 100644 --- a/pricing/fixed_pricing_test.go +++ b/pricing/fixed_pricing_test.go @@ -12,7 +12,7 @@ import ( var testJsonDataFixedPrice = "{ \"version\": 1, \"display_name\": \"Example1\", \"encoding\": \"grpc\", \"service_type\": \"grpc\", \"payment_expiration_threshold\": 40320, \"model_ipfs_hash\": \"Qmdiq8Hu6dYiwp712GtnbBxagyfYyvUY1HYqkH7iN76UCc\", \"mpe_address\": \"0x7E6366Fbe3bdfCE3C906667911FC5237Cc96BD08\", \"groups\": [ { \"endpoints\": [\"http://34.344.33.1:2379\",\"http://34.344.33.1:2389\"], \"group_id\": \"88ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\",\"group_name\": \"default_group\", \"pricing\": [ { \"price_model\": \"fixed_price\", \"default\":true, \"price_in_cogs\": 2 }, { \"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 } ] } ] }] }, { \"endpoints\": [\"http://97.344.33.1:2379\",\"http://67.344.33.1:2389\"], \"group_name\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"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 } ] } ] }] } ] } " func TestFixedPrice_GetPrice(t *testing.T) { - metadata, _ := blockchain.InitServiceMetaDataFromJson(testJsonDataFixedPrice) + metadata, _ := blockchain.InitServiceMetaDataFromJson([]byte(testJsonDataFixedPrice)) grpcCtx := &handler.GrpcStreamContext{} pricing, _ := InitPricingStrategy(metadata) diff --git a/pricing/pricing_strategy_test.go b/pricing/pricing_strategy_test.go index c3d38f59..a32fdc43 100644 --- a/pricing/pricing_strategy_test.go +++ b/pricing/pricing_strategy_test.go @@ -10,7 +10,7 @@ import ( var testJsonData = "{ \"version\": 1, \"display_name\": \"Example1\", \"encoding\": \"grpc\", \"service_type\": \"grpc\", \"payment_expiration_threshold\": 40320, \"model_ipfs_hash\": \"Qmdiq8Hu6dYiwp712GtnbBxagyfYyvUY1HYqkH7iN76UCc\", \"mpe_address\": \"0x7E6366Fbe3bdfCE3C906667911FC5237Cc96BD08\", \"groups\": [ { \"endpoints\": [\"http://34.344.33.1:2379\",\"http://34.344.33.1:2389\"], \"group_id\": \"88ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\",\"group_name\": \"default_group\", \"pricing\": [ { \"price_model\": \"fixed_price\", \"default\":true, \"price_in_cogs\": 2 }, { \"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 } ] } ] }] }, { \"endpoints\": [\"http://97.344.33.1:2379\",\"http://67.344.33.1:2389\"], \"group_name\": \"99ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\", \"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 } ] } ] }] } ] } " func TestPricing_GetPrice(t *testing.T) { - metadata, _ := blockchain.InitServiceMetaDataFromJson(testJsonData) + metadata, _ := blockchain.InitServiceMetaDataFromJson([]byte(testJsonData)) pricing, err := InitPricingStrategy(metadata) if pricing != nil { diff --git a/training/service_test.go b/training/service_test.go index f6572213..520e5515 100644 --- a/training/service_test.go +++ b/training/service_test.go @@ -72,8 +72,8 @@ func (suite *ModelServiceTestSuite) SetupSuite() { 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\": \"0x94d04332C4f5273feF69c4a52D24f42a3aF1F207\", \"endpoints\": [\"http://34.344.33.1:2379\",\"http://34.344.33.1:2389\"], \"group_id\": \"88ybRIg2wAx55mqVsA6sB4S7WxPQHNKqa4BPu/bhj+U=\",\"group_name\": \"default_group\", \"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 } ] } ] }] } ] } " - orgMetaData, _ := blockchain.InitOrganizationMetaDataFromJson(testJsonOrgGroupData) - serviceMetaData, _ := blockchain.InitServiceMetaDataFromJson(testJsonData) + orgMetaData, _ := blockchain.InitOrganizationMetaDataFromJson([]byte(testJsonOrgGroupData)) + serviceMetaData, _ := blockchain.InitServiceMetaDataFromJson([]byte(testJsonData)) suite.service = NewModelService(nil, serviceMetaData, orgMetaData, NewModelStorage(storage.NewMemStorage()), NewUerModelStorage(storage.NewMemStorage())) suite.senderPvtKy, _ = crypto.GenerateKey()