From 8cae03d3310f9a79b6826ea3785775f4d0fba489 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 26 May 2019 22:56:20 -0700 Subject: [PATCH] Begin some tests for z_createrawtransaction --- qa/pull-tester/rpc-tests.sh | 1 + qa/rpc-tests/wallet_raw_shielded.py | 58 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100755 qa/rpc-tests/wallet_raw_shielded.py diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 24e8566d5..8d4c2efa3 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -34,6 +34,7 @@ testScripts=( 'wallet_addresses.py' 'wallet_sapling.py' 'wallet_listnotes.py' + 'wallet_raw_shielded.py' 'listtransactions.py' 'mempool_resurrect_test.py' 'txn_doublespend.py' diff --git a/qa/rpc-tests/wallet_raw_shielded.py b/qa/rpc-tests/wallet_raw_shielded.py new file mode 100755 index 000000000..3691d039c --- /dev/null +++ b/qa/rpc-tests/wallet_raw_shielded.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python2 +# Copyright (c) 2018 The Zcash developers +# Copyright (c) 2019 The Hush developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal, start_nodes, wait_and_assert_operationid_status +from decimal import Decimal + +class WalletRawShielded(BitcoinTestFramework): + + def setup_nodes(self): + return start_nodes(4, self.options.tmpdir, [[ + '-nuparams=5ba81b19:202', # Overwinter + '-nuparams=76b809bb:204', # Sapling + ]] * 4) + + def run_test(self): + # Current height = 200 -> Sprout + alice = self.nodes[0] + assert_equal(200, alice.getblockcount()) + + # test that we can create a sapling zaddr before sapling activates + zaddr = alice.z_getnewaddress('sapling') + + # we've got lots of coinbase (taddr) but no shielded funds yet + assert_equal(0, Decimal(alice.z_gettotalbalance()['private'])) + + # Current height = 202 -> Overwinter. Default address type remains Sprout + alice.generate(2) + self.sync_all() + assert_equal(202, alice.getblockcount()) + + mining_addr = alice.listunspent()[0]['address'] + + # Shield coinbase funds + receive_amount_10 = Decimal('10.0') - Decimal('0.0001') + recipients = [{"address":zaddr, "amount":receive_amount_10}] + myopid = alice.z_sendmany(mining_addr, recipients) + txid1 = wait_and_assert_operationid_status(alice, myopid) + self.sync_all() + + # Generate a block to confirm shield coinbase tx + alice.generate(1) + self.sync_all() + + assert_equal(203, alice.getblockcount()) + newzaddr = alice.z_getnewaddress('sapling') + + # Simplest test: one input and one output, no change + inputs = [ {"txid":txid, "outindex": 0, "address": zaddr } ] + outputs = [ {"address":newzaddr, "amount": 9.9999 } ] + rawhex = alice.z_createrawtransaction(inputs,outputs) + print(rawhex) + +if __name__ == '__main__': + WalletRawShielded().main()