Skip to content

Commit

Permalink
Remove Goerli/Rinkeby tests (#1840)
Browse files Browse the repository at this point in the history
- Remove Goerli/Rinkeby tests
- Related to safe-global/safe-eth-py#734
- Add SEPOLIA graph for ENS
  • Loading branch information
Uxio0 authored Jan 26, 2024
1 parent 773ab9d commit 5489845
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Transactions can also be sent to the service to allow offchain collecting of sig
a transaction that is pending to be sent to the blockchain.

[Swagger (Mainnet version)](https://safe-transaction-mainnet.safe.global/)
[Swagger (Göerli version)](https://safe-transaction-goerli.safe.global/)
[More networks](https://docs.safe.global/safe-core-api/supported-networks)

## Index of contents

Expand Down
45 changes: 22 additions & 23 deletions safe_transaction_service/history/clients/ens_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
from cache_memoize import cache_memoize
from hexbytes import HexBytes

from gnosis.eth import EthereumNetwork


# TODO Move this class to safe-eth-py
class EnsClient:
def __init__(self, network_id: int):
base_url = "https://api.thegraph.com/subgraphs/name/ensdomains/"
if network_id == 3: # Ropsten
url = base_url + "ensropsten"
elif network_id == 4: # Rinkeby
url = base_url + "ensrinkeby"
elif network_id == 5: # Goerli
url = base_url + "ensgoerli"
self.ethereum_network = EthereumNetwork(network_id)
if network_id == self.ethereum_network.SEPOLIA:
url = (
"https://api.studio.thegraph.com/proxy/49574/enssepolia/version/latest/"
)
else: # Fallback to mainnet
url = base_url + "ens"
self.url: str = url
url = "https://api.thegraph.com/subgraphs/name/ensdomains/ens/"
self.url = url
self.request_timeout = 5 # Seconds
self.request_session = requests.Session()

Expand Down Expand Up @@ -53,15 +54,12 @@ def _query_by_domain_hash(self, domain_hash_str: str) -> Optional[str]:
"domain_hash", domain_hash_str
)
try:
r = self.request_session.post(
response = self.request_session.post(
self.url, json={"query": query}, timeout=self.request_timeout
)
except IOError:
return None

if not r.ok:
return None

"""
Example:
{
Expand All @@ -74,11 +72,13 @@ def _query_by_domain_hash(self, domain_hash_str: str) -> Optional[str]:
}
}
"""
data = r.json()
if data:
domains = data.get("data", {}).get("domains")
if domains:
return domains[0].get("labelName")
if response.ok:
data = response.json()
if data:
domains = data.get("data", {}).get("domains")
if domains:
return domains[0].get("labelName")
return None

def query_by_domain_hash(
self, domain_hash: Union[str, bytes, int]
Expand Down Expand Up @@ -134,15 +134,14 @@ def query_by_account(self, account: str) -> Optional[List[Dict[str, Any]]]:
"account_id", account.lower()
)
try:
r = self.request_session.post(
response = self.request_session.post(
self.url, json={"query": query}, timeout=self.request_timeout
)
except IOError:
return None

if not r.ok:
return None
else:
data = r.json()
if response.ok:
data = response.json()
if data:
return data.get("data", {}).get("account")
return None
88 changes: 79 additions & 9 deletions safe_transaction_service/history/tests/clients/test_ens_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,94 @@ def test_domain_hash_to_hex_str(self):
self.assertEqual(len(EnsClient.domain_hash_to_hex_str(2)), 66)

def test_query_by_account(self):
ens_client = EnsClient(EthereumNetwork.GOERLI.value) # Mainnet
ens_client = EnsClient(EthereumNetwork.MAINNET.value)
if not ens_client.is_available():
self.skipTest("ENS Goerli Client is not available")
self.skipTest("ENS Mainnet Client is not available")

self.assertEqual(
ens_client.query_by_account("0x0D28d3C544757B9DBb99AC33FcB774534D7C8a7D"),
ens_client.query_by_account("0x70608b1809c93Ec57160C266a38322144E9A9d28"),
{
"registrations": [
{
"expiryDate": "2308985592",
"expiryDate": "1763372829",
"domain": {
"labelName": "safe-treasury",
"labelhash": "0x136ff778d0f4bb244b1284dd5835c78a9fb425680d3a75aab24db723042494af",
"name": "safe-treasury.eth",
"isMigrated": True,
"parent": {"name": "eth"},
},
},
{
"expiryDate": "1775002833",
"domain": {
"labelName": "gnosis-safe",
"labelhash": "0x162be7f136f104c8cc5ce333cdb2ef94fa8270f4ca186ba6083634b8b93efa82",
"name": "gnosis-safe.eth",
"isMigrated": True,
"parent": {"name": "eth"},
},
},
{
"expiryDate": "1763371973",
"domain": {
"labelName": "safe-dao",
"labelhash": "0x3dcf430070cc5f52fbe66433a72fc6eed2860b28527f9016933599d41cbf6d9e",
"name": "safe-dao.eth",
"isMigrated": True,
"parent": {"name": "eth"},
},
},
{
"expiryDate": "1763373078",
"domain": {
"labelName": "safe-foundation",
"labelhash": "0x50270c4c4cf9837870f71a836cc4ab37d29e0a452eda3caa1b39cc8a29b96e90",
"name": "safe-foundation.eth",
"isMigrated": True,
"parent": {"name": "eth"},
},
},
{
"expiryDate": "1824427603",
"domain": {
"labelName": "safe",
"labelhash": "0xc318ae71df18dafd8fbd063284586ea242aa3d51bc2950f71d70d7fc205b875f",
"name": "safe.eth",
"isMigrated": True,
"parent": {"name": "eth"},
},
},
{
"expiryDate": "1763372390",
"domain": {
"labelName": "safe-token",
"labelhash": "0xc9ccb8a54110c76c01d4f63e9a9d760d8fd803aba14f4d2fa408200cc6b68cba",
"name": "safe-token.eth",
"isMigrated": True,
"parent": {"name": "eth"},
},
},
{
"expiryDate": "1763309068",
"domain": {
"labelName": "safe-multisig",
"labelhash": "0xce3f8bfd04bb347a13abbf6faca8dc5e4a281345a316019206742b60b6f1b053",
"name": "safe-multisig.eth",
"isMigrated": True,
"parent": {"name": "eth"},
},
},
{
"expiryDate": "1764337847",
"domain": {
"labelName": "safe-tx-service",
"labelhash": "0x4d9600e939c494d5af0e62d974199a3674381907b1a7469ff900d13ff74f04d1",
"name": "safe-tx-service.eth",
"labelName": "takebackownership",
"labelhash": "0xedc916efb805eea66b4d5496f670c0166ccd9d2453ded805fe1d82738944e8df",
"name": "takebackownership.eth",
"isMigrated": True,
"parent": {"name": "eth"},
},
}
},
]
},
)
Expand All @@ -62,7 +132,7 @@ def test_query_by_domain_hash(self):

def test_is_available(self):
for ethereum_network in (
EthereumNetwork.GOERLI,
EthereumNetwork.ROPSTEN,
EthereumNetwork.MAINNET,
):
with self.subTest(ethereum_network=ethereum_network):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
},
]

# trace_blocks 6067026 on Rinkeby
# trace_blocks([6067026]) on Rinkeby
trace_blocks_result = [
[
{
Expand Down
4 changes: 2 additions & 2 deletions safe_transaction_service/history/tests/mocks/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"type": "call",
}

rinkeby_traces = [
testnet_traces = [
{
"action": {
"from": "0x5aC255889882aCd3da2aA939679E3f3d4cea221e",
Expand Down Expand Up @@ -138,7 +138,7 @@
"transactionPosition": 0,
"type": "call",
},
]
] # Taken from Rinkeby

module_traces = [
{
Expand Down
14 changes: 4 additions & 10 deletions safe_transaction_service/history/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def _test_setup_service(
self.assertGreater(PeriodicTask.objects.count(), 0)

# Check last master copy was created
last_master_copy_address = "0x6851D6fDFAfD08c0295C392436245E5bc78B0185"
last_master_copy_address = "0x41675C099F32341bf84BFc5382aF534df5C7461a"
last_master_copy = SafeMasterCopy.objects.get(address=last_master_copy_address)
self.assertGreater(last_master_copy.initial_block_number, 0)
self.assertGreater(last_master_copy.tx_block_number, 0)

# Check last proxy factory was created
last_proxy_factory_address = "0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B"
last_proxy_factory_address = "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67"
last_proxy_factory = ProxyFactory.objects.get(
address=last_proxy_factory_address
)
Expand Down Expand Up @@ -390,14 +390,8 @@ def test_setup_service_mainnet_erc20_indexing_setup(self):
first_safe_block_deployed + 20,
)

def test_setup_service_rinkeby(self):
self._test_setup_service(EthereumNetwork.RINKEBY)

def test_setup_service_goerli(self):
self._test_setup_service(EthereumNetwork.GOERLI)

def test_setup_service_kovan(self):
self._test_setup_service(EthereumNetwork.KOVAN)
def test_setup_service_sepolia(self):
self._test_setup_service(EthereumNetwork.SEPOLIA)

@mock.patch.object(EthereumClient, "get_network", autospec=True)
def test_setup_service_not_valid_network(
Expand Down
4 changes: 2 additions & 2 deletions safe_transaction_service/history/tests/test_tx_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
SafeLastStatusFactory,
SafeMasterCopyFactory,
)
from .mocks.traces import call_trace, module_traces, rinkeby_traces
from .mocks.traces import call_trace, module_traces, testnet_traces

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -256,7 +256,7 @@ def test_tx_processor_with_factory(self):
TracingManager,
"trace_transaction",
autospec=True,
return_value=rinkeby_traces,
return_value=testnet_traces,
):
# call_trace has [] as a trace address and module txs need to get the grandfather tx, so [0,0] must
# be used
Expand Down
1 change: 0 additions & 1 deletion safe_transaction_service/tokens/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CRYPTO_KITTIES_CONTRACT_ADDRESSES = {
"0x06012c8cf97BEaD5deAe237070F9587f8E7A266d", # Mainnet
"0x16baF0dE678E52367adC69fD067E5eDd1D33e3bF", # Rinkeby
}

ENS_CONTRACTS_WITH_TLD = {
Expand Down
2 changes: 1 addition & 1 deletion safe_transaction_service/tokens/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def tearDown(self) -> None:
def test_fix_pool_tokens_task(self, get_network_mock: MagicMock):
self.assertEqual(fix_pool_tokens_task.delay().result, 0)

get_network_mock.return_value = EthereumNetwork.RINKEBY
get_network_mock.return_value = EthereumNetwork.SEPOLIA
self.assertIsNone(fix_pool_tokens_task.delay().result)

@mock.patch(
Expand Down

0 comments on commit 5489845

Please sign in to comment.