Browse Source

qa: Pad scriptPubKeys to get minimum sized txs

Github-Pull: #11423
Rebased-From: 364bae5f7a6b16eef63990154e48f19e7e693039
0.16
MarcoFalke 7 years ago
parent
commit
08334b73be
  1. 6
      test/functional/feature_bip68_sequence.py
  2. 3
      test/functional/feature_block.py
  3. 46
      test/functional/feature_rbf.py
  4. 6
      test/functional/feature_segwit.py
  5. 5
      test/functional/p2p_compactblocks.py
  6. 2
      test/functional/p2p_invalid_tx.py
  7. 14
      test/functional/p2p_segwit.py

6
test/functional/feature_bip68_sequence.py

@ -80,7 +80,7 @@ class BIP68Test(BitcoinTestFramework):
tx2.nVersion = 2 tx2.nVersion = 2
sequence_value = sequence_value & 0x7fffffff sequence_value = sequence_value & 0x7fffffff
tx2.vin = [CTxIn(COutPoint(tx1_id, 0), nSequence=sequence_value)] tx2.vin = [CTxIn(COutPoint(tx1_id, 0), nSequence=sequence_value)]
tx2.vout = [CTxOut(int(value-self.relayfee*COIN), CScript([b'a']))] tx2.vout = [CTxOut(int(value - self.relayfee * COIN), CScript([b'a' * 35]))]
tx2.rehash() tx2.rehash()
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx2)) assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx2))
@ -222,7 +222,7 @@ class BIP68Test(BitcoinTestFramework):
tx = CTransaction() tx = CTransaction()
tx.nVersion = 2 tx.nVersion = 2
tx.vin = [CTxIn(COutPoint(orig_tx.sha256, 0), nSequence=sequence_value)] tx.vin = [CTxIn(COutPoint(orig_tx.sha256, 0), nSequence=sequence_value)]
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee*COIN), CScript([b'a']))] tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee * COIN), CScript([b'a' * 35]))]
tx.rehash() tx.rehash()
if (orig_tx.hash in node.getrawmempool()): if (orig_tx.hash in node.getrawmempool()):
@ -350,7 +350,7 @@ class BIP68Test(BitcoinTestFramework):
tx3 = CTransaction() tx3 = CTransaction()
tx3.nVersion = 2 tx3.nVersion = 2
tx3.vin = [CTxIn(COutPoint(tx2.sha256, 0), nSequence=sequence_value)] tx3.vin = [CTxIn(COutPoint(tx2.sha256, 0), nSequence=sequence_value)]
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee*COIN), CScript([b'a']))] tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee * COIN), CScript([b'a' * 35]))]
tx3.rehash() tx3.rehash()
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx3)) assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx3))

3
test/functional/feature_block.py

@ -80,7 +80,7 @@ class FullBlockTest(ComparisonTestFramework):
block.vtx.extend(tx_list) block.vtx.extend(tx_list)
# this is a little handier to use than the version in blocktools.py # this is a little handier to use than the version in blocktools.py
def create_tx(self, spend_tx, n, value, script=CScript([OP_TRUE])): def create_tx(self, spend_tx, n, value, script=CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])):
tx = create_transaction(spend_tx, n, b"", value, script) tx = create_transaction(spend_tx, n, b"", value, script)
return tx return tx
@ -1288,6 +1288,5 @@ class FullBlockTest(ComparisonTestFramework):
chain1_tip += 2 chain1_tip += 2
if __name__ == '__main__': if __name__ == '__main__':
FullBlockTest().main() FullBlockTest().main()

46
test/functional/feature_rbf.py

@ -123,7 +123,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
tx1a = CTransaction() tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)] tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))] tx1a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
tx1a_hex = txToHex(tx1a) tx1a_hex = txToHex(tx1a)
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True) tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
@ -132,7 +132,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Should fail because we haven't changed the fee # Should fail because we haven't changed the fee
tx1b = CTransaction() tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)] tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1b.vout = [CTxOut(1*COIN, CScript([b'b']))] tx1b.vout = [CTxOut(1 * COIN, CScript([b'b' * 35]))]
tx1b_hex = txToHex(tx1b) tx1b_hex = txToHex(tx1b)
# This will raise an exception due to insufficient fee # This will raise an exception due to insufficient fee
@ -143,7 +143,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Extra 0.1 BTC fee # Extra 0.1 BTC fee
tx1b = CTransaction() tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)] tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))] tx1b.vout = [CTxOut(int(0.9 * COIN), CScript([b'b' * 35]))]
tx1b_hex = txToHex(tx1b) tx1b_hex = txToHex(tx1b)
# Replacement still disabled even with "enough fee" # Replacement still disabled even with "enough fee"
assert_raises_rpc_error(-26, "txn-mempool-conflict", self.nodes[1].sendrawtransaction, tx1b_hex, True) assert_raises_rpc_error(-26, "txn-mempool-conflict", self.nodes[1].sendrawtransaction, tx1b_hex, True)
@ -175,7 +175,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
remaining_value -= 1*COIN remaining_value -= 1*COIN
tx = CTransaction() tx = CTransaction()
tx.vin = [CTxIn(prevout, nSequence=0)] tx.vin = [CTxIn(prevout, nSequence=0)]
tx.vout = [CTxOut(remaining_value, CScript([1]))] tx.vout = [CTxOut(remaining_value, CScript([1, OP_DROP] * 15 + [1]))]
tx_hex = txToHex(tx) tx_hex = txToHex(tx)
txid = self.nodes[0].sendrawtransaction(tx_hex, True) txid = self.nodes[0].sendrawtransaction(tx_hex, True)
chain_txids.append(txid) chain_txids.append(txid)
@ -185,7 +185,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# child fees - 40 BTC - so this attempt is rejected. # child fees - 40 BTC - so this attempt is rejected.
dbl_tx = CTransaction() dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)] dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - 30*COIN, CScript([1]))] dbl_tx.vout = [CTxOut(initial_nValue - 30 * COIN, CScript([1] * 35))]
dbl_tx_hex = txToHex(dbl_tx) dbl_tx_hex = txToHex(dbl_tx)
# This will raise an exception due to insufficient fee # This will raise an exception due to insufficient fee
@ -194,7 +194,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Accepted with sufficient fee # Accepted with sufficient fee
dbl_tx = CTransaction() dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)] dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(1*COIN, CScript([1]))] dbl_tx.vout = [CTxOut(1 * COIN, CScript([1] * 35))]
dbl_tx_hex = txToHex(dbl_tx) dbl_tx_hex = txToHex(dbl_tx)
self.nodes[0].sendrawtransaction(dbl_tx_hex, True) self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
@ -247,7 +247,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Attempt double-spend, will fail because too little fee paid # Attempt double-spend, will fail because too little fee paid
dbl_tx = CTransaction() dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)] dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - fee*n, CScript([1]))] dbl_tx.vout = [CTxOut(initial_nValue - fee * n, CScript([1] * 35))]
dbl_tx_hex = txToHex(dbl_tx) dbl_tx_hex = txToHex(dbl_tx)
# This will raise an exception due to insufficient fee # This will raise an exception due to insufficient fee
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, dbl_tx_hex, True) assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, dbl_tx_hex, True)
@ -255,7 +255,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# 1 BTC fee is enough # 1 BTC fee is enough
dbl_tx = CTransaction() dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)] dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - fee*n - 1*COIN, CScript([1]))] dbl_tx.vout = [CTxOut(initial_nValue - fee * n - 1 * COIN, CScript([1] * 35))]
dbl_tx_hex = txToHex(dbl_tx) dbl_tx_hex = txToHex(dbl_tx)
self.nodes[0].sendrawtransaction(dbl_tx_hex, True) self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
@ -275,7 +275,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
dbl_tx = CTransaction() dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)] dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - 2*fee*n, CScript([1]))] dbl_tx.vout = [CTxOut(initial_nValue - 2 * fee * n, CScript([1] * 35))]
dbl_tx_hex = txToHex(dbl_tx) dbl_tx_hex = txToHex(dbl_tx)
# This will raise an exception # This will raise an exception
assert_raises_rpc_error(-26, "too many potential replacements", self.nodes[0].sendrawtransaction, dbl_tx_hex, True) assert_raises_rpc_error(-26, "too many potential replacements", self.nodes[0].sendrawtransaction, dbl_tx_hex, True)
@ -290,7 +290,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
tx1a = CTransaction() tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)] tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))] tx1a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
tx1a_hex = txToHex(tx1a) tx1a_hex = txToHex(tx1a)
self.nodes[0].sendrawtransaction(tx1a_hex, True) self.nodes[0].sendrawtransaction(tx1a_hex, True)
@ -311,7 +311,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
tx1a = CTransaction() tx1a = CTransaction()
tx1a.vin = [CTxIn(utxo1, nSequence=0)] tx1a.vin = [CTxIn(utxo1, nSequence=0)]
tx1a.vout = [CTxOut(int(1.1*COIN), CScript([b'a']))] tx1a.vout = [CTxOut(int(1.1 * COIN), CScript([b'a' * 35]))]
tx1a_hex = txToHex(tx1a) tx1a_hex = txToHex(tx1a)
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True) tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
@ -330,7 +330,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Spend tx1a's output to test the indirect case. # Spend tx1a's output to test the indirect case.
tx1b = CTransaction() tx1b = CTransaction()
tx1b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)] tx1b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
tx1b.vout = [CTxOut(1*COIN, CScript([b'a']))] tx1b.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
tx1b_hex = txToHex(tx1b) tx1b_hex = txToHex(tx1b)
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True) tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
tx1b_txid = int(tx1b_txid, 16) tx1b_txid = int(tx1b_txid, 16)
@ -351,7 +351,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
tx1 = CTransaction() tx1 = CTransaction()
tx1.vin = [CTxIn(confirmed_utxo)] tx1.vin = [CTxIn(confirmed_utxo)]
tx1.vout = [CTxOut(1*COIN, CScript([b'a']))] tx1.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
tx1_hex = txToHex(tx1) tx1_hex = txToHex(tx1)
self.nodes[0].sendrawtransaction(tx1_hex, True) self.nodes[0].sendrawtransaction(tx1_hex, True)
@ -390,7 +390,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
for i in range(MAX_REPLACEMENT_LIMIT+1): for i in range(MAX_REPLACEMENT_LIMIT+1):
tx_i = CTransaction() tx_i = CTransaction()
tx_i.vin = [CTxIn(COutPoint(txid, i), nSequence=0)] tx_i.vin = [CTxIn(COutPoint(txid, i), nSequence=0)]
tx_i.vout = [CTxOut(split_value-fee, CScript([b'a']))] tx_i.vout = [CTxOut(split_value - fee, CScript([b'a' * 35]))]
tx_i_hex = txToHex(tx_i) tx_i_hex = txToHex(tx_i)
self.nodes[0].sendrawtransaction(tx_i_hex, True) self.nodes[0].sendrawtransaction(tx_i_hex, True)
@ -423,14 +423,14 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Create a non-opting in transaction # Create a non-opting in transaction
tx1a = CTransaction() tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0xffffffff)] tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0xffffffff)]
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))] tx1a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
tx1a_hex = txToHex(tx1a) tx1a_hex = txToHex(tx1a)
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True) tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
# Shouldn't be able to double-spend # Shouldn't be able to double-spend
tx1b = CTransaction() tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)] tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))] tx1b.vout = [CTxOut(int(0.9 * COIN), CScript([b'b' * 35]))]
tx1b_hex = txToHex(tx1b) tx1b_hex = txToHex(tx1b)
# This will raise an exception # This will raise an exception
@ -441,14 +441,14 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Create a different non-opting in transaction # Create a different non-opting in transaction
tx2a = CTransaction() tx2a = CTransaction()
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0xfffffffe)] tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0xfffffffe)]
tx2a.vout = [CTxOut(1*COIN, CScript([b'a']))] tx2a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
tx2a_hex = txToHex(tx2a) tx2a_hex = txToHex(tx2a)
tx2a_txid = self.nodes[0].sendrawtransaction(tx2a_hex, True) tx2a_txid = self.nodes[0].sendrawtransaction(tx2a_hex, True)
# Still shouldn't be able to double-spend # Still shouldn't be able to double-spend
tx2b = CTransaction() tx2b = CTransaction()
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)] tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
tx2b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))] tx2b.vout = [CTxOut(int(0.9 * COIN), CScript([b'b' * 35]))]
tx2b_hex = txToHex(tx2b) tx2b_hex = txToHex(tx2b)
# This will raise an exception # This will raise an exception
@ -471,12 +471,12 @@ class ReplaceByFeeTest(BitcoinTestFramework):
tx3b = CTransaction() tx3b = CTransaction()
tx3b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)] tx3b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
tx3b.vout = [CTxOut(int(0.5*COIN), CScript([b'e']))] tx3b.vout = [CTxOut(int(0.5 * COIN), CScript([b'e' * 35]))]
tx3b_hex = txToHex(tx3b) tx3b_hex = txToHex(tx3b)
tx3c = CTransaction() tx3c = CTransaction()
tx3c.vin = [CTxIn(COutPoint(tx2a_txid, 0), nSequence=0)] tx3c.vin = [CTxIn(COutPoint(tx2a_txid, 0), nSequence=0)]
tx3c.vout = [CTxOut(int(0.5*COIN), CScript([b'f']))] tx3c.vout = [CTxOut(int(0.5 * COIN), CScript([b'f' * 35]))]
tx3c_hex = txToHex(tx3c) tx3c_hex = txToHex(tx3c)
self.nodes[0].sendrawtransaction(tx3b_hex, True) self.nodes[0].sendrawtransaction(tx3b_hex, True)
@ -493,7 +493,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
tx1a = CTransaction() tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)] tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))] tx1a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
tx1a_hex = txToHex(tx1a) tx1a_hex = txToHex(tx1a)
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True) tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
@ -519,14 +519,14 @@ class ReplaceByFeeTest(BitcoinTestFramework):
tx2a = CTransaction() tx2a = CTransaction()
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)] tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)]
tx2a.vout = [CTxOut(1*COIN, CScript([b'a']))] tx2a.vout = [CTxOut(1 * COIN, CScript([b'a' * 35]))]
tx2a_hex = txToHex(tx2a) tx2a_hex = txToHex(tx2a)
self.nodes[0].sendrawtransaction(tx2a_hex, True) self.nodes[0].sendrawtransaction(tx2a_hex, True)
# Lower fee, but we'll prioritise it # Lower fee, but we'll prioritise it
tx2b = CTransaction() tx2b = CTransaction()
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)] tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
tx2b.vout = [CTxOut(int(1.01*COIN), CScript([b'a']))] tx2b.vout = [CTxOut(int(1.01 * COIN), CScript([b'a' * 35]))]
tx2b.rehash() tx2b.rehash()
tx2b_hex = txToHex(tx2b) tx2b_hex = txToHex(tx2b)

6
test/functional/feature_segwit.py

@ -16,7 +16,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
from test_framework.mininode import sha256, CTransaction, CTxIn, COutPoint, CTxOut, COIN, ToHex, FromHex from test_framework.mininode import sha256, CTransaction, CTxIn, COutPoint, CTxOut, COIN, ToHex, FromHex
from test_framework.address import script_to_p2sh, key_to_p2pkh from test_framework.address import script_to_p2sh, key_to_p2pkh
from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, OP_TRUE from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, OP_TRUE, OP_DROP
from io import BytesIO from io import BytesIO
NODE_0 = 0 NODE_0 = 0
@ -218,7 +218,7 @@ class SegWitTest(BitcoinTestFramework):
# Now create tx2, which will spend from txid1. # Now create tx2, which will spend from txid1.
tx = CTransaction() tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b'')) tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b''))
tx.vout.append(CTxOut(int(49.99*COIN), CScript([OP_TRUE]))) tx.vout.append(CTxOut(int(49.99 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
tx2_hex = self.nodes[0].signrawtransaction(ToHex(tx))['hex'] tx2_hex = self.nodes[0].signrawtransaction(ToHex(tx))['hex']
txid2 = self.nodes[0].sendrawtransaction(tx2_hex) txid2 = self.nodes[0].sendrawtransaction(tx2_hex)
tx = FromHex(CTransaction(), tx2_hex) tx = FromHex(CTransaction(), tx2_hex)
@ -227,7 +227,7 @@ class SegWitTest(BitcoinTestFramework):
# Now create tx3, which will spend from txid2 # Now create tx3, which will spend from txid2
tx = CTransaction() tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b"")) tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b""))
tx.vout.append(CTxOut(int(49.95*COIN), CScript([OP_TRUE]))) # Huge fee tx.vout.append(CTxOut(int(49.95 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))) # Huge fee
tx.calc_sha256() tx.calc_sha256()
txid3 = self.nodes[0].sendrawtransaction(ToHex(tx)) txid3 = self.nodes[0].sendrawtransaction(ToHex(tx))
assert(tx.wit.is_null()) assert(tx.wit.is_null())

5
test/functional/p2p_compactblocks.py

@ -12,7 +12,8 @@ from test_framework.mininode import *
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment
from test_framework.script import CScript, OP_TRUE from test_framework.script import CScript, OP_TRUE, OP_DROP
# TestNode: A peer we use to send messages to bitcoind, and store responses. # TestNode: A peer we use to send messages to bitcoind, and store responses.
class TestNode(P2PInterface): class TestNode(P2PInterface):
@ -423,7 +424,7 @@ class CompactBlocksTest(BitcoinTestFramework):
for i in range(num_transactions): for i in range(num_transactions):
tx = CTransaction() tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(utxo[0], utxo[1]), b'')) tx.vin.append(CTxIn(COutPoint(utxo[0], utxo[1]), b''))
tx.vout.append(CTxOut(utxo[2] - 1000, CScript([OP_TRUE]))) tx.vout.append(CTxOut(utxo[2] - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
tx.rehash() tx.rehash()
utxo = [tx.sha256, 0, tx.vout[0].nValue] utxo = [tx.sha256, 0, tx.vout[0].nValue]
block.vtx.append(tx) block.vtx.append(tx)

2
test/functional/p2p_invalid_tx.py

@ -64,7 +64,7 @@ class InvalidTxRequestTest(ComparisonTestFramework):
# b'\x64' is OP_NOTIF # b'\x64' is OP_NOTIF
# Transaction will be rejected with code 16 (REJECT_INVALID) # Transaction will be rejected with code 16 (REJECT_INVALID)
tx1 = create_transaction(self.block1.vtx[0], 0, b'\x64', 50 * COIN - 12000) tx1 = create_transaction(self.block1.vtx[0], 0, b'\x64' * 35, 50 * COIN - 12000)
yield TestInstance([[tx1, RejectResult(16, b'mandatory-script-verify-flag-failed')]]) yield TestInstance([[tx1, RejectResult(16, b'mandatory-script-verify-flag-failed')]])
# TODO: test further transactions... # TODO: test further transactions...

14
test/functional/p2p_segwit.py

@ -168,7 +168,7 @@ class SegWitTest(BitcoinTestFramework):
# Create a transaction that spends the coinbase # Create a transaction that spends the coinbase
tx = CTransaction() tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(txid, 0), b"")) tx.vin.append(CTxIn(COutPoint(txid, 0), b""))
tx.vout.append(CTxOut(49*100000000, CScript([OP_TRUE]))) tx.vout.append(CTxOut(49 * 100000000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
tx.calc_sha256() tx.calc_sha256()
# Check that serializing it with or without witness is the same # Check that serializing it with or without witness is the same
@ -259,7 +259,7 @@ class SegWitTest(BitcoinTestFramework):
# Now create a new anyone-can-spend utxo for the next test. # Now create a new anyone-can-spend utxo for the next test.
tx4 = CTransaction() tx4 = CTransaction()
tx4.vin.append(CTxIn(COutPoint(tx3.sha256, 0), CScript([p2sh_program]))) tx4.vin.append(CTxIn(COutPoint(tx3.sha256, 0), CScript([p2sh_program])))
tx4.vout.append(CTxOut(tx3.vout[0].nValue-1000, CScript([OP_TRUE]))) tx4.vout.append(CTxOut(tx3.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
tx4.rehash() tx4.rehash()
test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, False, True) test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, False, True)
test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx4, False, True) test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx4, False, True)
@ -814,7 +814,7 @@ class SegWitTest(BitcoinTestFramework):
assert(len(self.utxo)) assert(len(self.utxo))
tx = CTransaction() tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
tx.vout.append(CTxOut(self.utxo[0].nValue-1000, CScript([OP_TRUE]))) tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
tx.wit.vtxinwit.append(CTxInWitness()) tx.wit.vtxinwit.append(CTxInWitness())
tx.wit.vtxinwit[0].scriptWitness.stack = [ b'a' ] tx.wit.vtxinwit[0].scriptWitness.stack = [ b'a' ]
tx.rehash() tx.rehash()
@ -866,7 +866,7 @@ class SegWitTest(BitcoinTestFramework):
assert(len(self.utxo)) assert(len(self.utxo))
tx = CTransaction() tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
tx.vout.append(CTxOut(self.utxo[0].nValue-1000, CScript([OP_TRUE]))) tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
tx.wit.vtxinwit.append(CTxInWitness()) tx.wit.vtxinwit.append(CTxInWitness())
tx.wit.vtxinwit[0].scriptWitness.stack = [ b'a' ] tx.wit.vtxinwit[0].scriptWitness.stack = [ b'a' ]
tx.rehash() tx.rehash()
@ -910,7 +910,7 @@ class SegWitTest(BitcoinTestFramework):
test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx3, True, False, b'tx-size') test_transaction_acceptance(self.nodes[1].rpc, self.std_node, tx3, True, False, b'tx-size')
# Remove witness stuffing, instead add extra witness push on stack # Remove witness stuffing, instead add extra witness push on stack
tx3.vout[0] = CTxOut(tx2.vout[0].nValue-1000, CScript([OP_TRUE])) tx3.vout[0] = CTxOut(tx2.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))
tx3.wit.vtxinwit[0].scriptWitness.stack = [CScript([CScriptNum(1)]), witness_program ] tx3.wit.vtxinwit[0].scriptWitness.stack = [CScript([CScriptNum(1)]), witness_program ]
tx3.rehash() tx3.rehash()
@ -1096,7 +1096,7 @@ class SegWitTest(BitcoinTestFramework):
# P2PKH output; just send tx's first output back to an anyone-can-spend. # P2PKH output; just send tx's first output back to an anyone-can-spend.
sync_mempools([self.nodes[0], self.nodes[1]]) sync_mempools([self.nodes[0], self.nodes[1]])
tx3.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")] tx3.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")]
tx3.vout = [CTxOut(tx.vout[0].nValue-1000, CScript([OP_TRUE]))] tx3.vout = [CTxOut(tx.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))]
tx3.wit.vtxinwit.append(CTxInWitness()) tx3.wit.vtxinwit.append(CTxInWitness())
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program] tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program]
tx3.rehash() tx3.rehash()
@ -1104,7 +1104,7 @@ class SegWitTest(BitcoinTestFramework):
else: else:
# tx and tx2 didn't go anywhere; just clean up the p2sh_tx output. # tx and tx2 didn't go anywhere; just clean up the p2sh_tx output.
tx3.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_program]))] tx3.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_program]))]
tx3.vout = [CTxOut(p2sh_tx.vout[0].nValue-1000, witness_program)] tx3.vout = [CTxOut(p2sh_tx.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))]
tx3.rehash() tx3.rehash()
test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, with_witness=True, accepted=True) test_transaction_acceptance(self.nodes[0].rpc, self.test_node, tx3, with_witness=True, accepted=True)

Loading…
Cancel
Save