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.
141 lines
6.0 KiB
Python
Executable File
141 lines
6.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2016-2024 The Hush developers
|
|
# Copyright (c) 2014-2015 The Bitcoin Core developers
|
|
# Distributed under the GPLv3 software license, see the accompanying
|
|
# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
|
|
|
#
|
|
# Test addressindex generation and fetching
|
|
#
|
|
|
|
import time
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import *
|
|
from test_framework.script import *
|
|
from test_framework.mininode import *
|
|
import binascii
|
|
|
|
class SpentIndexTest(BitcoinTestFramework):
|
|
|
|
def setup_chain(self):
|
|
print(("Initializing test directory "+self.options.tmpdir))
|
|
initialize_chain_clean(self.options.tmpdir, 4)
|
|
|
|
def setup_network(self):
|
|
self.nodes = []
|
|
# Nodes 0/1 are "wallet" nodes
|
|
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug"]))
|
|
self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-spentindex"]))
|
|
# Nodes 2/3 are used for testing
|
|
self.nodes.append(start_node(2, self.options.tmpdir, ["-debug", "-spentindex"]))
|
|
self.nodes.append(start_node(3, self.options.tmpdir, ["-debug", "-spentindex", "-txindex"]))
|
|
connect_nodes(self.nodes[0], 1)
|
|
connect_nodes(self.nodes[0], 2)
|
|
connect_nodes(self.nodes[0], 3)
|
|
|
|
self.is_network_split = False
|
|
self.sync_all()
|
|
|
|
def run_test(self):
|
|
print("Mining blocks...")
|
|
self.nodes[0].generate(105)
|
|
self.sync_all()
|
|
|
|
chain_height = self.nodes[1].getblockcount()
|
|
assert_equal(chain_height, 105)
|
|
|
|
# Check that
|
|
print("Testing spent index...")
|
|
|
|
privkey = "cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG"
|
|
address = "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW"
|
|
addressHash = "0b2f0a0c31bfe0406b0ccc1381fdbe311946dadc".decode("hex")
|
|
scriptPubKey = CScript([OP_DUP, OP_HASH160, addressHash, OP_EQUALVERIFY, OP_CHECKSIG])
|
|
unspent = self.nodes[0].listunspent()
|
|
tx = CTransaction()
|
|
amount = unspent[0]["amount"] * 100000000
|
|
tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
|
|
tx.vout = [CTxOut(amount, scriptPubKey)]
|
|
tx.rehash()
|
|
|
|
signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
|
|
txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True)
|
|
self.nodes[0].generate(1)
|
|
self.sync_all()
|
|
|
|
print("Testing getspentinfo method...")
|
|
|
|
# Check that the spentinfo works standalone
|
|
info = self.nodes[1].getspentinfo({"txid": unspent[0]["txid"], "index": unspent[0]["vout"]})
|
|
assert_equal(info["txid"], txid)
|
|
assert_equal(info["index"], 0)
|
|
assert_equal(info["height"], 106)
|
|
|
|
print("Testing getrawtransaction method...")
|
|
|
|
# Check that verbose raw transaction includes spent info
|
|
txVerbose = self.nodes[3].getrawtransaction(unspent[0]["txid"], 1)
|
|
assert_equal(txVerbose["vout"][unspent[0]["vout"]]["spentTxId"], txid)
|
|
assert_equal(txVerbose["vout"][unspent[0]["vout"]]["spentIndex"], 0)
|
|
assert_equal(txVerbose["vout"][unspent[0]["vout"]]["spentHeight"], 106)
|
|
|
|
# Check that verbose raw transaction includes input values
|
|
txVerbose2 = self.nodes[3].getrawtransaction(txid, 1)
|
|
assert_equal(txVerbose2["vin"][0]["value"], Decimal(unspent[0]["amount"]))
|
|
assert_equal(txVerbose2["vin"][0]["valueSat"], amount)
|
|
|
|
# Check that verbose raw transaction includes address values and input values
|
|
privkey2 = "cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG"
|
|
address2 = "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW"
|
|
addressHash2 = "0b2f0a0c31bfe0406b0ccc1381fdbe311946dadc".decode("hex")
|
|
scriptPubKey2 = CScript([OP_DUP, OP_HASH160, addressHash2, OP_EQUALVERIFY, OP_CHECKSIG])
|
|
tx2 = CTransaction()
|
|
tx2.vin = [CTxIn(COutPoint(int(txid, 16), 0))]
|
|
tx2.vout = [CTxOut(amount, scriptPubKey2)]
|
|
tx.rehash()
|
|
self.nodes[0].importprivkey(privkey)
|
|
signed_tx2 = self.nodes[0].signrawtransaction(binascii.hexlify(tx2.serialize()).decode("utf-8"))
|
|
txid2 = self.nodes[0].sendrawtransaction(signed_tx2["hex"], True)
|
|
|
|
# Check the mempool index
|
|
self.sync_all()
|
|
txVerbose3 = self.nodes[1].getrawtransaction(txid2, 1)
|
|
assert_equal(txVerbose3["vin"][0]["address"], address2)
|
|
assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"]))
|
|
assert_equal(txVerbose3["vin"][0]["valueSat"], amount)
|
|
|
|
# Check the database index
|
|
block_hash = self.nodes[0].generate(1)
|
|
self.sync_all()
|
|
|
|
txVerbose4 = self.nodes[3].getrawtransaction(txid2, 1)
|
|
assert_equal(txVerbose4["vin"][0]["address"], address2)
|
|
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
|
|
assert_equal(txVerbose4["vin"][0]["valueSat"], amount)
|
|
|
|
|
|
# Check block deltas
|
|
print("Testing getblockdeltas...")
|
|
|
|
block = self.nodes[3].getblockdeltas(block_hash[0])
|
|
assert_equal(len(block["deltas"]), 2)
|
|
assert_equal(block["deltas"][0]["index"], 0)
|
|
assert_equal(len(block["deltas"][0]["inputs"]), 0)
|
|
assert_equal(len(block["deltas"][0]["outputs"]), 0)
|
|
assert_equal(block["deltas"][1]["index"], 1)
|
|
assert_equal(block["deltas"][1]["txid"], txid2)
|
|
assert_equal(block["deltas"][1]["inputs"][0]["index"], 0)
|
|
assert_equal(block["deltas"][1]["inputs"][0]["address"], "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW")
|
|
assert_equal(block["deltas"][1]["inputs"][0]["satoshis"], amount * -1)
|
|
assert_equal(block["deltas"][1]["inputs"][0]["prevtxid"], txid)
|
|
assert_equal(block["deltas"][1]["inputs"][0]["prevout"], 0)
|
|
assert_equal(block["deltas"][1]["outputs"][0]["index"], 0)
|
|
assert_equal(block["deltas"][1]["outputs"][0]["address"], "mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW")
|
|
assert_equal(block["deltas"][1]["outputs"][0]["satoshis"], amount)
|
|
|
|
print("Passed\n")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
SpentIndexTest().main()
|