Beispiel #1
0
    def test_handle_tx_with_an_invalid_format(self):
        tx_bytes = \
            b"\xf8k" \
            b"!" \
            b"\x85\x0b\xdf\xd6>\x00\x82R\x08\x94\xf8\x04O\xf8$\xc2\xdc\xe1t\xb4\xee\x9f\x95\x8c*s\x84\x83" \
            b"\x18\x9e\x87\t<\xaf\xacj\x80\x00\x80&\xa0-\xbf,\xa9+\xae\xabJ\x03\xcd\xfa\xe3<\xbf$\x00e\xe2N|\xc9" \
            b"\xf7\xe2\xa9\x9c>\xdfn\x0cO\xc0\x16"

        result = transaction_validation.validate_transaction(
            tx_bytes,
            BlockchainProtocol(self.node.network.protocol.lower()),
            self.node.get_network_min_transaction_fee()
        )

        self.assertEqual(TxValidationStatus.INVALID_FORMAT, result)
Beispiel #2
0
    def test_handle_tx_with_an_invalid_signature(self):
        tx_bytes = \
            b"\xf8k" \
            b"!" \
            b"\x85\x0b\xdf\xd6>\x00" \
            b"\x82R\x08\x94" \
            b"\xf8\x04O\xf8$\xc2\xdc\xe1t\xb4\xee\x9f\x95\x8c*s\x84\x83\x18\x9e" \
            b"\x87\t<\xaf\xacj\x80\x00\x80" \
            b"!" \
            b"\xa0-\xbf,\xa9+\xae\xabJ\x03\xcd\xfa\xe3<\xbf$\x00e\xe2N|\xc9\xf7\xe2\xa9\x9c>\xdfn\x0cO\xc0\x16" \
            b"\xa0)\x11K=;\x96X}a\xd5\x00\x06eSz\xd1,\xe4>\xa1\x8c\xf8\x7f>\x0e:\xd1\xcd\x00?'?"

        result = transaction_validation.validate_transaction(
            tx_bytes,
            BlockchainProtocol(self.node.network.protocol.lower()),
            self.node.get_network_min_transaction_fee()
        )

        self.assertEqual(TxValidationStatus.INVALID_SIGNATURE, result)
Beispiel #3
0
    def test_handle_tx_with_low_fee(self):
        self.node.feed_manager.publish_to_feed = MagicMock()
        self.node.opts.ws = False

        tx_bytes = \
            b"\xf8k" \
            b"!" \
            b"\x85\x0b\xdf\xd6>\x00\x82R\x08\x94\xf8\x04O\xf8$\xc2\xdc\xe1t\xb4\xee\x9f\x95\x8c*s\x84\x83" \
            b"\x18\x9e\x87\t<\xaf\xacj\x80\x00\x80" \
            b"&" \
            b"\xa0" \
            b"-\xbf,\xa9+\xae\xabJ\x03\xcd\xfa\xe3<\xbf$\x00e\xe2N|\xc9\xf7\xe2\xa9\x9c>\xdfn\x0cO\xc0\x16" \
            b"\xa0)\x11K=;\x96X}a\xd5\x00\x06eSz\xd1,\xe4>\xa1\x8c\xf8\x7f>\x0e:\xd1\xcd\x00?'\x15"

        result = transaction_validation.validate_transaction(
            tx_bytes,
            BlockchainProtocol(self.node.network.protocol.lower()),
            510000000000
        )
        self.assertEqual(TxValidationStatus.LOW_FEE, result)
    def process_transactions_message_from_node(
        self,
        msg: Union[TxBtcMessage, TransactionsEthProtocolMessage, OntTxMessage],
        min_tx_network_fee: int,
        enable_transaction_validation: bool
    ) -> List[ProcessTransactionMessageFromNodeResult]:
        message_converter = cast(AbstractMessageConverter, self.node.message_converter)

        account_id = self.node.account_id if self.node.account_id is not None else constants.DECODED_EMPTY_ACCOUNT_ID
        # avoid filtering low fee transactions in tx_to_bx_txs to match extensions behavior
        bx_tx_messages = message_converter.tx_to_bx_txs(
            msg, self.network_num, self.node.default_tx_flag, min_tx_network_fee=0, account_id=account_id
        )

        result = []
        blockchain_protocol = BlockchainProtocol(self.network.protocol.lower())

        for bx_tx_message, tx_hash, tx_bytes in bx_tx_messages:
            transaction_key = self.get_transaction_key(tx_hash)
            tx_cache_key = self._tx_hash_to_cache_key(tx_hash)
            tx_seen_flag = (
                self.has_transaction_contents_by_cache_key(tx_cache_key)
                or self.removed_transaction_by_cache_key(tx_cache_key)
            )

            if not tx_seen_flag:
                self.set_transaction_contents_by_key(transaction_key, tx_bytes)

            tx_validation_status = TxValidationStatus.VALID_TX
            if enable_transaction_validation:
                tx_validation_status = transaction_validation.validate_transaction(
                    tx_bytes, blockchain_protocol, min_tx_network_fee
                )

            result.append(
                ProcessTransactionMessageFromNodeResult(
                    tx_seen_flag, tx_hash, tx_bytes, bx_tx_message, tx_validation_status
                )
            )

        return result
Beispiel #5
0
    def process_transactions_message_from_node(
        self,
        msg: Union[TxBtcMessage, TransactionsEthProtocolMessage, OntTxMessage],
        min_tx_network_fee: int,
        enable_transaction_validation: bool
    ) -> List[ProcessTransactionMessageFromNodeResult]:
        message_converter = cast(AbstractMessageConverter, self.node.message_converter)

        # avoid filtering low fee transactions in tx_to_bx_txs to match extensions behavior
        bx_tx_messages = message_converter.tx_to_bx_txs(
            msg, self.network_num, self.node.default_tx_quota_type, min_tx_network_fee=0
        )

        result = []
        blockchain_protocol = BlockchainProtocol(self.network.protocol.lower())

        for bx_tx_message, tx_hash, tx_bytes in bx_tx_messages:
            tx_cache_key = self._tx_hash_to_cache_key(tx_hash)
            tx_seen_flag = self.has_transaction_contents_by_cache_key(tx_cache_key)

            if not tx_seen_flag:
                self.set_transaction_contents(tx_hash, tx_bytes)

            tx_validation_status = TxValidationStatus.VALID_TX
            if enable_transaction_validation:
                tx_validation_status = transaction_validation.validate_transaction(
                    tx_bytes, blockchain_protocol, min_tx_network_fee
                )

            result.append(
                ProcessTransactionMessageFromNodeResult(
                    tx_seen_flag, tx_hash, tx_bytes, bx_tx_message, tx_validation_status
                )
            )

        return result