def test_request_get_headers_very_long_chain(self, mock): first_block = Block(CBlock(), BlockOrigin.public) first_block.prevBlock = None first_block.cached_hash = '0' tmp = first_block for i in range(1, 17): block = Block(CBlock(), BlockOrigin.public) block.prevBlock = tmp block.cached_hash = str(i) tmp = block mock.return_value = tmp headers = chainutil.request_get_headers([MagicMock()], BlockOrigin.public) self.assertEqual(len(headers), 5) self.assertEqual(headers[0], '16') self.assertEqual(headers[1], '15') self.assertEqual(headers[2], '13') self.assertEqual(headers[3], '9') self.assertEqual(headers[4], '1')
def test_adopt_two_blocks_lead_public(self): third_block_chain_b = Block(CBlock(), BlockOrigin.public) third_block_chain_b.height = 3 third_block_chain_b.prevBlock = self.second_block_chain_b third_block_chain_b.cached_hash = '3b' self.executor.execute(Action.adopt, self.first_block_chain_a, third_block_chain_b) self.assertTrue(self.networking.send_inv.called) blocks = [block.hash() for block in self.networking.send_inv.call_args[0][0]] self.assertEqual(len(blocks), 3) self.assertTrue('1b' in blocks) self.assertTrue('2b' in blocks) self.assertTrue('3b' in blocks)
def test_override_two_blocks_lead_private(self): third_block_chain_a = Block(CBlock(), BlockOrigin.private) third_block_chain_a.height = 3 third_block_chain_a.prevBlock = self.second_block_chain_a third_block_chain_a.cached_hash = '3a' self.executor.execute(Action.override, third_block_chain_a, self.first_block_chain_b) self.assertTrue(self.networking.send_inv.called) blocks = [block.hash() for block in self.networking.send_inv.call_args[0][0]] self.assertEqual(len(blocks), 3) self.assertTrue('1a' in blocks) self.assertTrue('2a' in blocks) self.assertTrue('1b' in blocks)