def test__batch_result_error_is_none(self):
     proxy = FakeBitcoinProxy()
     request = make_rpc_batch_request_entry("getblockcount", [])
     requests = [request]
     results = proxy._batch(requests)
     result = results[0]
     self.assertEqual(result["error"], None)
 def test__batch_empty_list_input(self):
     requests = []
     self.assertEqual(len(requests), 0)  # must be empty for test
     proxy = FakeBitcoinProxy()
     results = proxy._batch(requests)
     self.assertEqual(type(results), list)
     self.assertEqual(len(results), 0)
 def test__batch_result_keys(self):
     expected_keys = ["error", "id", "result"]
     proxy = FakeBitcoinProxy()
     request = make_rpc_batch_request_entry("getblockcount", [])
     requests = [request]
     results = proxy._batch(requests)
     result = results[0]
     self.assertTrue(
         all([
             expected_key in result.keys() for expected_key in expected_keys
         ]))
 def test__batch_returns_error_when_given_invalid_params(self):
     params = 1
     proxy = FakeBitcoinProxy()
     request = make_rpc_batch_request_entry("getblockcount", params)
     requests = [request]
     results = proxy._batch(requests)
     result = results[0]
     self.assertEqual(type(result), dict)
     self.assertIn("error", result.keys())
     self.assertIn("id", result.keys())
     self.assertIn("result", result.keys())
     self.assertEqual(result["result"], None)
     self.assertEqual(type(result["error"]), dict)
     self.assertIn("message", result["error"].keys())
     self.assertIn("code", result["error"].keys())
     self.assertEqual(result["error"]["message"], "Params must be an array")
    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__batch_gives_reasonable_getblockcount_result(self):
     proxy = FakeBitcoinProxy()
     request = make_rpc_batch_request_entry("getblockcount", [])
     requests = [request]
     results = proxy._batch(requests)
     self.assertEqual(results[0]["result"], -1)
 def test__batch_same_count_results_as_requests(self):
     proxy = FakeBitcoinProxy()
     request = make_rpc_batch_request_entry("getblockcount", [])
     requests = [request]
     results = proxy._batch(requests)
     self.assertEqual(len(requests), len(results))
 def test__batch_raises_when_no_params(self):
     proxy = FakeBitcoinProxy()
     with self.assertRaises(TypeError):
         proxy._batch()