Skip to content
Snippets Groups Projects
Commit f0a4903a authored by Moul's avatar Moul
Browse files

[mypy] Define class for tx tests counter (#163)

It was wrongly done before
Defining an attribute of a function
parent 7c38a863
No related branches found
No related tags found
1 merge request!214#163: Introduce mypy
...@@ -86,10 +86,10 @@ def patched_get_sources(pubkey): ...@@ -86,10 +86,10 @@ def patched_get_sources(pubkey):
max_ud = 0 max_ud = 0
max_tx = 3 max_tx = 3
elif pubkey == "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat": elif pubkey == "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat":
if patched_get_sources.counter == 0: if Counter.counter == 0:
max_ud = 0 max_ud = 0
max_tx = 53 max_tx = 53
elif patched_get_sources.counter == 1: elif Counter.counter == 1:
listinput.append( listinput.append(
InputSource( InputSource(
amount=100 * MAX_INPUTS_PER_TX, # 100 * 46 = 4600 amount=100 * MAX_INPUTS_PER_TX, # 100 * 46 = 4600
...@@ -105,10 +105,10 @@ def patched_get_sources(pubkey): ...@@ -105,10 +105,10 @@ def patched_get_sources(pubkey):
max_ud = 10 max_ud = 10
max_tx = 0 max_tx = 0
elif pubkey == "9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp": elif pubkey == "9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp":
if patched_get_sources.counter == 0: if Counter.counter == 0:
max_ud = 50 max_ud = 50
max_tx = 20 max_tx = 20
elif patched_get_sources.counter == 1: elif Counter.counter == 1:
listinput.append( listinput.append(
InputSource( InputSource(
amount=mock_ud_value * MAX_INPUTS_PER_TX, # 46 UD = 46*314 = 1444 amount=mock_ud_value * MAX_INPUTS_PER_TX, # 46 UD = 46*314 = 1444
...@@ -139,8 +139,9 @@ def patched_get_sources(pubkey): ...@@ -139,8 +139,9 @@ def patched_get_sources(pubkey):
balance = listinput_UD(listinput, balance, pubkey, max_ud) balance = listinput_UD(listinput, balance, pubkey, max_ud)
balance = listinput_TX(listinput, balance, max_tx) balance = listinput_TX(listinput, balance, max_tx)
patched_get_sources.counter += 1 Counter.counter += 1
return listinput, balance return listinput, balance
patched_get_sources.counter = 0 class Counter:
counter = 0
...@@ -28,7 +28,7 @@ from duniterpy.documents.transaction import ( ...@@ -28,7 +28,7 @@ from duniterpy.documents.transaction import (
from patched.auth import patched_auth_method from patched.auth import patched_auth_method
from patched.blockchain_tools import fake_block_id, patched_get_head_block from patched.blockchain_tools import fake_block_id, patched_get_head_block
from patched.money import patched_get_sources, patched_get_ud_value from patched.money import Counter, patched_get_sources, patched_get_ud_value
from patched.test_constants import mock_ud_value from patched.test_constants import mock_ud_value
from patched.tools import patched_get_currency_symbol from patched.tools import patched_get_currency_symbol
from patched.wot import patched_is_member from patched.wot import patched_is_member
...@@ -421,8 +421,8 @@ def test_get_list_input_for_transaction( ...@@ -421,8 +421,8 @@ def test_get_list_input_for_transaction(
# patched functions # patched functions
monkeypatch.setattr(money, "get_sources", patched_get_sources) monkeypatch.setattr(money, "get_sources", patched_get_sources)
# reset patched_get_sources counter # reset Counter.counter
patched_get_sources.counter = 0 Counter.counter = 0
# testing error exit # testing error exit
if isinstance(expected, str): if isinstance(expected, str):
with pytest.raises(SystemExit) as pytest_exit: with pytest.raises(SystemExit) as pytest_exit:
...@@ -830,7 +830,7 @@ def test_handle_intermediaries_transactions( ...@@ -830,7 +830,7 @@ def test_handle_intermediaries_transactions(
tx, "generate_and_send_transaction", patched_generate_and_send_transaction tx, "generate_and_send_transaction", patched_generate_and_send_transaction
) )
patched_get_sources.counter = 0 Counter.counter = 0
# testing # testing
tx.handle_intermediaries_transactions( tx.handle_intermediaries_transactions(
...@@ -1025,8 +1025,8 @@ def test_send_transaction( ...@@ -1025,8 +1025,8 @@ def test_send_transaction(
monkeypatch.setattr(money, "get_sources", patched_get_sources) monkeypatch.setattr(money, "get_sources", patched_get_sources)
monkeypatch.setattr(money, "get_ud_value", patched_get_ud_value) monkeypatch.setattr(money, "get_ud_value", patched_get_ud_value)
# reset patched_get_sources # reset Counter.counter
patched_get_sources.counter = 0 Counter.counter = 0
# total amount for pubkey_fifi # total amount for pubkey_fifi
total_amount = 5300 total_amount = 5300
# compute amounts list # compute amounts list
......
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