From 9c14c64fa0aa054e3c79f2545f15e7b4b68b0fec Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Sun, 6 Sep 2020 17:47:42 +0200
Subject: [PATCH] [fix] #336: tx_history: Handle multi-sig signature pubkeys
 display

Add tests for prefix()
Just import tx_history
Rework prefix()
---
 silkaj/tx_history.py     | 16 ++++++++++++----
 tests/test_tx_history.py | 35 +++++++++++++++++++++++++++--------
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/silkaj/tx_history.py b/silkaj/tx_history.py
index ea86cb4e..c265e950 100644
--- a/silkaj/tx_history.py
+++ b/silkaj/tx_history.py
@@ -253,10 +253,18 @@ def prefix(tx_addresses, outputs, occurence):
     """
     Pretty print with texttable
     Break line when several values in a cell
-    Handle Total line in case of multi-output txs
+
+    Received tx case, 'outputs' is not defined, then add a breakline
+    between the pubkeys except for the first occurence for multi-sig support
+
+    Sent tx case, handle "Total" line in case of multi-output txs
+    In case of multiple outputs, there is a "Total" on the top,
+    where there must be a breakline
     """
+
+    if not outputs:
+        return "\n" if occurence > 0 else ""
+
     if tx_addresses == "Total":
         return "\n"
-    if not outputs:
-        return ""
-    return "\n" if occurence + len(outputs) > 1 else ""
+    return "\n" if len(outputs) > 1 else ""
diff --git a/tests/test_tx_history.py b/tests/test_tx_history.py
index 60111fbc..edc2c03a 100644
--- a/tests/test_tx_history.py
+++ b/tests/test_tx_history.py
@@ -17,11 +17,8 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
 
 import pytest
 from duniterpy.api.client import Client
-from silkaj.tx_history import (
-    get_transactions_history,
-    remove_duplicate_txs,
-    generate_table,
-)
+
+from silkaj import tx_history
 from silkaj.constants import G1_DEFAULT_ENDPOINT
 
 
@@ -35,13 +32,35 @@ async def test_tx_history_generate_table():
     pubkey = "78ZwwgpgdH5uLZLbThUQH7LKwPgjMunYfLiCfUCySkM8"
 
     received_txs, sent_txs = list(), list()
-    await get_transactions_history(client, pubkey, received_txs, sent_txs)
+    await tx_history.get_transactions_history(client, pubkey, received_txs, sent_txs)
 
-    remove_duplicate_txs(received_txs, sent_txs)
-    txs_list = await generate_table(
+    tx_history.remove_duplicate_txs(received_txs, sent_txs)
+    txs_list = await tx_history.generate_table(
         received_txs, sent_txs, pubkey, ud_value, currency, uids
     )
     await client.close()
 
     for tx_list in txs_list:
         assert len(tx_list) == table_columns
+
+
+@pytest.mark.parametrize(
+    "tx_addresses, outputs, occurence, return_value",
+    [
+        (None, None, 0, ""),
+        (None, None, 1, "\n"),
+        (None, ["output1"], 0, ""),
+        (None, ["output1"], 1, ""),
+        (None, ["output1", "output2"], 0, "\n"),
+        (None, ["output1", "output2"], 1, "\n"),
+        ("pubkey", None, 0, ""),
+        ("pubkey", None, 1, "\n"),
+        ("pubkey", ["output1"], 0, ""),
+        ("pubkey", ["output1"], 1, ""),
+        ("Total", ["output1", "output2"], 0, "\n"),
+        ("pubkey", ["output1", "output2"], 0, "\n"),
+        ("pubkey", ["output1", "output2"], 1, "\n"),
+    ],
+)
+def test_prefix(tx_addresses, outputs, occurence, return_value):
+    assert tx_history.prefix(tx_addresses, outputs, occurence) == return_value
-- 
GitLab