Skip to content

Commit

Permalink
update tests for new flags
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSpuddy committed Nov 15, 2024
1 parent 02561ef commit 909aba5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
5 changes: 0 additions & 5 deletions src/disputable_values_monitor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
37 changes: 19 additions & 18 deletions src/disputable_values_monitor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down
15 changes: 9 additions & 6 deletions tests/test_auto_dispute_multiple_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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=""))
Expand All @@ -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

Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 909aba5

Please sign in to comment.