Skip to content

Commit ddedf9e

Browse files
committed
[SPT-777] New functional tests: call low-level; get-api-registry; metadata-assets, metadata-contacts; metadata-media
1 parent c460d4a commit ddedf9e

File tree

1 file changed

+54
-16
lines changed

1 file changed

+54
-16
lines changed

snet/cli/test/functional_tests/func_tests.py

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ def test_channel_3_print_filter_group(self):
274274
result = execute(["channel", "print-filter-group", self.org_id, self.group], self.parser, self.conf)
275275
assert self.max_id in result
276276

277-
278277
def test_channel_4_claim(self):
279278
execute(["account", "deposit", self.amount, "-y", "-q"], self.parser, self.conf)
280279
execute(["channel", "extend-add", self.max_id, "--amount", self.amount, "-y"], self.parser, self.conf)
@@ -289,23 +288,27 @@ def test_channel_4_claim(self):
289288
class TestAHClient(BaseTest):
290289
def setUp(self):
291290
super().setUp()
292-
self.org_id="egor-sing-test"
293-
self.service_id="hate-detection"
294-
self.group="default_group"
295-
self.identity_name="some_name"
296-
self.method="detection"
297-
self.params=("./detection.json")
291+
self.org_id = "egor-sing-test"
292+
self.service_id = "hate-detection"
293+
self.group = "default_group"
294+
self.identity_name = "some_name"
295+
self.method = "runsync"
296+
self.params = "./detection.json"
297+
self.endpoint = "https://ai-ui-service.singularitynet.io:8001"
298+
self.max_id = "357"
299+
self.nonce = "1"
300+
self.amount_in_cogs = "1"
298301

299302
def test_0_preparations(self):
300303
identity_list=execute(["identity", "list"], self.parser, self.conf)
301304
if self.identity_name not in identity_list:
302-
execute(["identity", "create", self.identity_name, "key", "--private-key", PRIVATE_KEY, "-de"], self.parser, self.conf)
305+
execute(["identity", "create", self.identity_name, "key", "--private-key", "faaf0c972a152459d97e7267280689583aae2d1caaa518cce7e412dd13f7b3e8", "-de"], self.parser, self.conf)
303306
execute(["network", "sepolia"], self.parser, self.conf)
304307
result = execute(["session"], self.parser, self.conf)
305308
assert "network: sepolia" in result
306309

307310
def test_1_channel_open(self):
308-
execute(["set", "default_eth_rpc_endpoint", INFURA], self.parser, self.conf)
311+
execute(["set", "default_eth_rpc_endpoint", "https://sepolia.infura.io/v3/047c3c4404ef4cbc90938371a8e34604"], self.parser, self.conf)
309312
execute(["account", "deposit", "0.0001", "-y"], self.parser, self.conf)
310313
self.block=int(execute(["channel", "block-number"], self.parser, self.conf))
311314
print(self.block)
@@ -314,15 +317,27 @@ def test_1_channel_open(self):
314317

315318
def test_2_service_call(self):
316319
params_file = open("detection.json", "w+")
317-
params_file.write("""
318-
{
319-
"text": "Hello man try to answer me soon"
320+
params_file.write("""{
321+
"input": {
322+
"text": "Hello man answer me soon"
323+
}
320324
}
321325
""")
322326
params_file.close()
323327
result=execute(["client", "call", self.org_id, self.service_id, self.group, self.method, self.params, "-y"], self.parser, self.conf)
324328
assert "spam" in result
325329

330+
def test_3_service_get_channel_state(self):
331+
result=execute(["client", "get-channel-state", self.max_id, self.endpoint], self.parser, self.conf)
332+
assert "current_unspent_amount_in_cogs = " in result
333+
334+
def test_4_call_low_level(self):
335+
result = execute(["client", "call-lowlevel", self.org_id, self.service_id, self.group, self.max_id, self.nonce, self.amount_in_cogs], self.parser, self.conf)
336+
assert "spam" in result
337+
338+
def test_5_get_api_registry(self):
339+
execute(["service", "get-api-registry", self.org_id, self.service_id, "./"], self.parser, self.conf)
340+
assert os.path.exists("./hate.proto")
326341

327342

328343
class TestAIOrganization(BaseTest):
@@ -360,6 +375,10 @@ def setUp(self):
360375
self.contributor = "Stasy"
361376
self.contributor_mail = "stasy@hotmail.com"
362377
self.tags = "new", "text2text", "t2t", "punctuality"
378+
self.hero_image = "./img.jpg"
379+
self.contact = "author"
380+
self.email = "author@hotmail.com"
381+
self.phone = "+1234567890"
363382

364383
def test_0_preparation(self):
365384
identity_list = execute(["identity", "list"], self.parser, self.conf)
@@ -421,15 +440,23 @@ def test_5_change_members(self):
421440
assert "event: OrganizationModified" in result_rem
422441

423442
def test_6_change_org_metadata(self):
443+
hero_image = open("img.jpg", "w+")
444+
hero_image.close()
445+
execute(["organization", "metadata-add-assets", self.hero_image, "hero_image"], self.parser, self.conf)
446+
execute(["organization", "metadata-remove-assets", "hero_image"], self.parser, self.conf)
447+
execute(["organization", "metadata-remove-all-assets"], self.parser, self.conf)
448+
execute(["organization", "metadata-add-contact", self.contact, "--email", self.email, "--phone", self.phone], self.parser, self.conf)
449+
execute(["organization", "metadata-remove-contacts", self.contact], self.parser, self.conf)
450+
execute(["organization", "metadata-remove-all-contacts"], self.parser, self.conf)
424451
execute(["organization", "metadata-add-description", "--description", self.new_description], self.parser, self.conf)
425452
execute(["organization", "update-metadata", self.org_id, "-y"], self.parser, self.conf)
426453
result = execute(["organization", "print-metadata", self.org_id], self.parser, self.conf)
427454
assert self.new_description in result
428455

429-
430456
def test_7_change_service_metadata(self):
431457
execute(["service", "metadata-remove-group", self.group_name], self.parser, self.conf)
432458
execute(["service", "metadata-add-group", self.group_name], self.parser, self.conf)
459+
execute(["organization", "update-group", self.group_name], self.parser, self.conf)
433460
execute(["service", "metadata-set-free-calls", self.group_name, self.free_calls], self.parser, self.conf)
434461
execute(["service", "metadata-set-freecall-signer-address", self.group_name, ADDR], self.parser, self.conf)
435462
execute(["service", "metadata-add-description", "--description", self.new_description, "--short-description", self.short_description, "--url", self.url],
@@ -438,25 +465,36 @@ def test_7_change_service_metadata(self):
438465
execute(["service", "metadata-add-contributor", self.contributor, self.contributor_mail], self.parser, self.conf)
439466
execute(["service", "metadata-remove-contributor", self.contributor_mail], self.parser, self.conf)
440467
execute(["service", "metadata-add-contributor", self.contributor, self.contributor_mail], self.parser, self.conf)
468+
execute(["service", "metadata-add-assets", self.hero_image, "hero_image"], self.parser, self.conf)
469+
execute(["service", "metadata-remove-assets", "hero_image"], self.parser, self.conf)
470+
execute(["service", "metadata-remove-all-assets"], self.parser, self.conf)
471+
execute(["service", "metadata-add-media", self.hero_image], self.parser, self.conf)
472+
execute(["service", "metadata-remove-media", "1"], self.parser, self.conf)
473+
execute(["service", "metadata-remove-all-media"], self.parser, self.conf)
441474
execute(["service", "metadata-add-tags", self.tags], self.parser, self.conf)
442475
execute(["service", "update-metadata", self.org_id, self.service_id, "-y"], self.parser, self.conf)
443476
result = execute(["service", "print-metadata", self.org_id, self.service_id], self.parser, self.conf)
444477
print(execute(["service", "print-metadata", self.org_id, self.service_id], self.parser, self.conf))
445478
print(execute(["service", "print-service-status", self.org_id, self.service_id], self.parser, self.conf))
446479
assert self.contributor in result
447480

481+
def test_8_get_api_metadata(self):
482+
os.remove(f"./ExampleService.proto")
483+
execute(["service", "get-api-metadata", "./"], self.parser, self.conf)
484+
assert os.path.exists(f"./ExampleService.proto")
448485

449-
def test_8_delete_service(self):
486+
def test_9_delete_service(self):
450487
result = execute(["service", "delete", self.org_id, self.service_id, "-y"], self.parser, self.conf)
451488
os.remove(f"./service_metadata.json")
452-
os.remove(f"./ExampleService.proto")
453489
assert "event: ServiceDeleted" in result
454490

455-
def test_9_delete_organization(self):
491+
def test_91_delete_organization(self):
456492
result=execute(["organization", "delete", self.org_id, "-y"], self.parser, self.conf)
457493
os.remove(f"./organization_metadata.json")
494+
os.remove(f"img.jpg")
458495
assert "event: OrganizationDeleted" in result
459496

460497

498+
461499
if __name__ == "__main__":
462500
unittest.main()

0 commit comments

Comments
 (0)