def test_block_message(self): message = messages.msg_block() cblock = CBlock() message.block = cblock block = Block(None, BlockOrigin.private) block.cached_hash = message.block.GetHash() self.chain.blocks = {block.hash(): block} self.networking.block_message(self.private_connection, message) self.assertEqual(self.chain.blocks[block.hash()].cblock, cblock)
def test_block_message_remove_from_blocks_in_flight(self): message = messages.msg_block() cblock = CBlock() message.block = cblock block = Block(None, BlockOrigin.private) block.cached_hash = message.block.GetHash() self.chain.blocks = {block.hash(): block} self.networking.blocks_in_flight = {block.hash(): 'in_flight'} self.networking.block_message(self.private_connection, message) self.assertEqual(len(self.networking.blocks_in_flight), 0)
def test_block(self): args = (0, "0", int(time.time()), "test") nonce = 0 target = "f" * 64 hash = Block.calculate_hash(*args, nonce, target) b = Block(*args, nonce=nonce, target=target, hash=hash) self.assertSerializable(Block, b, globals()) self.assertTrue(b.valid) b.hash = "aaa" self.assertFalse(b.valid)
def test_headers_message_known_blocks(self): cblock1 = CBlock(nNonce=1) block1 = Block(cblock1, None) cblock2 = CBlock(nNonce=2) block2 = Block(cblock2, None) self.chain.blocks = {block1.hash(): block1, block2.hash(): block2} self.networking.request_blocks = MagicMock() message = messages.msg_headers() message.headers = [cblock1.get_header(), cblock2.get_header()] self.networking.headers_message(self.public_connection1, message) self.assertFalse(self.public_connection1.send.called) self.assertFalse(self.chain.process_header.called) self.assertFalse(self.private_connection.send.called) self.assertTrue(self.networking.request_blocks.called) self.assertEqual(len(self.networking.request_blocks.call_args[0][1]), 0)
def test_block_message_two_times(self): message = messages.msg_block() cblock1 = CBlock(nNonce=1) cblock2 = CBlock(nNonce=2) message.block = cblock1 block = Block(None, BlockOrigin.private) block.cached_hash = message.block.GetHash() self.chain.blocks = {block.hash(): block} self.networking.block_message(self.private_connection, message) message.block = cblock2 self.networking.block_message(self.private_connection, message)