tAdd test for blockchain_transaction_get. - obelisk - Electrum server using libbitcoin as its backend HTML git clone https://git.parazyd.org/obelisk DIR Log DIR Files DIR Refs DIR README DIR LICENSE --- DIR commit 1b7192db606c869ab0a78fd04e4888f043051543 DIR parent f63d6b87ae4ef3469f6066718700ca6f821f7a42 HTML Author: parazyd <parazyd@dyne.org> Date: Fri, 9 Apr 2021 15:44:04 +0200 Add test for blockchain_transaction_get. Diffstat: M electrumobelisk/protocol.py | 4 ++-- M electrumobelisk/zeromq.py | 4 ++-- M test.py | 18 ++++++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) --- DIR diff --git a/electrumobelisk/protocol.py b/electrumobelisk/protocol.py t@@ -507,13 +507,13 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 # Behaviour is undefined in spec if not rawtx: - return {"result", None} + return {"result": None} if verbose: # TODO: Help needed return ERRORS["invalidrequest"] - return {"result", safe_hexlify(rawtx)} + return {"result": bh2u(rawtx)} async def blockchain_transaction_get_merkle(self, writer, query): # pylint: disable=W0613 """Method: blockchain.transaction.get_merkle DIR diff --git a/electrumobelisk/zeromq.py b/electrumobelisk/zeromq.py t@@ -324,7 +324,7 @@ class Client: bytes.fromhex(txid)[::-1]) if error_code: return error_code, None - return error_code, bh2u(data) + return error_code, data async def fetch_mempool_transaction(self, txid): """Fetch transaction by txid (including mempool)""" t@@ -334,7 +334,7 @@ class Client: bytes.fromhex(txid)[::-1]) if error_code: return error_code, None - return error_code, bh2u(data) + return error_code, data async def subscribe_scripthash(self, scripthash): """Subscribe to scripthash""" DIR diff --git a/test.py b/test.py t@@ -105,7 +105,6 @@ async def test_blockchain_scripthash_get_balance(protocol, writer): for i in expect: if res[expect.index(i)] != i: return "blockchain_scripthash_get_balance", False - return "blockchain_scripthash_get_balance", True t@@ -143,7 +142,6 @@ async def test_blockchain_scripthash_get_history(protocol, writer): if expect != res: return "blockchain_scripthash_get_history", False - return "blockchain_scripthash_get_history", True t@@ -171,10 +169,22 @@ async def test_blockchain_scripthash_listunspent(protocol, writer): if res != expect: return "blockchain_scripthash_listunspent", False - return "blockchain_scripthash_listunspent", True +async def test_blockchain_transaction_get(protocol, writer): + expect = "020000000001011caa5f4ba91ff0ab77712851c1b17943e68f28d46bb0d96cbc13cdbef53c2b87000000001716001412e6e94028ab399b67c1232383d12f1dd3fc03b5feffffff02a40111000000000017a914ff1d7f4c85c562764ca16daa11e97d10eda52ebf87a0860100000000001976a9144a0360eac874a569e82ca6b17274d90bccbcab5e88ac0247304402205392417f5ffba2c0f3a501476fb6872368b2065c53bf18b2a201691fb88cdbe5022016c68ec9e094ba2b06d4bdc6af996ac74b580ab9728c622bb5304aaff04cb6980121031092742ffdf5901ceafcccec090c58170ce1d0ec26963ef7c7a2738a415a317e0b121e00" + params = { + "params": + ["a9c3c22cc2589284288b28e802ea81723d649210d59dfa7e03af00475f4cec20"] + } + data = await protocol.blockchain_transaction_get(writer, params) + + if "result" not in data and data["result"] != expect: + return "blockchain_transaction_get", False + return "blockchain_transaction_get", True + + class MockWriter(asyncio.StreamWriter): """Mock class for StreamWriter""" def __init__(self): t@@ -207,7 +217,7 @@ async def main(): # test_blockchain_scripthash_subscribe, # test_blockchain_scripthash_unsubscribe, # test_blockchain_transaction_broadcast, - # test_blockchain_transaction_get, + test_blockchain_transaction_get, # test_blockchain_transaction_get_merkle, # test_blockchain_transaction_from_pos, # test_mempool_get_fee_histogram,