def import_empty_blocks(self, chain: Chain, number_blocks: int) -> int: total_gas_used = 0 for _ in range(1, number_blocks + 1): block = chain.import_block(chain.get_vm().block, False) total_gas_used = total_gas_used + block.header.gas_used logging.debug(format_block(block)) return total_gas_used
def test_mainnet_eip1085_matches_mainnet_genesis_header( mainnet_genesis_config): genesis_data = extract_genesis_data(mainnet_genesis_config) genesis_state = { address: account.to_dict() for address, account in genesis_data.state.items() } genesis_params = genesis_data.params.to_dict() chain = Chain.configure( vm_configuration=genesis_data.vm_configuration, chain_id=genesis_data.chain_id, ).from_genesis(AtomicDB(), genesis_params, genesis_state) genesis_header = chain.get_canonical_head() assert genesis_header == MAINNET_GENESIS_HEADER assert chain.chain_id == MainnetChain.chain_id actual_fork_blocks = tuple(zip(*chain.vm_configuration))[0] expected_fork_blocks = tuple(zip(*MainnetChain.vm_configuration))[0] assert actual_fork_blocks == expected_fork_blocks actual_homestead_vm = chain.vm_configuration[1][1] expected_homestead_vm = MainnetChain.vm_configuration[1][1] assert issubclass(actual_homestead_vm, HomesteadVM) assert actual_homestead_vm.support_dao_fork is True assert actual_homestead_vm.get_dao_fork_block_number( ) == expected_homestead_vm.get_dao_fork_block_number() # noqa: E501
def chain_with_block_validation(base_db, genesis_state): """ Return a Chain object containing just the genesis block. The Chain's state includes one funded account, which can be found in the funded_address in the chain itself. This Chain will perform all validations when importing new blocks, so only valid and finalized blocks can be used with it. If you want to test importing arbitrarily constructe, not finalized blocks, use the chain_without_block_validation fixture instead. """ genesis_params = { "bloom": 0, "coinbase": to_canonical_address("8888f1f195afa192cfee860698584c030f4c9db1"), "difficulty": 131072, "extra_data": b"B", "gas_limit": 3141592, "gas_used": 0, "mix_hash": decode_hex( "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" ), # noqa: E501 "nonce": decode_hex("0102030405060708"), "block_number": 0, "parent_hash": decode_hex( "0000000000000000000000000000000000000000000000000000000000000000" ), # noqa: E501 "receipt_root": decode_hex( "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" ), # noqa: E501 "timestamp": 1422494849, "transaction_root": decode_hex( "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" ), # noqa: E501 "uncles_hash": decode_hex( "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" ) # noqa: E501 } klass = Chain.configure( __name__='TestChain', vm_configuration=((constants.GENESIS_BLOCK_NUMBER, SpuriousDragonVM), ), network_id=1337, ) chain = klass.from_genesis(base_db, genesis_params, genesis_state) return chain
def test_goerli_eip1085_matches_goerli_chain(goerli_genesis_config): genesis_data = extract_genesis_data(goerli_genesis_config) genesis_state = { address: account.to_dict() for address, account in genesis_data.state.items() } genesis_params = genesis_data.params.to_dict() chain = Chain.configure( vm_configuration=genesis_data.vm_configuration, chain_id=genesis_data.chain_id, ).from_genesis(AtomicDB(), genesis_params, genesis_state) genesis_header = chain.get_canonical_head() assert genesis_header == GOERLI_GENESIS_HEADER
def chain_without_block_validation(base_db, genesis_state): """ Return a Chain object containing just the genesis block. This Chain does not perform any validation when importing new blocks. The Chain's state includes one funded account and a private key for it, which can be found in the funded_address and private_keys variables in the chain itself. """ # Disable block validation so that we don't need to construct finalized blocks. overrides = { 'import_block': import_block_without_validation, 'validate_block': lambda self, block: None, } SpuriousDragonVMForTesting = SpuriousDragonVM.configure( validate_seal=lambda block: None) klass = Chain.configure( __name__='TestChainWithoutBlockValidation', vm_configuration=((eth_constants.GENESIS_BLOCK_NUMBER, SpuriousDragonVMForTesting), ), chain_id=1337, **overrides, ) genesis_params = { 'block_number': eth_constants.GENESIS_BLOCK_NUMBER, 'difficulty': eth_constants.GENESIS_DIFFICULTY, 'gas_limit': 3141592, 'parent_hash': eth_constants.GENESIS_PARENT_HASH, 'coinbase': eth_constants.GENESIS_COINBASE, 'nonce': eth_constants.GENESIS_NONCE, 'mix_hash': eth_constants.GENESIS_MIX_HASH, 'extra_data': eth_constants.GENESIS_EXTRA_DATA, 'timestamp': 1501851927, } chain = klass.from_genesis(base_db, genesis_params, genesis_state) return chain
def test_vm_not_found_if_no_matching_block_number(genesis_header): chain_class = Chain.configure('ChainStartsAtBlock10', vm_configuration=((10, VM_A), )) with pytest.raises(VMNotFound): chain_class.get_vm_class_for_block_number(9)