Skip to content

Commit

Permalink
[FIX] Small bugs and unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
mccwdev committed Sep 17, 2021
1 parent c16da2e commit d6f72e5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
1 change: 0 additions & 1 deletion blocksmurfer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ def static_from_root():
app.register_blueprint(api_bp, url_prefix='/api/v1')
limiter.init_app(app)


return app
9 changes: 2 additions & 7 deletions blocksmurfer/explorer/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
# License, or (at your option) any later version.
#

from flask import abort, current_app, session
from flask import abort, current_app
from bitcoinlib.encoding import *
from bitcoinlib.keys import Address
from bitcoinlib.services.services import Service, ServiceError
from bitcoinlib.services.services import Service


# TODO: Use from Config
Expand All @@ -28,11 +28,6 @@
class SmurferService(Service):

def __init__(self, network_code='btc', timeout=5, *args, **kwargs):
# nw_enabled = network_code_translation.keys() if not current_app else current_app.config['NETWORKS_ENABLED']
# TODO: Enable other networks
# if not network_code and current_app:
# network_code = session.get('network_code', current_app.config['NETWORK_DEFAULT'])
# session['network_code'] = network_code
if network_code in current_app.config['NETWORKS_ENABLED'].keys():
network = current_app.config['NETWORKS_ENABLED'][network_code]
Service.__init__(self, network=network, timeout=timeout, *args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion blocksmurfer/templates/explorer/transaction.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h2>{{ _('Details') }}</h2>
<tr>
<td>Date</td>
<td>
{{ transaction.date.replace(tzinfo=tzutc).timestamp() | ctime}}
{{ transaction.date.replace(tzinfo=tzutc).timestamp() | ctime }}
</td>
</tr>
{% endif %}
Expand Down
16 changes: 8 additions & 8 deletions tests/test_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from flask import Config
from blocksmurfer import current_app
from tests.test_custom import CustomAssertions
from blocksmurfer.explorer.service import SmurferService
# from blocksmurfer.explorer.service import SmurferService
from bitcoinlib.services.services import Service


class TestingConfig(Config):
Expand Down Expand Up @@ -47,8 +48,8 @@ def test_about_page(self):
def test_provider_page(self):
response = self.app.get('/providers', follow_redirects=True)
self.assertIn(b'providers', response.data)
self.assertIn(b'blockcypher', response.data)
self.assertIn(b'https://api.smartbit.com.au/v1/', response.data)
self.assertIn(b'blockchair', response.data)
self.assertIn(b'https://blockstream.info/api/', response.data)
self.assertEqual(response.status_code, 200)

def test_search_address(self):
Expand Down Expand Up @@ -122,20 +123,18 @@ def test_explorer_transaction(self):

def test_explorer_transaction_segwit(self):
response = self.app.get('/btc/transaction/466490c0401d4d7ea781ca1a4ef22ac889c3404385c95c18edd1447c3a500d45')
self.assertIn(b'2020-01-08 03:52:41', response.data)
self.assertIn(b'bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej', response.data)
self.assertIn(b'0.15175083', response.data)
self.assertEqual(response.status_code, 200)

def test_explorer_transaction_coinbase(self):
response = self.app.get('/btc/transaction/ce242be116c5caf016185f4f4e75628843ecb18faeb2935c9a9c848464f693a4')
self.assertIn(b'2020-01-08', response.data)
self.assertIn(b'611838', response.data)
self.assertIn(b'3QLeXx1J9Tp3TBnQyHrhVxne9KqkAS9JSR', response.data)
self.assertEqual(response.status_code, 200)

def test_explorer_transaction_unconfirmed(self):
srv = SmurferService('btc')
srv = Service()
mempool = srv.mempool()
if not isinstance(mempool, list) or not mempool:
pass
Expand Down Expand Up @@ -318,7 +317,7 @@ def test_explorer_key_xpub(self):

def test_explorer_404(self):
response = self.app.get('/btc/strange_url')
self.assertIn(b'Error: Not Found', response.data)
self.assertIn(b'Not Found (404)', response.data)
self.assertEqual(response.status_code, 404)

def test_explorer_422_unknown_network(self):
Expand Down Expand Up @@ -568,7 +567,8 @@ def test_api_transaction_broadcast_already_include(self):
def test_api_transaction_broadcast_post_invalid_tx(self):
rawtx = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000"
response = self.app.post('/api/v1/btc/transaction_broadcast', data=rawtx)
self.assertIn(b'"Invalid raw transaction hex, could not parse: index out of range"', response.data)
self.assertIn(b'"Invalid raw transaction hex, could not parse: Malformed script, not enough data found"',
response.data)
self.assertEqual(response.status_code, 400)

def test_api_network(self):
Expand Down

0 comments on commit d6f72e5

Please sign in to comment.