def test_leveldb_hash_search_correct_input(mock_hash_to_address, f1, f2, f3):
    config = MythrilConfig()
    config.set_api_leveldb("some path")
    leveldb_search = MythrilLevelDB(leveldb=config.eth_db)
    f = io.StringIO()
    with redirect_stdout(f):
        leveldb_search.contract_hash_to_address(
            "0x0464e651bcc40de28fc7fcde269218d16850bac9689da5f4a6bd640fd3cdf6aa"
        )
    out = f.getvalue()
    mock_hash_to_address.assert_called()
    assert out == "0xddbb615cb2ffaff7233d8a6f3601621de94795e1\n"
Пример #2
0
def leveldb_search(config: MythrilConfig, args: argparse.Namespace):
    if args.search or args.contract_hash_to_address:
        leveldb_searcher = MythrilLevelDB(config.eth_db)
        if args.search:
            # Database search ops
            leveldb_searcher.search_db(args.search)

        else:
            # search corresponding address
            try:
                leveldb_searcher.contract_hash_to_address(args.contract_hash_to_address)
            except AddressNotFoundError:
                print("Address not found.")

        sys.exit()
Пример #3
0
def leveldb_search(config: MythrilConfig, args: Namespace):
    """
    Handle leveldb search
    :param config:
    :param args:
    :return:
    """
    if args.command in ("hash-to-address", "leveldb-search"):
        leveldb_searcher = MythrilLevelDB(config.eth_db)
        if args.command == "leveldb-search":
            # Database search ops
            leveldb_searcher.search_db(args.search)

        else:
            # search corresponding address
            try:
                leveldb_searcher.contract_hash_to_address(args.hash)
            except AddressNotFoundError:
                print("Address not found.")

        sys.exit()
def test_leveldb_hash_search_incorrect_input(f1, f2, f3):
    config = MythrilConfig()
    config.set_api_leveldb("some path")
    leveldb_search = MythrilLevelDB(leveldb=config.eth_db)
    with pytest.raises(CriticalError):
        leveldb_search.contract_hash_to_address("0x23")
def test_leveldb_code_search(mock_leveldb, f1, f2, f3):
    config = MythrilConfig()
    config.set_api_leveldb("some path")
    leveldb_search = MythrilLevelDB(leveldb=config.eth_db)
    leveldb_search.search_db("code#PUSH#")
    mock_leveldb.assert_called()