0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

Merge bitcoin/bitcoin#26277: test: Remove confusing DUMMY_P2WPKH_SCRIPT

fa8a305ddd test: Remove confusing DUMMY_P2WPKH_SCRIPT (MacroFake)

Pull request description:

  It is confusing because, it is *not* a P2WPKH script, and it is nonstandard.

  See also https://github.com/bitcoin/bitcoin/pull/26265/files#r989827855

  Fix all issues by removing it, and also remove the no longer needed `-acceptnonstdtxn` setting from the test.

ACKs for top commit:
  instagibbs:
    ACK fa8a305ddd
  theStack:
    Code-review ACK fa8a305ddd 📜

Tree-SHA512: 64f3e0009b055e4fd4428b20f3e85582e1608e9b06e500b8fbfeb91fc35ce510e69d051e8f48ce35d0320067793e12f4423b214cc1f68c217a5872e0ad97d211
This commit is contained in:
fanquake 2022-10-10 15:26:10 +08:00
commit 857f07dfd0
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -10,15 +10,21 @@ from test_framework.blocktools import (
NORMAL_GBT_REQUEST_PARAMS, NORMAL_GBT_REQUEST_PARAMS,
add_witness_commitment, add_witness_commitment,
create_block, create_block,
script_to_p2wsh_script,
) )
from test_framework.messages import ( from test_framework.messages import (
COIN, COIN,
COutPoint, COutPoint,
CTransaction, CTransaction,
CTxIn, CTxIn,
CTxInWitness,
CTxOut, CTxOut,
tx_from_hex, tx_from_hex,
) )
from test_framework.script import (
CScript,
OP_TRUE,
)
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
@ -26,7 +32,8 @@ from test_framework.util import (
assert_raises_rpc_error, assert_raises_rpc_error,
softfork_active, softfork_active,
) )
from test_framework.script_util import DUMMY_P2WPKH_SCRIPT
SCRIPT_W0_SH_OP_TRUE = script_to_p2wsh_script(CScript([OP_TRUE]))
SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31) SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31)
SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height) SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height)
@ -42,11 +49,9 @@ class BIP68Test(BitcoinTestFramework):
self.extra_args = [ self.extra_args = [
[ [
'-testactivationheight=csv@432', '-testactivationheight=csv@432',
"-acceptnonstdtxn=1",
], ],
[ [
'-testactivationheight=csv@432', '-testactivationheight=csv@432',
"-acceptnonstdtxn=0",
], ],
] ]
@ -100,7 +105,7 @@ class BIP68Test(BitcoinTestFramework):
# input to mature. # input to mature.
sequence_value = SEQUENCE_LOCKTIME_DISABLE_FLAG | 1 sequence_value = SEQUENCE_LOCKTIME_DISABLE_FLAG | 1
tx1.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), nSequence=sequence_value)] tx1.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), nSequence=sequence_value)]
tx1.vout = [CTxOut(value, DUMMY_P2WPKH_SCRIPT)] tx1.vout = [CTxOut(value, SCRIPT_W0_SH_OP_TRUE)]
tx1_signed = self.nodes[0].signrawtransactionwithwallet(tx1.serialize().hex())["hex"] tx1_signed = self.nodes[0].signrawtransactionwithwallet(tx1.serialize().hex())["hex"]
tx1_id = self.nodes[0].sendrawtransaction(tx1_signed) tx1_id = self.nodes[0].sendrawtransaction(tx1_signed)
@ -112,7 +117,9 @@ 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), DUMMY_P2WPKH_SCRIPT)] tx2.wit.vtxinwit = [CTxInWitness()]
tx2.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
tx2.vout = [CTxOut(int(value - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
tx2.rehash() tx2.rehash()
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, tx2.serialize().hex()) assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, tx2.serialize().hex())
@ -207,7 +214,7 @@ class BIP68Test(BitcoinTestFramework):
value += utxos[j]["amount"]*COIN value += utxos[j]["amount"]*COIN
# Overestimate the size of the tx - signatures should be less than 120 bytes, and leave 50 for the output # Overestimate the size of the tx - signatures should be less than 120 bytes, and leave 50 for the output
tx_size = len(tx.serialize().hex())//2 + 120*num_inputs + 50 tx_size = len(tx.serialize().hex())//2 + 120*num_inputs + 50
tx.vout.append(CTxOut(int(value-self.relayfee*tx_size*COIN/1000), DUMMY_P2WPKH_SCRIPT)) tx.vout.append(CTxOut(int(value - self.relayfee * tx_size * COIN / 1000), SCRIPT_W0_SH_OP_TRUE))
rawtx = self.nodes[0].signrawtransactionwithwallet(tx.serialize().hex())["hex"] rawtx = self.nodes[0].signrawtransactionwithwallet(tx.serialize().hex())["hex"]
if (using_sequence_locks and not should_pass): if (using_sequence_locks and not should_pass):
@ -236,7 +243,7 @@ class BIP68Test(BitcoinTestFramework):
tx2 = CTransaction() tx2 = CTransaction()
tx2.nVersion = 2 tx2.nVersion = 2
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)] tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), DUMMY_P2WPKH_SCRIPT)] tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
tx2_raw = self.nodes[0].signrawtransactionwithwallet(tx2.serialize().hex())["hex"] tx2_raw = self.nodes[0].signrawtransactionwithwallet(tx2.serialize().hex())["hex"]
tx2 = tx_from_hex(tx2_raw) tx2 = tx_from_hex(tx2_raw)
tx2.rehash() tx2.rehash()
@ -254,7 +261,9 @@ 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), DUMMY_P2WPKH_SCRIPT)] tx.wit.vtxinwit = [CTxInWitness()]
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
tx.rehash() tx.rehash()
if (orig_tx.hash in node.getrawmempool()): if (orig_tx.hash in node.getrawmempool()):
@ -367,7 +376,7 @@ class BIP68Test(BitcoinTestFramework):
tx2 = CTransaction() tx2 = CTransaction()
tx2.nVersion = 1 tx2.nVersion = 1
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)] tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), DUMMY_P2WPKH_SCRIPT)] tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
# sign tx2 # sign tx2
tx2_raw = self.nodes[0].signrawtransactionwithwallet(tx2.serialize().hex())["hex"] tx2_raw = self.nodes[0].signrawtransactionwithwallet(tx2.serialize().hex())["hex"]
@ -382,7 +391,9 @@ 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), DUMMY_P2WPKH_SCRIPT)] tx3.wit.vtxinwit = [CTxInWitness()]
tx3.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
tx3.rehash() tx3.rehash()
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, tx3.serialize().hex()) assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, tx3.serialize().hex())