Repository: tellor-io/telliot-feeds (language: python)

Issue:
Doesn't attempt to settle pool after failed to previously
For the DIVA integration: Ran out of gas so couldn't call the settle function, then when restarting it didn't try to settle again, when it should.


Discussion / hints:
Maybe just use the graph instead of local db
I think it should still avoid attempting to settle multiple times, so repeat transaction reverts don't drain the funds of the reporter.

Instead, make a subcommand to clear the local report/settle db (pickle file).

Fix patch:
diff --git a/src/telliot_feeds/cli/commands/integrations.py b/src/telliot_feeds/cli/commands/integrations.py
new file mode 100644
index 00000000..8b02ee12
--- /dev/null
+++ b/src/telliot_feeds/cli/commands/integrations.py
@@ -0,0 +1,12 @@
+import click
+
+from telliot_feeds.integrations.diva_protocol.cli import diva
+
+
+@click.group()
+def integrations() -> None:
+    """Commands for Tellor Protocol integrations."""
+    pass
+
+
+integrations.add_command(diva)
diff --git a/src/telliot_feeds/cli/main.py b/src/telliot_feeds/cli/main.py
index 3cfa4c46..1cb774e7 100644
--- a/src/telliot_feeds/cli/main.py
+++ b/src/telliot_feeds/cli/main.py
@@ -9,6 +9,7 @@
 from click.core import Context
 
 from telliot_feeds.cli.commands.catalog import catalog
+from telliot_feeds.cli.commands.integrations import integrations
 from telliot_feeds.cli.commands.query import query
 from telliot_feeds.cli.commands.report import report
 from telliot_feeds.cli.commands.settle import settle
@@ -65,6 +66,7 @@ def main(
 main.add_command(query)
 main.add_command(catalog)
 main.add_command(settle)
+main.add_command(integrations)
 
 if __name__ == "__main__":
     main()
diff --git a/src/telliot_feeds/integrations/diva_protocol/cli.py b/src/telliot_feeds/integrations/diva_protocol/cli.py
new file mode 100644
index 00000000..6eb2ccc1
--- /dev/null
+++ b/src/telliot_feeds/integrations/diva_protocol/cli.py
@@ -0,0 +1,41 @@
+import click
+
+from telliot_feeds.integrations.diva_protocol.utils import get_reported_pools
+from telliot_feeds.integrations.diva_protocol.utils import update_reported_pools
+
+
+@click.group()
+def diva() -> None:
+    """Commands for Diva Protocol integration."""
+    pass
+
+
+@diva.group()
+def cache() -> None:
+    """Commands for interacting with reported/settled pools cache (pickle file)."""
+    pass
+
+
+@cache.command()
+def view() -> None:
+    """View reported/settled pools cache."""
+    cache = get_reported_pools()
+    if cache:
+        click.echo("Reported/Settled Pools Cache:")
+    else:
+        click.echo("Reported/Settled Pools Cache is empty")
+        return
+    for pool_id in cache:
+        click.echo(f"Pool ID: {pool_id}")
+        expiry, status = cache[pool_id]
+        click.echo(f"\tExpiry: {expiry}")
+        click.echo(f"\tSettle status: {status}")
+
+
+@cache.command()
+def clear() -> None:
+    """Clear reported/settled pools cache.
+
+    Creates and saves an empty dict as a pickle file in the telliot default dir."""
+    update_reported_pools({})
+    click.echo("Cleared reported/settled pools cache")


Test patch:
diff --git a/tests/cli/test_diva_cli.py b/tests/cli/test_diva_cli.py
index 77854399..1a21c08d 100644
--- a/tests/cli/test_diva_cli.py
+++ b/tests/cli/test_diva_cli.py
@@ -42,9 +42,26 @@ def mock_parse_profit(*args, **kwargs):
         assert result.exit_code == 0
 
 
-def test_integrations_help_cmd():
-    # ensure diva cmd is available
-    pass
+def test_available_cmds():
+    """Test help command for integrations."""
+    runner = CliRunner()
+    result = runner.invoke(cli_main, ["integrations", "--help"])
+
+    assert result.exit_code == 0
+    assert "diva  Commands for Diva Protocol integration." in result.stdout
+
+    result = runner.invoke(cli_main, ["integrations", "diva", "--help"])
+
+    assert result.exit_code == 0
+    assert "Commands for interacting with reported/settled pools cache" in result.stdout
+
+    result = runner.invoke(cli_main, ["integrations", "diva", "cache", "--help"])
+    view_msg = "view   View reported/settled pools cache."
+    clear_msg = "clear  Clear reported/settled pools cache."
+
+    assert result.exit_code == 0
+    assert view_msg in result.stdout
+    assert clear_msg in result.stdout
 
 
 def test_diva_help_cmd():