@@ -434,17 +434,55 @@ def _test_getblock(self):
434434 miniwallet .send_self_transfer (fee_rate = fee_per_kb , from_node = node )
435435 blockhash = self .generate (node , 1 )[0 ]
436436
437- self .log .info ("Test getblock with verbosity 1 doesn't include fee" )
438- block = node .getblock (blockhash , 1 )
439- assert 'fee' not in block ['tx' ][1 ]
440-
441- self .log .info ('Test getblock with verbosity 2 includes expected fee' )
442- block = node .getblock (blockhash , 2 )
443- tx = block ['tx' ][1 ]
444- assert 'fee' in tx
445- assert_equal (tx ['fee' ], tx ['vsize' ] * fee_per_byte )
446-
447- self .log .info ("Test getblock with verbosity 2 still works with pruned Undo data" )
437+ def assert_fee_not_in_block (verbosity ):
438+ block = node .getblock (blockhash , verbosity )
439+ assert 'fee' not in block ['tx' ][1 ]
440+
441+ def assert_fee_in_block (verbosity ):
442+ block = node .getblock (blockhash , verbosity )
443+ tx = block ['tx' ][1 ]
444+ assert 'fee' in tx
445+ assert_equal (tx ['fee' ], tx ['vsize' ] * fee_per_byte )
446+
447+ def assert_vin_contains_prevout (verbosity ):
448+ block = node .getblock (blockhash , verbosity )
449+ tx = block ["tx" ][1 ]
450+ total_vin = Decimal ("0.00000000" )
451+ total_vout = Decimal ("0.00000000" )
452+ for vin in tx ["vin" ]:
453+ assert "prevout" in vin
454+ assert_equal (set (vin ["prevout" ].keys ()), set (("value" , "height" , "generated" , "scriptPubKey" )))
455+ assert_equal (vin ["prevout" ]["generated" ], True )
456+ total_vin += vin ["prevout" ]["value" ]
457+ for vout in tx ["vout" ]:
458+ total_vout += vout ["value" ]
459+ assert_equal (total_vin , total_vout + tx ["fee" ])
460+
461+ def assert_vin_does_not_contain_prevout (verbosity ):
462+ block = node .getblock (blockhash , verbosity )
463+ tx = block ["tx" ][1 ]
464+ if isinstance (tx , str ):
465+ # In verbosity level 1, only the transaction hashes are written
466+ pass
467+ else :
468+ for vin in tx ["vin" ]:
469+ assert "prevout" not in vin
470+
471+ self .log .info ("Test that getblock with verbosity 1 doesn't include fee" )
472+ assert_fee_not_in_block (1 )
473+
474+ self .log .info ('Test that getblock with verbosity 2 and 3 includes expected fee' )
475+ assert_fee_in_block (2 )
476+ assert_fee_in_block (3 )
477+
478+ self .log .info ("Test that getblock with verbosity 1 and 2 does not include prevout" )
479+ assert_vin_does_not_contain_prevout (1 )
480+ assert_vin_does_not_contain_prevout (2 )
481+
482+ self .log .info ("Test that getblock with verbosity 3 includes prevout" )
483+ assert_vin_contains_prevout (3 )
484+
485+ self .log .info ("Test that getblock with verbosity 2 and 3 still works with pruned Undo data" )
448486 datadir = get_datadir_path (self .options .tmpdir , 0 )
449487
450488 self .log .info ("Test getblock with invalid verbosity type returns proper error message" )
@@ -458,8 +496,10 @@ def move_block_file(old, new):
458496 # Move instead of deleting so we can restore chain state afterwards
459497 move_block_file ('rev00000.dat' , 'rev_wrong' )
460498
461- block = node .getblock (blockhash , 2 )
462- assert 'fee' not in block ['tx' ][1 ]
499+ assert_fee_not_in_block (2 )
500+ assert_fee_not_in_block (3 )
501+ assert_vin_does_not_contain_prevout (2 )
502+ assert_vin_does_not_contain_prevout (3 )
463503
464504 # Restore chain state
465505 move_block_file ('rev_wrong' , 'rev00000.dat' )
0 commit comments