From fa762a3fd43e49f8572be69e9129cd9170855f76 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 3 Nov 2020 11:31:46 +0100 Subject: test: Remove unused unnamed parameter from block.serialize call All blocks and transactions are serialized with witness, no need to set this --- test/functional/feature_taproot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/feature_taproot.py b/test/functional/feature_taproot.py index 3e47e24a3b..f3741b1c17 100755 --- a/test/functional/feature_taproot.py +++ b/test/functional/feature_taproot.py @@ -1218,7 +1218,7 @@ class TaprootTest(BitcoinTestFramework): witness and add_witness_commitment(block) block.rehash() block.solve() - block_response = node.submitblock(block.serialize(True).hex()) + block_response = node.submitblock(block.serialize().hex()) if err_msg is not None: 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) if (accept): -- cgit v1.2.3 From fa1dea19fc50db449386c9f969adc5ad327a0f0d Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 3 Nov 2020 12:04:03 +0100 Subject: test: Fix deser issue in create_block Without the fix a hex-string can not be parsed: File "./test/functional/test_framework/blocktools.py", line 82, in create_block txo.deserialize(io.BytesIO(tx)) TypeError: a bytes-like object is required, not 'str' Also, remove io import and repace it with our FromHex() helper --- test/functional/test_framework/blocktools.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py index 64bc7e0485..6b7214f03a 100644 --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -5,7 +5,6 @@ """Utilities for manipulating blocks and transactions.""" from binascii import a2b_hex -import io import struct import time import unittest @@ -45,7 +44,6 @@ from .script import ( hash160, ) from .util import assert_equal -from io import BytesIO WITNESS_SCALE_FACTOR = 4 MAX_BLOCK_SIGOPS = 20000 @@ -78,9 +76,7 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl if txlist: for tx in txlist: if not hasattr(tx, 'calc_sha256'): - txo = CTransaction() - txo.deserialize(io.BytesIO(tx)) - tx = txo + tx = FromHex(CTransaction(), tx) block.vtx.append(tx) block.hashMerkleRoot = block.calc_merkle_root() block.calc_sha256() @@ -166,8 +162,7 @@ def create_transaction(node, txid, to_address, *, amount): sign for the output that is being spent. """ raw_tx = create_raw_transaction(node, txid, to_address, amount=amount) - tx = CTransaction() - tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx))) + tx = FromHex(CTransaction(), raw_tx) return tx def create_raw_transaction(node, txid, to_address, *, amount): -- cgit v1.2.3 From fac865b72d5c0e01fce74b84ab21e5ebbf069327 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 3 Nov 2020 11:55:43 +0100 Subject: test: Fix intermittent feature_taproot issue The transaction is too large to fit into the mempool, so put it into a block. https://travis-ci.org/github/bitcoin/bitcoin/jobs/740987240#L7217 test 2020-11-03T01:31:08.645000Z TestFramework (ERROR): JSONRPC error Traceback (most recent call last): File "./test/functional/test_framework/test_framework.py", line 126, in main self.run_test() File "./test/functional/feature_taproot.py", line 1448, in run_test self.nodes[1].sendtoaddress(address=addr, amount=int(self.nodes[1].getbalance() * 70000000) / 100000000) File "./test/functional/test_framework/coverage.py", line 47, in __call__ return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs) File "./test/functional/test_framework/authproxy.py", line 146, in __call__ raise JSONRPCException(response['error'], status) test_framework.authproxy.JSONRPCException: Transaction too large (-6) --- test/functional/feature_taproot.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/functional/feature_taproot.py b/test/functional/feature_taproot.py index f3741b1c17..c12d53b306 100755 --- a/test/functional/feature_taproot.py +++ b/test/functional/feature_taproot.py @@ -9,6 +9,7 @@ from test_framework.blocktools import ( create_block, add_witness_commitment, MAX_BLOCK_SIGOPS_WEIGHT, + NORMAL_GBT_REQUEST_PARAMS, WITNESS_SCALE_FACTOR, ) from test_framework.messages import ( @@ -1443,10 +1444,22 @@ class TaprootTest(BitcoinTestFramework): self.nodes[1].generate(101) self.test_spenders(self.nodes[1], spenders_taproot_active(), input_counts=[1, 2, 2, 2, 2, 3]) - # Transfer % of funds to pre-taproot node. + # Transfer funds to pre-taproot node. addr = self.nodes[0].getnewaddress() - self.nodes[1].sendtoaddress(address=addr, amount=int(self.nodes[1].getbalance() * 70000000) / 100000000) - self.nodes[1].generate(1) + rawtx = self.nodes[1].createrawtransaction( + inputs=[{ + 'txid': i['txid'], + 'vout': i['vout'] + } for i in self.nodes[1].listunspent()], + outputs={addr: self.nodes[1].getbalance()}, + ) + rawtx = self.nodes[1].signrawtransactionwithwallet(rawtx)['hex'] + # Transaction is too large to fit into the mempool, so put it into a block + block = create_block(tmpl=self.nodes[1].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS), txlist=[rawtx]) + add_witness_commitment(block) + block.rehash() + block.solve() + assert_equal(None, self.nodes[1].submitblock(block.serialize().hex())) self.sync_blocks() # Pre-taproot activation tests. -- cgit v1.2.3 From 50eb0c2512842b96a0128a7d592a357665f6e006 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 21 Oct 2020 13:06:34 -0700 Subject: Small improvements to the Taproot functional tests The "whitelist" and "connect_nodes" is not needed in feature_taproot.py, so remove it. The changes to key.py are required when running the unit tests from the test folder. Failure on current master: [test]$ python -m unittest functional/test_framework/key.py .E ====================================================================== ERROR: test_schnorr_testvectors (functional.test_framework.key.TestFrameworkKey) Implement the BIP340 test vectors (read from bip340_test_vectors.csv). ---------------------------------------------------------------------- Traceback (most recent call last): File "test/functional/test_framework/key.py", line 526, in test_schnorr_testvectors with open(os.path.join(sys.path[0], 'test_framework', 'bip340_test_vectors.csv'), newline='', encoding='utf8') as csvfile: FileNotFoundError: [Errno 2] No such file or directory: 'test/test_framework/bip340_test_vectors.csv' ---------------------------------------------------------------------- Ran 2 tests in 0.775s FAILED (errors=1) --- test/functional/feature_taproot.py | 4 +--- test/functional/test_framework/key.py | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/functional/feature_taproot.py b/test/functional/feature_taproot.py index c12d53b306..6e28cfb265 100755 --- a/test/functional/feature_taproot.py +++ b/test/functional/feature_taproot.py @@ -1200,7 +1200,7 @@ class TaprootTest(BitcoinTestFramework): self.num_nodes = 2 self.setup_clean_chain = True # Node 0 has Taproot inactive, Node 1 active. - self.extra_args = [["-whitelist=127.0.0.1", "-par=1", "-vbparams=taproot:1:1"], ["-whitelist=127.0.0.1", "-par=1"]] + self.extra_args = [["-par=1", "-vbparams=taproot:1:1"], ["-par=1"]] def block_submit(self, node, txs, msg, err_msg, cb_pubkey=None, fees=0, sigops_weight=0, witness=False, accept=False): @@ -1437,8 +1437,6 @@ class TaprootTest(BitcoinTestFramework): self.log.info(" - Done") def run_test(self): - self.connect_nodes(0, 1) - # Post-taproot activation tests go first (pre-taproot tests' blocks are invalid post-taproot). self.log.info("Post-activation tests...") self.nodes[1].generate(101) diff --git a/test/functional/test_framework/key.py b/test/functional/test_framework/key.py index a6bc187985..64e82e614c 100644 --- a/test/functional/test_framework/key.py +++ b/test/functional/test_framework/key.py @@ -10,7 +10,6 @@ import csv import hashlib import os import random -import sys import unittest from .util import modinv @@ -22,6 +21,7 @@ def TaggedHash(tag, data): return hashlib.sha256(ss).digest() def xor_bytes(b0, b1): + assert len(b0) == len(b1) return bytes(x ^ y for (x, y) in zip(b0, b1)) def jacobi_symbol(n, k): @@ -523,7 +523,8 @@ class TestFrameworkKey(unittest.TestCase): def test_schnorr_testvectors(self): """Implement the BIP340 test vectors (read from bip340_test_vectors.csv).""" num_tests = 0 - with open(os.path.join(sys.path[0], 'test_framework', 'bip340_test_vectors.csv'), newline='', encoding='utf8') as csvfile: + vectors_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'bip340_test_vectors.csv') + with open(vectors_file, newline='', encoding='utf8') as csvfile: reader = csv.reader(csvfile) next(reader) for row in reader: -- cgit v1.2.3