Skip to content

Commit 4fd37d0

Browse files
committed
Merge #20292: test: Fix intermittent feature_taproot issue
fab9008 ci: Bump timeout factor (MarcoFalke) 50eb0c2 Small improvements to the Taproot functional tests (Pieter Wuille) fac865b test: Fix intermittent feature_taproot issue (MarcoFalke) fa1dea1 test: Fix deser issue in create_block (MarcoFalke) fa762a3 test: Remove unused unnamed parameter from block.serialize call (MarcoFalke) Pull request description: This fixes three bugs. Also, fix some unrelated code style issues. Please refer to the commit messages for more information. ACKs for top commit: laanwj: Code review ACK fab9008 Tree-SHA512: 4e22c240cf345710f3b21fc63243126b90014b3656d0865ff87156e958dd1442e6572c6c0a5701dbbe503eee931a0ceb66eeeb3553137f3d1f5afd27a9f9cada
2 parents 05aeeee + fab9008 commit 4fd37d0

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

ci/test/00_setup_env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export RUN_SECURITY_TESTS=${RUN_SECURITY_TESTS:-false}
3838
# By how much to scale the test_runner timeouts (option --timeout-factor).
3939
# This is needed because some ci machines have slow CPU or disk, so sanitizers
4040
# might be slow or a reindex might be waiting on disk IO.
41-
export TEST_RUNNER_TIMEOUT_FACTOR=${TEST_RUNNER_TIMEOUT_FACTOR:-4}
41+
export TEST_RUNNER_TIMEOUT_FACTOR=${TEST_RUNNER_TIMEOUT_FACTOR:-40}
4242
export TEST_RUNNER_ENV=${TEST_RUNNER_ENV:-}
4343
export RUN_FUZZ_TESTS=${RUN_FUZZ_TESTS:-false}
4444
export EXPECTED_TESTS_DURATION_IN_SECONDS=${EXPECTED_TESTS_DURATION_IN_SECONDS:-1000}

test/functional/feature_taproot.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
create_block,
1010
add_witness_commitment,
1111
MAX_BLOCK_SIGOPS_WEIGHT,
12+
NORMAL_GBT_REQUEST_PARAMS,
1213
WITNESS_SCALE_FACTOR,
1314
)
1415
from test_framework.messages import (
@@ -1199,7 +1200,7 @@ def set_test_params(self):
11991200
self.num_nodes = 2
12001201
self.setup_clean_chain = True
12011202
# Node 0 has Taproot inactive, Node 1 active.
1202-
self.extra_args = [["-whitelist=127.0.0.1", "-par=1", "-vbparams=taproot:1:1"], ["-whitelist=127.0.0.1", "-par=1"]]
1203+
self.extra_args = [["-par=1", "-vbparams=taproot:1:1"], ["-par=1"]]
12031204

12041205
def block_submit(self, node, txs, msg, err_msg, cb_pubkey=None, fees=0, sigops_weight=0, witness=False, accept=False):
12051206

@@ -1218,7 +1219,7 @@ def block_submit(self, node, txs, msg, err_msg, cb_pubkey=None, fees=0, sigops_w
12181219
witness and add_witness_commitment(block)
12191220
block.rehash()
12201221
block.solve()
1221-
block_response = node.submitblock(block.serialize(True).hex())
1222+
block_response = node.submitblock(block.serialize().hex())
12221223
if err_msg is not None:
12231224
assert block_response is not None and err_msg in block_response, "Missing error message '%s' from block response '%s': %s" % (err_msg, "(None)" if block_response is None else block_response, msg)
12241225
if (accept):
@@ -1436,17 +1437,27 @@ def test_spenders(self, node, spenders, input_counts):
14361437
self.log.info(" - Done")
14371438

14381439
def run_test(self):
1439-
self.connect_nodes(0, 1)
1440-
14411440
# Post-taproot activation tests go first (pre-taproot tests' blocks are invalid post-taproot).
14421441
self.log.info("Post-activation tests...")
14431442
self.nodes[1].generate(101)
14441443
self.test_spenders(self.nodes[1], spenders_taproot_active(), input_counts=[1, 2, 2, 2, 2, 3])
14451444

1446-
# Transfer % of funds to pre-taproot node.
1445+
# Transfer funds to pre-taproot node.
14471446
addr = self.nodes[0].getnewaddress()
1448-
self.nodes[1].sendtoaddress(address=addr, amount=int(self.nodes[1].getbalance() * 70000000) / 100000000)
1449-
self.nodes[1].generate(1)
1447+
rawtx = self.nodes[1].createrawtransaction(
1448+
inputs=[{
1449+
'txid': i['txid'],
1450+
'vout': i['vout']
1451+
} for i in self.nodes[1].listunspent()],
1452+
outputs={addr: self.nodes[1].getbalance()},
1453+
)
1454+
rawtx = self.nodes[1].signrawtransactionwithwallet(rawtx)['hex']
1455+
# Transaction is too large to fit into the mempool, so put it into a block
1456+
block = create_block(tmpl=self.nodes[1].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS), txlist=[rawtx])
1457+
add_witness_commitment(block)
1458+
block.rehash()
1459+
block.solve()
1460+
assert_equal(None, self.nodes[1].submitblock(block.serialize().hex()))
14501461
self.sync_blocks()
14511462

14521463
# Pre-taproot activation tests.

test/functional/test_framework/blocktools.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""Utilities for manipulating blocks and transactions."""
66

77
from binascii import a2b_hex
8-
import io
98
import struct
109
import time
1110
import unittest
@@ -45,7 +44,6 @@
4544
hash160,
4645
)
4746
from .util import assert_equal
48-
from io import BytesIO
4947

5048
WITNESS_SCALE_FACTOR = 4
5149
MAX_BLOCK_SIGOPS = 20000
@@ -78,9 +76,7 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl
7876
if txlist:
7977
for tx in txlist:
8078
if not hasattr(tx, 'calc_sha256'):
81-
txo = CTransaction()
82-
txo.deserialize(io.BytesIO(tx))
83-
tx = txo
79+
tx = FromHex(CTransaction(), tx)
8480
block.vtx.append(tx)
8581
block.hashMerkleRoot = block.calc_merkle_root()
8682
block.calc_sha256()
@@ -166,8 +162,7 @@ def create_transaction(node, txid, to_address, *, amount):
166162
sign for the output that is being spent.
167163
"""
168164
raw_tx = create_raw_transaction(node, txid, to_address, amount=amount)
169-
tx = CTransaction()
170-
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx)))
165+
tx = FromHex(CTransaction(), raw_tx)
171166
return tx
172167

173168
def create_raw_transaction(node, txid, to_address, *, amount):

test/functional/test_framework/key.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import hashlib
1111
import os
1212
import random
13-
import sys
1413
import unittest
1514

1615
from .util import modinv
@@ -22,6 +21,7 @@ def TaggedHash(tag, data):
2221
return hashlib.sha256(ss).digest()
2322

2423
def xor_bytes(b0, b1):
24+
assert len(b0) == len(b1)
2525
return bytes(x ^ y for (x, y) in zip(b0, b1))
2626

2727
def jacobi_symbol(n, k):
@@ -523,7 +523,8 @@ def test_schnorr(self):
523523
def test_schnorr_testvectors(self):
524524
"""Implement the BIP340 test vectors (read from bip340_test_vectors.csv)."""
525525
num_tests = 0
526-
with open(os.path.join(sys.path[0], 'test_framework', 'bip340_test_vectors.csv'), newline='', encoding='utf8') as csvfile:
526+
vectors_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'bip340_test_vectors.csv')
527+
with open(vectors_file, newline='', encoding='utf8') as csvfile:
527528
reader = csv.reader(csvfile)
528529
next(reader)
529530
for row in reader:

0 commit comments

Comments
 (0)