Exemple #1
0
def test_from_serialized_correctly_deserializes_full_data(
        dummy_block_full_hash, dummy_block):
    block = Block.from_serialized(dummy_block_full_hash)
    assert block.version == 0
    assert block.timestamp == 24760440
    assert block.height == 2243161
    assert block.previous_block_hex == b"2b324b8b33a85802"
    assert block.previous_block == "3112633353705641986"
    assert block.number_of_transactions == 2
    assert block.total_amount == 3890300
    assert block.total_fee == 70000000
    assert block.reward == 200000000
    assert block.payload_length == 224
    assert block.payload_hash == (
        "3784b953afcf936bdffd43fdf005b5732b49c1fc6b11e195c364c20b2eb06282")
    assert block.generator_public_key == (
        "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325")
    assert block.block_signature == (
        "3045022100eee6c37b5e592e99811d588532726353592923f347c701d52912e6d583443e40022"
        "0277ffe38ad31e216ba0907c4738fed19b2071246b150c72c0a52bae4477ebe29")
    assert block.id == "10977713934532967004"
    assert block.id_hex == b"9858aca939b17a5c"
    assert block.transactions is not None
    assert len(block.transactions) == 2
    for transaction, expected in zip(block.transactions,
                                     dummy_block["transactions"]):
        assert transaction.version == 1
        assert transaction.network == 23
        assert transaction.type == expected["type"]
        assert transaction.timestamp == expected["timestamp"]
        assert transaction.sender_public_key == expected["senderPublicKey"]
        assert transaction.fee == expected["fee"]
        assert transaction.amount == expected["amount"]
        assert transaction.asset == expected["asset"]
Exemple #2
0
    def consume_queue(self):
        while True:
            serialized_block = self.process_queue.pop_block()
            if serialized_block:
                last_block = self.database.get_last_block()
                block = Block.from_serialized(serialized_block)
                status = self.process_block(block, last_block)
                logger.info(status)
                if status in [BLOCK_ACCEPTED, BLOCK_DISCARDED_BUT_CAN_BE_BROADCASTED]:
                    # TODO: Broadcast only current block
                    milestone = config.get_milestone(block.height)
                    current_slot = slots.get_slot_number(block.height, time.get_time())
                    if current_slot * milestone["blocktime"] <= block.timestamp:
                        # TODO: THIS IS MISSING
                        logger.error("MISSING: IMPLEMENT BROADCASTING")
            else:
                # TODO: change this
                logger.info("Nothing to process. Sleeping for 1 sec")
                sleep(1)

            # Our chain can get out of sync when it doesn't receive all the blocks
            # to the p2p endpoint, so if we're not in sync, force sync to the last
            # block
            last_block = self.database.get_last_block()
            if not self.is_synced(last_block):
                logger.info("Force syncing with the network as we got out of sync")
                self.sync_chain()
                logger.info("Done force syncing")
Exemple #3
0
def test_from_serialized_correctly_sets_deserialized_types(
        dummy_block_hash, dummy_block):
    block = Block.from_serialized(dummy_block_hash)

    assert isinstance(block.version, int)
    assert isinstance(block.timestamp, int)
    assert isinstance(block.height, int)
    assert isinstance(block.previous_block_hex, bytes)
    assert isinstance(block.previous_block, str)
    assert isinstance(block.number_of_transactions, int)
    assert isinstance(block.total_amount, int)
    assert isinstance(block.total_fee, int)
    assert isinstance(block.reward, int)
    assert isinstance(block.payload_length, int)
    assert isinstance(block.payload_hash, str)
    assert isinstance(block.generator_public_key, str)
    assert isinstance(block.block_signature, str)
    assert isinstance(block.id, str)
    assert isinstance(block.id_hex, bytes)
    assert isinstance(block.transactions, list)