Commit d3f7de6d authored by matograine's avatar matograine

starting rebase over dev.

parent 42fe11b2
Pipeline #6773 failed with stages
in 59 seconds
......@@ -146,8 +146,41 @@ def check_transaction_values(
)
async def display_pubkey(tx, message, pubkey):
"""
For transaction_confirmation,
Displays a pubkey and the eventually associated id.
"""
tx.append([message + " (pubkey)", pubkey])
id = await is_member(pubkey)
if id:
tx.append([message + " (id)", id["uid"]])
async def display_output_and_amount(tx, outputAddresses, tx_amount, currency_symbol):
"""
For transaction_confirmation,
Displays the receiver(s) and the amount(s) of one or many output(s).
"""
if len(tx_amount) == 1:
for outputAddress in outputAddresses:
await display_pubkey(tx, "to", outputAddress)
await display_amount(tx, "amount", tx_amount[0], currency_symbol)
if len(tx_amount) > 1:
c = 0
while c < len(outputAddresses):
await display_pubkey(tx, "to", outputAddresses[c])
await display_amount(tx, "amount", tx_amount[c], currency_symbol)
c += 1
async def transaction_confirmation(
issuer_pubkey, pubkey_amount, tx_amount, outputAddresses, outputBackChange, comment
issuer_pubkey,
pubkey_amount,
tx_amount,
totalAmount,
outputAddresses,
outputBackChange,
comment,
):
"""
Generate transaction confirmation
......@@ -158,46 +191,26 @@ async def transaction_confirmation(
tx.append(
["pubkey’s balance before tx", str(pubkey_amount / 100) + " " + currency_symbol]
)
tx.append(
[
"tx amount (unit)",
str(tx_amount / 100 * len(outputAddresses)) + " " + currency_symbol,
]
)
tx.append(
[
"tx amount (relative)",
str(round(tx_amount / await UDValue().ud_value, 4))
+ " UD "
+ currency_symbol,
]
)
await display_amount(tx, "total amount", totalAmount, currency_symbol)
tx.append(
[
"pubkey’s balance after tx",
str(((pubkey_amount - tx_amount * len(outputAddresses)) / 100))
+ " "
+ currency_symbol,
str(((pubkey_amount - totalAmount) / 100)) + " " + currency_symbol,
]
)
tx.append(["from (pubkey)", issuer_pubkey])
id_from = await is_member(issuer_pubkey)
if id_from:
tx.append(["from (id)", id_from["uid"]])
for outputAddress in outputAddresses:
tx.append(["to (pubkey)", outputAddress])
id_to = await is_member(outputAddress)
if id_to:
tx.append(["to (id)", id_to["uid"]])
await display_pubkey(tx, "from", issuer_pubkey)
await display_output_and_amount(tx, outputAddresses, tx_amount, currency_symbol)
if outputBackChange:
tx.append(["Backchange (pubkey)", outputBackChange])
id_backchange = await is_member(outputBackChange)
if id_backchange:
tx.append(["Backchange (id)", id_backchange["uid"]])
await display_pubkey(tx, "Backchange", outputBackChange)
tx.append(["comment", comment])
return tx
async def get_list_input_for_transaction(pubkey, TXamount):
listinput, amount = await get_sources(pubkey)
......
import pytest
from silkaj.tx import truncBase
from silkaj.tx import truncBase, display_pubkey, display_amount, total_amount, display_output_and_amount
from silkaj.money import UDValue
@pytest.mark.parametrize(
"amount,base,expected",
[(0, 0, 0), (10, 2, 0), (100, 2, 100), (306, 2, 300), (3060, 3, 3000)],
)
# truncBase()
@pytest.mark.parametrize('amount,base,expected', [
(0, 0, 0),
(10, 2, 0),
(100, 2, 100),
(306, 2, 300),
(3060, 3, 3000),
])
def test_truncBase(amount, base, expected):
assert truncBase(amount, base) == expected
#display_amount()
@pytest.mark.parametrize('message, amount, currency_symbol', [
("Total", 10, "Ğ1"),
])
@pytest.mark.asyncio
async def test_display_amount(message, amount, currency_symbol):
amount_UD = float(amount) * await UDValue().ud_value
expected = (message + " (unit | relative)", str(amount/100) + " " + currency_symbol + " || " + str(amount_UD) + " UD")
tx = await display_amount ([], message, amount, currency_symbol) == expected
assert tx == expected
#display_pubkey()
@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 == "":
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
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