Skip to content
Snippets Groups Projects
Commit 99bc94d1 authored by matograine's avatar matograine
Browse files

[test] #213 modify patched_get_source()

* create inputs lists in source_dict.py
* patched_get_sources() now has a `counter` attribute, and can return different values if called twice
    * can mock the result of an intermediary transaction.
* mod test_get_list_input_for_transaction() to reset the patched_get_sources counter.
parent 09697aaa
No related branches found
No related tags found
No related merge requests found
from silkaj.money import amount_in_current_base
from duniterpy.documents.transaction import InputSource
from utils_tests import pubkey_list, mock_ud_value
from patched.source_dict import sources_dict
# mock UDValue
......@@ -11,67 +12,25 @@ async def patched_ud_value(self):
# mock get_sources()
async def patched_get_sources(pubkey):
"""
Returns transaction sources.
This function does not cover all possibilities : no other unlock conditions than SIG(pubkey).
Returns transaction sources lists.
If called 2 or 3 times (depending on the pubkey), will return the expected input list after an intermediary tx for the first 40 inputs.
Tests using this function should reset the counter at the egining of each test case.
See source_dict.py for inputs lists.
if pubkey == CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp : 3 TXsources, amount = 600
if pubkey == HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat : 53 TXsources, amount = 143100
if pubkey == 2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY : 10 UDsources, amount = 3140
if pubkey == 9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp : 50 UDsources and 20 TXsources, amount = 36700
else : 0 sources, amount = 0
For convenience, the hash is always the same. This should change for other testing purposes.
"""
def listinput_UD(listinput, amount, pubkey, max_ud, total):
while max_ud > 0 and total > 0:
listinput.append(
InputSource(
amount=mock_ud_value,
base=0,
source="D",
origin_id=pubkey,
index=max_ud,
)
)
amount += amount_in_current_base(listinput[-1])
max_ud -= 1
total -= 1
def listinput_TX(listinput, amount, max_tx, total):
orig_max = max_tx + 1
while max_tx > 0 and total > 0:
listinput.append(
InputSource(
amount=(orig_max - max_tx) * 100,
base=0,
source="T",
origin_id="1F3059ABF35D78DFB5AFFB3DEAB4F76878B04DB6A14757BBD6B600B1C19157E7",
index=max_tx,
)
)
amount += amount_in_current_base(listinput[-1])
max_tx -= 1
total -= 1
listinput, n = list(), 0
inputs = sources_dict[pubkey][patched_get_sources.counter]
amount = 0
if pubkey == "CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp":
max_tx = 3
max_ud = 0
elif pubkey == "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat":
max_tx = 53
max_ud = 0
elif pubkey == "2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY":
max_tx = 0
max_ud = 10
elif pubkey == "9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp":
max_tx = 20
max_ud = 50
else:
max_tx = 0
max_ud = 0
for input in inputs:
amount += amount_in_current_base(input)
patched_get_sources.counter += 1
return inputs, amount
total = max_tx + max_ud
listinput_TX(listinput, amount, max_tx, total)
listinput_UD(listinput, amount, pubkey, max_ud, total)
return listinput, amount
patched_get_sources.counter = 0
This diff is collapsed.
......@@ -439,6 +439,8 @@ async def test_get_list_input_for_transaction(
# patched functions
monkeypatch.setattr("silkaj.money.get_sources", patched_get_sources)
# reset patched_get_sources counter
patched_get_sources.counter = 0
# testing error exit
if isinstance(expected, str):
with pytest.raises(SystemExit) as pytest_exit:
......
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