@@ -333,23 +333,29 @@ def test_state_fixtures(fixture, fixture_vm_class):
333333 try :
334334 header , receipt , computation = vm .apply_transaction (vm .block .header , transaction )
335335 except ValidationError as err :
336- # Transaction is fully invalid....
337- # INSANITY: https://github.com/ethereum/go-ethereum/commit/32f28a9360d26a661d55915915f12fd3c70f012b#diff-f53696be8527ac422b8d4de7c8e945c1R149
338- if isinstance (vm , PRE_STATE_CLEARING_VMS ):
339- state .account_db .touch_account (vm .block .header .coinbase )
340- state .account_db .persist ()
341- vm .block = vm .block .copy (header = vm .block .header .copy (state_root = state .state_root ))
342-
343336 logger .warning ("Got transaction error" , exc_info = True )
344- block = vm .block
345-
346337 transaction_error = err
347338 else :
348339 transaction_error = False
349340
350341 transactions = vm .block .transactions + (transaction , )
351342 receipts = vm .block .get_receipts (chaindb ) + (receipt , )
352- block = vm .set_block_transactions (vm .block , header , transactions , receipts )
343+ vm .block = vm .set_block_transactions (vm .block , header , transactions , receipts )
344+ finally :
345+ # INSANITY: https://github.com/ethereum/go-ethereum/commit/32f28a9360d26a661d55915915f12fd3c70f012b#diff-f53696be8527ac422b8d4de7c8e945c1R149
346+ # This is necessary due to the manner in which the state tests are
347+ # generated. State tests are generated from the BlockChainTest tests
348+ # in which these transactions are included in the larger context of a
349+ # block and thus, the mechanisms which would touch/create/clear the
350+ # coinbase account based on the mining reward are present during test
351+ # generation, but not part of the execution, thus we must artificially
352+ # touch the coinbase account to satisfy the state root that the tests
353+ # expect.
354+ if isinstance (vm , PRE_STATE_CLEARING_VMS ):
355+ state .account_db .touch_account (vm .block .header .coinbase )
356+ state .account_db .persist ()
357+ vm .block = vm .block .copy (header = vm .block .header .copy (state_root = state .state_root ))
358+ block = vm .block
353359
354360 if not transaction_error :
355361 log_entries = computation .get_log_entries ()
0 commit comments