From 19697025c6e3be176abb056ce5c24ed15f6ed616 Mon Sep 17 00:00:00 2001 From: Eirik Ogilvie-Wigley Date: Thu, 13 Sep 2018 16:34:23 -0600 Subject: [PATCH] Add test for signing raw transactions offline --- qa/pull-tester/rpc-tests.sh | 1 + qa/rpc-tests/signrawtransaction_offline.py | 57 ++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 qa/rpc-tests/signrawtransaction_offline.py diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 25ecc409a..9953b85ee 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -43,6 +43,7 @@ testScripts=( 'merkle_blocks.py' # 'fundrawtransaction.py' 'signrawtransactions.py' + 'signrawtransaction_offline.py' 'walletbackup.py' 'key_import_export.py' 'nodehandling.py' diff --git a/qa/rpc-tests/signrawtransaction_offline.py b/qa/rpc-tests/signrawtransaction_offline.py new file mode 100755 index 000000000..5eadf2cb3 --- /dev/null +++ b/qa/rpc-tests/signrawtransaction_offline.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python2 + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal, assert_true, connect_nodes_bi, \ + initialize_chain_clean, start_node + +class SignOfflineTest (BitcoinTestFramework): + # Setup Methods + def setup_chain(self): + print "Initializing test directory " + self.options.tmpdir + initialize_chain_clean(self.options.tmpdir, 2) + + def setup_network(self): + self.nodes = [ start_node(0, self.options.tmpdir, ["-nuparams=5ba81b19:10"]) ] + self.is_network_split = False + self.sync_all() + + # Tests + def run_test(self): + print "Mining blocks..." + self.nodes[0].generate(101) + + offline_node = start_node(1, self.options.tmpdir, ["-maxconnections=0", "-nuparams=5ba81b19:10"]) + self.nodes.append(offline_node) + + assert_equal(0, len(offline_node.getpeerinfo())) # make sure node 1 has no peers + + privkeys = [self.nodes[0].dumpprivkey(self.nodes[0].getnewaddress())] + taddr = self.nodes[0].getnewaddress() + + tx = self.nodes[0].listunspent()[0] + txid = tx['txid'] + scriptpubkey = tx['scriptPubKey'] + + create_inputs = [{'txid': txid, 'vout': 0}] + sign_inputs = [{'txid': txid, 'vout': 0, 'scriptPubKey': scriptpubkey, 'amount': 10}] + + create_hex = self.nodes[0].createrawtransaction(create_inputs, {taddr: 9.9999}) + print "create:" + print create_hex + + signed_tx = offline_node.signrawtransaction(create_hex, sign_inputs, privkeys) + print "sign:" + print signed_tx + + # If we return the transaction hash, then we have have not thrown an error (success) + online_tx_hash = self.nodes[0].sendrawtransaction(signed_tx['hex']) + assert_true(len(online_tx_hash) > 0) + + #signed_hex = signed_tx['hex'] + #print "decoded:" + #print self.nodes[0].decoderawtransaction(signed_hex) + print "sent:" + print online_tx_hash + +if __name__ == '__main__': + SignOfflineTest().main() \ No newline at end of file