diff --git a/src/disputable_values_monitor/cli.py b/src/disputable_values_monitor/cli.py index 221ce0e..5536322 100644 --- a/src/disputable_values_monitor/cli.py +++ b/src/disputable_values_monitor/cli.py @@ -115,11 +115,6 @@ async def start( logger.error("auto-disputing enabled, but no account provided (see --help)") return - if account_name and not is_disputing: - click.echo("Telliot account provided but not disputing? (see --help)") - logger.error("Telliot account provided, but not disputing? (see --help)") - return - account: ChainedAccount = select_account(cfg, account_name, password, skip_confirmations) display_rows = [] diff --git a/src/disputable_values_monitor/utils.py b/src/disputable_values_monitor/utils.py index 94af865..9cedbfc 100644 --- a/src/disputable_values_monitor/utils.py +++ b/src/disputable_values_monitor/utils.py @@ -77,26 +77,27 @@ def select_account( cfg: TelliotConfig, account: Optional[str], password: Optional[str], skip_confirmations: Optional[bool] ) -> Optional[ChainedAccount]: """Select an account for disputing, allow no account to be chosen.""" - - if account is not None: - accounts = find_accounts(name=account) - if skip_confirmations: - return None - else: - run_alerts_only = click.confirm("Missing an account to send disputes. Run alerts only?") - if not run_alerts_only: - new_account = setup_account(cfg.main.chain_id) - if new_account is not None: - click.echo(f"{new_account.name} selected!") - return new_account + accounts = None + if account is None: + if skip_confirmations: return None else: - return None - - if password is not None: - accounts[0].unlock(password=password) - - accounts[0].unlock() + run_alerts_only = click.confirm("Missing an account to send disputes. Run alerts only?") + if not run_alerts_only: + new_account = setup_account(cfg.main.chain_id) + if new_account is not None: + click.echo(f"{new_account.name} selected!") + return new_account + return None + else: + return None + else: + accounts = find_accounts(name=account) + if password is None: + accounts[0].unlock() + click.echo(f"Your account name: {accounts[0].name if accounts else None}") + else: + accounts[0].unlock(password=password) return accounts[0] diff --git a/tests/test_auto_dispute_multiple_ids.py b/tests/test_auto_dispute_multiple_ids.py index 7045b0d..70bf816 100644 --- a/tests/test_auto_dispute_multiple_ids.py +++ b/tests/test_auto_dispute_multiple_ids.py @@ -153,9 +153,12 @@ async def submit_multiple_bad_values(stake_deposited: Awaitable[TelliotCore]): @pytest.mark.asyncio async def fetch_timestamp(oracle, query_id, chain_timestamp): """fetches a value's timestamp from oracle""" - timestamp, status = await oracle.read("getDataBefore", query_id, chain_timestamp) - assert timestamp[2] > 0 - assert status.ok, status.error + try: + timestamp, status = await oracle.read("getDataBefore", query_id, chain_timestamp) + assert timestamp is not None and len(timestamp) > 2 and timestamp[2] > 0 + assert status.ok, status.error + except Exception as e: + pytest.fail(f"Failed to fetch a valid timestamp: {e}") return timestamp @@ -165,7 +168,7 @@ async def check_dispute(oracle, query_id, timestamp): return indispute -async def setup_and_start(is_disputing, config, config_patches=None): +async def setup_and_start(is_disputing, config, config_patches=None, skip_confirmations=False, password=None): # using exit stack makes nested patching easier to read with ExitStack() as stack: stack.enter_context(patch("getpass.getpass", return_value="")) @@ -187,7 +190,7 @@ async def setup_and_start(is_disputing, config, config_patches=None): try: async with async_timeout.timeout(9): - await start(False, 8, "disputer-test-acct", is_disputing, 0.1, 0) + await start(False, 8, "disputer-test-acct", is_disputing, 0.1, 0, skip_confirmations, password) except asyncio.TimeoutError: pass @@ -300,7 +303,7 @@ async def test_evm_type_alert(submit_multiple_bad_values: Awaitable[TelliotCore] ] # not disputing just alerting # if evm type is in dispute config it will be checked for equality - await setup_and_start(False, config, config_patches) + await setup_and_start(False, config, config_patches, skip_confirmations=True, password=None) assert "Cannot evaluate percent difference on text/addresses/bytes" in caplog.text diff --git a/tests/test_utils.py b/tests/test_utils.py index 06ac7a8..d110b22 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -58,7 +58,7 @@ def test_select_account(): cfg = TelliotConfig() if not find_accounts("disputer-test-acct"): - ChainedAccount.add("disputer-test-acct1", [1, 5, 4, 1337, 80001], os.getenv("PRIVATE_KEY"), "") + ChainedAccount.add("disputer-test-acct", [1, 5, 4, 1337, 80001, 80002, 11155111], os.getenv("PRIVATE_KEY"), "") with mock.patch("click.confirm", return_value=True): account = select_account(cfg, None)