@@ -932,3 +932,84 @@ def test_hook_chaining(node_factory):
932
932
assert (l2 .daemon .is_in_log (
933
933
r'plugin-hook-chain-even.py: htlc_accepted called for payment_hash {}' .format (hash3 )
934
934
))
935
+
936
+
937
+ def test_bitcoin_backend (node_factory , bitcoind ):
938
+ """
939
+ This tests interaction with the Bitcoin backend, but not specifically bcli
940
+ """
941
+ l1 = node_factory .get_node (start = False , options = {"disable-plugin" : "bcli" },
942
+ may_fail = True , allow_broken_log = True )
943
+
944
+ # We don't start if we haven't all the required methods registered.
945
+ plugin = os .path .join (os .getcwd (), "tests/plugins/bitcoin/part1.py" )
946
+ l1 .daemon .opts ["plugin" ] = plugin
947
+ try :
948
+ l1 .daemon .start ()
949
+ except ValueError :
950
+ assert l1 .daemon .is_in_log ("Missing a Bitcoin plugin command" )
951
+ # Now we should start if all the commands are registered, even if they
952
+ # are registered by two distincts plugins.
953
+ del l1 .daemon .opts ["plugin" ]
954
+ l1 .daemon .opts ["plugin-dir" ] = os .path .join (os .getcwd (),
955
+ "tests/plugins/bitcoin/" )
956
+ try :
957
+ l1 .daemon .start ()
958
+ except ValueError :
959
+ msg = "All Bitcoin plugin commands registered"
960
+ assert l1 .daemon .is_in_log (msg )
961
+ else :
962
+ raise Exception ("We registered all commands but couldn't start!" )
963
+ else :
964
+ raise Exception ("We could start without all commands registered !!" )
965
+
966
+ # But restarting with just bcli is ok
967
+ del l1 .daemon .opts ["plugin-dir" ]
968
+ del l1 .daemon .opts ["disable-plugin" ]
969
+ l1 .start ()
970
+ assert l1 .daemon .is_in_log ("bitcoin-cli initialized and connected to"
971
+ " bitcoind" )
972
+
973
+
974
+ def test_bcli (node_factory , bitcoind ):
975
+ """
976
+ This tests the bcli plugin, used to gather Bitcoin data from a local
977
+ bitcoind.
978
+ Mostly sanity checks of the interface..
979
+ """
980
+ l1 , l2 = node_factory .get_nodes (2 )
981
+
982
+ # We cant stop it dynamically
983
+ with pytest .raises (RpcError ):
984
+ l1 .rpc .plugin_stop ("bcli" )
985
+
986
+ # Failure case of feerate is tested in test_misc.py
987
+ assert "feerate" in l1 .rpc .call ("getfeerate" , {"blocks" : 3 ,
988
+ "mode" : "CONSERVATIVE" })
989
+
990
+ resp = l1 .rpc .call ("getchaininfo" )
991
+ assert resp ["chain" ] == "regtest"
992
+ for field in ["headercount" , "blockcount" , "ibd" ]:
993
+ assert field in resp
994
+
995
+ # We shouldn't get upset if we ask for an unknown-yet block
996
+ resp = l1 .rpc .call ("getrawblockbyheight" , {"height" : 500 })
997
+ assert resp ["blockhash" ] is resp ["block" ] is None
998
+ resp = l1 .rpc .call ("getrawblockbyheight" , {"height" : 50 })
999
+ assert resp ["blockhash" ] is not None and resp ["blockhash" ] is not None
1000
+ # Some other bitcoind-failure cases for this call are covered in
1001
+ # tests/test_misc.py
1002
+
1003
+ l1 .fundwallet (10 ** 5 )
1004
+ l1 .connect (l2 )
1005
+ txid = l1 .rpc .fundchannel (l2 .info ["id" ], 10 ** 4 )["txid" ]
1006
+ txo = l1 .rpc .call ("getutxout" , {"txid" : txid , "vout" : 0 })
1007
+ assert (Millisatoshi (txo ["amount" ]) == Millisatoshi (10 ** 4 * 10 ** 3 )
1008
+ and txo ["script" ].startswith ("0020" ))
1009
+ l1 .rpc .close (l2 .info ["id" ])
1010
+ # When output is spent, it should give us null !
1011
+ txo = l1 .rpc .call ("getutxout" , {"txid" : txid , "vout" : 0 })
1012
+ assert txo ["amount" ] is txo ["script" ] is None
1013
+
1014
+ resp = l1 .rpc .call ("sendrawtransaction" , {"tx" : "dummy" })
1015
+ assert not resp ["success" ] and "decode failed" in resp ["errmsg" ]
0 commit comments