Example #1
0
    def _set_samples(self, domain: str) -> (list, list, list, list):
        buf_blocks = list()
        buf_transactions_on_blocks = list(
        )  # block's transaction list which means confirmed transaction list
        buf_transactions = list()  # return value of 'get_transaction'
        buf_transaction_results = list(
        )  # return value of 'get_transaction_result'

        icon_service = IconService(HTTPProvider(domain, VERSION_FOR_TEST))
        target_block_heights = self._set_target_heights()
        for height in target_block_heights:
            block = icon_service.get_block(height, full_response=True)
            block = block['result']
            buf_blocks.append(block)
            for transaction in block[
                    'confirmed_transaction_list' if block['version'] ==
                    BLOCK_0_1A_VERSION else 'transactions']:
                buf_transactions_on_blocks.append(transaction)

                if ('tx_hash' or 'txHash') in transaction:
                    tx_hash = transaction['tx_hash' if 'tx_hash' in
                                          transaction else 'txHash']
                    tx_hash = add_0x_prefix(tx_hash)
                    tx = icon_service.get_transaction(tx_hash,
                                                      full_response=True)
                    tx = tx['result']
                    buf_transactions.append(tx)
                    tx_result = icon_service.get_transaction_result(
                        tx_hash, full_response=True)
                    tx_result = tx_result['result']
                    buf_transaction_results.append(tx_result)

        return buf_blocks, buf_transactions_on_blocks, buf_transactions, buf_transaction_results
    def test_integrate_converter(self):
        """
        Test integrating for the converter which checks that all of the data
        about the block, transaction, and transaction result have the right format.

        [Purpose]
        Check all of the data about the block, transaction, and transaction result.

        [Scenario]
        1. Get the last block data and validate the block data.
        2. Get all of the transaction data on that block and validate the transaction data.
        3. Get all of the transaction result data on that transaction and validate the transaction result data.
        4. Repeatedly, get the other blocks from the last to the first and validate all of three kinds of the data.
        """
        logger = getLogger("TEST CONVERTER")

        # No need to use logging, remove the line.
        set_logger(logger, 'DEBUG')

        logger.debug("TEST CONVERTER START")

        icon_service = IconService(HTTPProvider(TEST_HTTP_ENDPOINT_URI_V3))

        # Scenario 1: Get the last block data and validate the block data.
        last_block_height = icon_service.get_block("latest")["height"]

        for height in range(
                0, last_block_height if last_block_height < 30 else 30):
            # Scenario 2: Get all of the transaction data on that block and validate the transaction data.
            block = icon_service.get_block(height)
            # pprint.pprint(block)
            self.assertTrue(validate_block(block))

            # Except for the genesis block
            if height > 0:
                for transaction_in_block in block[
                        "confirmed_transaction_list"]:
                    # Scenario 3: Get all of the transaction result data on that transaction
                    # and validate the transaction result data.
                    transaction_result = icon_service.get_transaction_result(
                        transaction_in_block["txHash"])
                    # logger.debug(transaction_result)
                    # pprint.pprint(transaction_result)
                    self.assertTrue(
                        validate_transaction_result(transaction_result))
                    # Scenario 4: Repeatedly, get the other blocks from the last to the first
                    # and validate all of three kinds of the data.
                    transaction = icon_service.get_transaction(
                        transaction_in_block["txHash"])
                    # logger.debug(transaction)
                    # pprint.pprint(transaction)
                    self.assertTrue(validate_transaction(transaction))
    def txbyhash(self, conf):
        """Query transaction using given transaction hash.

        :param conf: txbyhash command configuration.
        :return: result of query.
        """
        uri, version = uri_parser(conf['uri'])
        icon_service = IconService(HTTPProvider(uri, version))

        response = icon_service.get_transaction(conf['hash'], True)

        if "error" in response:
            print('Got an error response')
            print(f"Can not get transaction \n{json.dumps(response, indent=4)}")
        else:
            print(f"Transaction : {json.dumps(response, indent=4)}")

        return response
    def test_integrate_converter(self):
        """
        Test integrating for the converter which checks that all of the data
        about the block, transaction, and transaction result have the right format.

        [Purpose]
        Check all of the data about the block, transaction, and transaction result.

        [Scenario]
        1. Get the last block data and validate the block data.
        2. Get all of the transaction data on that block and validate the transaction data.
        3. Get all of the transaction result data on that transaction and validate the transaction result data.
        4. Repeatedly, get the other blocks from the last to the first and validate all of three kinds of the data.
        """
        icon_service = IconService(HTTPProvider(BASE_DOMAIN_URL_V3_FOR_TEST, VERSION_FOR_TEST))

        # Scenario 1: Get the last block data and validate the block data.
        last_block_height = icon_service.get_block("latest")["height"]

        for height in range(0, last_block_height if last_block_height < 30 else 30):
            # Scenario 2: Get all of the transaction data on that block and validate the transaction data.
            block = icon_service.get_block(height)
            # pprint.pprint(block)
            self.assertTrue(validate_block(block))

            # Except for the genesis block
            if height > 0:
                for transaction_in_block in block["confirmed_transaction_list"]:
                    # Scenario 3: Get all of the transaction result data on that transaction
                    # and validate the transaction result data.
                    transaction_result = icon_service.get_transaction_result(transaction_in_block["txHash"])
                    # logger.debug(transaction_result)
                    # pprint.pprint(transaction_result)
                    self.assertTrue(validate_transaction_result(transaction_result))
                    # Scenario 4: Repeatedly, get the other blocks from the last to the first
                    # and validate all of three kinds of the data.
                    transaction = icon_service.get_transaction(transaction_in_block["txHash"])
                    # logger.debug(transaction)
                    # pprint.pprint(transaction)
                    self.assertTrue(validate_transaction(transaction))
print("Loading transactions ...")
transactions = json.loads(open("transactions.json", "r").read())

# Creates an IconService instance using the HTTP provider and set a provider.
icon_service = IconService(HTTPProvider("https://wallet.icon.foundation", 3))

results = json.loads(open("results.json", "r+").read())

for index, txHash in enumerate(transactions):

    print("%d / %d ..." % (index, len(transactions)))
    if txHash in results:
        print("%s already present" % txHash)
        continue

    tx_result = icon_service.get_transaction(txHash)

    if tx_result['dataType'] and tx_result['dataType'] == 'call':
        results[txHash] = {
            'from': tx_result['from'],
            'timestamp': tx_result['timestamp'],
            'txHash': tx_result['txHash'],
            'blockHeight': tx_result['blockHeight'],
            'method': tx_result['data']['method']
        }
        open("results.json", "w+").write(json.dumps(results))

print("Saving database ...")
open("results.json", "w+").write(json.dumps(results))
Example #6
0
    def test_integrate_converter(self):
        """
        Test integrating for the converter which checks that all of the data
        about the block, transaction, and transaction result have the right format.

        [Purpose]
        Check all of the data about the block, transaction, and transaction result.

        [Scenario]
        1. Get the last block data and validate the block data.
        2. Get all of the transaction data on that block and validate the transaction data.
        3. Get all of the transaction result data on that transaction and validate the transaction result data.
        4. Repeatedly, get the other blocks from the last to the first and validate all of three kinds of the data.
        """
        test_domains = self.domains + [BASE_DOMAIN_URL_V3_FOR_TEST]
        max_block_height = 100
        for domain in test_domains:
            icon_service = IconService(HTTPProvider(domain, VERSION_FOR_TEST))
            last_block_height = icon_service.get_block("latest")["height"]
            block_versions = [BLOCK_0_1A_VERSION, BLOCK_0_3_VERSION]
            for block_version in block_versions:
                if block_version == BLOCK_0_1A_VERSION:
                    block_template = BLOCK_0_1a
                    key_name_of_transactions = 'confirmed_transaction_list'
                else:
                    # After Mainnet apply for block 0.3, remove this remark right away.
                    continue

                    block_template = BLOCK_0_3
                    key_name_of_transactions = 'transactions'

                for height in range(last_block_height if last_block_height <
                                    max_block_height else max_block_height):
                    # Check block
                    block = icon_service.get_block(height,
                                                   full_response=True,
                                                   block_version=block_version)
                    block = block['result']
                    converted_block = icon_service.get_block(
                        height, block_version=block_version)
                    block_template = get_block_template_to_convert_transactions_for_genesis(
                        block, block_template)
                    self.assertTrue(
                        validate_block(block_template, block, converted_block))

                    if block["height"] == 0:
                        continue

                    for transaction_in_block in converted_block[
                            key_name_of_transactions]:
                        # Check transaction result
                        tx_result = icon_service.get_transaction_result(
                            transaction_in_block["txHash"], True)
                        tx_result = tx_result['result']
                        converted_transaction_result = icon_service.get_transaction_result(
                            transaction_in_block["txHash"])
                        self.assertTrue(
                            validate_transaction_result(
                                TRANSACTION_RESULT, tx_result,
                                converted_transaction_result))

                        # Check transaction
                        transaction = icon_service.get_transaction(
                            transaction_in_block["txHash"], True)
                        transaction = transaction['result']
                        converted_transaction = icon_service.get_transaction(
                            transaction_in_block["txHash"])
                        self.assertTrue(
                            validate_transaction(TRANSACTION, transaction,
                                                 converted_transaction))