def test_registry_retrieve(self):
     logging.info('Calling registry_retrieve..\n org_id: %s',
                  hex_to_utf8(self.__org_id))
     result = self.__eth_conn.registry_retrieve(self.__org_id)
     logging.info(
         'registry_retrieve contract status [%s, %s, %s, %d]',
         result[0], hex_to_utf8(result[1]), pretty_ids(result[2]),
         result[3])
     self.assertEqual(
         result[0], self.__new_uri,
         "Registry retrieve response not matched for uri")
     self.assertEqual(
         hex_to_utf8(result[1]),
         hex_to_utf8(self.__sc_addr),
         "Registry retrieve response not matched for " +
         "smart contract address")
     self.assertEqual(
         result[2][0], self.__app_type_ids[0],
         "Registry retrieve response not matched for app id type list " +
         "index 0")
     self.assertEqual(
         result[2][1], self.__app_type_ids[1],
         "Registry retrieve response not matched for app id type list " +
         "index 1")
     self.assertEqual(
         result[2][2], self.__new_app_id[0],
         "Registry retrieve response not matched for app id type list " +
         "index 2")
     self.assertEqual(
         result[3], self.__new_status.value,
         "Registry retrieve response not matched for status")
 def test_worker_register(self):
     self.__worker_id = urandom(32)
     self.__worker_type = WorkerType.TEE_SGX
     self.__details = json.dumps({
         "workOrderSyncUri":
         "http://worker-order:8008".encode("utf-8").hex()
     })
     self.__org_id = urandom(32)
     self.__application_ids = [urandom(32), urandom(32)]
     logging.info(
         "Calling worker_register contract..\n worker_id: %s\n " +
         "worker_type: %d\n " +
         "orgId: %s\n applicationIds %s\n details %s",
         hex_to_utf(self.__worker_id), self.__worker_type.value,
         hex_to_utf(self.__org_id), pretty_ids(self.__application_ids),
         self.__details)
     result = self.__eth_conn.worker_register(self.__worker_id,
                                              self.__worker_type,
                                              self.__org_id,
                                              self.__application_ids,
                                              self.__details)
     self.assertIsNotNone(result["txn_receipt"],
                          "transaction execution failed")
     logging.info(
         "worker_register status \n{'status': %s', \n'txn_receipt': %s}",
         result["status"],
         json.dumps(json.loads(Web3.toJSON(result["txn_receipt"])),
                    indent=4))
     self.assertEqual(result["status"], "added",
                      "worker register response not matched")
Example #3
0
 def test_registry_lookup_next(self):
     lookup_tag = "test"
     logging.info(
         'Calling registry_lookup_next..\n application_id: %s\n ' +
         'lookup_tag: %s', hex_to_utf8(self.__app_type_ids[0]), lookup_tag)
     result = self.__eth_conn.registry_lookup_next(self.__app_type_ids[0],
                                                   lookup_tag)
     logging.info('registry_lookup_next contract status [%d, %s, %s]',
                  result[0], result[1], pretty_ids(result[2]))
 def registry_retrieve(self, org_id):
     if self.worker_registry_list == None:
         logger.error("ERROR: Worker registry list adaptor not initialized")
         sys.exit(1)
     retrieve_result = self.worker_registry_list.registry_retrieve(org_id)
     logger.info("Registry retrieved: [%s, %s, %s, %d]", retrieve_result[0],
                 hex_to_utf(retrieve_result[1]),
                 pretty_ids(retrieve_result[2]), retrieve_result[3])
     return retrieve_result
Example #5
0
 def test_registry_lookup(self):
     logging.info('Calling registry_lookup..\n application_id: %s',
                  hex_to_utf8(self.__app_type_ids[0]))
     result = self.__eth_conn.registry_lookup(self.__app_type_ids[0])
     logging.info('registry_lookup contract status [%d, %s, %s]', result[0],
                  result[1], pretty_ids(result[2]))
     self.assertEqual(result[0], 1,
                      "Registry lookup response total count not matched")
     self.assertEqual(result[2][0], self.__org_id,
                      "Registry lookup response not matched for org id")
 def registry_lookup(self, app_type_id=None):
     if self.worker_registry_list == None:
         logger.error("ERROR: Worker registry list adaptor not initialized")
         sys.exit(1)
     if app_type_id:
         lookup_result = self.worker_registry_list.registry_lookup(
             app_type_id=app_type_id)
     else:
         lookup_result = self.worker_registry_list.registry_lookup()
     logger.info("Registry Lookup result: [%d, %s, %s]", lookup_result[0],
                 lookup_result[1], pretty_ids(lookup_result[2]))
     return lookup_result
 def test_registry_update(self):
     self.__new_app_id = [urandom(32)]
     self.__new_uri = 'http://localhost:1947'
     logging.info(
         'Calling registry_update contract..\n org_id: %s\n uri: %s\n ' +
         'sc_addr: %s\n application_ids: %s', hex_to_utf8(self.__org_id),
         self.__new_uri, hex_to_utf8(self.__sc_addr),
         pretty_ids(self.__new_app_id))
     result = self.__fabric_conn.registry_update(self.__org_id,
                                                 self.__new_uri,
                                                 self.__sc_addr,
                                                 self.__new_app_id)
     logging.info("registry_update contract status \n%s", result)
     self.assertIsNotNone(result, "Registry update response not matched")
 def test_worker_lookup_next(self):
     lookUpTag = ""
     logging.info(
         "Calling worker_lookup_next..\n worker_type: %d\n" +
         "orgId: %s\n applicationId:%s\n lookUpTag: %s",
         self.__worker_type.value, hex_to_utf(self.__org_id),
         hex_to_utf(self.__application_ids[0]), lookUpTag)
     result = self.__eth_conn.worker_lookup_next(self.__worker_type,
                                                 self.__org_id,
                                                 self.__application_ids[0],
                                                 lookUpTag)
     logging.info("worker_lookup_next status [%d, %s, %s]", result[0],
                  result[1], pretty_ids(result[2]))
     self.assertEqual(result[0], 0,
                      "worker_lookup_next response count doesn't match")
 def test_worker_lookup(self):
     logging.info(
         "Calling worker_lookup..\n worker_type: %d\n orgId: %s\n " +
         "applicationId: %s", self.__worker_type.value,
         hex_to_utf(self.__org_id), hex_to_utf(self.__application_ids[0]))
     result = self.__eth_conn.worker_lookup(self.__worker_type,
                                            self.__org_id,
                                            self.__application_ids[0])
     logging.info("worker_lookup status [%d, %s, %s]", result[0], result[1],
                  pretty_ids(result[2]))
     match = self.__worker_id in result[2]
     self.assertEqual(result[0], 1,
                      "Worker lookup response count doesn't match")
     self.assertTrue(match,
                     "Worker lookup response worker id doesn't match")
 def test_registry_add(self):
     self.__org_id = urandom(32)
     self.__uri = "http://127.0.0.1:1947"
     self.__sc_addr = urandom(32)
     self.__app_type_ids = [urandom(32), urandom(32)]
     logging.info(
         'Calling registry_add contract..\n org_id: %s\n ' +
         'uri: %s\n ' + 'sc_addr: %s\n application_ids: %s',
         hex_to_utf8(self.__org_id), self.__uri,
         hex_to_utf8(self.__sc_addr), pretty_ids(self.__app_type_ids))
     result = self.__fabric_conn.registry_add(self.__org_id, self.__uri,
                                              self.__sc_addr,
                                              self.__app_type_ids)
     logging.info("registry_add contract status \n %s", result)
     self.assertIsNotNone(result, "Registry add response not matched")
Example #11
0
    def test_registry_update(self):
        self.__new_app_id = [urandom(32)]
        self.__new_uri = 'http://worker2:8008'
        logging.info(
            'Calling registry_update contract..\n org_id: %s\n uri: %s\n \
sc_addr: %s\n application_ids: %s', hex_to_utf(self.__org_id), self.__new_uri,
            hex_to_utf(self.__sc_addr), pretty_ids(self.__new_app_id))
        result = self.__eth_conn.registry_update(self.__org_id, self.__new_uri,
                                                 self.__sc_addr,
                                                 self.__new_app_id)
        logging.info(
            "registry_update contract status \n{'status': %s', \n'txn_receipt': %s}",
            result["status"],
            json.dumps(json.loads(Web3.toJSON(result["txn_receipt"])),
                       indent=4))
        self.assertEqual(result['status'], 'added',
                         "Registry update response not matched")
Example #12
0
 def test_registry_add(self):
     self.__org_id = urandom(32)
     self.__uri = "http://127.0.0.1:1947"
     self.__sc_addr = urandom(32)
     self.__app_type_ids = [urandom(32), urandom(32)]
     logging.info(
         'Calling registry_add contract..\n org_id: %s\n ' +
         'uri: %s\n ' + 'sc_addr: %s\n application_ids: %s',
         hex_to_utf8(self.__org_id), self.__uri,
         hex_to_utf8(self.__sc_addr), pretty_ids(self.__app_type_ids))
     result = self.__eth_conn.registry_add(self.__org_id, self.__uri,
                                           self.__sc_addr,
                                           self.__app_type_ids)
     logging.info(
         "registry_add contract status \n{'status': %s', \n" +
         "'txn_receipt': %s}", result["status"],
         json.dumps(json.loads(Web3.toJSON(result["txn_receipt"])),
                    indent=4))
     self.assertEqual(result['status'], 'added',
                      "Registry add response not matched")
 def test_worker_register(self):
     self.__worker_id = urandom(32)
     self.__worker_type = WorkerType.TEE_SGX
     self.__details = json.dumps({
         "workOrderSyncUri":
         "http://worker-order:8008".encode("utf-8").hex()
     })
     self.__org_id = urandom(32)
     self.__application_ids = [urandom(32), urandom(32)]
     logging.info(
         "Calling worker_register contract..\n worker_id: %s\n " +
         "worker_type: %d\n " +
         "orgId: %s\n applicationIds %s\n details %s",
         hex_to_utf8(self.__worker_id), self.__worker_type.value,
         hex_to_utf8(self.__org_id), pretty_ids(self.__application_ids),
         self.__details)
     result = self.__eth_conn.worker_register(self.__worker_id,
                                              self.__worker_type,
                                              self.__org_id,
                                              self.__application_ids,
                                              self.__details)
     logging.info("worker_register status \n %s", result)
     self.assertIsNotNone(result, "transaction execution failed")
 def test_worker_retrieve(self):
     logging.info("Calling worker_retrieve..\n worker_id: %s",
                  hex_to_utf(self.__worker_id))
     result = self.__eth_conn.worker_retrieve(self.__worker_id)
     logging.info("worker_retrieve status [%d, %s, %s, %s, %d]", result[0],
                  hex_to_utf(result[1]), pretty_ids(result[2]), result[3],
                  result[4])
     self.assertEqual(result[0], self.__worker_type.value,
                      "Worker retrieve response worker type doesn't match")
     self.assertEqual(
         result[1], self.__org_id,
         "Worker retrieve response organization id doesn't match")
     self.assertEqual(
         result[2][0], self.__application_ids[0],
         "Worker retrieve response application id[0] doesn't match")
     self.assertEqual(
         result[2][1], self.__application_ids[1],
         "Worker retrieve response application id[1] doesn't match")
     self.assertEqual(
         result[3], self.__new_details,
         "Worker retrieve response worker details doesn't match")
     self.assertEqual(
         result[4], self.__status.value,
         "Worker retrieve response worker status doesn't match")
Example #15
0
 def test_pretty_ids(self):
     """Tests to verify pretty_ids(ids) function
     """
     ids = [b'abec2c5f', b'\xab\xec\x2c\x5f']
     expected_pretty_ids = ["6162656332633566", "abec2c5f"]
     self.assertTrue(pretty_ids(ids) == expected_pretty_ids)