Skip to content
Snippets Groups Projects
Commit 6ee8c48d authored by matograine's avatar matograine
Browse files

[mod] #111 : create MINIMAL_TX_AMOUNT, CENT_MULT_TO_UNIT constants

* both constants imported to tx.py
* MINIMAL_TX_AMOUNT used in --amount click option
* import silkaj.money and change related functions calls

* introduce one test case for send_transaction()
parent 9b671a9c
No related branches found
No related tags found
No related merge requests found
......@@ -27,3 +27,5 @@ SUCCESS_EXIT_STATUS = 0
FAILURE_EXIT_STATUS = 1
BMA_MAX_BLOCKS_CHUNK_SIZE = 5000
PUBKEY_PATTERN = "[1-9A-HJ-NP-Za-km-z]{43,44}"
MINIMAL_TX_AMOUNT = 0.01
CENT_MULT_TO_UNIT = 100
......@@ -26,13 +26,12 @@ from silkaj.network_tools import ClientInstance, HeadBlock
from silkaj.crypto_tools import check_public_key
from silkaj.tools import message_exit, CurrencySymbol, coroutine
from silkaj.auth import auth_method
from silkaj.money import (
get_sources,
get_amount_from_pubkey,
UDValue,
amount_in_current_base,
from silkaj import money
from silkaj.constants import (
SOURCES_PER_TX,
MINIMAL_TX_AMOUNT,
CENT_MULT_TO_UNIT,
)
from silkaj.constants import SOURCES_PER_TX
from silkaj.tui import display_amount, display_pubkey
from duniterpy.api.bma.tx import process
......@@ -46,8 +45,10 @@ from duniterpy.documents.transaction import OutputSource, Unlock, SIGParameter
"--amount",
"-a",
multiple=True,
type=FloatRange(0.01),
help="Quantitative amount(s):\n-a <amount>\nMinimum amount is 0.01.",
type=FloatRange(MINIMAL_TX_AMOUNT),
help="Quantitative amount(s):\n-a <amount>\nMinimum amount is {0}".format(
MINIMAL_TX_AMOUNT
),
cls=MutuallyExclusiveOption,
mutually_exclusive=["amountsud", "allsources"],
)
......@@ -104,7 +105,7 @@ async def send_transaction(
key = auth_method()
issuer_pubkey = key.pubkey
pubkey_amount = await get_amount_from_pubkey(issuer_pubkey)
pubkey_amount = await money.get_amount_from_pubkey(issuer_pubkey)
if allsources:
tx_amount = pubkey_amount[0]
outputAddresses = recipients.split(":")
......@@ -149,7 +150,7 @@ async def transaction_amount(amount, amountUD, allSources):
if amount:
return round(amount * 100)
if amountUD:
return round(amountUD * await UDValue().ud_value)
return round(amountUD * await money.UDValue().ud_value)
def check_transaction_values(
......@@ -177,7 +178,7 @@ async def transaction_confirmation(
"""
currency_symbol = await CurrencySymbol().symbol
ud_value = await UDValue().ud_value
ud_value = await money.UDValue().ud_value
tx = list()
tx.append(
["pubkey’s balance before tx", str(pubkey_amount / 100) + " " + currency_symbol]
......@@ -212,7 +213,7 @@ async def transaction_confirmation(
async def get_list_input_for_transaction(pubkey, TXamount):
listinput, amount = await get_sources(pubkey)
listinput, amount = await money.get_sources(pubkey)
# generate final list source
listinputfinal = []
......@@ -220,8 +221,8 @@ async def get_list_input_for_transaction(pubkey, TXamount):
intermediatetransaction = False
for input in listinput:
listinputfinal.append(input)
totalAmountInput += amount_in_current_base(input)
TXamount -= amount_in_current_base(input)
totalAmountInput += money.amount_in_current_base(input)
TXamount -= money.amount_in_current_base(input)
# if more than 40 sources, it's an intermediate transaction
if len(listinputfinal) >= SOURCES_PER_TX:
intermediatetransaction = True
......
......@@ -3,6 +3,7 @@ from click.testing import CliRunner
from silkaj.tx import transaction_amount
from silkaj.money import UDValue
from silkaj.cli import cli
from silkaj.constants import MINIMAL_TX_AMOUNT
@pytest.mark.asyncio
......@@ -61,3 +62,7 @@ def test_tx_passed_amount_cli():
result = CliRunner().invoke(cli, ["tx", "-r", "A", "-r", "B", "--allSources"])
assert "Error: the --allSources" in result.output
assert result.exit_code == 1
result = CliRunner().invoke(cli, ["tx", "-r", "A", "-a", MINIMAL_TX_AMOUNT - 0.001])
assert 'Error: Invalid value for "--amount"' in result.output
assert result.exit_code == 2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment