Skip to content
Snippets Groups Projects
Commit 5031b5e9 authored by matograine's avatar matograine
Browse files

[test] #213: move useful test patched functions

* Move patched functions from test_membership.py to relevant files
    * blockchain_tools.py
        * create mocked_block variable
        * make both patched_block and patched_head_block return mocked_block
    * auth.py
    * wot.py
* modify a pubkey list in patched/wot.py
* change calls in the tests
* change pubkeys in patched/money.py to match new pubkey_list
parent 9a353cea
No related branches found
No related tags found
1 merge request!130#213: Write unit tests for the transaction command
# This file contains patches for auth functions.
from duniterpy.key import SigningKey
def patched_auth_method(uid):
"""
insecure way to test keys
"""
return SigningKey.from_credentials(uid, uid)
def patched_auth_by_seed():
......
# This file contains fake values for testing purposes
currency = "g1"
mocked_block = {
"number": 48000,
"time": 1592243760,
"unitbase": 0,
"currency": currency,
"hash": "0000010D30B1284D34123E036B7BE0A449AE9F2B928A77D7D20E3BDEAC7EE14C",
}
async def patched_params(self):
return {
"msValidity": 31557600,
"msPeriod": 5259600,
}
async def patched_block(self, number):
return mocked_block
## mock head_block()
async def patched_head_block(self):
mocked_head_block = {
"number": 48000,
"unitbase": 0,
"currency": "g1",
"hash": "0000010D30B1284D34123E036B7BE0A449AE9F2B928A77D7D20E3BDEAC7EE14C",
}
return mocked_head_block
return mocked_block
......@@ -21,20 +21,11 @@ from silkaj.constants import G1_SYMBOL
from silkaj.money import amount_in_current_base
from duniterpy.documents.transaction import InputSource
## Mocked values
# mock UDValue
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
async def patched_ud_value(self):
return mock_ud_value
......@@ -85,16 +76,16 @@ async def patched_get_sources(pubkey):
listinput, n = list(), 0
amount = 0
if pubkey == "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw":
if pubkey == "CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp":
max_tx = 3
max_ud = 0
elif pubkey == "4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw":
elif pubkey == "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat":
max_tx = 53
max_ud = 0
elif pubkey == "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh":
elif pubkey == "2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY":
max_tx = 0
max_ud = 10
elif pubkey == "C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH":
elif pubkey == "9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp":
max_tx = 20
max_ud = 50
else:
......
pubkey_list = [
{"pubkey": "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "uid": ""},
{"pubkey": "4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw", "uid": ""},
{"pubkey": "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", "uid": "riri"},
{"pubkey": "C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", "uid": "fifi"},
{"pubkey": "7Hr6oUxE6nGZxFG7gVbpMK6oUkNTh5eU686EiCXWCrBF", "uid": "loulou"},
{"pubkey": "9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp", "uid": ""},
{"pubkey": "BUhLyJT17bzDVXW66xxfk1F7947vytmwJVadTaWb8sJS", "uid": ""},
{"pubkey": "CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp", "uid": "riri"},
{"pubkey": "HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", "uid": "fifi"},
{"pubkey": "2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY", "uid": "loulou"},
]
# mock is_member
async def patched_is_member(pubkey):
for account in pubkey_list:
......@@ -13,3 +14,40 @@ async def patched_is_member(pubkey):
if account["uid"]:
return account
return False
# patch wot requirements
async def patched_wot_requirements_one_pending(pubkey, identity_uid):
return {
"identities": [
{
"uid": "toto",
"pendingMemberships": [
{
"membership": "IN",
"issuer": "5B8iMAzq1dNmFe3ZxFTBQkqhq4fsztg1gZvxHXCk1XYH",
"number": 613206,
"blockNumber": 613206,
"userid": "moul-test",
"expires_on": 1598624404,
"type": "IN",
}
],
"membershipPendingExpiresIn": 6311520,
"membershipExpiresIn": 2603791,
},
],
}
async def patched_wot_requirements_no_pending(pubkey, identity_uid):
return {
"identities": [
{
"uid": "toto",
"pendingMemberships": [],
"membershipPendingExpiresIn": 0,
"membershipExpiresIn": 3724115,
}
]
}
......@@ -27,7 +27,17 @@ from duniterpy.documents import Membership, block_uid
from duniterpy.api import bma
from duniterpy.key import SigningKey
from patched.blockchain_tools import patched_head_block
from patched.blockchain_tools import (
currency,
patched_params,
patched_block,
patched_head_block,
)
from patched.wot import (
patched_wot_requirements_one_pending,
patched_wot_requirements_no_pending,
)
from silkaj import auth, wot
from silkaj.cli import cli
from silkaj.network_tools import ClientInstance
......@@ -46,9 +56,7 @@ else:
from asynctest.mock import CoroutineMock as AsyncMock
# To be moved/merged into tests/patched.py or tests/patched/<module_name>.py
currency = "g1"
# Values and patches
pubkey = "EA7Dsw39ShZg4SpURsrgMaMqrweJPUFPYHwZA8e92e3D"
identity_timestamp = block_uid(
"0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"
......@@ -71,58 +79,6 @@ async def patched_choose_identity(pubkey):
)
async def patched_params(self):
return {
"msValidity": 31557600,
"msPeriod": 5259600,
}
async def patched_block(self, number):
return {
"number": 48000,
"time": 1592243760,
"currency": currency,
"hash": "0000A51FF952B76AAA594A46CA0C8156A56988D2B2B57BE18ECB4F3CFC25CEC2",
}
async def patched_wot_requirements_one_pending(pubkey, identity_uid):
return {
"identities": [
{
"uid": "toto",
"pendingMemberships": [
{
"membership": "IN",
"issuer": "5B8iMAzq1dNmFe3ZxFTBQkqhq4fsztg1gZvxHXCk1XYH",
"number": 613206,
"blockNumber": 613206,
"userid": "moul-test",
"expires_on": 1598624404,
"type": "IN",
}
],
"membershipPendingExpiresIn": 6311520,
"membershipExpiresIn": 2603791,
},
],
}
async def patched_wot_requirements_no_pending(pubkey, identity_uid):
return {
"identities": [
{
"uid": "toto",
"pendingMemberships": [],
"membershipPendingExpiresIn": 0,
"membershipExpiresIn": 3724115,
}
]
}
@pytest.mark.parametrize(
"dry_run, confirmation, exit_code",
[
......
......@@ -49,7 +49,7 @@ def test_display_amount(message, amount, currency_symbol):
@pytest.mark.parametrize(
"message, pubkey, id",
[
("From", "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", "riri"),
("From", "CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp", "riri"),
("To", "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", ""),
],
)
......
......@@ -429,24 +429,24 @@ async def test_generate_transaction_document(
@pytest.mark.parametrize(
"pubkey, TXamount, expected",
[
("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", 200, (2, 300, False)),
("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", 600, (3, 600, False)),
("CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp", 200, (2, 300, False)),
("CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp", 600, (3, 600, False)),
(
"DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",
"CtM5RZHopnSRAAoWNgTWrUhDEmspcCAxn6fuCEWDWudp",
800,
"Error: you don't have enough money",
),
("4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw", 143100, (40, 82000, True)),
("BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", 200, (1, 314, False)),
("BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", 3140, (10, 3140, False)),
("HcRgKh4LwbQVYuAc3xAdCynYXpKoiPE6qdxCMa8JeHat", 143100, (40, 82000, True)),
("2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY", 200, (1, 314, False)),
("2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY", 3140, (10, 3140, False)),
(
"BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh",
"2sq4w8yYVDWNxVWZqGWWDriFf5z7dn7iLahDCvEEotuY",
5000,
"Error: you don't have enough money",
),
("C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", 2900, (8, 3600, False)),
("C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", 22500, (25, 22570, False)),
("C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", 29000, (40, 27280, True)),
("9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp", 2900, (8, 3600, False)),
("9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp", 22500, (25, 22570, False)),
("9cwBBgXcSVMT74xiKYygX6FM5yTdwd3NABj1CfHbbAmp", 29000, (40, 27280, True)),
],
)
@pytest.mark.asyncio
......
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