Skip to content

Commit

Permalink
Remove unused token QR code from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
devos50 committed Oct 13, 2020
1 parent a1e65dc commit 263fa96
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 408 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,109 +75,3 @@ async def test_get_statistics_no_data(enable_api, mock_ipv8, session):
assert stats["peers_that_pk_helped"] == 0
assert stats["peers_that_helped_pk"] == 0
assert "latest_block" not in stats


@pytest.mark.asyncio
async def test_get_bootstrap_identity_no_community(enable_api, session):
"""
Testing whether the API returns error 404 if no trustchain community is loaded when bootstrapping a new identity
"""
await do_request(session, 'trustchain/bootstrap', expected_code=404)


@pytest.mark.asyncio
async def test_get_bootstrap_identity_all_tokens(enable_api, mock_ipv8, session):
"""
Testing whether the API return all available tokens when no argument is supplied
"""
transaction = {b'up': 100, b'down': 0, b'total_up': 100, b'total_down': 0}
transaction2 = {'up': 100, 'down': 0}

test_block = TrustChainBlock()
test_block.type = b'tribler_bandwidth'
test_block.transaction = transaction
test_block._transaction = encode(transaction)
test_block.public_key = session.trustchain_community.my_peer.public_key.key_to_bin()
test_block.hash = test_block.calculate_hash()
session.trustchain_community.persistence.add_block(test_block)

response_dict = await do_request(session, 'trustchain/bootstrap', expected_code=200)
assert response_dict['transaction'] == transaction2


@pytest.mark.asyncio
async def test_get_bootstrap_identity_partial_tokens(enable_api, mock_ipv8, session):
"""
Testing whether the API return partial available credit when argument is supplied
"""
transaction = {b'up': 100, b'down': 0, b'total_up': 100, b'total_down': 0}
transaction2 = {'up': 50, 'down': 0}

test_block = TrustChainBlock()
test_block.type = b'tribler_bandwidth'
test_block.transaction = transaction
test_block._transaction = encode(transaction)
test_block.public_key = session.trustchain_community.my_peer.public_key.key_to_bin()
test_block.hash = test_block.calculate_hash()
session.trustchain_community.persistence.add_block(test_block)

response_dict = await do_request(session, 'trustchain/bootstrap?amount=50', expected_code=200)
assert response_dict['transaction'] == transaction2


@pytest.mark.asyncio
async def test_get_bootstrap_identity_not_enough_tokens(enable_api, mock_ipv8, session):
"""
Testing whether the API returns error 400 if bandwidth is to low when bootstrapping a new identity
"""
transaction = {b'up': 100, b'down': 0, b'total_up': 100, b'total_down': 0}
test_block = TrustChainBlock()
test_block.type = b'tribler_bandwidth'
test_block.transaction = transaction
test_block._transaction = encode(transaction)
test_block.public_key = session.trustchain_community.my_peer.public_key.key_to_bin()
test_block.hash = test_block.calculate_hash()
session.trustchain_community.persistence.add_block(test_block)

await do_request(session, 'trustchain/bootstrap?amount=200', expected_code=400)


@pytest.mark.asyncio
async def test_get_bootstrap_identity_not_enough_tokens_2(enable_api, mock_ipv8, session):
"""
Testing whether the API returns error 400 if bandwidth is to low when bootstrapping a new identity
"""
transaction = {b'up': 0, b'down': 100, b'total_up': 0, b'total_down': 100}
test_block = TrustChainBlock()
test_block.type = b'tribler_bandwidth'
test_block.transaction = transaction
test_block._transaction = encode(transaction)
test_block.public_key = session.trustchain_community.my_peer.public_key.key_to_bin()
test_block.hash = test_block.calculate_hash()
session.trustchain_community.persistence.add_block(test_block)

await do_request(session, 'trustchain/bootstrap?amount=10', expected_code=400)


@pytest.mark.asyncio
async def test_get_bootstrap_identity_zero_amount(enable_api, mock_ipv8, session):
"""
Testing whether the API returns error 400 if amount is zero when bootstrapping a new identity
"""
await do_request(session, 'trustchain/bootstrap?amount=0', expected_code=400)


@pytest.mark.asyncio
async def test_get_bootstrap_identity_negative_amount(enable_api, mock_ipv8, session):
"""
Testing whether the API returns error 400 if amount is negative when bootstrapping a new identity
"""
await do_request(session, 'trustchain/bootstrap?amount=-1', expected_code=400)


@pytest.mark.asyncio
async def test_get_bootstrap_identity_string(enable_api, mock_ipv8, session):
"""
Testing whether the API returns error 400 if amount is string when bootstrapping a new identity
"""
await do_request(session, 'trustchain/bootstrap?amount=aaa', expected_code=400)
58 changes: 2 additions & 56 deletions src/tribler-core/tribler_core/restapi/trustchain_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from marshmallow.fields import Integer, String

from tribler_core.restapi.rest_endpoint import HTTP_BAD_REQUEST, HTTP_NOT_FOUND, RESTEndpoint, RESTResponse
from tribler_core.restapi.rest_endpoint import HTTP_NOT_FOUND, RESTEndpoint, RESTResponse
from tribler_core.utilities.unicode import recursive_unicode


Expand All @@ -16,8 +16,7 @@ class TrustchainEndpoint(RESTEndpoint):
"""

def setup_routes(self):
self.app.add_routes([web.get('/statistics', self.get_statistics),
web.get('/bootstrap', self.bootstrap)])
self.app.add_routes([web.get('/statistics', self.get_statistics)])

@docs(
tags=["TrustChain"],
Expand All @@ -41,56 +40,3 @@ async def get_statistics(self, request):
if 'MB' not in self.session.wallets:
return RESTResponse({"error": "TrustChain community not found"}, status=HTTP_NOT_FOUND)
return RESTResponse({'statistics': recursive_unicode(self.session.wallets['MB'].get_statistics())})

@docs(
tags=["TrustChain"],
summary="Generate a new identity and transfers bandwidth tokens to it..",
parameters=[{
'in': 'query',
'name': 'amount',
'description': 'Specifies how much tokens need to be emptied into the new identity',
'type': 'integer',
'required': True
}],
responses={
200: {
"schema": schema(TrustchainBootstrapResponse={
'private_key': String,
'transaction': schema(BootstrapTransaction={
'down': Integer,
'up': Integer
}),
'block': schema(BootstrapBlock={
'block_hash': String,
'sequence_number': String
})
})
}
}
)
async def bootstrap(self, request):
if 'MB' not in self.session.wallets:
return RESTResponse({"error": "bandwidth wallet not found"}, status=HTTP_NOT_FOUND)
bandwidth_wallet = self.session.wallets['MB']

available_tokens = bandwidth_wallet.get_bandwidth_tokens()

args = request.query
if 'amount' in args:
try:
amount = int(args['amount'])
except ValueError:
return RESTResponse({"error": "Provided token amount is not a number"}, status=HTTP_BAD_REQUEST)

if amount <= 0:
return RESTResponse({"error": "Provided token amount is zero or negative"}, status=HTTP_BAD_REQUEST)
else:
amount = available_tokens

if amount <= 0 or amount > available_tokens:
return RESTResponse({"error": "Not enough bandwidth tokens available"}, status=HTTP_BAD_REQUEST)

result = bandwidth_wallet.bootstrap_new_identity(amount)
result['private_key'] = result['private_key'].decode('utf-8')
result['block']['block_hash'] = result['block']['block_hash'].decode('utf-8')
return RESTResponse(result)
143 changes: 3 additions & 140 deletions src/tribler-gui/tribler_gui/qt_resources/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ color: white;
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>3</number>
<number>2</number>
</property>
<widget class="ChannelContentsWidget" name="personal_channel_page"/>
<widget class="ChannelContentsWidget" name="search_results_page"/>
Expand Down Expand Up @@ -1377,8 +1377,8 @@ border-top: 1px solid #555;
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>607</height>
<width>854</width>
<height>710</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
Expand Down Expand Up @@ -2741,143 +2741,6 @@ High anonymity</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="max_disk_space_input">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>250</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_58">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">font-weight: bold;
color: white;</string>
</property>
<property name="text">
<string>Bandwidth tokens emptying into another account (offline)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_60">
<property name="text">
<string>Bandwidth tokens can be emptied into another </string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="empty_tokens_button_layout">
<item>
<widget class="EllipseButton" name="fully_empty_tokens_button">
<property name="minimumSize">
<size>
<width>0</width>
<height>24</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>24</height>
</size>
</property>
<property name="text">
<string>FULLY EMPTY TOKENS</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_87">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>15</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="EllipseButton" name="partially_empty_tokens_button">
<property name="minimumSize">
<size>
<width>0</width>
<height>24</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>24</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>PARTIALLY EMPTY TOKENS</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_74">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_59">
<property name="styleSheet">
<string notr="true">font-weight: bold;
color: orange;</string>
</property>
<property name="text">
<string>Warning: this is a one-way action that cannot be reverted. If the QR code is not scanned, funds will be lost.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
Expand Down

0 comments on commit 263fa96

Please sign in to comment.