Skip to content

Commit fa52eb5

Browse files
author
MarcoFalke
committed
test: Remove True argument to CBlock::serialize
Unnamed arguments are confusing as to what they mean without looking up the function signature. Since segwit is active by default in regtest, and all blocks are serialized with witness (#15664, c459c5f), remove the argument `with_witness=True` from all calls to `CBlock::serialize` and `BlockTransactions::serialize`. This diff has been created with a script, but is better reviewed without a scripted diff. sed -i --regexp-extended -e 's/block(_?[2a-z]*)\.serialize\([a-z_]*=?True/block\1.serialize(/g' $(git grep -l serialize ./test)
1 parent c459c5f commit fa52eb5

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

test/functional/feature_bip68_sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def test_bip68_not_consensus(self):
378378
add_witness_commitment(block)
379379
block.solve()
380380

381-
self.nodes[0].submitblock(block.serialize(True).hex())
381+
self.nodes[0].submitblock(block.serialize().hex())
382382
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
383383

384384
def activateCSV(self):

test/functional/feature_nulldummy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def block_submit(self, node, txs, witness=False, accept=False):
108108
witness and add_witness_commitment(block)
109109
block.rehash()
110110
block.solve()
111-
node.submitblock(block.serialize(True).hex())
111+
node.submitblock(block.serialize().hex())
112112
if (accept):
113113
assert_equal(node.getbestblockhash(), block.hash)
114114
self.tip = block.sha256

test/functional/p2p_segwit.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_virtual_size(witness_block):
111111
112112
Virtual size is base + witness/4."""
113113
base_size = len(witness_block.serialize(with_witness=False))
114-
total_size = len(witness_block.serialize(with_witness=True))
114+
total_size = len(witness_block.serialize())
115115
# the "+3" is so we round up
116116
vsize = int((3 * base_size + total_size + 3) / 4)
117117
return vsize
@@ -403,7 +403,7 @@ def test_block_relay(self):
403403
block_hash = int(block_hash, 16)
404404
block = self.test_node.request_block(block_hash, 2)
405405
wit_block = self.test_node.request_block(block_hash, 2 | MSG_WITNESS_FLAG)
406-
assert_equal(block.serialize(True), wit_block.serialize(True))
406+
assert_equal(block.serialize(), wit_block.serialize())
407407
assert_equal(block.serialize(), hex_str_to_bytes(rpc_block))
408408
else:
409409
# After activation, witness blocks and non-witness blocks should
@@ -419,15 +419,15 @@ def test_block_relay(self):
419419
rpc_block = self.nodes[0].getblock(block.hash, False)
420420
non_wit_block = self.test_node.request_block(block.sha256, 2)
421421
wit_block = self.test_node.request_block(block.sha256, 2 | MSG_WITNESS_FLAG)
422-
assert_equal(wit_block.serialize(True), hex_str_to_bytes(rpc_block))
422+
assert_equal(wit_block.serialize(), hex_str_to_bytes(rpc_block))
423423
assert_equal(wit_block.serialize(False), non_wit_block.serialize())
424-
assert_equal(wit_block.serialize(True), block.serialize(True))
424+
assert_equal(wit_block.serialize(), block.serialize())
425425

426426
# Test size, vsize, weight
427427
rpc_details = self.nodes[0].getblock(block.hash, True)
428-
assert_equal(rpc_details["size"], len(block.serialize(True)))
428+
assert_equal(rpc_details["size"], len(block.serialize()))
429429
assert_equal(rpc_details["strippedsize"], len(block.serialize(False)))
430-
weight = 3 * len(block.serialize(False)) + len(block.serialize(True))
430+
weight = 3 * len(block.serialize(False)) + len(block.serialize())
431431
assert_equal(rpc_details["weight"], weight)
432432

433433
# Upgraded node should not ask for blocks from unupgraded
@@ -884,13 +884,13 @@ def test_block_malleability(self):
884884

885885
# We can't send over the p2p network, because this is too big to relay
886886
# TODO: repeat this test with a block that can be relayed
887-
self.nodes[0].submitblock(block.serialize(True).hex())
887+
self.nodes[0].submitblock(block.serialize().hex())
888888

889889
assert self.nodes[0].getbestblockhash() != block.hash
890890

891891
block.vtx[0].wit.vtxinwit[0].scriptWitness.stack.pop()
892892
assert get_virtual_size(block) < MAX_BLOCK_BASE_SIZE
893-
self.nodes[0].submitblock(block.serialize(True).hex())
893+
self.nodes[0].submitblock(block.serialize().hex())
894894

895895
assert self.nodes[0].getbestblockhash() == block.hash
896896

@@ -969,7 +969,7 @@ def test_witness_block_size(self):
969969
assert_equal(vsize, MAX_BLOCK_BASE_SIZE + 1)
970970
# Make sure that our test case would exceed the old max-network-message
971971
# limit
972-
assert len(block.serialize(True)) > 2 * 1024 * 1024
972+
assert len(block.serialize()) > 2 * 1024 * 1024
973973

974974
test_witness_block(self.nodes[0], self.test_node, block, accepted=False)
975975

@@ -997,14 +997,14 @@ def test_submit_block(self):
997997
add_witness_commitment(block, nonce=1)
998998
block.vtx[0].wit = CTxWitness() # drop the nonce
999999
block.solve()
1000-
self.nodes[0].submitblock(block.serialize(True).hex())
1000+
self.nodes[0].submitblock(block.serialize().hex())
10011001
assert self.nodes[0].getbestblockhash() != block.hash
10021002

10031003
# Now redo commitment with the standard nonce, but let bitcoind fill it in.
10041004
add_witness_commitment(block, nonce=0)
10051005
block.vtx[0].wit = CTxWitness()
10061006
block.solve()
1007-
self.nodes[0].submitblock(block.serialize(True).hex())
1007+
self.nodes[0].submitblock(block.serialize().hex())
10081008
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
10091009

10101010
# This time, add a tx with non-empty witness, but don't supply
@@ -1019,7 +1019,7 @@ def test_submit_block(self):
10191019
block_2.vtx[0].vout.pop()
10201020
block_2.vtx[0].wit = CTxWitness()
10211021

1022-
self.nodes[0].submitblock(block_2.serialize(True).hex())
1022+
self.nodes[0].submitblock(block_2.serialize().hex())
10231023
# Tip should not advance!
10241024
assert self.nodes[0].getbestblockhash() != block_2.hash
10251025

test/functional/test_framework/messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ def __repr__(self):
11551155
class msg_witness_block(msg_block):
11561156
__slots__ = ()
11571157
def serialize(self):
1158-
r = self.block.serialize(with_witness=True)
1158+
r = self.block.serialize()
11591159
return r
11601160

11611161

@@ -1454,5 +1454,5 @@ class msg_witness_blocktxn(msg_blocktxn):
14541454

14551455
def serialize(self):
14561456
r = b""
1457-
r += self.block_transactions.serialize(with_witness=True)
1457+
r += self.block_transactions.serialize()
14581458
return r

test/functional/wallet_bumpfee.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def submit_block_with_tx(node, tx):
360360
block.hashMerkleRoot = block.calc_merkle_root()
361361
add_witness_commitment(block)
362362
block.solve()
363-
node.submitblock(block.serialize(True).hex())
363+
node.submitblock(block.serialize().hex())
364364
return block
365365

366366
def test_no_more_inputs_fails(rbf_node, dest_address):

0 commit comments

Comments
 (0)