Skip to content

Commit b4d3309

Browse files
author
MarcoFalke
committed
scripted-diff: Use named arguments in feature_block
-BEGIN VERIFY SCRIPT- sed -i --regexp-extended -e "s/sync_blocks\((.*?), (True|False), (1.?), /sync_blocks(\1, success=\2, reject_code=\3, reject_reason=/g" ./test/functional/feature_block.py -END VERIFY SCRIPT-
1 parent 749ba35 commit b4d3309

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

test/functional/feature_block.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def run_test(self):
169169
self.log.info("Reject a block where the miner creates too much coinbase reward")
170170
self.move_tip(6)
171171
b9 = self.next_block(9, spend=out[4], additional_coinbase_value=1)
172-
self.sync_blocks([b9], False, 16, b'bad-cb-amount', reconnect=True)
172+
self.sync_blocks([b9], success=False, reject_code=16, reject_reason=b'bad-cb-amount', reconnect=True)
173173

174174
# Create a fork that ends in a block with too much fee (the one that causes the reorg)
175175
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -181,7 +181,7 @@ def run_test(self):
181181
self.sync_blocks([b10], False)
182182

183183
b11 = self.next_block(11, spend=out[4], additional_coinbase_value=1)
184-
self.sync_blocks([b11], False, 16, b'bad-cb-amount', reconnect=True)
184+
self.sync_blocks([b11], success=False, reject_code=16, reject_reason=b'bad-cb-amount', reconnect=True)
185185

186186
# Try again, but with a valid fork first
187187
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -194,7 +194,7 @@ def run_test(self):
194194
b13 = self.next_block(13, spend=out[4])
195195
self.save_spendable_output()
196196
b14 = self.next_block(14, spend=out[5], additional_coinbase_value=1)
197-
self.sync_blocks([b12, b13, b14], False, 16, b'bad-cb-amount', reconnect=True)
197+
self.sync_blocks([b12, b13, b14], success=False, reject_code=16, reject_reason=b'bad-cb-amount', reconnect=True)
198198

199199
# New tip should be b13.
200200
assert_equal(node.getbestblockhash(), b13.hash)
@@ -213,7 +213,7 @@ def run_test(self):
213213
self.log.info("Reject a block with too many checksigs")
214214
too_many_checksigs = CScript([OP_CHECKSIG] * (MAX_BLOCK_SIGOPS))
215215
b16 = self.next_block(16, spend=out[6], script=too_many_checksigs)
216-
self.sync_blocks([b16], False, 16, b'bad-blk-sigops', reconnect=True)
216+
self.sync_blocks([b16], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
217217

218218
# Attempt to spend a transaction created on a different fork
219219
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -222,7 +222,7 @@ def run_test(self):
222222
self.log.info("Reject a block with a spend from a re-org'ed out tx")
223223
self.move_tip(15)
224224
b17 = self.next_block(17, spend=txout_b3)
225-
self.sync_blocks([b17], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
225+
self.sync_blocks([b17], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
226226

227227
# Attempt to spend a transaction created on a different fork (on a fork this time)
228228
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -235,7 +235,7 @@ def run_test(self):
235235
self.sync_blocks([b18], False)
236236

237237
b19 = self.next_block(19, spend=out[6])
238-
self.sync_blocks([b19], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
238+
self.sync_blocks([b19], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
239239

240240
# Attempt to spend a coinbase at depth too low
241241
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -244,7 +244,7 @@ def run_test(self):
244244
self.log.info("Reject a block spending an immature coinbase.")
245245
self.move_tip(15)
246246
b20 = self.next_block(20, spend=out[7])
247-
self.sync_blocks([b20], False, 16, b'bad-txns-premature-spend-of-coinbase')
247+
self.sync_blocks([b20], success=False, reject_code=16, reject_reason=b'bad-txns-premature-spend-of-coinbase')
248248

249249
# Attempt to spend a coinbase at depth too low (on a fork this time)
250250
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -257,7 +257,7 @@ def run_test(self):
257257
self.sync_blocks([b21], False)
258258

259259
b22 = self.next_block(22, spend=out[5])
260-
self.sync_blocks([b22], False, 16, b'bad-txns-premature-spend-of-coinbase')
260+
self.sync_blocks([b22], success=False, reject_code=16, reject_reason=b'bad-txns-premature-spend-of-coinbase')
261261

262262
# Create a block on either side of MAX_BLOCK_BASE_SIZE and make sure its accepted/rejected
263263
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@@ -286,7 +286,7 @@ def run_test(self):
286286
tx.vout = [CTxOut(0, script_output)]
287287
b24 = self.update_block(24, [tx])
288288
assert_equal(len(b24.serialize()), MAX_BLOCK_BASE_SIZE + 1)
289-
self.sync_blocks([b24], False, 16, b'bad-blk-length', reconnect=True)
289+
self.sync_blocks([b24], success=False, reject_code=16, reject_reason=b'bad-blk-length', reconnect=True)
290290

291291
b25 = self.next_block(25, spend=out[7])
292292
self.sync_blocks([b25], False)
@@ -304,7 +304,7 @@ def run_test(self):
304304
# update_block causes the merkle root to get updated, even with no new
305305
# transactions, and updates the required state.
306306
b26 = self.update_block(26, [])
307-
self.sync_blocks([b26], False, 16, b'bad-cb-length', reconnect=True)
307+
self.sync_blocks([b26], success=False, reject_code=16, reject_reason=b'bad-cb-length', reconnect=True)
308308

309309
# Extend the b26 chain to make sure bitcoind isn't accepting b26
310310
b27 = self.next_block(27, spend=out[7])
@@ -316,7 +316,7 @@ def run_test(self):
316316
b28.vtx[0].vin[0].scriptSig = b'\x00' * 101
317317
b28.vtx[0].rehash()
318318
b28 = self.update_block(28, [])
319-
self.sync_blocks([b28], False, 16, b'bad-cb-length', reconnect=True)
319+
self.sync_blocks([b28], success=False, reject_code=16, reject_reason=b'bad-cb-length', reconnect=True)
320320

321321
# Extend the b28 chain to make sure bitcoind isn't accepting b28
322322
b29 = self.next_block(29, spend=out[7])
@@ -352,7 +352,7 @@ def run_test(self):
352352
too_many_multisigs = CScript([OP_CHECKMULTISIG] * (MAX_BLOCK_SIGOPS // 20))
353353
b32 = self.next_block(32, spend=out[9], script=too_many_multisigs)
354354
assert_equal(get_legacy_sigopcount_block(b32), MAX_BLOCK_SIGOPS + 1)
355-
self.sync_blocks([b32], False, 16, b'bad-blk-sigops', reconnect=True)
355+
self.sync_blocks([b32], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
356356

357357
# CHECKMULTISIGVERIFY
358358
self.log.info("Accept a block with the max number of OP_CHECKMULTISIGVERIFY sigops")
@@ -365,7 +365,7 @@ def run_test(self):
365365
self.log.info("Reject a block with too many OP_CHECKMULTISIGVERIFY sigops")
366366
too_many_multisigs = CScript([OP_CHECKMULTISIGVERIFY] * (MAX_BLOCK_SIGOPS // 20))
367367
b34 = self.next_block(34, spend=out[10], script=too_many_multisigs)
368-
self.sync_blocks([b34], False, 16, b'bad-blk-sigops', reconnect=True)
368+
self.sync_blocks([b34], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
369369

370370
# CHECKSIGVERIFY
371371
self.log.info("Accept a block with the max number of OP_CHECKSIGVERIFY sigops")
@@ -378,7 +378,7 @@ def run_test(self):
378378
self.log.info("Reject a block with too many OP_CHECKSIGVERIFY sigops")
379379
too_many_checksigs = CScript([OP_CHECKSIGVERIFY] * (MAX_BLOCK_SIGOPS))
380380
b36 = self.next_block(36, spend=out[11], script=too_many_checksigs)
381-
self.sync_blocks([b36], False, 16, b'bad-blk-sigops', reconnect=True)
381+
self.sync_blocks([b36], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
382382

383383
# Check spending of a transaction in a block which failed to connect
384384
#
@@ -395,12 +395,12 @@ def run_test(self):
395395
txout_b37 = b37.vtx[1]
396396
tx = self.create_and_sign_transaction(out[11], 0)
397397
b37 = self.update_block(37, [tx])
398-
self.sync_blocks([b37], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
398+
self.sync_blocks([b37], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
399399

400400
# attempt to spend b37's first non-coinbase tx, at which point b37 was still considered valid
401401
self.move_tip(35)
402402
b38 = self.next_block(38, spend=txout_b37)
403-
self.sync_blocks([b38], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
403+
self.sync_blocks([b38], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
404404

405405
# Check P2SH SigOp counting
406406
#
@@ -492,7 +492,7 @@ def run_test(self):
492492
tx.rehash()
493493
new_txs.append(tx)
494494
self.update_block(40, new_txs)
495-
self.sync_blocks([b40], False, 16, b'bad-blk-sigops', reconnect=True)
495+
self.sync_blocks([b40], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
496496

497497
# same as b40, but one less sigop
498498
self.log.info("Accept a block with the max number of P2SH sigops")
@@ -555,7 +555,7 @@ def run_test(self):
555555
self.block_heights[b45.sha256] = self.block_heights[self.tip.sha256] + 1
556556
self.tip = b45
557557
self.blocks[45] = b45
558-
self.sync_blocks([b45], False, 16, b'bad-cb-missing', reconnect=True)
558+
self.sync_blocks([b45], success=False, reject_code=16, reject_reason=b'bad-cb-missing', reconnect=True)
559559

560560
self.log.info("Reject a block with no transactions")
561561
self.move_tip(44)
@@ -570,7 +570,7 @@ def run_test(self):
570570
self.tip = b46
571571
assert 46 not in self.blocks
572572
self.blocks[46] = b46
573-
self.sync_blocks([b46], False, 16, b'bad-blk-length', reconnect=True)
573+
self.sync_blocks([b46], success=False, reject_code=16, reject_reason=b'bad-blk-length', reconnect=True)
574574

575575
self.log.info("Reject a block with invalid work")
576576
self.move_tip(44)
@@ -593,7 +593,7 @@ def run_test(self):
593593
b49 = self.next_block(49)
594594
b49.hashMerkleRoot += 1
595595
b49.solve()
596-
self.sync_blocks([b49], False, 16, b'bad-txnmrklroot', reconnect=True)
596+
self.sync_blocks([b49], success=False, reject_code=16, reject_reason=b'bad-txnmrklroot', reconnect=True)
597597

598598
self.log.info("Reject a block with incorrect POW limit")
599599
self.move_tip(44)
@@ -607,15 +607,15 @@ def run_test(self):
607607
b51 = self.next_block(51)
608608
cb2 = create_coinbase(51, self.coinbase_pubkey)
609609
b51 = self.update_block(51, [cb2])
610-
self.sync_blocks([b51], False, 16, b'bad-cb-multiple', reconnect=True)
610+
self.sync_blocks([b51], success=False, reject_code=16, reject_reason=b'bad-cb-multiple', reconnect=True)
611611

612612
self.log.info("Reject a block with duplicate transactions")
613613
# Note: txns have to be in the right position in the merkle tree to trigger this error
614614
self.move_tip(44)
615615
b52 = self.next_block(52, spend=out[15])
616616
tx = self.create_tx(b52.vtx[1], 0, 1)
617617
b52 = self.update_block(52, [tx, tx])
618-
self.sync_blocks([b52], False, 16, b'bad-txns-duplicate', reconnect=True)
618+
self.sync_blocks([b52], success=False, reject_code=16, reject_reason=b'bad-txns-duplicate', reconnect=True)
619619

620620
# Test block timestamps
621621
# -> b31 (8) -> b33 (9) -> b35 (10) -> b39 (11) -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15)
@@ -682,7 +682,7 @@ def run_test(self):
682682
assert_equal(len(b56.vtx), 3)
683683
b56 = self.update_block(56, [tx1])
684684
assert_equal(b56.hash, b57.hash)
685-
self.sync_blocks([b56], False, 16, b'bad-txns-duplicate', reconnect=True)
685+
self.sync_blocks([b56], success=False, reject_code=16, reject_reason=b'bad-txns-duplicate', reconnect=True)
686686

687687
# b57p2 - a good block with 6 tx'es, don't submit until end
688688
self.move_tip(55)
@@ -702,7 +702,7 @@ def run_test(self):
702702
assert_equal(b56p2.hash, b57p2.hash)
703703
assert_equal(len(b56p2.vtx), 6)
704704
b56p2 = self.update_block("b56p2", [tx3, tx4])
705-
self.sync_blocks([b56p2], False, 16, b'bad-txns-duplicate', reconnect=True)
705+
self.sync_blocks([b56p2], success=False, reject_code=16, reject_reason=b'bad-txns-duplicate', reconnect=True)
706706

707707
self.move_tip("57p2")
708708
self.sync_blocks([b57p2], True)
@@ -727,15 +727,15 @@ def run_test(self):
727727
tx.vout.append(CTxOut(0, b""))
728728
tx.calc_sha256()
729729
b58 = self.update_block(58, [tx])
730-
self.sync_blocks([b58], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
730+
self.sync_blocks([b58], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
731731

732732
# tx with output value > input value
733733
self.log.info("Reject a block with a transaction with outputs > inputs")
734734
self.move_tip(57)
735735
b59 = self.next_block(59)
736736
tx = self.create_and_sign_transaction(out[17], 51 * COIN)
737737
b59 = self.update_block(59, [tx])
738-
self.sync_blocks([b59], False, 16, b'bad-txns-in-belowout', reconnect=True)
738+
self.sync_blocks([b59], success=False, reject_code=16, reject_reason=b'bad-txns-in-belowout', reconnect=True)
739739

740740
# reset to good chain
741741
self.move_tip(57)
@@ -759,7 +759,7 @@ def run_test(self):
759759
b61.vtx[0].rehash()
760760
b61 = self.update_block(61, [])
761761
assert_equal(b60.vtx[0].serialize(), b61.vtx[0].serialize())
762-
self.sync_blocks([b61], False, 16, b'bad-txns-BIP30', reconnect=True)
762+
self.sync_blocks([b61], success=False, reject_code=16, reject_reason=b'bad-txns-BIP30', reconnect=True)
763763

764764
# Test tx.isFinal is properly rejected (not an exhaustive tx.isFinal test, that should be in data-driven transaction tests)
765765
#
@@ -776,7 +776,7 @@ def run_test(self):
776776
assert(tx.vin[0].nSequence < 0xffffffff)
777777
tx.calc_sha256()
778778
b62 = self.update_block(62, [tx])
779-
self.sync_blocks([b62], False, 16, b'bad-txns-nonfinal')
779+
self.sync_blocks([b62], success=False, reject_code=16, reject_reason=b'bad-txns-nonfinal')
780780

781781
# Test a non-final coinbase is also rejected
782782
#
@@ -790,7 +790,7 @@ def run_test(self):
790790
b63.vtx[0].vin[0].nSequence = 0xDEADBEEF
791791
b63.vtx[0].rehash()
792792
b63 = self.update_block(63, [])
793-
self.sync_blocks([b63], False, 16, b'bad-txns-nonfinal')
793+
self.sync_blocks([b63], success=False, reject_code=16, reject_reason=b'bad-txns-nonfinal')
794794

795795
# This checks that a block with a bloated VARINT between the block_header and the array of tx such that
796796
# the block is > MAX_BLOCK_BASE_SIZE with the bloated varint, but <= MAX_BLOCK_BASE_SIZE without the bloated varint,
@@ -824,7 +824,7 @@ def run_test(self):
824824
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0)))
825825
b64a = self.update_block("64a", [tx])
826826
assert_equal(len(b64a.serialize()), MAX_BLOCK_BASE_SIZE + 8)
827-
self.sync_blocks([b64a], False, 1, b'error parsing message')
827+
self.sync_blocks([b64a], success=False, reject_code=1, reject_reason=b'error parsing message')
828828

829829
# bitcoind doesn't disconnect us for sending a bloated block, but if we subsequently
830830
# resend the header message, it won't send us the getdata message again. Just
@@ -866,7 +866,7 @@ def run_test(self):
866866
tx1 = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue)
867867
tx2 = self.create_and_sign_transaction(tx1, 1)
868868
b66 = self.update_block(66, [tx2, tx1])
869-
self.sync_blocks([b66], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
869+
self.sync_blocks([b66], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
870870

871871
# Attempt to double-spend a transaction created in a block
872872
#
@@ -881,7 +881,7 @@ def run_test(self):
881881
tx2 = self.create_and_sign_transaction(tx1, 1)
882882
tx3 = self.create_and_sign_transaction(tx1, 2)
883883
b67 = self.update_block(67, [tx1, tx2, tx3])
884-
self.sync_blocks([b67], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
884+
self.sync_blocks([b67], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
885885

886886
# More tests of block subsidy
887887
#
@@ -900,7 +900,7 @@ def run_test(self):
900900
b68 = self.next_block(68, additional_coinbase_value=10)
901901
tx = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue - 9)
902902
b68 = self.update_block(68, [tx])
903-
self.sync_blocks([b68], False, 16, b'bad-cb-amount', reconnect=True)
903+
self.sync_blocks([b68], success=False, reject_code=16, reject_reason=b'bad-cb-amount', reconnect=True)
904904

905905
self.log.info("Accept a block claiming the correct subsidy in the coinbase transaction")
906906
self.move_tip(65)
@@ -924,7 +924,7 @@ def run_test(self):
924924
tx.vin.append(CTxIn(COutPoint(bogus_tx.sha256, 0), b"", 0xffffffff))
925925
tx.vout.append(CTxOut(1, b""))
926926
b70 = self.update_block(70, [tx])
927-
self.sync_blocks([b70], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
927+
self.sync_blocks([b70], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
928928

929929
# Test accepting an invalid block which has the same hash as a valid one (via merkle tree tricks)
930930
#
@@ -949,7 +949,7 @@ def run_test(self):
949949
assert_equal(b72.sha256, b71.sha256)
950950

951951
self.move_tip(71)
952-
self.sync_blocks([b71], False, 16, b'bad-txns-duplicate', reconnect=True)
952+
self.sync_blocks([b71], success=False, reject_code=16, reject_reason=b'bad-txns-duplicate', reconnect=True)
953953

954954
self.move_tip(72)
955955
self.sync_blocks([b72], True)
@@ -987,7 +987,7 @@ def run_test(self):
987987
tx = self.create_and_sign_transaction(out[22], 1, CScript(a))
988988
b73 = self.update_block(73, [tx])
989989
assert_equal(get_legacy_sigopcount_block(b73), MAX_BLOCK_SIGOPS + 1)
990-
self.sync_blocks([b73], False, 16, b'bad-blk-sigops', reconnect=True)
990+
self.sync_blocks([b73], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
991991

992992
# b74/75 - if we push an invalid script element, all prevous sigops are counted,
993993
# but sigops after the element are not counted.
@@ -1011,7 +1011,7 @@ def run_test(self):
10111011
a[MAX_BLOCK_SIGOPS + 4] = 0xff
10121012
tx = self.create_and_sign_transaction(out[22], 1, CScript(a))
10131013
b74 = self.update_block(74, [tx])
1014-
self.sync_blocks([b74], False, 16, b'bad-blk-sigops', reconnect=True)
1014+
self.sync_blocks([b74], success=False, reject_code=16, reject_reason=b'bad-blk-sigops', reconnect=True)
10151015

10161016
self.move_tip(72)
10171017
b75 = self.next_block(75)
@@ -1160,7 +1160,7 @@ def run_test(self):
11601160
b89a = self.next_block("89a", spend=out[32])
11611161
tx = self.create_tx(tx1, 0, 0, CScript([OP_TRUE]))
11621162
b89a = self.update_block("89a", [tx])
1163-
self.sync_blocks([b89a], False, 16, b'bad-txns-inputs-missingorspent', reconnect=True)
1163+
self.sync_blocks([b89a], success=False, reject_code=16, reject_reason=b'bad-txns-inputs-missingorspent', reconnect=True)
11641164

11651165
self.log.info("Test a re-org of one week's worth of blocks (1088 blocks)")
11661166

0 commit comments

Comments
 (0)