Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_csv_activation.py
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
from itertools import product | from itertools import product | ||||
import time | import time | ||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
make_conform_to_ctor, | make_conform_to_ctor, | ||||
) | ) | ||||
from test_framework.messages import COIN, CTransaction, FromHex, ToHex | from test_framework.messages import XEC, CTransaction, FromHex, ToHex | ||||
from test_framework.p2p import P2PDataStore | from test_framework.p2p import P2PDataStore | ||||
from test_framework.script import ( | from test_framework.script import ( | ||||
CScript, | CScript, | ||||
OP_CHECKSEQUENCEVERIFY, | OP_CHECKSEQUENCEVERIFY, | ||||
OP_DROP, | OP_DROP, | ||||
OP_TRUE, | OP_TRUE, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def sign_transaction(node, unsignedtx): | ||||
rawtx = ToHex(unsignedtx) | rawtx = ToHex(unsignedtx) | ||||
signresult = node.signrawtransactionwithwallet(rawtx) | signresult = node.signrawtransactionwithwallet(rawtx) | ||||
tx = FromHex(CTransaction(), signresult['hex']) | tx = FromHex(CTransaction(), signresult['hex']) | ||||
return tx | return tx | ||||
def spend_tx(node, prev_tx, address): | def spend_tx(node, prev_tx, address): | ||||
spendtx = create_transaction( | spendtx = create_transaction( | ||||
node, prev_tx.hash, address, amount=(prev_tx.vout[0].nValue - 1000) / COIN) | node, prev_tx.hash, address, amount=(prev_tx.vout[0].nValue - 1000) / XEC) | ||||
spendtx.nVersion = prev_tx.nVersion | spendtx.nVersion = prev_tx.nVersion | ||||
pad_tx(spendtx) | pad_tx(spendtx) | ||||
spendtx.rehash() | spendtx.rehash() | ||||
return spendtx | return spendtx | ||||
def create_bip112special(node, input, txversion, address): | def create_bip112special(node, input, txversion, address): | ||||
tx = create_transaction( | tx = create_transaction( | ||||
node, input, address, amount=Decimal("49.98")) | node, input, address, amount=Decimal("49980000")) | ||||
tx.nVersion = txversion | tx.nVersion = txversion | ||||
tx.vout[0].scriptPubKey = CScript( | tx.vout[0].scriptPubKey = CScript( | ||||
[-1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | [-1, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | ||||
tx.rehash() | tx.rehash() | ||||
signtx = sign_transaction(node, tx) | signtx = sign_transaction(node, tx) | ||||
signtx.rehash() | signtx.rehash() | ||||
return signtx | return signtx | ||||
def send_generic_input_tx(node, coinbases, address): | def send_generic_input_tx(node, coinbases, address): | ||||
return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction( | return node.sendrawtransaction(ToHex(sign_transaction(node, create_transaction( | ||||
node, node.getblock(coinbases.pop())['tx'][0], address, amount=Decimal("49.99"))))) | node, node.getblock(coinbases.pop())['tx'][0], address, amount=Decimal("49990000"))))) | ||||
def create_bip68txs(node, bip68inputs, txversion, address, locktime_delta=0): | def create_bip68txs(node, bip68inputs, txversion, address, locktime_delta=0): | ||||
"""Returns a list of bip68 transactions with different bits set.""" | """Returns a list of bip68 transactions with different bits set.""" | ||||
txs = [] | txs = [] | ||||
assert len(bip68inputs) >= 16 | assert len(bip68inputs) >= 16 | ||||
for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): | for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): | ||||
locktime = relative_locktime(sdf, srhb, stf, srlb) | locktime = relative_locktime(sdf, srhb, stf, srlb) | ||||
tx = create_transaction( | tx = create_transaction( | ||||
node, bip68inputs[i], address, amount=Decimal("49.98")) | node, bip68inputs[i], address, amount=Decimal("49980000")) | ||||
tx.nVersion = txversion | tx.nVersion = txversion | ||||
tx.vin[0].nSequence = locktime + locktime_delta | tx.vin[0].nSequence = locktime + locktime_delta | ||||
tx = sign_transaction(node, tx) | tx = sign_transaction(node, tx) | ||||
tx.rehash() | tx.rehash() | ||||
txs.append({'tx': tx, 'sdf': sdf, 'stf': stf}) | txs.append({'tx': tx, 'sdf': sdf, 'stf': stf}) | ||||
return txs | return txs | ||||
def create_bip112txs(node, bip112inputs, varyOP_CSV, | def create_bip112txs(node, bip112inputs, varyOP_CSV, | ||||
txversion, address, locktime_delta=0): | txversion, address, locktime_delta=0): | ||||
"""Returns a list of bip112 transactions with different bits set.""" | """Returns a list of bip112 transactions with different bits set.""" | ||||
txs = [] | txs = [] | ||||
assert len(bip112inputs) >= 16 | assert len(bip112inputs) >= 16 | ||||
for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): | for i, (sdf, srhb, stf, srlb) in enumerate(product(*[[True, False]] * 4)): | ||||
locktime = relative_locktime(sdf, srhb, stf, srlb) | locktime = relative_locktime(sdf, srhb, stf, srlb) | ||||
tx = create_transaction( | tx = create_transaction( | ||||
node, bip112inputs[i], address, amount=Decimal("49.98")) | node, bip112inputs[i], address, amount=Decimal("49980000")) | ||||
if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed | if (varyOP_CSV): # if varying OP_CSV, nSequence is fixed | ||||
tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta | tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME + locktime_delta | ||||
else: # vary nSequence instead, OP_CSV is fixed | else: # vary nSequence instead, OP_CSV is fixed | ||||
tx.vin[0].nSequence = locktime + locktime_delta | tx.vin[0].nSequence = locktime + locktime_delta | ||||
tx.nVersion = txversion | tx.nVersion = txversion | ||||
if (varyOP_CSV): | if (varyOP_CSV): | ||||
tx.vout[0].scriptPubKey = CScript( | tx.vout[0].scriptPubKey = CScript( | ||||
[locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | [locktime, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE]) | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.log.info( | self.log.info( | ||||
"Not yet activated, height = 574 (will activate for block 576, not 575)") | "Not yet activated, height = 574 (will activate for block 576, not 575)") | ||||
assert_equal(get_csv_status(self.nodes[0]), False) | assert_equal(get_csv_status(self.nodes[0]), False) | ||||
# Test both version 1 and version 2 transactions for all tests | # Test both version 1 and version 2 transactions for all tests | ||||
# BIP113 test transaction will be modified before each use to | # BIP113 test transaction will be modified before each use to | ||||
# put in appropriate block time | # put in appropriate block time | ||||
bip113tx_v1 = create_transaction( | bip113tx_v1 = create_transaction( | ||||
self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49.98")) | self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49980000")) | ||||
bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE | bip113tx_v1.vin[0].nSequence = 0xFFFFFFFE | ||||
bip113tx_v1.nVersion = 1 | bip113tx_v1.nVersion = 1 | ||||
bip113tx_v2 = create_transaction( | bip113tx_v2 = create_transaction( | ||||
self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49.98")) | self.nodes[0], bip113input, self.nodeaddress, amount=Decimal("49980000")) | ||||
bip113tx_v2.vin[0].nSequence = 0xFFFFFFFE | bip113tx_v2.vin[0].nSequence = 0xFFFFFFFE | ||||
bip113tx_v2.nVersion = 2 | bip113tx_v2.nVersion = 2 | ||||
# For BIP68 test all 16 relative sequence locktimes | # For BIP68 test all 16 relative sequence locktimes | ||||
bip68txs_v1 = create_bip68txs( | bip68txs_v1 = create_bip68txs( | ||||
self.nodes[0], bip68inputs, 1, self.nodeaddress) | self.nodes[0], bip68inputs, 1, self.nodeaddress) | ||||
bip68txs_v2 = create_bip68txs( | bip68txs_v2 = create_bip68txs( | ||||
self.nodes[0], bip68inputs, 2, self.nodeaddress) | self.nodes[0], bip68inputs, 2, self.nodeaddress) | ||||
▲ Show 20 Lines • Show All 340 Lines • Show Last 20 Lines |