Files
hush3/qa/rpc-tests/wallet_treestate.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

107 lines
4.4 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2016-2024 The Hush developers
# Copyright (c) 2016 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.util import assert_equal, initialize_chain_clean, \
start_nodes, connect_nodes_bi, wait_and_assert_operationid_status
import time
from decimal import Decimal
class WalletTreeStateTest (BitcoinTestFramework):
def setup_chain(self):
print(("Initializing test directory "+self.options.tmpdir))
initialize_chain_clean(self.options.tmpdir, 4)
# Start nodes with -regtestprotectcoinbase to set fCoinbaseMustBeProtected to true.
def setup_network(self, split=False):
self.nodes = start_nodes(3, self.options.tmpdir, extra_args=[['-regtestprotectcoinbase','-debug=zrpc']] * 3 )
connect_nodes_bi(self.nodes,0,1)
connect_nodes_bi(self.nodes,1,2)
connect_nodes_bi(self.nodes,0,2)
self.is_network_split=False
self.sync_all()
def run_test (self):
print("Mining blocks...")
self.nodes[0].generate(100)
self.sync_all()
self.nodes[1].generate(101)
self.sync_all()
mytaddr = self.nodes[0].getnewaddress() # where coins were mined
myzaddr = self.nodes[0].z_getnewaddress()
# Spend coinbase utxos to create three notes of 9.99990000 each
recipients = []
recipients.append({"address":myzaddr, "amount":Decimal('10.0') - Decimal('0.0001')})
myopid = self.nodes[0].z_sendmany(mytaddr, recipients)
wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
self.nodes[1].generate(1)
self.sync_all()
myopid = self.nodes[0].z_sendmany(mytaddr, recipients)
wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
self.nodes[1].generate(1)
self.sync_all()
myopid = self.nodes[0].z_sendmany(mytaddr, recipients)
wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
self.nodes[1].generate(1)
self.sync_all()
# Check balance
resp = self.nodes[0].z_getbalance(myzaddr)
assert_equal(Decimal(resp), Decimal('9.9999') * 3 )
# We want to test a real-world situation where during the time spent creating a transaction
# with joinsplits, other transactions containing joinsplits have been mined into new blocks,
# which result in the treestate changing whilst creating the transaction.
# Tx 1 will change the treestate while Tx 2 containing chained joinsplits is still being generated
recipients = []
recipients.append({"address":self.nodes[2].z_getnewaddress(), "amount":Decimal('10.0') - Decimal('0.0001')})
myopid = self.nodes[0].z_sendmany(mytaddr, recipients)
wait_and_assert_operationid_status(self.nodes[0], myopid)
# Tx 2 will consume all three notes, which must take at least two joinsplits. This is regardless of
# the z_sendmany implementation because there are only two inputs per joinsplit.
recipients = []
recipients.append({"address":self.nodes[2].z_getnewaddress(), "amount":Decimal('18')})
recipients.append({"address":self.nodes[2].z_getnewaddress(), "amount":Decimal('11.9997') - Decimal('0.0001')})
myopid = self.nodes[0].z_sendmany(myzaddr, recipients)
# Wait for Tx 2 to begin executing...
for x in range(1, 60):
results = self.nodes[0].z_getoperationstatus([myopid])
status = results[0]["status"]
if status == "executing":
break
time.sleep(1)
# Now mine Tx 1 which will change global treestate before Tx 2's second joinsplit begins processing
self.sync_all()
self.nodes[1].generate(1)
self.sync_all()
# Wait for Tx 2 to be created
wait_and_assert_operationid_status(self.nodes[0], myopid)
# Note that a bug existed in v1.0.0-1.0.3 where Tx 2 creation would fail with an error:
# "Witness for spendable note does not have same anchor as change input"
# Check balance
resp = self.nodes[0].z_getbalance(myzaddr)
assert_equal(Decimal(resp), Decimal('0.0'))
if __name__ == '__main__':
WalletTreeStateTest().main()