Skip to content
Snippets Groups Projects
Commit 9c14c64f authored by Moul's avatar Moul
Browse files

[fix] #336: tx_history: Handle multi-sig signature pubkeys display

Add tests for prefix()
Just import tx_history
Rework prefix()
parent 77e2b9f5
No related branches found
No related tags found
2 merge requests!146Merge dev into master branch to complete v0.8.0 development cycle,!141#336: tx_history: Handle multi-sig signature pubkeys display
...@@ -253,10 +253,18 @@ def prefix(tx_addresses, outputs, occurence): ...@@ -253,10 +253,18 @@ def prefix(tx_addresses, outputs, occurence):
""" """
Pretty print with texttable Pretty print with texttable
Break line when several values in a cell 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": if tx_addresses == "Total":
return "\n" return "\n"
if not outputs: return "\n" if len(outputs) > 1 else ""
return ""
return "\n" if occurence + len(outputs) > 1 else ""
...@@ -17,11 +17,8 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>. ...@@ -17,11 +17,8 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
import pytest import pytest
from duniterpy.api.client import Client from duniterpy.api.client import Client
from silkaj.tx_history import (
get_transactions_history, from silkaj import tx_history
remove_duplicate_txs,
generate_table,
)
from silkaj.constants import G1_DEFAULT_ENDPOINT from silkaj.constants import G1_DEFAULT_ENDPOINT
...@@ -35,13 +32,35 @@ async def test_tx_history_generate_table(): ...@@ -35,13 +32,35 @@ async def test_tx_history_generate_table():
pubkey = "78ZwwgpgdH5uLZLbThUQH7LKwPgjMunYfLiCfUCySkM8" pubkey = "78ZwwgpgdH5uLZLbThUQH7LKwPgjMunYfLiCfUCySkM8"
received_txs, sent_txs = list(), list() 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) tx_history.remove_duplicate_txs(received_txs, sent_txs)
txs_list = await generate_table( txs_list = await tx_history.generate_table(
received_txs, sent_txs, pubkey, ud_value, currency, uids received_txs, sent_txs, pubkey, ud_value, currency, uids
) )
await client.close() await client.close()
for tx_list in txs_list: for tx_list in txs_list:
assert len(tx_list) == table_columns 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
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