Files
hush3/qa/rpc-tests/wallet_sapling.py
dan_s 72b287e467 qa: Port RPC tests to Python 3, add comprehensive test runner
Migrate all 92 Python files in qa/ from Python 2 to Python 3:
- Update shebangs from python2 to python3
- Replace print statements with print() calls
- Fix imports (http.client, urllib.parse, queue, io, functools)
- Convert xrange→range, 0L→0, long→int, cmp→key functions
- Fix except/as syntax, bytes/str handling, integer division
- Use relative imports in test_framework/ package

Add qa/run-tests.sh: multi-stage test runner (1183 lines)
- Stage 1: Build/binary verification
- Stage 2: Security hardening (PIE, NX, RELRO, canary, FORTIFY)
- Stage 3-4: Boost/Google test binaries
- Stage 5: Library tests (secp256k1, univalue)
- Stage 6: RandomX validation (live chain mining + block checks)
- Stage 7: RPC integration (skipped: regtest mining incompatible)
- Stage 8: Source code invariant checks
- Stage 8b: DragonX-specific source checks (11 tests)
- Flags: --chain=dragonx, --live-dragonx, --save-release, --quick
- Timestamped reports with release archiving to qa/release-reports/

Add qa/clean-test-reports.sh for housekeeping (--keep=N, --dry-run)

Fix test build infrastructure:
- src/Makefile.gtest.include: fix zcash_gtest→hush_gtest refs,
  remove 17 stale source files, add LIBZCASH/LIBHUSH/LIBRANDOMX
- src/Makefile.test.include: remove stale sources, deduplicate
  LDADD/CXXFLAGS, add missing libraries
- src/gtest/test_checkblock.cpp: add height param to ContextualCheckBlock
- src/test/test_bitcoin.cpp: remove JoinSplitTestingSetup (dead code)

Add qa/test-reports/ to .gitignore for transient output.
2026-02-27 22:38:43 -06:00

155 lines
6.2 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2016-2024 The Hush developers
# Copyright (c) 2018 The Zcash developers
# Distributed under the GPLv3 software license, see the accompanying
# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import (
assert_equal,
start_nodes,
wait_and_assert_operationid_status,
)
from decimal import Decimal
# Test wallet behaviour with Sapling addresses
class WalletSaplingTest(BitcoinTestFramework):
def setup_nodes(self):
return start_nodes(4, self.options.tmpdir, [[
#'-nuparams=5ba81b19:201', # Overwinter
#'-nuparams=76b809bb:203', # Sapling
#'-experimentalfeatures', '-zmergetoaddress',
]] * 4)
def run_test(self):
# Sanity-check the test harness
assert_equal(self.nodes[0].getblockcount(), 200)
# Activate Overwinter
self.nodes[2].generate(1)
self.sync_all()
self.nodes[2].generate(2)
self.sync_all()
taddr0 = self.nodes[0].getnewaddress()
# Skip over the address containing node 1's coinbase
self.nodes[1].getnewaddress()
taddr1 = self.nodes[1].getnewaddress()
saplingAddr0 = self.nodes[0].z_getnewaddress('sapling')
saplingAddr1 = self.nodes[1].z_getnewaddress('sapling')
# Verify addresses
assert(saplingAddr0 in self.nodes[0].z_listaddresses())
assert(saplingAddr1 in self.nodes[1].z_listaddresses())
assert_equal(self.nodes[0].z_validateaddress(saplingAddr0)['type'], 'sapling')
assert_equal(self.nodes[0].z_validateaddress(saplingAddr1)['type'], 'sapling')
# Verify balance
assert_equal(self.nodes[0].z_getbalance(saplingAddr0), Decimal('0'))
assert_equal(self.nodes[1].z_getbalance(saplingAddr1), Decimal('0'))
assert_equal(self.nodes[1].z_getbalance(taddr1), Decimal('0'))
# Node 0 shields some funds
# taddr -> Sapling
# -> taddr (change)
recipients = []
recipients.append({"address": saplingAddr0, "amount": Decimal('20')})
myopid = self.nodes[0].z_sendmany(taddr0, recipients, 1, 0)
mytxid = wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
# Verify priority of tx is MAX_PRIORITY, defined as 1E+16 (10000000000000000)
mempool = self.nodes[0].getrawmempool(True)
assert(Decimal(mempool[mytxid]['startingpriority']) == Decimal('1E+16'))
self.nodes[2].generate(1)
self.sync_all()
# Verify balance
assert_equal(self.nodes[0].z_getbalance(saplingAddr0), Decimal('20'))
assert_equal(self.nodes[1].z_getbalance(saplingAddr1), Decimal('0'))
assert_equal(self.nodes[1].z_getbalance(taddr1), Decimal('0'))
# Node 0 sends some shielded funds to node 1
# Sapling -> Sapling
# -> Sapling (change)
recipients = []
recipients.append({"address": saplingAddr1, "amount": Decimal('15')})
myopid = self.nodes[0].z_sendmany(saplingAddr0, recipients, 1, 0)
mytxid = wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
# Verify priority of tx is MAX_PRIORITY, defined as 1E+16 (10000000000000000)
mempool = self.nodes[0].getrawmempool(True)
assert(Decimal(mempool[mytxid]['startingpriority']) == Decimal('1E+16'))
self.nodes[2].generate(1)
self.sync_all()
# Verify balance
assert_equal(self.nodes[0].z_getbalance(saplingAddr0), Decimal('5'))
assert_equal(self.nodes[1].z_getbalance(saplingAddr1), Decimal('15'))
assert_equal(self.nodes[1].z_getbalance(taddr1), Decimal('0'))
# Node 1 sends some shielded funds to node 0, as well as unshielding
# Sapling -> Sapling
# -> taddr
# -> Sapling (change)
recipients = []
recipients.append({"address": saplingAddr0, "amount": Decimal('5')})
recipients.append({"address": taddr1, "amount": Decimal('5')})
myopid = self.nodes[1].z_sendmany(saplingAddr1, recipients, 1, 0)
mytxid = wait_and_assert_operationid_status(self.nodes[1], myopid)
self.sync_all()
# Verify priority of tx is MAX_PRIORITY, defined as 1E+16 (10000000000000000)
mempool = self.nodes[1].getrawmempool(True)
assert(Decimal(mempool[mytxid]['startingpriority']) == Decimal('1E+16'))
self.nodes[2].generate(1)
self.sync_all()
# Verify balance
assert_equal(self.nodes[0].z_getbalance(saplingAddr0), Decimal('10'))
assert_equal(self.nodes[1].z_getbalance(saplingAddr1), Decimal('5'))
assert_equal(self.nodes[1].z_getbalance(taddr1), Decimal('5'))
# Verify existence of Sapling related JSON fields
resp = self.nodes[0].getrawtransaction(mytxid, 1)
assert_equal(resp['valueBalance'], Decimal('5'))
assert(len(resp['vShieldedSpend']) == 1)
assert(len(resp['vShieldedOutput']) == 2)
assert('bindingSig' in resp)
shieldedSpend = resp['vShieldedSpend'][0]
assert('cv' in shieldedSpend)
assert('anchor' in shieldedSpend)
assert('nullifier' in shieldedSpend)
assert('rk' in shieldedSpend)
assert('proof' in shieldedSpend)
assert('spendAuthSig' in shieldedSpend)
shieldedOutput = resp['vShieldedOutput'][0]
assert('cv' in shieldedOutput)
assert('cmu' in shieldedOutput)
assert('ephemeralKey' in shieldedOutput)
assert('encCiphertext' in shieldedOutput)
assert('outCiphertext' in shieldedOutput)
assert('proof' in shieldedOutput)
# Verify importing a spending key will update the nullifiers and witnesses correctly
sk0 = self.nodes[0].z_exportkey(saplingAddr0)
self.nodes[2].z_importkey(sk0, "yes")
assert_equal(self.nodes[2].z_getbalance(saplingAddr0), Decimal('10'))
sk1 = self.nodes[1].z_exportkey(saplingAddr1)
self.nodes[2].z_importkey(sk1, "yes")
assert_equal(self.nodes[2].z_getbalance(saplingAddr1), Decimal('5'))
if __name__ == '__main__':
WalletSaplingTest().main()