def test_getblockcount_many(self): blockhash0 = "00008c0c84aee66413f1e8ff95fdca5e8ebf35c94b090290077cdcea64936301" blockhash1 = "0000b9fc70e9a8bb863a8c37f0f3d10d4d3e99e0e94bd42b35f0fdbb497399eb" blocks = [ {"hash": blockhash0}, {"hash": blockhash1, "previousblockhash": blockhash0}, ] proxy = FakeBitcoinProxy(blocks=blocks) count = proxy.getblockcount() self.assertEqual(count, len(blocks) - 1)
def test__batch_getblockhash_many(self): block_count = 100 blocks = [] previous_blockhash = None for counter in range(0, block_count): blockhash = "00008c0c84aee66413f1e8ff95fdca5e8ebf35c94b090290077cdcea649{}".format(counter) block_data = { "hash": blockhash, } if previous_blockhash: block_data["previous_blockhash"] = previous_blockhash blocks.append(block_data) previous_blockhash = blockhash proxy = FakeBitcoinProxy(blocks=blocks) count = proxy.getblockcount() self.assertEqual(count, len(blocks) - 1) requests = [] for counter in range(0, count + 1): # from 0 to len(blocks) request = make_rpc_batch_request_entry("getblockhash", [counter]) requests.append(request) results = proxy._batch(requests) self.assertEqual(type(results), list) self.assertEqual(len(results), len(requests)) for (counter, result) in enumerate(results): self.assertEqual(result["error"], None) expected_blockhash = "00008c0c84aee66413f1e8ff95fdca5e8ebf35c94b090290077cdcea649{}".format(counter) self.assertEqual(result["result"], expected_blockhash)
def test_getblockcount_zero(self): blocks = [] proxy = FakeBitcoinProxy(blocks=blocks) count = proxy.getblockcount() self.assertEqual(count, len(blocks) - 1)