Beispiel #1
0
def test_from_serialized_raises_value_error_if_transaction_type_does_not_exist(
):
    serialized_hex = b"ffffff7b"
    with pytest.raises(ValueError) as excinfo:
        from_serialized(serialized_hex)
    assert str(
        excinfo.value) == "Couldn't find transaction type 123 in mapping"
Beispiel #2
0
    def get_blocks(self, height, limit, serialized, with_transactions=False):
        blocks = (Block.select().where(
            Block.height.between(height,
                                 height + limit)).order_by(Block.height.asc()))

        if with_transactions:
            block_ids = [block.id for block in blocks]
            transactions = (Transaction.select().where(
                Transaction.block_id.in_(block_ids)).order_by(
                    Transaction.block_id.asc(), Transaction.sequence.asc()))

            transactions_map = defaultdict(list)
            for trans in transactions:
                # TODO: implement from_object on transaction and use that, instead of
                # creating it from serialized data.
                if serialized:
                    transactions_map[trans.block_id].append(trans.serialized)
                else:
                    transactions_map[trans.block_id].append(
                        from_serialized(trans.serialized))
        crypto_blocks = []
        for block in blocks:
            crypto_block = CryptoBlock.from_object(block)
            if with_transactions:
                crypto_block.transactions = transactions_map[block.id]
            crypto_blocks.append(crypto_block)
        return crypto_blocks
Beispiel #3
0
 def _deserialize_transactions(self, buff):
     transaction_lenghts = []
     for _ in range(self.number_of_transactions):
         transaction_lenghts.append(buff.pop_uint32())
     self.transactions = []
     for trans_len in transaction_lenghts:
         serialized_hex = hexlify(buff.pop_bytes(trans_len))
         self.transactions.append(from_serialized(serialized_hex))
Beispiel #4
0
def test_from_serialized_raises_type_error_if_hex_not_bytes():
    with pytest.raises(TypeError) as excinfo:
        from_serialized("not_bytes")
    assert str(excinfo.value) == "serialized_hex must be bytes"
Beispiel #5
0
def test_from_serialized(dummy_transaction_hash):
    transaction = from_serialized(dummy_transaction_hash)
    assert isinstance(transaction, TransferTransaction)
    assert (transaction.id ==
            "f861b25c9a87fc8913282da8855ee63b9cbaa9324543377a5bdfc5afccb92aaa")