Skip to content

Commit da5fdbb

Browse files
committed
Test relay of version 2 transactions
1 parent 5cb1d8a commit da5fdbb

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

qa/rpc-tests/bip68-sequence.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#
7-
# Test BIP68 implementation (mempool only)
7+
# Test BIP68 implementation
88
#
99

1010
from test_framework.test_framework import BitcoinTestFramework
@@ -26,8 +26,10 @@ class BIP68Test(BitcoinTestFramework):
2626
def setup_network(self):
2727
self.nodes = []
2828
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-blockprioritysize=0"]))
29+
self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-blockprioritysize=0", "-acceptnonstdtxn=0"]))
2930
self.is_network_split = False
3031
self.relayfee = self.nodes[0].getnetworkinfo()["relayfee"]
32+
connect_nodes(self.nodes[0], 1)
3133

3234
def run_test(self):
3335
# Generate some coins
@@ -42,10 +44,18 @@ def run_test(self):
4244
print "Running test sequence-lock-unconfirmed-inputs"
4345
self.test_sequence_lock_unconfirmed_inputs()
4446

45-
# This test needs to change when BIP68 becomes consensus
46-
print "Running test BIP68 not consensus"
47+
print "Running test BIP68 not consensus before versionbits activation"
4748
self.test_bip68_not_consensus()
4849

50+
print "Verifying nVersion=2 transactions aren't standard"
51+
self.test_version2_relay(before_activation=True)
52+
53+
print "Activating BIP68 (and 112/113)"
54+
self.activateCSV()
55+
56+
print "Verifying nVersion=2 transactions are now standard"
57+
self.test_version2_relay(before_activation=False)
58+
4959
print "Passed\n"
5060

5161
# Test that BIP68 is not in effect if tx version is 1, or if
@@ -333,8 +343,12 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
333343
self.nodes[0].invalidateblock(self.nodes[0].getblockhash(cur_height+1))
334344
self.nodes[0].generate(10)
335345

336-
# Make sure that BIP68 isn't being used to validate blocks.
346+
# Make sure that BIP68 isn't being used to validate blocks, prior to
347+
# versionbits activation. If more blocks are mined prior to this test
348+
# being run, then it's possible the test has activated the soft fork, and
349+
# this test should be moved to run earlier, or deleted.
337350
def test_bip68_not_consensus(self):
351+
assert(get_bip9_status(self.nodes[0], 'csv')['status'] != 'active')
338352
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 2)
339353

340354
tx1 = FromHex(CTransaction(), self.nodes[0].getrawtransaction(txid))
@@ -381,6 +395,30 @@ def test_bip68_not_consensus(self):
381395
self.nodes[0].submitblock(ToHex(block))
382396
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
383397

398+
def activateCSV(self):
399+
# activation should happen at block height 432 (3 periods)
400+
min_activation_height = 432
401+
height = self.nodes[0].getblockcount()
402+
assert(height < 432)
403+
self.nodes[0].generate(432-height)
404+
assert(get_bip9_status(self.nodes[0], 'csv')['status'] == 'active')
405+
sync_blocks(self.nodes)
406+
407+
# Use self.nodes[1] to test standardness relay policy
408+
def test_version2_relay(self, before_activation):
409+
inputs = [ ]
410+
outputs = { self.nodes[1].getnewaddress() : 1.0 }
411+
rawtx = self.nodes[1].createrawtransaction(inputs, outputs)
412+
rawtxfund = self.nodes[1].fundrawtransaction(rawtx)['hex']
413+
tx = FromHex(CTransaction(), rawtxfund)
414+
tx.nVersion = 2
415+
tx_signed = self.nodes[1].signrawtransaction(ToHex(tx))["hex"]
416+
try:
417+
tx_id = self.nodes[1].sendrawtransaction(tx_signed)
418+
assert(before_activation == False)
419+
except:
420+
assert(before_activation)
421+
384422

385423
if __name__ == '__main__':
386424
BIP68Test().main()

0 commit comments

Comments
 (0)