Skip to content
Snippets Groups Projects
Commit c0b4e9e4 authored by matograine's avatar matograine Committed by Moul
Browse files

[test] #111 : Send multiple amounts

* add transaction_amount() unittest
parent abb39ce8
No related branches found
No related tags found
No related merge requests found
import pytest
from silkaj.tx import truncBase, transaction_confirmation
from silkaj.tx import truncBase, transaction_confirmation, transaction_amount
from silkaj.tui import display_pubkey, display_amount
from silkaj.money import UDValue
from silkaj.constants import G1_SYMBOL
......@@ -184,3 +184,85 @@ async def test_transaction_confirmation(
comment,
)
assert tx == expected
# transaction_amount()
@pytest.mark.parametrize(
"amount, amountUD, outputAddresses, expected",
[
("10", None, ["DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw"], ([1000], 1000)),
(
"10:2.367",
None,
[
"DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",
"4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw",
],
([1000, 237], 1237),
),
(
"10",
None,
[
"DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",
"4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw",
],
([1000], 2000),
),
(None, "1.263", ["DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw"], ([397], 397)),
(
None,
"0.5:10",
[
"DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",
"4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw",
],
([157, 3140], 3297),
),
(
None,
"0.5",
[
"DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",
"4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw",
],
([157], 314),
),
(
"10:56",
None,
["DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw"],
"Error : The number of passed recipients (--output) is not the same as the passed amounts (--amount).",
),
(
None,
"1:45",
"DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",
"Error : The number of passed recipients (--output) is not the same as the passed amounts (--amount).",
),
],
)
@pytest.mark.asyncio
async def test_transaction_amount(
amount, amountUD, outputAddresses, expected, capsys, monkeypatch
):
# patched functions
monkeypatch.setattr("silkaj.money.UDValue.get_ud_value", patched.ud_value)
if amount:
amount_given = amount
if amountUD:
amount_given = amountUD
# test errors
if len(amount_given.split(":")) != 1 and len(outputAddresses) != len(
amount_given.split(":")
):
# check program exit on error
with pytest.raises(SystemExit) as pytest_exit:
# read output to check error.
await transaction_amount(amount, amountUD, outputAddresses)
assert expected == capsys.readouterr()
assert pytest_exit.type == SystemExit
# test good values
else:
assert expected == await transaction_amount(amount, amountUD, outputAddresses)
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