Пример #1
0
    def test_is_hex_string_prefixed_with_0x(self):
        """Unit test for checking whether hex string with 0x or not.
        """
        def is_hex_string_prefixed_with_0x(value: str):
            if is_0x_prefixed(value) and is_lowercase_hex_string(
                    remove_0x_prefix(value)):
                return True
            else:
                return False

        # 0x74657374
        valid_value1 = add_0x_prefix("test".encode().hex())
        self.assertTrue(is_hex_string_prefixed_with_0x(valid_value1))

        # 74657374
        invalid_value1 = remove_0x_prefix(valid_value1)
        self.assertFalse(is_hex_string_prefixed_with_0x(invalid_value1))
        self.assertFalse(
            is_hex_string_prefixed_with_0x(add_cx_prefix(invalid_value1)))

        invalid_value2 = "Abcd"
        self.assertFalse(is_hex_string_prefixed_with_0x(invalid_value2))
        self.assertFalse(
            is_hex_string_prefixed_with_0x(add_0x_prefix(invalid_value2)))

        invalid_value3 = "123aAc"
        self.assertFalse(is_hex_string_prefixed_with_0x(invalid_value3))
        self.assertFalse(
            is_hex_string_prefixed_with_0x(add_0x_prefix(invalid_value3)))
Пример #2
0
 def test_get_transaction_invalid(self, _make_id):
     tx_hash = "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
     # case 1: when tx_hash is invalid - no prefixed
     self.assertRaises(DataTypeException, self.icon_service.get_transaction,
                       remove_0x_prefix(tx_hash))
     # case 2: when tx_hash is invalid - wrong prefixed
     self.assertRaises(DataTypeException, self.icon_service.get_transaction,
                       add_cx_prefix(remove_0x_prefix(tx_hash)))
     # case 3: when tx_hash is invalid - too short
     self.assertRaises(DataTypeException, self.icon_service.get_transaction,
                       tx_hash[:15])
 def test_get_transaction_by_hash(self):
     # case 0: when tx_hash is valid
     result = self.icon_service.get_transaction(self.tx_hash)
     self.assertTrue(result)
     # case 1: when tx_hash is invalid - no prefixed
     self.assertRaises(DataTypeException, self.icon_service.get_transaction,
                       remove_0x_prefix(self.tx_hash))
     # case 2: when tx_hash is invalid - wrong prefixed
     self.assertRaises(DataTypeException, self.icon_service.get_transaction,
                       add_cx_prefix(remove_0x_prefix(self.tx_hash)))
     # case 3: when tx_hash is invalid - too short
     self.assertRaises(DataTypeException, self.icon_service.get_transaction,
                       self.tx_hash[:15])
     # case 4: when tx_hash is invalid - not exist
     self.assertRaises(JSONRPCException, self.icon_service.get_transaction,
                       self.tx_hash_invalid)
Пример #4
0
    def test_validate_transaction(self):
        result = self.icon_service.get_transaction_result(self.tx_hash)
        self.assertTrue(is_transaction_result(result))

        # case 1: when tx_hash is invalid - no prefixed
        self.assertRaises(DataTypeException,
                          self.icon_service.get_transaction_result,
                          remove_0x_prefix(self.tx_hash))
        # case 2: when tx_hash is invalid - wrong prefixed
        self.assertRaises(DataTypeException,
                          self.icon_service.get_transaction_result,
                          add_cx_prefix(remove_0x_prefix(self.tx_hash)))
        # case 3: when tx_hash is invalid - too short
        self.assertRaises(DataTypeException,
                          self.icon_service.get_transaction_result,
                          self.tx_hash[:15])
        # case 4: when tx_hash is invalid - not exist
        tx_hash_invalid = add_0x_prefix(os.urandom(32).hex())
        self.assertRaises(JSONRPCException,
                          self.icon_service.get_transaction_result,
                          tx_hash_invalid)