@@ -862,3 +862,47 @@ def test_bitcoin_backend(node_factory, bitcoind):
862
862
| stat .S_IXOTH )
863
863
del l1 .daemon .opts ["plugin-dir" ]
864
864
l1 .start ()
865
+
866
+
867
+ def test_bcli (node_factory , bitcoind ):
868
+ """
869
+ This tests the bcli plugin, used to gather Bitcoin data from a local
870
+ bitcoind.
871
+ Mostly sanity checks of the interface..
872
+ """
873
+ l1 , l2 = node_factory .get_nodes (2 )
874
+
875
+ # We cant stop it dynamically
876
+ with pytest .raises (RpcError ):
877
+ l1 .rpc .plugin_stop ("bcli" )
878
+
879
+ # Failure case of feerate is tested in test_misc.py
880
+ assert "feerate" in l1 .rpc .call ("getfeerate" , {"blocks" : 3 ,
881
+ "mode" : "CONSERVATIVE" })
882
+
883
+ resp = l1 .rpc .call ("getchaininfo" )
884
+ assert resp ["chain" ] == "regtest"
885
+ for field in ["headercount" , "blockcount" , "ibd" ]:
886
+ assert field in resp
887
+
888
+ # We shouldn't get upset if we ask for an unknown-yet block
889
+ resp = l1 .rpc .call ("getrawblockbyheight" , {"height" : 500 })
890
+ assert resp ["blockhash" ] is resp ["block" ] is None
891
+ resp = l1 .rpc .call ("getrawblockbyheight" , {"height" : 50 })
892
+ assert resp ["blockhash" ] is not None and resp ["blockhash" ] is not None
893
+ # Some other bitcoind-failure cases for this call are covered in
894
+ # tests/test_misc.py
895
+
896
+ l1 .fundwallet (10 ** 5 )
897
+ l1 .connect (l2 )
898
+ txid = l1 .rpc .fundchannel (l2 .info ["id" ], 10 ** 4 )["txid" ]
899
+ txo = l1 .rpc .call ("gettxout" , {"txid" : txid , "vout" : 0 })
900
+ assert (Millisatoshi (txo ["amount" ]) == Millisatoshi (10 ** 4 * 10 ** 3 )
901
+ and txo ["script" ].startswith ("0020" ))
902
+ l1 .rpc .close (l2 .info ["id" ])
903
+ # When output is spent, it should give us null !
904
+ txo = l1 .rpc .call ("gettxout" , {"txid" : txid , "vout" : 0 })
905
+ assert txo ["amount" ] is txo ["script" ] is None
906
+
907
+ resp = l1 .rpc .call ("sendrawtransaction" , {"tx" : "dummy" })
908
+ assert not resp ["success" ] and "decode failed" in resp ["errmsg" ]
0 commit comments