2016-05-06 11:23:48 +02:00
#!/usr/bin/env python3
2023-08-16 19:27:31 +02:00
# Copyright (c) 2015-2020 The Bitcoin Core developers
2016-05-06 11:23:48 +02:00
# Distributed under the MIT software license, see the accompanying
2016-03-11 00:36:55 +01:00
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
2019-08-15 22:02:02 +02:00
""" Test CSV soft fork activation.
2016-03-11 00:36:55 +01:00
This soft fork will activate the following BIPS :
BIP 68 - nSequence relative lock times
BIP 112 - CHECKSEQUENCEVERIFY
BIP 113 - MedianTimePast semantics for nLockTime
2021-04-19 09:47:54 +02:00
mine 83 blocks whose coinbases will be used to generate inputs for our tests
mine 344 blocks and seed block chain with the 83 inputs used for our tests at height 427
2019-08-15 22:02:02 +02:00
mine 2 blocks and verify soft fork not yet activated
mine 1 block and test that soft fork is activated ( rules enforced for next block )
2016-03-11 00:36:55 +01:00
Test BIP 113 is enforced
Mine 4 blocks so next height is 580 and test BIP 68 is enforced for time and height
Mine 1 block so next height is 581 and test BIP 68 now passes time but not height
Mine 1 block so next height is 582 and test BIP 68 now passes time and height
Test that BIP 112 is enforced
Various transactions will be used to test that the BIPs rules are not enforced before the soft fork activates
And that after the soft fork activates transactions pass and fail as they should according to the rules .
For each BIP , transactions of versions 1 and 2 will be tested .
- - - - - - - - - - - - - - - -
BIP 113 :
bip113tx - modify the nLocktime variable
BIP 68 :
bip68txs - 16 txs with nSequence relative locktime of 10 with various bits set as per the relative_locktimes below
BIP 112 :
bip112txs_vary_nSequence - 16 txs with nSequence relative_locktimes of 10 evaluated against 10 OP_CSV OP_DROP
bip112txs_vary_nSequence_9 - 16 txs with nSequence relative_locktimes of 9 evaluated against 10 OP_CSV OP_DROP
bip112txs_vary_OP_CSV - 16 txs with nSequence = 10 evaluated against varying { relative_locktimes of 10 } OP_CSV OP_DROP
bip112txs_vary_OP_CSV_9 - 16 txs with nSequence = 9 evaluated against varying { relative_locktimes of 10 } OP_CSV OP_DROP
bip112tx_special - test negative argument to OP_CSV
2020-02-28 16:49:18 +01:00
bip112tx_emptystack - test empty stack ( = no argument ) OP_CSV
2019-01-07 10:55:35 +01:00
"""
2020-01-11 02:31:44 +01:00
from itertools import product
2019-01-07 10:55:35 +01:00
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
from test_framework . blocktools import (
create_block ,
create_coinbase ,
TIME_GENESIS_BLOCK ,
)
2024-01-15 20:35:29 +01:00
from test_framework . p2p import P2PDataStore
2020-01-11 02:31:44 +01:00
from test_framework . script import (
CScript ,
OP_CHECKSEQUENCEVERIFY ,
OP_DROP ,
)
2019-02-15 14:56:43 +01:00
from test_framework . test_framework import BitcoinTestFramework
2020-01-11 02:31:44 +01:00
from test_framework . util import (
assert_equal ,
2019-08-15 22:02:02 +02:00
softfork_active ,
2020-01-11 02:31:44 +01:00
)
2021-05-25 07:26:18 +02:00
from test_framework . wallet import (
MiniWallet ,
MiniWalletMode ,
)
2020-01-11 02:31:44 +01:00
2020-02-28 16:49:18 +01:00
TESTING_TX_COUNT = 83 # Number of testing transactions: 1 BIP113 tx, 16 BIP68 txs, 66 BIP112 txs (see comments above)
COINBASE_BLOCK_COUNT = TESTING_TX_COUNT # Number of coinbase blocks we need to generate as inputs for our txs
2020-01-11 02:31:44 +01:00
BASE_RELATIVE_LOCKTIME = 10
SEQ_DISABLE_FLAG = 1 << 31
SEQ_RANDOM_HIGH_BIT = 1 << 25
SEQ_TYPE_FLAG = 1 << 22
SEQ_RANDOM_LOW_BIT = 1 << 18
2021-09-10 10:02:03 +02:00
2020-01-11 02:31:44 +01:00
def relative_locktime ( sdf , srhb , stf , srlb ) :
""" Returns a locktime with certain bits set. """
locktime = BASE_RELATIVE_LOCKTIME
if sdf :
locktime | = SEQ_DISABLE_FLAG
if srhb :
locktime | = SEQ_RANDOM_HIGH_BIT
if stf :
locktime | = SEQ_TYPE_FLAG
if srlb :
locktime | = SEQ_RANDOM_LOW_BIT
return locktime
2021-09-10 10:02:03 +02:00
2020-01-11 02:31:44 +01:00
def all_rlt_txs ( txs ) :
return [ tx [ ' tx ' ] for tx in txs ]
2021-09-24 14:04:51 +02:00
CSV_ACTIVATION_HEIGHT = 432
2020-01-11 02:31:44 +01:00
class BIP68_112_113Test ( BitcoinTestFramework ) :
2017-09-01 18:47:13 +02:00
def set_test_params ( self ) :
2016-03-11 00:36:55 +01:00
self . num_nodes = 1
2017-09-01 18:47:13 +02:00
self . setup_clean_chain = True
2024-08-01 22:31:06 +02:00
# Must set '-dip3params=2000:2000' to create pre-dip3 blocks only
2020-02-28 05:18:57 +01:00
self . extra_args = [ [
2021-09-10 10:02:03 +02:00
' -peertimeout=999999 ' , # bump because mocktime might cause a disconnect otherwise
2020-02-28 05:18:57 +01:00
' -whitelist=noban@127.0.0.1 ' ,
2024-08-01 22:31:06 +02:00
' -dip3params=2000:2000 ' ,
2021-09-24 14:04:51 +02:00
f ' -testactivationheight=csv@ { CSV_ACTIVATION_HEIGHT } ' ,
2020-02-28 16:49:18 +01:00
' -par=1 ' , # Use only one script thread to get the exact reject reason for testing
2020-02-28 05:18:57 +01:00
] ]
2019-12-09 19:52:38 +01:00
self . supports_cli = False
2016-03-11 00:36:55 +01:00
2019-06-21 15:44:29 +02:00
def setup_network ( self ) :
self . setup_nodes ( )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
def create_self_transfer_from_utxo ( self , input_tx ) :
utxo = self . miniwallet . get_utxo ( txid = input_tx . rehash ( ) , mark_as_spent = False )
tx = self . miniwallet . create_self_transfer ( from_node = self . nodes [ 0 ] , utxo_to_spend = utxo ) [ ' tx ' ]
return tx
def create_bip112special ( self , input , txversion ) :
tx = self . create_self_transfer_from_utxo ( input )
tx . nVersion = txversion
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( tx )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
tx . vin [ 0 ] . scriptSig = CScript ( [ - 1 , OP_CHECKSEQUENCEVERIFY , OP_DROP ] + list ( CScript ( tx . vin [ 0 ] . scriptSig ) ) )
return tx
def create_bip112emptystack ( self , input , txversion ) :
tx = self . create_self_transfer_from_utxo ( input )
tx . nVersion = txversion
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( tx )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
tx . vin [ 0 ] . scriptSig = CScript ( [ OP_CHECKSEQUENCEVERIFY ] + list ( CScript ( tx . vin [ 0 ] . scriptSig ) ) )
return tx
def send_generic_input_tx ( self , coinbases ) :
input_txid = self . nodes [ 0 ] . getblock ( coinbases . pop ( ) , 2 ) [ ' tx ' ] [ 0 ] [ ' txid ' ]
utxo_to_spend = self . miniwallet . get_utxo ( txid = input_txid )
return self . miniwallet . send_self_transfer ( from_node = self . nodes [ 0 ] , utxo_to_spend = utxo_to_spend ) [ ' tx ' ]
def create_bip68txs ( self , bip68inputs , txversion , locktime_delta = 0 ) :
""" Returns a list of bip68 transactions with different bits set. """
txs = [ ]
assert len ( bip68inputs ) > = 16
for i , ( sdf , srhb , stf , srlb ) in enumerate ( product ( * [ [ True , False ] ] * 4 ) ) :
locktime = relative_locktime ( sdf , srhb , stf , srlb )
tx = self . create_self_transfer_from_utxo ( bip68inputs [ i ] )
tx . nVersion = txversion
tx . vin [ 0 ] . nSequence = locktime + locktime_delta
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( tx )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
tx . rehash ( )
txs . append ( { ' tx ' : tx , ' sdf ' : sdf , ' stf ' : stf } )
return txs
def create_bip112txs ( self , bip112inputs , varyOP_CSV , txversion , locktime_delta = 0 ) :
""" Returns a list of bip68 transactions with different bits set. """
txs = [ ]
assert len ( bip112inputs ) > = 16
for i , ( sdf , srhb , stf , srlb ) in enumerate ( product ( * [ [ True , False ] ] * 4 ) ) :
locktime = relative_locktime ( sdf , srhb , stf , srlb )
tx = self . create_self_transfer_from_utxo ( bip112inputs [ i ] )
2021-09-10 10:02:03 +02:00
if varyOP_CSV : # if varying OP_CSV, nSequence is fixed
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
tx . vin [ 0 ] . nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta
else : # vary nSequence instead, OP_CSV is fixed
tx . vin [ 0 ] . nSequence = locktime + locktime_delta
tx . nVersion = txversion
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( tx )
2021-09-10 10:02:03 +02:00
if varyOP_CSV :
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
tx . vin [ 0 ] . scriptSig = CScript ( [ locktime , OP_CHECKSEQUENCEVERIFY , OP_DROP ] + list ( CScript ( tx . vin [ 0 ] . scriptSig ) ) )
else :
tx . vin [ 0 ] . scriptSig = CScript ( [ BASE_RELATIVE_LOCKTIME , OP_CHECKSEQUENCEVERIFY , OP_DROP ] + list ( CScript ( tx . vin [ 0 ] . scriptSig ) ) )
tx . rehash ( )
txs . append ( { ' tx ' : tx , ' sdf ' : sdf , ' stf ' : stf } )
return txs
2018-09-13 12:33:15 +02:00
2019-08-15 22:02:02 +02:00
def generate_blocks ( self , number ) :
test_blocks = [ ]
2020-08-11 02:50:34 +02:00
for _ in range ( number ) :
2019-08-15 22:02:02 +02:00
block = self . create_test_block ( [ ] )
2020-01-11 02:31:44 +01:00
test_blocks . append ( block )
2016-03-11 00:36:55 +01:00
self . last_block_time + = 600
self . tip = block . sha256
self . tipheight + = 1
return test_blocks
2019-08-15 22:02:02 +02:00
def create_test_block ( self , txs ) :
2016-03-11 00:36:55 +01:00
block = create_block ( self . tip , create_coinbase ( self . tipheight + 1 ) , self . last_block_time + 600 )
2019-08-15 22:02:02 +02:00
block . nVersion = 4
2016-03-11 00:36:55 +01:00
block . vtx . extend ( txs )
block . hashMerkleRoot = block . calc_merkle_root ( )
block . rehash ( )
block . solve ( )
return block
2020-02-28 16:49:18 +01:00
def send_blocks ( self , blocks , success = True , reject_reason = None ) :
2020-01-11 02:31:44 +01:00
""" Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block.
Call with success = False if the tip shouldn ' t advance to the most recent block. " " "
2020-09-25 14:18:21 +02:00
self . helper_peer . send_blocks_and_test ( blocks , self . nodes [ 0 ] , success = success , reject_reason = reject_reason )
2020-01-11 02:31:44 +01:00
def run_test ( self ) :
2020-09-25 14:18:21 +02:00
self . helper_peer = self . nodes [ 0 ] . add_p2p_connection ( P2PDataStore ( ) )
2021-05-25 07:26:18 +02:00
self . miniwallet = MiniWallet ( self . nodes [ 0 ] , mode = MiniWalletMode . RAW_P2PK )
2020-01-11 02:31:44 +01:00
self . log . info ( " Generate blocks in the past for coinbase outputs. " )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
self . coinbase_blocks = self . miniwallet . generate ( COINBASE_BLOCK_COUNT ) # blocks generated for inputs
2018-04-18 13:48:59 +02:00
# set time so that there was enough time to build up to 1000 blocks 10 minutes apart on top of the last one
# without worrying about getting into the future
2019-02-15 14:56:43 +01:00
self . nodes [ 0 ] . setmocktime ( TIME_GENESIS_BLOCK + 600 * 1000 + 100 )
2020-02-28 16:49:18 +01:00
self . tipheight = COINBASE_BLOCK_COUNT # height of the next block to build
2019-02-15 14:56:43 +01:00
self . last_block_time = TIME_GENESIS_BLOCK
2020-01-11 02:31:44 +01:00
self . tip = int ( self . nodes [ 0 ] . getbestblockhash ( ) , 16 )
2016-03-11 00:36:55 +01:00
2019-08-15 22:02:02 +02:00
# Activation height is hardcoded
2021-09-10 10:02:03 +02:00
test_blocks = self . generate_blocks ( CSV_ACTIVATION_HEIGHT - 5 - COINBASE_BLOCK_COUNT )
2019-08-15 22:02:02 +02:00
#test_blocks = self.generate_blocks(345)
2020-04-14 12:00:16 +02:00
self . send_blocks ( test_blocks )
2019-08-15 22:02:02 +02:00
assert not softfork_active ( self . nodes [ 0 ] , ' csv ' )
2016-03-11 00:36:55 +01:00
2019-08-15 22:02:02 +02:00
# Inputs at height = 431
2020-01-11 02:31:44 +01:00
#
2019-08-15 22:02:02 +02:00
# Put inputs for all tests in the chain at height 431 (tip now = 430) (time increases by 600s per block)
2016-03-11 00:36:55 +01:00
# Note we reuse inputs for v1 and v2 txs so must test these separately
# 16 normal inputs
bip68inputs = [ ]
2020-08-11 02:50:34 +02:00
for _ in range ( 16 ) :
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip68inputs . append ( self . send_generic_input_tx ( self . coinbase_blocks ) )
2020-01-11 02:31:44 +01:00
2016-03-11 00:36:55 +01:00
# 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
bip112basicinputs = [ ]
2020-08-11 02:50:34 +02:00
for _ in range ( 2 ) :
2016-03-11 00:36:55 +01:00
inputs = [ ]
2020-08-11 02:50:34 +02:00
for _ in range ( 16 ) :
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
inputs . append ( self . send_generic_input_tx ( self . coinbase_blocks ) )
2016-03-11 00:36:55 +01:00
bip112basicinputs . append ( inputs )
2020-01-11 02:31:44 +01:00
2016-03-11 00:36:55 +01:00
# 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
bip112diverseinputs = [ ]
2020-08-11 02:50:34 +02:00
for _ in range ( 2 ) :
2016-03-11 00:36:55 +01:00
inputs = [ ]
2020-08-11 02:50:34 +02:00
for _ in range ( 16 ) :
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
inputs . append ( self . send_generic_input_tx ( self . coinbase_blocks ) )
2016-03-11 00:36:55 +01:00
bip112diverseinputs . append ( inputs )
2020-01-11 02:31:44 +01:00
2016-03-11 00:36:55 +01:00
# 1 special input with -1 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip112specialinput = self . send_generic_input_tx ( self . coinbase_blocks )
2020-02-28 16:49:18 +01:00
# 1 special input with (empty stack) OP_CSV (actually will be prepended to spending scriptSig)
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip112emptystackinput = self . send_generic_input_tx ( self . coinbase_blocks )
2020-01-11 02:31:44 +01:00
2016-03-11 00:36:55 +01:00
# 1 normal input
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip113input = self . send_generic_input_tx ( self . coinbase_blocks )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . setmocktime ( self . last_block_time + 600 )
2019-08-15 22:02:02 +02:00
inputblockhash = self . nodes [ 0 ] . generate ( 1 ) [ 0 ] # 1 block generated for inputs to be in chain at height 431
2019-02-15 14:56:43 +01:00
self . nodes [ 0 ] . setmocktime ( TIME_GENESIS_BLOCK + 600 * 1000 + 100 )
2020-01-11 02:31:44 +01:00
self . tip = int ( inputblockhash , 16 )
2016-03-11 00:36:55 +01:00
self . tipheight + = 1
self . last_block_time + = 600
2020-02-28 16:49:18 +01:00
assert_equal ( len ( self . nodes [ 0 ] . getblock ( inputblockhash , True ) [ " tx " ] ) , TESTING_TX_COUNT + 1 )
2016-03-11 00:36:55 +01:00
# 2 more version 4 blocks
2019-08-15 22:02:02 +02:00
test_blocks = self . generate_blocks ( 2 )
2020-04-14 12:00:16 +02:00
self . send_blocks ( test_blocks )
2020-01-11 02:31:44 +01:00
2019-08-15 22:02:02 +02:00
assert_equal ( self . tipheight , CSV_ACTIVATION_HEIGHT - 2 )
self . log . info ( " Height = {} , CSV not yet active (will activate for block {} , not {} ) " . format ( self . tipheight , CSV_ACTIVATION_HEIGHT , CSV_ACTIVATION_HEIGHT - 1 ) )
assert not softfork_active ( self . nodes [ 0 ] , ' csv ' )
2016-03-11 00:36:55 +01:00
# Test both version 1 and version 2 transactions for all tests
# BIP113 test transaction will be modified before each use to put in appropriate block time
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip113tx_v1 = self . create_self_transfer_from_utxo ( bip113input )
2016-03-11 00:36:55 +01:00
bip113tx_v1 . vin [ 0 ] . nSequence = 0xFFFFFFFE
2016-12-15 17:03:23 +01:00
bip113tx_v1 . nVersion = 1
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip113tx_v2 = self . create_self_transfer_from_utxo ( bip113input )
2016-03-11 00:36:55 +01:00
bip113tx_v2 . vin [ 0 ] . nSequence = 0xFFFFFFFE
bip113tx_v2 . nVersion = 2
# For BIP68 test all 16 relative sequence locktimes
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip68txs_v1 = self . create_bip68txs ( bip68inputs , 1 )
bip68txs_v2 = self . create_bip68txs ( bip68inputs , 2 )
2016-03-11 00:36:55 +01:00
# For BIP112 test:
# 16 relative sequence locktimes of 10 against 10 OP_CSV OP_DROP inputs
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip112txs_vary_nSequence_v1 = self . create_bip112txs ( bip112basicinputs [ 0 ] , False , 1 )
bip112txs_vary_nSequence_v2 = self . create_bip112txs ( bip112basicinputs [ 0 ] , False , 2 )
2016-03-11 00:36:55 +01:00
# 16 relative sequence locktimes of 9 against 10 OP_CSV OP_DROP inputs
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip112txs_vary_nSequence_9_v1 = self . create_bip112txs ( bip112basicinputs [ 1 ] , False , 1 , - 1 )
bip112txs_vary_nSequence_9_v2 = self . create_bip112txs ( bip112basicinputs [ 1 ] , False , 2 , - 1 )
2016-03-11 00:36:55 +01:00
# sequence lock time of 10 against 16 (relative_lock_time) OP_CSV OP_DROP inputs
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip112txs_vary_OP_CSV_v1 = self . create_bip112txs ( bip112diverseinputs [ 0 ] , True , 1 )
bip112txs_vary_OP_CSV_v2 = self . create_bip112txs ( bip112diverseinputs [ 0 ] , True , 2 )
2016-03-11 00:36:55 +01:00
# sequence lock time of 9 against 16 (relative_lock_time) OP_CSV OP_DROP inputs
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip112txs_vary_OP_CSV_9_v1 = self . create_bip112txs ( bip112diverseinputs [ 1 ] , True , 1 , - 1 )
bip112txs_vary_OP_CSV_9_v2 = self . create_bip112txs ( bip112diverseinputs [ 1 ] , True , 2 , - 1 )
2016-03-11 00:36:55 +01:00
# -1 OP_CSV OP_DROP input
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip112tx_special_v1 = self . create_bip112special ( bip112specialinput , 1 )
bip112tx_special_v2 = self . create_bip112special ( bip112specialinput , 2 )
2020-02-28 16:49:18 +01:00
# (empty stack) OP_CSV input
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip112tx_emptystack_v1 = self . create_bip112emptystack ( bip112emptystackinput , 1 )
bip112tx_emptystack_v2 = self . create_bip112emptystack ( bip112emptystackinput , 2 )
2020-01-11 02:31:44 +01:00
self . log . info ( " TESTING " )
2016-03-11 00:36:55 +01:00
2020-01-11 02:31:44 +01:00
self . log . info ( " Pre-Soft Fork Tests. All txs should pass. " )
self . log . info ( " Test version 1 txs " )
2016-03-11 00:36:55 +01:00
success_txs = [ ]
2020-02-28 16:49:18 +01:00
# BIP113 tx, -1 CSV tx and empty stack CSV tx should succeed
2020-01-11 02:31:44 +01:00
bip113tx_v1 . nLockTime = self . last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( bip113tx_v1 )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
success_txs . append ( bip113tx_v1 )
2016-03-11 00:36:55 +01:00
success_txs . append ( bip112tx_special_v1 )
2020-02-28 16:49:18 +01:00
success_txs . append ( bip112tx_emptystack_v1 )
2016-03-11 00:36:55 +01:00
# add BIP 68 txs
success_txs . extend ( all_rlt_txs ( bip68txs_v1 ) )
# add BIP 112 with seq=10 txs
success_txs . extend ( all_rlt_txs ( bip112txs_vary_nSequence_v1 ) )
success_txs . extend ( all_rlt_txs ( bip112txs_vary_OP_CSV_v1 ) )
# try BIP 112 with seq=9 txs
success_txs . extend ( all_rlt_txs ( bip112txs_vary_nSequence_9_v1 ) )
success_txs . extend ( all_rlt_txs ( bip112txs_vary_OP_CSV_9_v1 ) )
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( success_txs ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
2020-01-11 02:31:44 +01:00
self . log . info ( " Test version 2 txs " )
2016-03-11 00:36:55 +01:00
success_txs = [ ]
2020-02-28 16:49:18 +01:00
# BIP113 tx, -1 CSV tx and empty stack CSV tx should succeed
2020-01-11 02:31:44 +01:00
bip113tx_v2 . nLockTime = self . last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( bip113tx_v2 )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
success_txs . append ( bip113tx_v2 )
2016-03-11 00:36:55 +01:00
success_txs . append ( bip112tx_special_v2 )
2020-02-28 16:49:18 +01:00
success_txs . append ( bip112tx_emptystack_v2 )
2016-03-11 00:36:55 +01:00
# add BIP 68 txs
success_txs . extend ( all_rlt_txs ( bip68txs_v2 ) )
# add BIP 112 with seq=10 txs
success_txs . extend ( all_rlt_txs ( bip112txs_vary_nSequence_v2 ) )
success_txs . extend ( all_rlt_txs ( bip112txs_vary_OP_CSV_v2 ) )
# try BIP 112 with seq=9 txs
success_txs . extend ( all_rlt_txs ( bip112txs_vary_nSequence_9_v2 ) )
success_txs . extend ( all_rlt_txs ( bip112txs_vary_OP_CSV_9_v2 ) )
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( success_txs ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
2019-08-15 22:02:02 +02:00
# 1 more version 4 block to get us to height 432 so the fork should now be active for the next block
assert not softfork_active ( self . nodes [ 0 ] , ' csv ' )
test_blocks = self . generate_blocks ( 1 )
2020-04-14 12:00:16 +02:00
self . send_blocks ( test_blocks )
2019-08-15 22:02:02 +02:00
assert softfork_active ( self . nodes [ 0 ] , ' csv ' )
2016-03-11 00:36:55 +01:00
2020-01-11 02:31:44 +01:00
self . log . info ( " Post-Soft Fork Tests. " )
2016-03-11 00:36:55 +01:00
2020-01-11 02:31:44 +01:00
self . log . info ( " BIP 113 tests " )
2016-03-11 00:36:55 +01:00
# BIP 113 tests should now fail regardless of version number if nLockTime isn't satisfied by new rules
2020-01-11 02:31:44 +01:00
bip113tx_v1 . nLockTime = self . last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( bip113tx_v1 )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip113tx_v1 . rehash ( )
2020-01-11 02:31:44 +01:00
bip113tx_v2 . nLockTime = self . last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( bip113tx_v2 )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip113tx_v2 . rehash ( )
for bip113tx in [ bip113tx_v1 , bip113tx_v2 ] :
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ bip113tx ] ) ] , success = False , reject_reason = ' bad-txns-nonfinal ' )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
2016-03-11 00:36:55 +01:00
# BIP 113 tests should now pass if the locktime is < MTP
2020-01-11 02:31:44 +01:00
bip113tx_v1 . nLockTime = self . last_block_time - 600 * 5 - 1 # < MTP of prior block
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( bip113tx_v1 )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip113tx_v1 . rehash ( )
2020-01-11 02:31:44 +01:00
bip113tx_v2 . nLockTime = self . last_block_time - 600 * 5 - 1 # < MTP of prior block
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( bip113tx_v2 )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
bip113tx_v2 . rehash ( )
for bip113tx in [ bip113tx_v1 , bip113tx_v2 ] :
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( [ bip113tx ] ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
2019-08-15 22:02:02 +02:00
# Next block height = 437 after 4 blocks of random version
test_blocks = self . generate_blocks ( 4 )
2020-04-14 12:00:16 +02:00
self . send_blocks ( test_blocks )
2020-01-11 02:31:44 +01:00
self . log . info ( " BIP 68 tests " )
self . log . info ( " Test version 1 txs - all should still pass " )
2016-03-11 00:36:55 +01:00
success_txs = [ ]
success_txs . extend ( all_rlt_txs ( bip68txs_v1 ) )
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( success_txs ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
2020-01-11 02:31:44 +01:00
self . log . info ( " Test version 2 txs " )
2016-03-11 00:36:55 +01:00
# All txs with SEQUENCE_LOCKTIME_DISABLE_FLAG set pass
2020-01-11 02:31:44 +01:00
bip68success_txs = [ tx [ ' tx ' ] for tx in bip68txs_v2 if tx [ ' sdf ' ] ]
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( bip68success_txs ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
2020-01-11 02:31:44 +01:00
2016-03-11 00:36:55 +01:00
# All txs without flag fail as we are at delta height = 8 < 10 and delta time = 8 * 600 < 10 * 512
2020-01-11 02:31:44 +01:00
bip68timetxs = [ tx [ ' tx ' ] for tx in bip68txs_v2 if not tx [ ' sdf ' ] and tx [ ' stf ' ] ]
2016-03-11 00:36:55 +01:00
for tx in bip68timetxs :
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ tx ] ) ] , success = False , reject_reason = ' bad-txns-nonfinal ' )
2020-01-11 02:31:44 +01:00
bip68heighttxs = [ tx [ ' tx ' ] for tx in bip68txs_v2 if not tx [ ' sdf ' ] and not tx [ ' stf ' ] ]
2016-03-11 00:36:55 +01:00
for tx in bip68heighttxs :
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ tx ] ) ] , success = False , reject_reason = ' bad-txns-nonfinal ' )
2016-03-11 00:36:55 +01:00
2019-08-15 22:02:02 +02:00
# Advance one block to 438
test_blocks = self . generate_blocks ( 1 )
2020-04-14 12:00:16 +02:00
self . send_blocks ( test_blocks )
2016-03-11 00:36:55 +01:00
# Height txs should fail and time txs should now pass 9 * 600 > 10 * 512
bip68success_txs . extend ( bip68timetxs )
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( bip68success_txs ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
for tx in bip68heighttxs :
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ tx ] ) ] , success = False , reject_reason = ' bad-txns-nonfinal ' )
2016-03-11 00:36:55 +01:00
2019-08-15 22:02:02 +02:00
# Advance one block to 439
test_blocks = self . generate_blocks ( 1 )
2020-04-14 12:00:16 +02:00
self . send_blocks ( test_blocks )
2016-03-11 00:36:55 +01:00
# All BIP 68 txs should pass
bip68success_txs . extend ( bip68heighttxs )
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( bip68success_txs ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
2020-01-11 02:31:44 +01:00
self . log . info ( " BIP 112 tests " )
self . log . info ( " Test version 1 txs " )
2016-03-11 00:36:55 +01:00
2020-02-28 16:49:18 +01:00
# -1 OP_CSV tx and (empty stack) OP_CSV tx should fail
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ bip112tx_special_v1 ] ) ] , success = False ,
reject_reason = ' non-mandatory-script-verify-flag (Negative locktime) ' )
2020-02-28 16:49:18 +01:00
self . send_blocks ( [ self . create_test_block ( [ bip112tx_emptystack_v1 ] ) ] , success = False ,
reject_reason = ' non-mandatory-script-verify-flag (Operation not valid with the current stack size) ' )
2016-03-11 00:36:55 +01:00
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 1 txs should still pass
2020-01-11 02:31:44 +01:00
success_txs = [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_v1 if tx [ ' sdf ' ] ]
success_txs + = [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_9_v1 if tx [ ' sdf ' ] ]
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( success_txs ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, version 1 txs should now fail
2020-01-11 02:31:44 +01:00
fail_txs = all_rlt_txs ( bip112txs_vary_nSequence_v1 )
fail_txs + = all_rlt_txs ( bip112txs_vary_nSequence_9_v1 )
2020-02-28 21:07:36 +01:00
fail_txs + = [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_v1 if not tx [ ' sdf ' ] ]
2020-01-11 02:31:44 +01:00
fail_txs + = [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx [ ' sdf ' ] ]
2016-03-11 00:36:55 +01:00
for tx in fail_txs :
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ tx ] ) ] , success = False ,
reject_reason = ' non-mandatory-script-verify-flag (Locktime requirement not satisfied) ' )
2020-01-11 02:31:44 +01:00
self . log . info ( " Test version 2 txs " )
2016-03-11 00:36:55 +01:00
2020-02-28 16:49:18 +01:00
# -1 OP_CSV tx and (empty stack) OP_CSV tx should fail
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ bip112tx_special_v2 ] ) ] , success = False ,
reject_reason = ' non-mandatory-script-verify-flag (Negative locktime) ' )
2020-02-28 16:49:18 +01:00
self . send_blocks ( [ self . create_test_block ( [ bip112tx_emptystack_v2 ] ) ] , success = False ,
reject_reason = ' non-mandatory-script-verify-flag (Operation not valid with the current stack size) ' )
2016-03-11 00:36:55 +01:00
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 2 txs should pass (all sequence locks are met)
2020-01-11 02:31:44 +01:00
success_txs = [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_v2 if tx [ ' sdf ' ] ]
success_txs + = [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_9_v2 if tx [ ' sdf ' ] ]
2016-03-11 00:36:55 +01:00
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( success_txs ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
2020-01-11 02:31:44 +01:00
# SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV for all remaining txs ##
2016-03-11 00:36:55 +01:00
2020-01-11 02:31:44 +01:00
# All txs with nSequence 9 should fail either due to earlier mismatch or failing the CSV check
fail_txs = all_rlt_txs ( bip112txs_vary_nSequence_9_v2 )
fail_txs + = [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_9_v2 if not tx [ ' sdf ' ] ]
2016-03-11 00:36:55 +01:00
for tx in fail_txs :
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ tx ] ) ] , success = False ,
reject_reason = ' non-mandatory-script-verify-flag (Locktime requirement not satisfied) ' )
2016-03-11 00:36:55 +01:00
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in nSequence, tx should fail
2020-01-11 02:31:44 +01:00
fail_txs = [ tx [ ' tx ' ] for tx in bip112txs_vary_nSequence_v2 if tx [ ' sdf ' ] ]
2016-03-11 00:36:55 +01:00
for tx in fail_txs :
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ tx ] ) ] , success = False ,
reject_reason = ' non-mandatory-script-verify-flag (Locktime requirement not satisfied) ' )
2016-03-11 00:36:55 +01:00
# If sequencelock types mismatch, tx should fail
2020-01-11 02:31:44 +01:00
fail_txs = [ tx [ ' tx ' ] for tx in bip112txs_vary_nSequence_v2 if not tx [ ' sdf ' ] and tx [ ' stf ' ] ]
fail_txs + = [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_v2 if not tx [ ' sdf ' ] and tx [ ' stf ' ] ]
2016-03-11 00:36:55 +01:00
for tx in fail_txs :
2020-02-28 21:07:36 +01:00
self . send_blocks ( [ self . create_test_block ( [ tx ] ) ] , success = False ,
reject_reason = ' non-mandatory-script-verify-flag (Locktime requirement not satisfied) ' )
2016-03-11 00:36:55 +01:00
# Remaining txs should pass, just test masking works properly
2020-01-11 02:31:44 +01:00
success_txs = [ tx [ ' tx ' ] for tx in bip112txs_vary_nSequence_v2 if not tx [ ' sdf ' ] and not tx [ ' stf ' ] ]
success_txs + = [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_v2 if not tx [ ' sdf ' ] and not tx [ ' stf ' ] ]
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( success_txs ) ] )
2016-03-11 00:36:55 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
# Additional test, of checking that comparison of two time types works properly
time_txs = [ ]
2020-01-11 02:31:44 +01:00
for tx in [ tx [ ' tx ' ] for tx in bip112txs_vary_OP_CSV_v2 if not tx [ ' sdf ' ] and tx [ ' stf ' ] ] :
tx . vin [ 0 ] . nSequence = BASE_RELATIVE_LOCKTIME | SEQ_TYPE_FLAG
2021-05-24 08:29:05 +02:00
self . miniwallet . sign_tx ( tx )
Merge bitcoin/bitcoin#21900: test: use MiniWallet for feature_csv_activation.py
bd7f27d16dacf6f7de3b4f6bd052def41d9601be refactor: feature_csv_activation.py: move tx helper functions to methods (Sebastian Falbesoner)
2eca46b0aa0ecf4738500b53523d7013985b387d test: use MiniWallet for feature_csv_activation.py (Sebastian Falbesoner)
Pull request description:
This PR enables one more of the non-wallet functional tests (feature_csv_activation.py) to be run even with the Bitcoin Core wallet disabled by using the new MiniWallet instead, as proposed in #20078.
Short reviewers guideline:
- Since we exclusively work with anyone-can-spend outputs here (raw scriptPubKey = OP_TRUE), signing is not needed anymore. The function `sign_transaction` and its calls are removed, after changing a tx (e.g. its scriptSig or nVersion) a simple `.rehash()` call is sufficient. Also, generating an address `self.nodeaddress` (and with that, passing it to the the various test tx creation/sending helper methods) is not needed anymore and removed.
- The test repeatedly uses the same input for creating different txs (e.g. with different txversions 1 and 2). To let `MiniWallet` create a tx with a specific input, we have to call `.get_utxo()` before which also marks the UTXO as spent. The method is changed to also support keeping the UTXO in its internal list (`mark_as_spent=False`). With the behaviour on master, the second call to `.get_utxo()` with the same input would fail.
- To keep the diff in the first commit short, the `miniwallet` is set as a global variable, to avoid passing it on every tx creation/spending helper. The global is eliminated in the second (refactoring) commit, where all the helpers are moved to the test class as methods. By that, we can use `self.nodes[0]` directly in the helpers and don't have to pass it again and again. I think there could still be a lot of improvements/refactoring done in the test, but that should hopefully serve as a good basis.
ACKs for top commit:
laanwj:
Code review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be
MarcoFalke:
review ACK bd7f27d16dacf6f7de3b4f6bd052def41d9601be 🐕
Tree-SHA512: 24fb6a0f7702bae40d5271d197119827067d4b597e954d182e4c1aa5d0fa870368eb3ffed469b26713fa8ff8eb3ecc06abc80b2449cd68156d5559e7ae8a2b11
2021-05-10 17:50:15 +02:00
tx . rehash ( )
time_txs . append ( tx )
2016-03-11 00:36:55 +01:00
2020-04-14 12:00:16 +02:00
self . send_blocks ( [ self . create_test_block ( time_txs ) ] )
2020-01-11 02:31:44 +01:00
self . nodes [ 0 ] . invalidateblock ( self . nodes [ 0 ] . getbestblockhash ( ) )
2016-03-11 00:36:55 +01:00
2021-09-10 10:02:03 +02:00
2016-03-11 00:36:55 +01:00
if __name__ == ' __main__ ' :
BIP68_112_113Test ( ) . main ( )