Skip to content
Snippets Groups Projects
Commit 5d2df929 authored by Vincent Texier's avatar Vincent Texier
Browse files

[fix] #798 fix conditions in table_model.change_transfer and cover with test

add custom function "total_amount" to test db
parent 133b2574
No related branches found
No related tags found
1 merge request!778Release 0.51.0
......@@ -17,7 +17,7 @@ from sakia.data.entities import Transaction
from sakia.constants import MAX_CONFIRMATIONS
from sakia.data.processors import BlockchainProcessor
from .sql_adapter import TxHistorySqlAdapter
from sakia.data.repositories import TransactionsRepo, DividendsRepo
from sakia.data.repositories import TransactionsRepo, DividendsRepo, SourcesRepo
from sakia.data.entities.transaction import STOPLINE_HASH
......@@ -82,6 +82,7 @@ class HistoryTableModel(QAbstractTableModel):
self.sql_adapter = TxHistorySqlAdapter(self.app.db.conn)
self.transactions_repo = TransactionsRepo(self.app.db.conn)
self.dividends_repo = DividendsRepo(self.app.db.conn)
self.sources_repo = SourcesRepo(self.app.db.conn)
self.current_page = 0
self.ts_from = ts_from
self.ts_to = ts_to
......@@ -138,6 +139,20 @@ class HistoryTableModel(QAbstractTableModel):
)
def change_transfer(self, transfer):
# capture sources associated with tx
sources = self.sources_repo.get_all(
currency=transfer.currency, identifier=transfer.sha_hash
)
# capture complex conditions
sources_conditions = [
source.conditions
for source in sources
if "%&&%" in source.conditions or "%||%" in source.conditions
]
transfer.conditions = (
sources_conditions[0] if len(sources_conditions) > 0 else None
)
for i, data in enumerate(self.transfers_data):
if (
data[HistoryTableModel.columns_types.index("txhash")]
......
......@@ -46,7 +46,13 @@ def meta_repo(version=0):
sqlite3.register_adapter(BlockUID, str)
sqlite3.register_adapter(bool, int)
sqlite3.register_converter("BOOLEAN", lambda v: bool(int(v)))
def total_amount(amount, amount_base):
return amount * 10 ** amount_base
con = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)
con.create_function("total_amount", 2, total_amount)
meta_repo = SakiaDatabase(
con,
ConnectionsRepo(con),
......
import time
import pytest
from sakia.gui.navigation.txhistory.table_model import HistoryTableModel
@pytest.mark.asyncio
async def test_tx_history_table_model(
application_with_one_connection, fake_server_with_blockchain, bob, alice
):
application_with_one_connection.instanciate_services()
bob_connection = application_with_one_connection.db.connections_repo.get_one(
pubkey=bob.key.pubkey
)
date_start = time.time() - 86400
date_end = time.time()
history_table_model = HistoryTableModel(
application_with_one_connection,
application_with_one_connection,
bob_connection,
date_start,
date_end,
application_with_one_connection.identities_service,
application_with_one_connection.transactions_service,
)
# send transaction with lock_mode 0
(
_,
sakia_tx_list,
) = await application_with_one_connection.documents_service.send_money(
bob_connection, bob.salt, bob.password, alice.key.pubkey, 100, 0, None, 0, None
)
history_table_model.init_transfers()
transfers = application_with_one_connection.transactions_service.transfers(
bob.key.pubkey
)
# test transfer change
history_table_model.change_transfer(transfers[0])
assert len(history_table_model.transfers_data) == 1
conditions_data = history_table_model.transfers_data[0][
HistoryTableModel.columns_types.index("conditions")
]
assert conditions_data is None
# send transaction with lock_mode_1
(
_,
sakia_tx_list,
) = await application_with_one_connection.documents_service.send_money(
bob_connection, bob.salt, bob.password, alice.key.pubkey, 100, 0, None, 1, None
)
history_table_model.init_transfers()
transfers = application_with_one_connection.transactions_service.transfers(
bob.key.pubkey
)
# test transfer change
history_table_model.change_transfer(transfers[0])
assert len(history_table_model.transfers_data) == 2
conditions_data = history_table_model.transfers_data[1][
HistoryTableModel.columns_types.index("conditions")
]
assert (
conditions_data
== "SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo) || (SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7) && CSV(604800))"
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment