Skip to content

Commit

Permalink
pytest: add some functional tests for bcli
Browse files Browse the repository at this point in the history
  • Loading branch information
darosior committed Feb 6, 2020
1 parent a6ec2a8 commit 3cf1571
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test_plugin.py
Expand Up @@ -862,3 +862,47 @@ def test_bitcoin_backend(node_factory, bitcoind):
| stat.S_IXOTH)
del l1.daemon.opts["plugin-dir"]
l1.start()


def test_bcli(node_factory, bitcoind):
"""
This tests the bcli plugin, used to gather Bitcoin data from a local
bitcoind.
Mostly sanity checks of the interface..
"""
l1, l2 = node_factory.get_nodes(2)

# We cant stop it dynamically
with pytest.raises(RpcError):
l1.rpc.plugin_stop("bcli")

# Failure case of feerate is tested in test_misc.py
assert "feerate" in l1.rpc.call("getfeerate", {"blocks": 3,
"mode": "CONSERVATIVE"})

resp = l1.rpc.call("getchaininfo")
assert resp["chain"] == "regtest"
for field in ["headercount", "blockcount", "ibd"]:
assert field in resp

# We shouldn't get upset if we ask for an unknown-yet block
resp = l1.rpc.call("getrawblockbyheight", {"height": 500})
assert resp["blockhash"] is resp["block"] is None
resp = l1.rpc.call("getrawblockbyheight", {"height": 50})
assert resp["blockhash"] is not None and resp["blockhash"] is not None
# Some other bitcoind-failure cases for this call are covered in
# tests/test_misc.py

l1.fundwallet(10**5)
l1.connect(l2)
txid = l1.rpc.fundchannel(l2.info["id"], 10**4)["txid"]
txo = l1.rpc.call("gettxout", {"txid": txid, "vout": 0})
assert (Millisatoshi(txo["amount"]) == Millisatoshi(10**4 * 10**3)
and txo["script"].startswith("0020"))
l1.rpc.close(l2.info["id"])
# When output is spent, it should give us null !
txo = l1.rpc.call("gettxout", {"txid": txid, "vout": 0})
assert txo["amount"] is txo["script"] is None

resp = l1.rpc.call("sendrawtransaction", {"tx": "dummy"})
assert not resp["success"] and "decode failed" in resp["errmsg"]

0 comments on commit 3cf1571

Please sign in to comment.