aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/script_util.py
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2019-10-11 14:47:38 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2019-10-14 15:03:11 +0200
commit32d665c2657793c8b2cc7248d26d80a940acfe20 (patch)
tree82af55789519306ce39db9595b5e3fb1a3debdf9 /test/functional/test_framework/script_util.py
parent08ed87e8875d72a1d8b157b67bbd431253d7db24 (diff)
downloadbitcoin-32d665c2657793c8b2cc7248d26d80a940acfe20.tar.xz
test: fix "tx-size-small" errors after default address change
Addresses #17043, affects RBF and BIP68 functional tests. The "tx-size-small" policy rule rejects transactions with a non-witness size of smaller than 82 bytes (see src/validation.cpp:MemPoolAccept::PreChecks(...)), which corresponds to a transaction with 1 segwit input and 1 P2WPKH output. Through the default address change, the created test transactions have segwit inputs now and sending to short scriptPubKeys might violate this rule. By bumping the dummy scriptPubKey size to 22 bytes (= the size of a P2WPKH scriptPubKey), on all occurences the problem is solved. The dummy scriptPubKey has the format: 21 <21-byte-long string of 'a' or 1s> former commit messages, now squashed: test: rbf, bip68: use constant DUMMY_P2WPKH_SCRIPT for bumped scriptPubKey test: rbf, bip68: use constant DUMMY_P2WPKH_SCRIPT for dummy scriptPubKeys (b'a' * 35) test: rbf, bip68: comment DUMMY_P2WPKH_SCRIPT constant, put into common (new) module
Diffstat (limited to 'test/functional/test_framework/script_util.py')
-rwxr-xr-xtest/functional/test_framework/script_util.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/functional/test_framework/script_util.py b/test/functional/test_framework/script_util.py
new file mode 100755
index 0000000000..5ef67226c4
--- /dev/null
+++ b/test/functional/test_framework/script_util.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+# Copyright (c) 2019 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""Useful Script constants and utils."""
+from test_framework.script import CScript
+
+# To prevent a "tx-size-small" policy rule error, a transaction has to have a
+# non-witness size of at least 82 bytes (MIN_STANDARD_TX_NONWITNESS_SIZE in
+# src/policy/policy.h). Considering a Tx with the smallest possible single
+# input (blank, empty scriptSig), and with an output omitting the scriptPubKey,
+# we get to a minimum size of 60 bytes:
+#
+# Tx Skeleton: 4 [Version] + 1 [InCount] + 1 [OutCount] + 4 [LockTime] = 10 bytes
+# Blank Input: 32 [PrevTxHash] + 4 [Index] + 1 [scriptSigLen] + 4 [SeqNo] = 41 bytes
+# Output: 8 [Amount] + 1 [scriptPubKeyLen] = 9 bytes
+#
+# Hence, the scriptPubKey of the single output has to have a size of at
+# least 22 bytes, which corresponds to the size of a P2WPKH scriptPubKey.
+# The following script constant consists of a single push of 21 bytes of 'a':
+# <PUSH_21> <21-bytes of 'a'>
+# resulting in a 22-byte size. It should be used whenever (small) fake
+# scriptPubKeys are needed, to guarantee that the minimum transaction size is
+# met.
+DUMMY_P2WPKH_SCRIPT = CScript([b'a' * 21])