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

Issue:
Support New Query Type -- [AutopayAddresses/TellorOracleAddress]
Query implementation is needed for DVM
- [x] Links to [dataSpecs](https://github.com/tellor-io/dataSpecs) issue & new query type file
- [x] Add query type (subclass `AbiQuery`)


Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index 28d7900d..a70798e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -167,4 +167,7 @@ package-lock.json
 package.json
 
 # aws keys
-*.pem
\ No newline at end of file
+*.pem
+
+# ignore stray test files
+reported_pools.pickle
diff --git a/src/telliot_feeds/queries/tellor/autopay_addresses.py b/src/telliot_feeds/queries/tellor/autopay_addresses.py
new file mode 100644
index 00000000..06dc2c8a
--- /dev/null
+++ b/src/telliot_feeds/queries/tellor/autopay_addresses.py
@@ -0,0 +1,31 @@
+import logging
+from dataclasses import dataclass
+
+from telliot_feeds.dtypes.value_type import ValueType
+from telliot_feeds.queries.abi_query import AbiQuery
+
+logger = logging.getLogger(__name__)
+
+
+@dataclass
+class AutopayAddresses(AbiQuery):
+    """Returns an array of current Tellor autopay addresses.
+    It is used for retrieving user vote weights for disputes in the governance contract.
+
+    Attributes:
+        phantom:
+            Empty bytes, always used for query types with no arguments
+
+    See the data spec for more info about this query type:
+    https://github.com/tellor-io/dataSpecs/blob/main/types/AutopayAddresses.md
+    """
+
+    @property
+    def value_type(self) -> ValueType:
+        """Data type returned for a AutopayAddresses query.
+
+        - `address[]`: the addresses of the Tellor Autopay contracts
+        - `packed`: false
+        """
+
+        return ValueType(abi_type="address[]", packed=False)
diff --git a/src/telliot_feeds/queries/tellor/tellor_oracle_address.py b/src/telliot_feeds/queries/tellor/tellor_oracle_address.py
new file mode 100644
index 00000000..6b92b7fe
--- /dev/null
+++ b/src/telliot_feeds/queries/tellor/tellor_oracle_address.py
@@ -0,0 +1,31 @@
+import logging
+from dataclasses import dataclass
+
+from telliot_feeds.dtypes.value_type import ValueType
+from telliot_feeds.queries.abi_query import AbiQuery
+
+logger = logging.getLogger(__name__)
+
+
+@dataclass
+class TellorOracleAddress(AbiQuery):
+    """Returns the latest Tellor oracle address.
+    It is used for updating the time based rewards recipient on Ethereum mainnet.
+
+    Attributes:
+        phantom:
+            Empty bytes, always used for query types with no arguments
+
+    See the data spec for more info about this query type:
+    https://github.com/tellor-io/dataSpecs/blob/main/types/TellorOracleAddress.md
+    """
+
+    @property
+    def value_type(self) -> ValueType:
+        """Data type returned for a TellorOracleAddress query.
+
+        - `address`: the address of the Tellor oracle
+        - `packed`: false
+        """
+
+        return ValueType(abi_type="address", packed=False)


Test patch:
diff --git a/tests/queries/test_query_support.py b/tests/queries/test_query_support.py
index f9512289..67ebcf4f 100644
--- a/tests/queries/test_query_support.py
+++ b/tests/queries/test_query_support.py
@@ -11,7 +11,13 @@ def test_all_query_types_in_catalog():
     for q in AbiQuery.__subclasses__():
         print("Checking", q.__name__)
         # skip legacy type
-        if q.__name__ in ("LegacyRequest", "FakeQueryType"):
+        if q.__name__ in (
+            "LegacyRequest",
+            "FakeQueryType",
+            "MimicryCollectionStat",
+            "AutopayAddresses",
+            "TellorOracleAddress",
+        ):
             continue
         assert q.__name__ in q_types
 
diff --git a/tests/queries/test_query_tellor_addresses.py b/tests/queries/test_query_tellor_addresses.py
new file mode 100644
index 00000000..1e2668bc
--- /dev/null
+++ b/tests/queries/test_query_tellor_addresses.py
@@ -0,0 +1,82 @@
+""" Unit tests for TellorOracleAddress and AutopayAddresses queries
+
+Copyright (c) 2021-, Tellor Development Community
+Distributed under the terms of the MIT License.
+"""
+from eth_abi import decode_abi
+from web3 import Web3
+
+from telliot_feeds.queries.tellor.autopay_addresses import AutopayAddresses
+from telliot_feeds.queries.tellor.tellor_oracle_address import TellorOracleAddress
+
+
+def test_autopay_constructor():
+    """Validate autopay query."""
+    q = AutopayAddresses()
+
+    exp = "0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000104175746f70617941646472657373657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"  # noqa: E501
+
+    assert q.query_data.hex() == exp
+
+    query_type, encoded_param_vals = decode_abi(["string", "bytes"], q.query_data)
+    assert query_type == "AutopayAddresses"
+
+    phantom_bytes = decode_abi(["bytes"], encoded_param_vals)[0]
+    assert isinstance(phantom_bytes, bytes)
+    assert phantom_bytes == b""
+
+    exp = "3ab34a189e35885414ac4e83c5a7faa9d8f03a4d530728ef516d203d91d6309c"
+    assert q.query_id.hex() == exp
+
+
+def test_autopay_encode_decode_reported_val():
+    """Ensure expected encoding/decoding behavior."""
+    q = AutopayAddresses()
+
+    # an address value indicating the current tellor autopay addresses
+    current_autopay_addresses = ["0x9BE9B0CFA89Ea800556C6efbA67b455D336db1D0"]
+
+    submit_value = q.value_type.encode(current_autopay_addresses)
+    assert isinstance(submit_value, bytes)
+
+    decoded_result = q.value_type.decode(submit_value)
+    assert isinstance(decoded_result, tuple)
+
+    assert Web3.toChecksumAddress(decoded_result[0]) == "0x9BE9B0CFA89Ea800556C6efbA67b455D336db1D0"
+
+
+def test_oracle_address_constructor():
+    """Validate TellorOracleAddress query."""
+
+    q = TellorOracleAddress()
+
+    exp = "00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000001354656c6c6f724f7261636c654164647265737300000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"  # noqa: E501
+
+    assert q.query_data.hex() == exp
+
+    query_type, encoded_param_vals = decode_abi(["string", "bytes"], q.query_data)
+    assert query_type == "TellorOracleAddress"
+
+    phantom_bytes = decode_abi(["bytes"], encoded_param_vals)[0]
+    assert isinstance(phantom_bytes, bytes)
+    assert phantom_bytes == b""
+
+    exp = "cf0c5863be1cf3b948a9ff43290f931399765d051a60c3b23a4e098148b1f707"
+    assert q.query_id.hex() == exp
+
+
+def test_oracle_address_encode_decode_reported_val():
+    """Ensure expected encoding/decoding behavior."""
+
+    q = TellorOracleAddress()
+
+    # an address value indicating the current tellor autopay addresses
+    current_oracle_addresses = "0xB3B662644F8d3138df63D2F43068ea621e2981f9"
+
+    submit_value = q.value_type.encode(current_oracle_addresses)
+    assert isinstance(submit_value, bytes)
+
+    decoded_result = q.value_type.decode(submit_value)
+    assert isinstance(decoded_result, str)
+
+    assert Web3.toChecksumAddress(decoded_result) == "0xB3B662644F8d3138df63D2F43068ea621e2981f9"