diff --git a/src/sakia/gui/navigation/txhistory/table_model.py b/src/sakia/gui/navigation/txhistory/table_model.py index 1d2f02d2ff918e711c2298e1725c3b6bf0abcc06..11c05b78a85555ae42d338d3056cf6ca0138c0fe 100644 --- a/src/sakia/gui/navigation/txhistory/table_model.py +++ b/src/sakia/gui/navigation/txhistory/table_model.py @@ -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")] diff --git a/tests/conftest.py b/tests/conftest.py index bfacda2a34d914f1ef265abe05e1649d177a298b..1e69c829baefbf74d5f750a4aff0d0f0bdbab259 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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), diff --git a/tests/functional/test_txhistory_controller.py b/tests/functional/test_txhistory_controller.py new file mode 100644 index 0000000000000000000000000000000000000000..2cefdf17386ff2ae2fdbab61e7a67c989683e77a --- /dev/null +++ b/tests/functional/test_txhistory_controller.py @@ -0,0 +1,74 @@ +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))" + )