Skip to content
Snippets Groups Projects
Commit 09697aaa authored by matograine's avatar matograine
Browse files

[test] #213 Create pubkey list and simple pubkey generation for testing.

* create utils_tests()
    * function test_key(<string>) will return the key with salt = string ;  passwd = string and default scrypt parameters.
    * pubkey list is for quicker access
* change pubkeys calls in the tests
* import mock_ud_value in patched/money.py
parent 486b5e1c
No related branches found
No related tags found
No related merge requests found
from silkaj.money import amount_in_current_base from silkaj.money import amount_in_current_base
from duniterpy.documents.transaction import InputSource from duniterpy.documents.transaction import InputSource
from utils_tests import pubkey_list, mock_ud_value
## Mocked values
mock_ud_value = 314
pubkey_list = [
{"pubkey": "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "uid": ""},
{"pubkey": "4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw", "uid": ""},
{"pubkey": "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", "uid": "riri"},
{"pubkey": "C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", "uid": "fifi"},
{"pubkey": "7Hr6oUxE6nGZxFG7gVbpMK6oUkNTh5eU686EiCXWCrBF", "uid": "loulou"},
]
# mock UDValue # mock UDValue
...@@ -24,10 +13,10 @@ async def patched_get_sources(pubkey): ...@@ -24,10 +13,10 @@ async def patched_get_sources(pubkey):
""" """
Returns transaction sources. Returns transaction sources.
This function does not cover all possibilities : no other unlock conditions than SIG(pubkey). This function does not cover all possibilities : no other unlock conditions than SIG(pubkey).
if pubkey == DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw : 3 TXsources, amount = 600 if pubkey == CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp : 3 TXsources, amount = 600
if pubkey == 4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw : 53 TXsources, amount = 143100 if pubkey == HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat : 53 TXsources, amount = 143100
if pubkey == BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh : 10 UDsources, amount = 3140 if pubkey == 2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY : 10 UDsources, amount = 3140
if pubkey == C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH : 50 UDsources and 20 TXsources, amount = 36700 if pubkey == 9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp : 50 UDsources and 20 TXsources, amount = 36700
else : 0 sources, amount = 0 else : 0 sources, amount = 0
For convenience, the hash is always the same. This should change for other testing purposes. For convenience, the hash is always the same. This should change for other testing purposes.
""" """
...@@ -65,16 +54,16 @@ async def patched_get_sources(pubkey): ...@@ -65,16 +54,16 @@ async def patched_get_sources(pubkey):
listinput, n = list(), 0 listinput, n = list(), 0
amount = 0 amount = 0
if pubkey == "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw": if pubkey == "CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp":
max_tx = 3 max_tx = 3
max_ud = 0 max_ud = 0
elif pubkey == "4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw": elif pubkey == "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat":
max_tx = 53 max_tx = 53
max_ud = 0 max_ud = 0
elif pubkey == "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh": elif pubkey == "2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY":
max_tx = 0 max_tx = 0
max_ud = 10 max_ud = 10
elif pubkey == "C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH": elif pubkey == "9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp":
max_tx = 20 max_tx = 20
max_ud = 50 max_ud = 50
else: else:
......
...@@ -408,24 +408,24 @@ async def test_generate_transaction_document( ...@@ -408,24 +408,24 @@ async def test_generate_transaction_document(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"pubkey, TXamount, expected", "pubkey, TXamount, expected",
[ [
("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", 200, (2, 300, False)), ("CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp", 200, (2, 300, False)),
("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", 600, (3, 600, False)), ("CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp", 600, (3, 600, False)),
( (
"DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp",
800, 800,
"Error: you don't have enough money", "Error: you don't have enough money",
), ),
("4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw", 143100, (40, 82000, True)), ("HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", 143100, (40, 82000, True)),
("BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", 200, (1, 314, False)), ("2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY", 200, (1, 314, False)),
("BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", 3140, (10, 3140, False)), ("2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY", 3140, (10, 3140, False)),
( (
"BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", "2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY",
5000, 5000,
"Error: you don't have enough money", "Error: you don't have enough money",
), ),
("C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", 2900, (8, 3600, False)), ("9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp", 2900, (8, 3600, False)),
("C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", 22500, (25, 22570, False)), ("9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp", 22500, (25, 22570, False)),
("C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", 29000, (40, 27280, True)), ("9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp", 29000, (40, 27280, True)),
], ],
) )
@pytest.mark.asyncio @pytest.mark.asyncio
......
# This file contains helpers for testing.
from duniterpy.key import SigningKey
mock_ud_value = 314
pubkey_list = [
{"pubkey": "9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp", "uid": ""},
{"pubkey": "BUhLyJT17bzDVXW66xxfk1F7947vytmwJVadTaWb8sJS", "uid": ""},
{"pubkey": "CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp", "uid": "riri"},
{"pubkey": "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", "uid": "fifi"},
{"pubkey": "2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY", "uid": "loulou"},
]
def insecure_key(pass_salt):
"""
generate unsecure keys for testing purpose.
pubkey(riri) = CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp
pubkey(fifi) = HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat
pubkey(loulou) = 2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY
pubkey(0) = 9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp
pubkey(1) = BUhLyJT17bzDVXW66xxfk1F7947vytmwJVadTaWb8sJS
"""
return SigningKey.from_credentials(pass_salt, pass_salt)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment