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_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)
     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")
 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")
Esempio n. 4
0
    def test_hex_to_utf8(self):
        """Tests to verify hex_to_utf8(binary) function
        """
        binhex = b'\xab\xec\x2c\x5f'  # random input case
        utfstr = hex_to_utf8(binhex)
        self.assertEqual(utfstr, "abec2c5f")

        binhex = b'abec2c5f'  # random input case
        utfstr = hex_to_utf8(binhex)
        self.assertEqual(utfstr, "6162656332633566")

        binhex = b''  # empty input case
        utfstr = hex_to_utf8(binhex)
        self.assertEqual(utfstr, "")
 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")
Esempio n. 6
0
 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_utf8(self.__org_id), hex_to_utf8(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_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_utf8(self.__org_id),
         hex_to_utf8(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_utf8(self.__org_id), hex_to_utf8(self.__application_ids[0]))
     result = self.__eth_conn.worker_lookup(
         self.__worker_type,
         '419c007ce1f6ecb2e52a830b03a0c8be36438b94c950d9cf2aeb48b0f99a8276',
         '7b1d714fc499ddc59dde26683a0bf928848801087dc5f0372c340c120848ed7b')
     logging.info("worker_lookup result {} {}".format(result, type(result)))
     logging.info("worker_lookup status {} {} {}".format(
         result[0], result[1], result[2]))
     match = byte_array_to_hex_str(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_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_utf8(self.__org_id), self.__new_uri,
            hex_to_utf8(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")
 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.__fabric_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], result[2])
 def test_worker_set_status(self):
     self.__status = WorkerStatus.DECOMMISSIONED
     logging.info(
         "Calling worker_set_status..\n worker_id: %s\n status: %d",
         hex_to_utf8(self.__worker_id), self.__status.value)
     result = self.__eth_conn.worker_set_status(self.__worker_id,
                                                self.__status)
     logging.info("worker_set_status status \n%s", result)
     self.assertIsNotNone(result, "worker set status response not matched")
 def test_registry_lookup(self):
     logging.info('Calling registry_lookup..\n application_id: %s',
                  hex_to_utf8(self.__app_type_ids[0]))
     result = self.__fabric_conn.registry_lookup(self.__app_type_ids[0])
     logging.info('registry_lookup contract status [%d, %s, %s]', result[0],
                  result[1], 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 test_registry_set_status(self):
     self.__new_status = RegistryStatus.OFF_LINE
     logging.info(
         'Calling registry_set_status contract..\n org_id: %s\n status: %d',
         hex_to_utf8(self.__org_id), self.__new_status.value)
     result = self.__fabric_conn.registry_set_status(
         self.__org_id, self.__new_status)
     logging.info("registry_set_status contract status \n%s", result)
     self.assertIsNotNone(result,
                          "Registry set status response not matched")
Esempio n. 14
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_update(self):
     self.__new_details = json.dumps({
         "workOrderSyncUri":
         "http://worker-order:8008".encode("utf-8").hex(),
         "workOrderNotifyUri":
         "http://worker-order-notify:9909".encode("utf-8").hex()
     })
     logging.info("Calling worker_update..\n worker_id: %s\n details: %s",
                  hex_to_utf8(self.__worker_id), self.__new_details)
     result = self.__eth_conn.worker_update(self.__worker_id,
                                            self.__new_details)
     logging.info("worker_update status \n %s", result)
     self.assertIsNotNone(result, "worker update 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_set_status(self):
     self.__status = WorkerStatus.DECOMMISSIONED
     logging.info(
         "Calling worker_set_status..\n worker_id: %s\n status: %d",
         hex_to_utf8(self.__worker_id), self.__status.value)
     result = self.__eth_conn.worker_set_status(self.__worker_id,
                                                self.__status)
     logging.info(
         "worker_set_status 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 set status response not matched")
Esempio n. 18
0
 def test_registry_set_status(self):
     self.__new_status = RegistryStatus.OFF_LINE
     logging.info(
         'Calling registry_set_status contract..\n org_id: %s\n status: %d',
         hex_to_utf8(self.__org_id), self.__new_status.value)
     result = self.__eth_conn.registry_set_status(self.__org_id,
                                                  self.__new_status)
     logging.info(
         "registry_set_status 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 set status response not matched")
Esempio n. 19
0
 def test_worker_retrieve(self):
     logging.info("Calling worker_retrieve..\n worker_id: %s",
                  hex_to_utf8(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_utf8(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")
 def test_worker_update(self):
     self.__new_details = json.dumps({
         "workOrderSyncUri":
         "http://worker-order:8008".encode("utf-8").hex(),
         "workOrderNotifyUri":
         "http://worker-order-notify:9909".encode("utf-8").hex()
     })
     logging.info("Calling worker_update..\n worker_id: %s\n details: %s",
                  hex_to_utf8(self.__worker_id), self.__new_details)
     result = self.__eth_conn.worker_update(self.__worker_id,
                                            self.__new_details)
     logging.info(
         "worker_update 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 update response not matched")