obelisk

Electrum server using libbitcoin as its backend
git clone https://git.parazyd.org/obelisk
Log | Files | Refs | README | LICENSE

commit 6bdd6ef5754fa88ddcb3736fbd9acd8a37db2e58
parent 82ce1faffe224f34f490d96c3b658216c5a60316
Author: parazyd <parazyd@dyne.org>
Date:   Fri, 16 Apr 2021 12:43:08 +0200

Add more test units.

Diffstat:
Mobelisk/protocol.py | 4++--
Mtests/test_electrum_protocol.py | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 57 insertions(+), 18 deletions(-)

diff --git a/obelisk/protocol.py b/obelisk/protocol.py @@ -75,7 +75,7 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 elif chain == "testnet": self.genesis = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943" else: - raise ValueError(f"Invalid chain '{chain}'") + raise ValueError(f"Invalid chain '{chain}'") # pragma: no cover # Here we map available methods to their respective functions self.methodmap = { @@ -648,7 +648,7 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 """ return {"result": DONATION_ADDR} - async def server_features(self, writer, query): # pylint: disable=W0613 + async def server_features(self, writer, query): # pylint: disable=W0613 # pragma: no cover """Method: server.features Return a list of features and services supported by the server. """ diff --git a/tests/test_electrum_protocol.py b/tests/test_electrum_protocol.py @@ -85,6 +85,20 @@ def assert_equal(data, expect): # pragma: no cover raise +async def test_server_version(protocol, writer, method): + params = ["obelisk 42", [SERVER_PROTO_MIN, SERVER_PROTO_MAX]] + expect = {"result": [f"obelisk {VERSION}", SERVER_PROTO_MAX]} + data = await protocol.server_version(writer, {"params": params}) + assert_equal(data["result"], expect["result"]) + + +async def test_ping(protocol, writer, method): + params = [] + expect = get_expect(method, params) + data = await protocol.ping(writer, {"params": params}) + assert_equal(data["result"], expect["result"]) + + async def test_block_header(protocol, writer, method): params = [[123], [1, 5]] for i in params: @@ -101,6 +115,13 @@ async def test_block_headers(protocol, writer, method): assert_equal(data["result"], expect["result"]) +async def test_estimatefee(protocol, writer, method): + params = [2] + expect = -1 + data = await protocol.estimatefee(writer, {"params": params}) + assert_equal(data["result"], expect) + + async def test_headers_subscribe(protocol, writer, method): params = [[]] for i in params: @@ -109,6 +130,12 @@ async def test_headers_subscribe(protocol, writer, method): assert_equal(data["result"], expect["result"]) +async def test_relayfee(protocol, writer, method): + expect = 0.00001 + data = await protocol.relayfee(writer, {"params": []}) + assert_equal(data["result"], expect) + + async def test_scripthash_get_balance(protocol, writer, method): params = [ ["c036b0ff3ad79662cd517cd5fe1fa0af07377b9262d16f276f11ced69aaa6921"], @@ -194,18 +221,29 @@ async def test_transaction_id_from_pos(protocol, writer, method): assert_equal(data["result"], expect["result"]) -async def test_ping(protocol, writer, method): - params = [] - expect = get_expect(method, params) - data = await protocol.ping(writer, {"params": params}) - assert_equal(data["result"], expect["result"]) +async def test_get_fee_histogram(protocol, writer, method): + data = await protocol.get_fee_histogram(writer, {"params": []}) + assert_equal(data["result"], [[0, 0]]) -async def test_server_version(protocol, writer, method): - params = ["obelisk 42", [SERVER_PROTO_MIN, SERVER_PROTO_MAX]] - expect = {"result": [f"obelisk {VERSION}", SERVER_PROTO_MAX]} - data = await protocol.server_version(writer, {"params": params}) - assert_equal(data["result"], expect["result"]) +async def test_add_peer(protocol, writer, method): + data = await protocol.add_peer(writer, {"params": []}) + assert_equal(data["result"], False) + + +async def test_banner(protocol, writer, method): + data = await protocol.banner(writer, {"params": []}) + assert_equal(type(data["result"]), str) + + +async def test_donation_address(protocol, writer, method): + data = await protocol.donation_address(writer, {"params": []}) + assert_equal(type(data["result"]), str) + + +async def test_peers_subscribe(protocol, writer, method): + data = await protocol.peers_subscribe(writer, {"params": []}) + assert_equal(data["result"], []) class MockWriter(asyncio.StreamWriter): # pragma: no cover @@ -227,9 +265,9 @@ orchestration = { "server.ping": test_ping, "blockchain.block.header": test_block_header, "blockchain.block.headers": test_block_headers, - # "blockchain.estimatefee": test_estimatefee, + "blockchain.estimatefee": test_estimatefee, "blockchain.headers.subscribe": test_headers_subscribe, - # "blockchain.relayfee": test_relayfee, + "blockchain.relayfee": test_relayfee, "blockchain.scripthash.get_balance": test_scripthash_get_balance, "blockchain.scripthash.get_history": test_scripthash_get_history, # "blockchain.scripthash.get_mempool": test_scripthash_get_mempool, @@ -240,11 +278,12 @@ orchestration = { "blockchain.transaction.get": test_transaction_get, "blockchain.transaction.get_merkle": test_transaction_get_merkle, "blockchain.transaction.id_from_pos": test_transaction_id_from_pos, - # "mempool.get_fee_histogram": test_get_fee_histogram, - # "server.add_peer": test_add_peer, - # "server.donation_address": test_donation_address, + "mempool.get_fee_histogram": test_get_fee_histogram, + "server.add_peer": test_add_peer, + "server.banner": test_banner, + "server.donation_address": test_donation_address, # "server.features": test_server_features, - # "server.peers_subscribe": test_peers_subscribe, + "server.peers_subscribe": test_peers_subscribe, }