Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
semyon-dev committed Oct 15, 2024
1 parent 38eed6b commit 02fab90
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 31 deletions.
7 changes: 3 additions & 4 deletions blockchain/orginzationMetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
}
Expand Down
12 changes: 6 additions & 6 deletions blockchain/serviceMetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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 ")
}
Expand Down
4 changes: 2 additions & 2 deletions escrow/control_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
4 changes: 2 additions & 2 deletions escrow/free_call_payment_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions escrow/free_call_state_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion escrow/free_call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion escrow/income_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions escrow/token_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
6 changes: 3 additions & 3 deletions etcddb/etcddb_conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand Down
Loading

0 comments on commit 02fab90

Please sign in to comment.