Commit c27d1846 authored by matograine's avatar matograine

adding display_output_and_amount() test.

Adding a bug in the test : the test should not pass... and it passes ! I guess this needs a review.
parent 1ee155e3
import pytest
from silkaj.tx import truncBase, display_pubkey, display_amount, total_amount
from silkaj.tx import truncBase, display_pubkey, display_amount, total_amount, display_output_and_amount
from silkaj.money import UDValue
# truncBase()
......@@ -29,15 +29,55 @@ async def test_display_amount(message, amount, currency_symbol):
@pytest.mark.parametrize('message, pubkey, id', [
("From", "CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd", "Matograine"),
("To", "9qJjmuYi4Sti89Lm81G7AoFo5QLpmxd1NSMqN4Z1BwhS", ""),
("To", "9qJjmuYi4Sti89Lm81G7AoFo5QLpmxd1NSMqN4Z1BwhS", "TRUC"),
])
@pytest.mark.asyncio
async def test_display_pubkey(message, pubkey, id):
if id == []:
if id == "":
expected = [[message + " (pubkey)", pubkey]]
if id == "TRUC":
expected = "DEBUG : test passes even if it shoundn't"
else:
expected = [[message + " (pubkey)", pubkey], [message + " (id)", id]]
assert display_pubkey(message, pubkey) == expected
#display_output_and_amount()
@pytest.mark.parametrize('outputAddresses, tx_amount, currency_symbol, id', [
("CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd", 10, "Ğ1", "Matograine"),
(["d88fPFbDdJXJANHH7hedFMaRyGcnVZj9c5cDaE76LRN"], 10, "Ğ1", ""),
(["CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd", "d88fPFbDdJXJANHH7hedFMaRyGcnVZj9c5cDaE76LRN"], 10, "Ğ1", ["Matograine", ""]),
(["CmFKubyqbmJWbhyH2eEPVSSs4H4NeXGDfrETzEnRFtPd", "d88fPFbDdJXJANHH7hedFMaRyGcnVZj9c5cDaE76LRN"], [10, 23.65], "Ğ1", ["Matograine", ""]),
])
@pytest.mark.asyncio
async def test_display_output_and_amount(outputAddresses, tx_amount, currency_symbol, id):
if len(outputAddresses) == 1:
amount_UD = float(tx_amount) * await UDValue().ud_value
if id == "":
expected = [["to (pubkey)", outputAddresses], ["amount (unit | relative)", str(tx_amount/100) + " " + currency_symbol + " || " + str(amount_UD) + " UD"]]
elif id != "":
expected = [["to (pubkey)", outputAddresses], ["to (id)", id], ["amount (unit | relative)", str(tx_amount/100) + " " + currency_symbol + " || " + str(amount_UD) + " UD"]]
elif len(outputAddresses) != 1 and len(tx_amount) == 1:
amount_UD = float(tx_amount) * await UDValue().ud_value
a = 0
while a < len(outputAddresses):
if id(a) == []:
expected = expected.append(["to (pubkey)", outputAddresses(a)], ["amount (unit | relative)", str(tx_amount/100) + " " + currency_symbol + " || " + str(amount_UD) + " UD"])
a = a+1
elif id(a) != []:
expected = expected.append(["to (pubkey)", outputAddresses(a)], ["to (id)", id(a)], ["amount (unit | relative)", str(tx_amount/100) + " " + currency_symbol + " || " + str(amount_UD) + " UD"])
a = a+1
elif len(outputAddresses) != 1 and len(tx_amount) != 1:
a = 0
while a < len(outputAddresses):
amount_UD = float(tx_amount(a)) * await UDValue().ud_value
if id(a) == "":
expected = expected.append(["to (pubkey)", outputAddresses(a)], ["amount (unit | relative)", str(tx_amount(a)/100) + " " + currency_symbol + " || " + str(amount_UD) + " UD"])
a = a+1
elif id(a) != "":
expected = expected.append(["to (pubkey)", outputAddresses(a)], ["to (id)", id(a)], ["amount (unit | relative)", str(tx_amount(a)/100) + " " + currency_symbol + " || " + str(amount_UD) + " UD"])
a = a+1
assert display_output_and_amount(outputAddresses, tx_amount, currency_symbol) == expected
## total_amount()
#pytest.mark.parametrize('amount, outputAdresses, expected', [
# (0, "d88fPFbDdJXJANHH7hedFMaRyGcnVZj9c5cDaE76LRN", 0),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment