• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-eth-py / 13834119283

13 Mar 2025 12:03PM UTC coverage: 93.954% (+0.004%) from 93.95%
13834119283

push

github

web-flow
Fix tx-service api url builder (#1589)

* Fix tx-service api url builder

* Update safe_eth/util/http.py

Co-authored-by: Uxío <Uxio0@users.noreply.github.com>

---------

Co-authored-by: Uxío <Uxio0@users.noreply.github.com>

25 of 27 new or added lines in 3 files covered. (92.59%)

1 existing line in 1 file now uncovered.

9510 of 10122 relevant lines covered (93.95%)

2.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/safe_eth/safe/api/base_api.py
1
from abc import ABC
3✔
2
from typing import Dict, Optional
3✔
3

4
import requests
3✔
5

6
from safe_eth.eth.ethereum_client import (
3✔
7
    EthereumClient,
8
    EthereumNetwork,
9
    EthereumNetworkNotSupported,
10
)
11
from safe_eth.util.http import build_full_url, prepare_http_session
3✔
12

13

14
class SafeAPIException(Exception):
3✔
15
    pass
3✔
16

17

18
class SafeBaseAPI(ABC):
3✔
19
    URL_BY_NETWORK: Dict[EthereumNetwork, str] = {}
3✔
20

21
    def __init__(
3✔
22
        self,
23
        network: EthereumNetwork,
24
        ethereum_client: Optional[EthereumClient] = None,
25
        base_url: Optional[str] = None,
26
        request_timeout: int = 10,
27
    ):
28
        """
29
        :param network: Network for the transaction service
30
        :param ethereum_client:
31
        :param base_url: If a custom transaction service is used
32
        :raises: EthereumNetworkNotSupported
33
        """
34
        self.network = network
3✔
35
        self.ethereum_client = ethereum_client
3✔
36
        self.base_url = base_url or self.URL_BY_NETWORK.get(network, "")
3✔
37
        if not self.base_url:
3✔
38
            raise EthereumNetworkNotSupported(network)
3✔
39
        self.http_session = prepare_http_session(10, 100)
3✔
40
        self.request_timeout = request_timeout
3✔
41

42
    @classmethod
3✔
43
    def from_ethereum_client(cls, ethereum_client: EthereumClient) -> "SafeBaseAPI":
3✔
44
        ethereum_network = ethereum_client.get_network()
3✔
45
        return cls(ethereum_network, ethereum_client=ethereum_client)
3✔
46

47
    def _get_request(self, url: str) -> requests.Response:
3✔
48
        full_url = build_full_url(self.base_url, url)
3✔
49
        return self.http_session.get(full_url, timeout=self.request_timeout)
3✔
50

51
    def _post_request(self, url: str, payload: Dict) -> requests.Response:
3✔
NEW
52
        full_url = build_full_url(self.base_url, url)
×
53
        return self.http_session.post(
×
54
            full_url,
55
            json=payload,
56
            headers={"Content-type": "application/json"},
57
            timeout=self.request_timeout,
58
        )
59

60
    def _delete_request(self, url: str, payload: Dict) -> requests.Response:
3✔
NEW
61
        full_url = build_full_url(self.base_url, url)
×
62
        return self.http_session.delete(
×
63
            full_url,
64
            json=payload,
65
            headers={"Content-type": "application/json"},
66
            timeout=self.request_timeout,
67
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc