def manifest_with_no_matching_deployments(w3, tmpdir, safe_math_manifest): w3.testing.mine(5) incorrect_genesis_hash = b"\x00" * 31 + b"\x01" block = w3.eth.getBlock("earliest") block_uri = create_block_uri(w3.toHex(incorrect_genesis_hash), w3.toHex(block.hash)) manifest = copy.deepcopy(safe_math_manifest) manifest["deployments"][block_uri] = { "SafeMathLib": { "contract_type": "SafeMathLib", "address": "0x8d2c532d7d211816a2807a411f947b211569b68c", "transaction": "0xaceef751507a79c2dee6aa0e9d8f759aa24aab081f6dcf6835d792770541cb2b", "block": "0x420cb2b2bd634ef42f9082e1ee87a8d4aeeaf506ea5cdeddaa8ff7cbf911810c", } } return manifest
def create_latest_block_uri(w3: Web3, from_blocks_ago: int = 3) -> URI: """ Creates a block uri for the given w3 instance. Defaults to 3 blocks prior to the "latest" block to accommodate for block reorgs. If using a testnet with less than 3 mined blocks, adjust :from_blocks_ago:. """ chain_id = to_hex(get_genesis_block_hash(w3)) latest_block_tx_receipt = w3.eth.getBlock("latest") target_block_number = latest_block_tx_receipt.number - from_blocks_ago if target_block_number < 0: raise Exception( f"Only {latest_block_tx_receipt.number} blocks avaible on provided w3, " f"cannot create latest block uri for {from_blocks_ago} blocks ago." ) recent_block = to_hex(w3.eth.getBlock(target_block_number).hash) return create_block_uri(chain_id, recent_block)