Skip to content

Commit ecc4787

Browse files
committed
Remove rest.Bitcoin.com
1 parent 2d3ebc4 commit ecc4787

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

bitcash/network/APIs/BitcoinDotComAPI.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ def __init__(self, network_endpoint: str):
3232

3333
# Default endpoints to use for this interface
3434
DEFAULT_ENDPOINTS = {
35-
"mainnet": [
36-
"https://rest.bch.actorforth.org/v2/",
37-
"https://rest.bitcoin.com/v2/",
38-
],
35+
"mainnet": ["https://rest.bch.actorforth.org/v2/"],
3936
"testnet": ["https://trest.bitcoin.com/v2/"],
4037
"regtest": ["http://localhost:12500/v2/"],
4138
}

tests/network/test_services.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import bitcash
21
import os
3-
import pytest
42
import time
3+
import copy
4+
import unittest
5+
6+
import pytest
7+
import bitcash
58
from bitcash.exceptions import InvalidEndpointURLProvided
69
from bitcash.network.meta import Unspent
710
from bitcash.network.services import (
@@ -166,36 +169,46 @@ def test_get_unspent_testnet_failure(self):
166169

167170

168171
@decorate_methods(catch_errors_raise_warnings, NetworkAPI.IGNORED_ERRORS)
169-
class TestBitcoinDotComAPI:
172+
class TestBitcoinDotComAPI(unittest.TestCase):
170173
# Mainnet
171174
# Note: There are 1 second sleeps because the default mainnet API has
172175
# rate limiting and will return 503 if we query it too quickly.
173176

177+
def setUp(self):
178+
# Save a copy of the original os.environ.
179+
# Note that this makes the tests slower, but is necessary on some test cases
180+
# to avoid side effects.
181+
# TODO: Refactor this to only be used when necessary.
182+
self.original_environ = copy.deepcopy(os.environ)
183+
184+
def tearDown(self):
185+
# Restore the original os.environ after the test.
186+
os.environ = self.original_environ
187+
174188
def test_invalid_endpoint_url_mainnet(self):
175189
for url in INVALID_ENDPOINT_URLS:
176190
with pytest.raises(InvalidEndpointURLProvided):
177191
BitcoinDotComAPI(url)
178192

179-
def test_get_single_endpoint_for_env_variable(self):
193+
def test_get_single_endpoint_for_env_variable_bitcoincom(self):
180194
os.environ["BITCOINCOM_API_MAINNET"] = VALID_ENDPOINT_URLS[0]
195+
os.environ["CHAINGRAPH_API_MAINNET"] = "%mainnet"
181196
endpoints = get_endpoints_for("mainnet")
182197
assert len(endpoints) == 3
183198
assert isinstance(endpoints[0], ChaingraphAPI) # default
184199
assert isinstance(endpoints[1], ChaingraphAPI) # default
185200
assert isinstance(endpoints[2], BitcoinDotComAPI) # env
186-
os.environ.pop("BITCOINCOM_API_MAINNET")
201+
202+
def test_get_single_endpoint_for_env_variable_chaingraph(self):
187203
os.environ["CHAINGRAPH_API"] = VALID_ENDPOINT_URLS[0]
188204
os.environ["CHAINGRAPH_API_MAINNET"] = "%mainnet"
189205
endpoints = get_endpoints_for("mainnet")
190-
assert len(endpoints) == 3
206+
assert len(endpoints) == 2
191207
assert isinstance(endpoints[0], ChaingraphAPI) # env
192208
assert isinstance(endpoints[1], BitcoinDotComAPI) # default
193-
assert isinstance(endpoints[2], BitcoinDotComAPI) # default
194209
assert endpoints[0].node_like == "%mainnet"
195-
os.environ.pop("CHAINGRAPH_API")
196-
os.environ.pop("CHAINGRAPH_API_MAINNET")
197210

198-
def test_get_multiple_endpoint_for_env_variable(self):
211+
def test_get_multiple_endpoint_for_env_variable_bitcoincom(self):
199212
os.environ["BITCOINCOM_API_MAINNET_1"] = VALID_ENDPOINT_URLS[0]
200213
os.environ["BITCOINCOM_API_MAINNET_2"] = VALID_ENDPOINT_URLS[1]
201214
endpoints = get_endpoints_for("mainnet")
@@ -204,22 +217,19 @@ def test_get_multiple_endpoint_for_env_variable(self):
204217
assert isinstance(endpoints[1], ChaingraphAPI) # default
205218
assert isinstance(endpoints[2], BitcoinDotComAPI) # env
206219
assert isinstance(endpoints[3], BitcoinDotComAPI) # env
207-
os.environ.pop("BITCOINCOM_API_MAINNET_1")
208-
os.environ.pop("BITCOINCOM_API_MAINNET_2")
209-
os.environ["CHAINGRAPH_API_1"] = VALID_ENDPOINT_URLS[0]
210-
os.environ["CHAINGRAPH_API_2"] = VALID_ENDPOINT_URLS[1]
220+
221+
def test_get_multiple_endpoint_for_env_variable_chaingraph(self):
222+
os.environ = self.original_environ
223+
os.environ["CHAINGRAPH_API_1"] = "https://demo.chaingraph.cash/v1/graphql"
224+
os.environ["CHAINGRAPH_API_2"] = "https://demo.chaingraph.cash/v1/graphql"
211225
os.environ["CHAINGRAPH_API_MAINNET_2"] = "%mainnet"
212226
endpoints = get_endpoints_for("mainnet")
213-
assert len(endpoints) == 4
227+
assert len(endpoints) == 3
214228
assert isinstance(endpoints[0], ChaingraphAPI) # default
215229
assert isinstance(endpoints[1], ChaingraphAPI) # default
216230
assert isinstance(endpoints[2], BitcoinDotComAPI) # env
217-
assert isinstance(endpoints[3], BitcoinDotComAPI) # env
218231
assert endpoints[0].node_like == "%"
219232
assert endpoints[1].node_like == "%mainnet"
220-
os.environ.pop("CHAINGRAPH_API_1")
221-
os.environ.pop("CHAINGRAPH_API_2")
222-
os.environ.pop("CHAINGRAPH_API_MAINNET_2")
223233

224234
def test_get_balance_mainnet_return_type(self):
225235
time.sleep(1)

0 commit comments

Comments
 (0)