Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • appimage
  • check_uniq_node_by_endpoints
  • dev
  • feature/agent_architecture
  • feature/backend
  • fix_ci
  • fix_ci_osx
  • fix_dbus_error
  • fix_gitlab
  • fix_travis#1105
  • fixappveyor
  • gitlab
  • landscape
  • master
  • pyinstaller
  • pyqt5.6
  • qt5.7
  • qtwebengine
  • sakia020
  • translations
  • 0.1.0
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.11.0
  • 0.11.1
  • 0.11.2
  • 0.11.3
  • 0.11.4
  • 0.11.4.post1
  • 0.11.5
  • 0.12.0
  • 0.12.1dev1
  • 0.12.1dev2
  • 0.12.1dev3
  • 0.12.1dev4
  • 0.12.dev1
  • 0.12.dev2
  • 0.12.dev3
  • 0.12.dev4
  • 0.12.dev5
  • 0.12rc1
  • 0.2.0
  • 0.2.1
  • 0.20.0
  • 0.20.0dev1
  • 0.20.0dev10
  • 0.20.0dev12
  • 0.20.0dev13
  • 0.20.0dev14
  • 0.20.0dev15
  • 0.20.0dev16
  • 0.20.0dev2
  • 0.20.0dev3
  • 0.20.0dev3-test1
  • 0.20.0dev4
  • 0.20.0dev5
  • 0.20.0dev6
  • 0.20.0dev7
  • 0.20.0dev8
  • 0.20.0dev9
  • 0.20.1
  • 0.20.10
  • 0.20.11
  • 0.20.13
  • 0.20.2
  • 0.20.3
  • 0.20.4
  • 0.20.5
  • 0.20.6
  • 0.20.7
  • 0.20.8
  • 0.20.9
  • 0.3.0
  • 0.30.0
  • 0.30.0beta
  • 0.30.0beta1
  • 0.30.0beta2
  • 0.30.0beta3
  • 0.30.0beta4
  • 0.30.0beta5
  • 0.30.0beta6
  • 0.30.0beta7
  • 0.30.0beta8
  • 0.30.0beta9
  • 0.30.1
  • 0.30.10
  • 0.30.11
  • 0.30.12
  • 0.30.13
  • 0.30.14
  • 0.30.2
  • 0.30.3
  • 0.30.4
  • 0.30.5
  • 0.30.6
  • 0.30.7
  • 0.30.8
  • 0.30.9
  • 0.31.0
  • 0.31.0.post1
  • 0.31.1
  • 0.31.2
  • 0.31.3
  • 0.31.4
  • 0.31.5
  • 0.31.6
  • 0.32.0
  • 0.32.0-linux
  • 0.32.0RC1
  • 0.32.0RC2
  • 0.32.0RC3
  • 0.32.0RC4
  • 0.32.0RC5
  • 0.32.0RC6
  • 0.32.1
  • 0.32.10
  • 0.32.10post1
  • 0.32.2
  • 0.32.3
120 results

Target

Select target project
  • cebash/sakia
  • santiago/sakia
  • jonas/sakia
3 results
Select Git revision
  • Docker
  • Docker-debian9
  • check_uniq_node_by_endpoints
  • dev
  • feature/agent_architecture
  • feature/backend
  • fix_ci
  • fix_ci_osx
  • fix_dbus_error
  • fix_travis#1105
  • fixappveyor
  • gitlab
  • landscape
  • master
  • pyinstaller
  • pyqt5.6
  • qt5.7
  • qtwebengine
  • sakia020
  • translations
  • 0.1.0
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.11.0
  • 0.11.1
  • 0.11.2
  • 0.11.3
  • 0.11.4
  • 0.11.4.post1
  • 0.11.5
  • 0.12.0
  • 0.12.1dev1
  • 0.12.1dev2
  • 0.12.1dev3
  • 0.12.1dev4
  • 0.12.dev1
  • 0.12.dev2
  • 0.12.dev3
  • 0.12.dev4
  • 0.12.dev5
  • 0.12rc1
  • 0.2.0
  • 0.2.1
  • 0.20.0
  • 0.20.0dev1
  • 0.20.0dev10
  • 0.20.0dev12
  • 0.20.0dev13
  • 0.20.0dev14
  • 0.20.0dev15
  • 0.20.0dev16
  • 0.20.0dev2
  • 0.20.0dev3
  • 0.20.0dev3-test1
  • 0.20.0dev4
  • 0.20.0dev5
  • 0.20.0dev6
  • 0.20.0dev7
  • 0.20.0dev8
  • 0.20.0dev9
  • 0.20.1
  • 0.20.10
  • 0.20.11
  • 0.20.13
  • 0.20.2
  • 0.20.3
  • 0.20.4
  • 0.20.5
  • 0.20.6
  • 0.20.7
  • 0.20.8
  • 0.20.9
  • 0.3.0
  • 0.30.0
  • 0.30.0beta
  • 0.30.0beta1
  • 0.30.0beta2
  • 0.30.0beta3
  • 0.30.0beta4
  • 0.30.0beta5
  • 0.30.0beta6
  • 0.30.0beta7
  • 0.30.0beta8
  • 0.30.0beta9
  • 0.30.1
  • 0.30.10
  • 0.30.11
  • 0.30.12
  • 0.30.13
  • 0.30.14
  • 0.30.2
  • 0.30.3
  • 0.30.4
  • 0.30.5
  • 0.30.6
  • 0.30.7
  • 0.30.8
  • 0.30.9
  • 0.31.0
  • 0.31.0.post1
  • 0.31.1
  • 0.31.2
  • 0.31.3
  • 0.31.4
  • 0.31.5
  • 0.31.6
  • 0.32.0
  • 0.32.0-linux
  • 0.32.0RC1
  • 0.32.0RC2
  • 0.32.0RC3
  • 0.32.0RC4
  • 0.32.0RC5
  • 0.32.0RC6
  • 0.32.1
  • 0.32.10
  • 0.32.10post1
  • 0.32.2
  • 0.32.3
120 results
Show changes
...@@ -3,7 +3,9 @@ from sakia.money import Relative ...@@ -3,7 +3,9 @@ from sakia.money import Relative
def test_value(application_with_one_connection, bob): def test_value(application_with_one_connection, bob):
referential = Relative(13555300, bob.currency, application_with_one_connection, None) referential = Relative(
13555300, bob.currency, application_with_one_connection, None
)
value = referential.value() value = referential.value()
assert value == pytest.approx(58177.253218) assert value == pytest.approx(58177.253218)
......
...@@ -3,21 +3,23 @@ from sakia.money import RelativeZSum ...@@ -3,21 +3,23 @@ from sakia.money import RelativeZSum
def test_value(application_with_one_connection, bob): def test_value(application_with_one_connection, bob):
referential = RelativeZSum(2702, bob.currency, application_with_one_connection, None) referential = RelativeZSum(
2702, bob.currency, application_with_one_connection, None
)
value = referential.value() value = referential.value()
assert value == approx(8.70007) assert value == approx(2702)
def test_differential(application_with_one_connection, bob): def test_differential(application_with_one_connection, bob):
referential = RelativeZSum(111, bob.currency, application_with_one_connection, None) referential = RelativeZSum(111, bob.currency, application_with_one_connection, None)
value = referential.value() value = referential.value()
assert value == approx(-3.521619496) assert value == approx(111)
def test_localized_no_si(application_with_one_connection, bob): def test_localized_no_si(application_with_one_connection, bob):
referential = RelativeZSum(110, bob.currency, application_with_one_connection, None) referential = RelativeZSum(110, bob.currency, application_with_one_connection, None)
value = referential.localized(units=True) value = referential.localized(units=True)
assert value == "-3.53 R0 UD" assert value == "110.00 R0 UD"
def test_localized_with_si(application_with_one_connection, bob): def test_localized_with_si(application_with_one_connection, bob):
...@@ -25,7 +27,7 @@ def test_localized_with_si(application_with_one_connection, bob): ...@@ -25,7 +27,7 @@ def test_localized_with_si(application_with_one_connection, bob):
referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) referential = RelativeZSum(1, bob.currency, application_with_one_connection, None)
value = referential.localized(units=True, show_base=True) value = referential.localized(units=True, show_base=True)
assert value == "-4.040487 R0 UD" assert value == "1.000000 R0 UD"
def test_localized_no_units_no_si(application_with_one_connection, bob): def test_localized_no_units_no_si(application_with_one_connection, bob):
...@@ -33,7 +35,7 @@ def test_localized_no_units_no_si(application_with_one_connection, bob): ...@@ -33,7 +35,7 @@ def test_localized_no_units_no_si(application_with_one_connection, bob):
referential = RelativeZSum(110, bob.currency, application_with_one_connection, None) referential = RelativeZSum(110, bob.currency, application_with_one_connection, None)
value = referential.localized(units=False, show_base=False) value = referential.localized(units=False, show_base=False)
assert value == "-3.526336" assert value == "110.000000"
def test_localized_no_units_with_si(application_with_one_connection, bob): def test_localized_no_units_with_si(application_with_one_connection, bob):
...@@ -41,7 +43,7 @@ def test_localized_no_units_with_si(application_with_one_connection, bob): ...@@ -41,7 +43,7 @@ def test_localized_no_units_with_si(application_with_one_connection, bob):
referential = RelativeZSum(1, bob.currency, application_with_one_connection, None) referential = RelativeZSum(1, bob.currency, application_with_one_connection, None)
value = referential.localized(units=False, show_base=True) value = referential.localized(units=False, show_base=True)
assert value == "-4.040487" assert value == "1.000000"
def test_diff_localized_no_si(application_with_one_connection, bob): def test_diff_localized_no_si(application_with_one_connection, bob):
......
import pytest
@pytest.mark.asyncio
async def test_lock_mode_0(application_with_one_connection, fake_server, bob, alice):
"""
Test the lock mode 0, Receiver signature
:param application_with_one_connection:
:param fake_server:
:param bob:
:param alice:
:return:
"""
# check money amount in bob account
amount = application_with_one_connection.sources_service.amount(bob.key.pubkey)
assert amount == 1584
# create connection to have sources...
bob_connection = application_with_one_connection.db.connections_repo.get_one(
pubkey=bob.key.pubkey
)
# send transaction
(
_,
sakia_tx_list,
) = await application_with_one_connection.documents_service.send_money(
bob_connection, bob.salt, bob.password, alice.key.pubkey, 100, 0, None, 0, None
)
assert len(sakia_tx_list) == 1
assert (
"Outputs:\n100:0:SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)\n"
in sakia_tx_list[0].raw
)
@pytest.mark.asyncio
async def test_lock_mode_1(application_with_one_connection, fake_server, bob, alice):
"""
Test the lock mode 0, Receiver signature OR (Sender signature AND CSV(one week delay))
:param application_with_one_connection:
:param fake_server:
:param bob:
:param alice:
:return:
"""
# check money amount in bob account
amount = application_with_one_connection.sources_service.amount(bob.key.pubkey)
assert amount == 1584
# create connection to have sources...
bob_connection = application_with_one_connection.db.connections_repo.get_one(
pubkey=bob.key.pubkey
)
# send transaction
(
_,
sakia_tx_list,
) = await application_with_one_connection.documents_service.send_money(
bob_connection, bob.salt, bob.password, alice.key.pubkey, 100, 0, None, 1, None
)
assert len(sakia_tx_list) == 1
assert (
"Outputs:\n100:0:SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo) || (SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7) && CSV(604800))\n"
in sakia_tx_list[0].raw
)
import hashlib
import pypeg2
import pytest
from duniterpy.documents.transaction import output
from sakia.data.entities import Transaction
from sakia.data.repositories import TransactionsRepo
from sakia.services import sources
def test_parse_source_condition(application_with_one_connection, alice, bob):
application_with_one_connection.instanciate_services()
issuer = alice.key.pubkey
receiver = bob.key.pubkey
condition = output.Condition.token(
output.SIG.token(receiver),
output.Operator.token("||"),
output.Condition.token(
output.SIG.token(issuer),
output.Operator.token("&&"),
output.CSV.token(604800),
),
)
assert (
application_with_one_connection.sources_service.find_signature_in_condition(
condition, receiver
)
is True
)
assert (
application_with_one_connection.sources_service.find_signature_in_condition(
condition, issuer
)
is True
)
assert (
application_with_one_connection.sources_service.find_signature_in_condition(
condition, "badpubkey"
)
is False
)
condition = output.Condition.token(
output.Condition.token(
output.CSV.token(604800),
output.Operator.token("&&"),
output.SIG.token(issuer),
),
output.Operator.token("||"),
output.SIG.token(receiver),
)
assert (
application_with_one_connection.sources_service.find_signature_in_condition(
condition, receiver
)
is True
)
assert (
application_with_one_connection.sources_service.find_signature_in_condition(
condition, issuer
)
is True
)
assert (
application_with_one_connection.sources_service.find_signature_in_condition(
condition, "badpubkey"
)
is False
)
def test_evaluate_condition_source_lock_mode_0(
application_with_one_connection, bob, alice, meta_repo
):
application_with_one_connection.instanciate_services()
# capture blockchain median time
median_time = (
application_with_one_connection.blockchain_service._blockchain_processor.time(
application_with_one_connection.currency
)
)
tx_hash = "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365"
# add a transaction in bob tx history
transactions_repo = TransactionsRepo(meta_repo.conn)
transactions_repo.insert(
Transaction(
"testcurrency",
bob.key.pubkey,
tx_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey,
bob.key.pubkey,
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
transactions_repo.insert(
Transaction(
"testcurrency",
alice.key.pubkey,
tx_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey,
bob.key.pubkey,
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# test simple signature condition
condition = output.Condition.token(
output.SIG.token(bob.key.pubkey),
)
# bob can spend this source
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[bob.key.pubkey],
[],
tx_hash,
)
assert result is True
assert _errors is None
# alice can not
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[alice.key.pubkey],
[],
tx_hash,
)
assert result is False
assert _errors == [
(
pypeg2.compose(condition),
sources.EVALUATE_CONDITION_ERROR_SIG,
bob.key.pubkey,
)
]
def test_evaluate_condition_source_lock_mode_1(
application_with_one_connection, bob, alice, meta_repo
):
application_with_one_connection.instanciate_services()
# capture blockchain median time
median_time = (
application_with_one_connection.blockchain_service._blockchain_processor.time(
application_with_one_connection.currency
)
)
tx_hash = "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365"
# add a transaction in bob tx history
transactions_repo = TransactionsRepo(meta_repo.conn)
transactions_repo.insert(
Transaction(
"testcurrency",
bob.key.pubkey,
tx_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey,
bob.key.pubkey,
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
transactions_repo.insert(
Transaction(
"testcurrency",
alice.key.pubkey,
tx_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey,
bob.key.pubkey,
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# test condition: receiver or (issuer and CSV(one week))
delay = 604800
condition = output.Condition.token(
output.SIG.token(bob.key.pubkey),
output.Operator.token("||"),
output.Condition.token(
output.SIG.token(alice.key.pubkey),
output.Operator.token("&&"),
output.CSV.token(delay),
),
)
# bob spend his source
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[bob.key.pubkey],
[],
tx_hash,
)
assert result is True
assert _errors == [
(
"SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo",
),
("CSV(604800)", sources.EVALUATE_CONDITION_ERROR_CSV, median_time + delay),
]
# alice try to get back this source before the CSV delay
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[alice.key.pubkey],
[],
tx_hash,
)
assert result is False
assert _errors == [
("CSV(604800)", sources.EVALUATE_CONDITION_ERROR_CSV, median_time + delay),
(
"SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7",
),
]
# Transaction was made one week ago...
transactions_repo.update(
Transaction(
"testcurrency",
bob.key.pubkey,
tx_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time - delay,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey,
bob.key.pubkey,
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
transactions_repo.update(
Transaction(
"testcurrency",
alice.key.pubkey,
tx_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time - delay,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey,
bob.key.pubkey,
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
tx = transactions_repo.get_one(sha_hash=tx_hash)
assert tx.timestamp == median_time - delay
# bob try to spend his source
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[bob.key.pubkey],
[],
tx_hash,
)
assert result is True
assert _errors == [
(
"SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo",
)
]
# alice can get back this source after the CSV delay
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[alice.key.pubkey],
[],
tx_hash,
)
assert result is True
assert _errors == [
(
"SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7",
)
]
def test_evaluate_condition_source_multisig(
application_with_one_connection, bob, alice, meta_repo
):
application_with_one_connection.instanciate_services()
# capture blockchain median time
median_time = (
application_with_one_connection.blockchain_service._blockchain_processor.time(
application_with_one_connection.currency
)
)
tx_hash = "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365"
# add a transaction in bob tx history
transactions_repo = TransactionsRepo(meta_repo.conn)
transactions_repo.insert(
Transaction(
"testcurrency",
bob.key.pubkey,
tx_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey,
bob.key.pubkey,
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
transactions_repo.insert(
Transaction(
"testcurrency",
alice.key.pubkey,
tx_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey,
bob.key.pubkey,
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# test condition: multi signatures
condition = output.Condition.token(
output.SIG.token(bob.key.pubkey),
output.Operator.token("&&"),
output.SIG.token(alice.key.pubkey),
)
# bob can not spend this source alone
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[bob.key.pubkey],
[],
tx_hash,
)
assert result is False
assert _errors == [
(
"SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo",
)
]
# alice can not spend this source alone
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[alice.key.pubkey],
[],
tx_hash,
)
assert result is False
assert _errors == [
(
"SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7",
)
]
# alice && bob together only can spend this source
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
condition,
[alice.key.pubkey, bob.key.pubkey],
[],
tx_hash,
)
assert result is True
assert _errors is None
def test_evaluate_condition_source_atomic_swap(
application_with_one_connection, bob, alice, meta_repo
):
application_with_one_connection.instanciate_services()
transactions_repo = TransactionsRepo(meta_repo.conn)
# capture blockchain median time
median_time = (
application_with_one_connection.blockchain_service._blockchain_processor.time(
application_with_one_connection.currency
)
)
tx1_hash = "FCAD5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365"
# add TX1 transaction in alice tx history
transactions_repo.insert(
Transaction(
"testcurrency",
alice.key.pubkey, # alice history
tx1_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey, # do not care
bob.key.pubkey, # do not care
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# add TX1 transaction in bob tx history
transactions_repo.insert(
Transaction(
"testcurrency",
bob.key.pubkey, # bob history
tx1_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey, # do not care
bob.key.pubkey, # do not care
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# atomic swap initiator TX1 condition created by alice
# (XHX(password) && SIG(bob)) || (SIG(alice) && SIG(bob)) || (SIG(alice) && CSV(48h))
password = "test".encode("utf8") # password must be encoded in str not unicode
hash_password = hashlib.sha256(password).hexdigest().upper()
delay_48h = 172800
tx1_condition = output.Condition.token(
output.Condition.token(
output.Condition.token(
output.XHX.token(hash_password),
output.Operator.token("&&"),
output.SIG.token(bob.key.pubkey),
),
output.Operator.token("||"),
output.Condition.token(
output.SIG.token(alice.key.pubkey),
output.Operator.token("&&"),
output.SIG.token(bob.key.pubkey),
),
),
output.Operator.token("||"),
output.Condition.token(
output.SIG.token(alice.key.pubkey),
output.Operator.token("&&"),
output.CSV.token(delay_48h),
),
)
tx2_hash = "ACAB5A388AC8A811B45A9334A375585E77071AA9F6E5B6896582961A6C66F365"
# add TX2 transaction in alice tx history
transactions_repo.insert(
Transaction(
"testcurrency",
alice.key.pubkey, # alice history
tx2_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey, # do not care
bob.key.pubkey, # do not care
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# add TX2 transaction in bob tx history
transactions_repo.insert(
Transaction(
"testcurrency",
bob.key.pubkey, # bob history
tx2_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey, # do not care
bob.key.pubkey, # do not care
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# test atomic swap participant TX2 condition created by bob with alice password hash
# (XHX(password) && SIG(alice)) || (SIG(alice) && SIG(bob)) || (SIG(bob) && CSV(24h))
delay_24h = 86400
tx2_condition = output.Condition.token(
output.Condition.token(
output.Condition.token(
output.XHX.token(hash_password),
output.Operator.token("&&"),
output.SIG.token(alice.key.pubkey),
),
output.Operator.token("||"),
output.Condition.token(
output.SIG.token(alice.key.pubkey),
output.Operator.token("&&"),
output.SIG.token(bob.key.pubkey),
),
),
output.Operator.token("||"),
output.Condition.token(
output.SIG.token(bob.key.pubkey),
output.Operator.token("&&"),
output.CSV.token(delay_24h),
),
)
# alice spend the source from tx2 with the password
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx2_condition,
[alice.key.pubkey],
[password],
tx2_hash,
)
assert result is True
assert _errors == [
(
"SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7",
),
(
"SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7",
),
("CSV(86400)", sources.EVALUATE_CONDITION_ERROR_CSV, median_time + delay_24h),
]
# the password is revealed in the unlock of the tx3 spending tx2
# bob can now spend tx1 using the password
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx1_condition,
[bob.key.pubkey],
[password],
tx1_hash,
)
assert result is True
assert _errors == [
(
"SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo",
),
(
"SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo",
),
("CSV(172800)", "locked by a delay until", median_time + delay_48h),
]
# alice and bob can sign together to spend tx1
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx1_condition,
[bob.key.pubkey, alice.key.pubkey],
[password],
tx1_hash,
)
assert result is True
assert _errors == [
("CSV(172800)", sources.EVALUATE_CONDITION_ERROR_CSV, median_time + delay_48h)
]
# alice and bob can sign together to spend tx2
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx2_condition,
[bob.key.pubkey, alice.key.pubkey],
[password],
tx2_hash,
)
assert result is True
assert _errors == [
("CSV(86400)", sources.EVALUATE_CONDITION_ERROR_CSV, median_time + delay_24h)
]
# alice can not spend the source from tx2 without the password
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx2_condition,
[alice.key.pubkey],
[],
tx2_hash,
)
assert result is False
assert _errors == [
(
"XHX(9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08)",
sources.EVALUATE_CONDITION_ERROR_XHX,
"9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08",
),
(
"SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7",
),
(
"SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7",
),
("CSV(86400)", "locked by a delay until", median_time + delay_24h),
]
# bob can not spend tx1 without the password
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx1_condition,
[bob.key.pubkey],
[],
tx1_hash,
)
assert result is False
assert _errors == [
(
"XHX(9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08)",
sources.EVALUATE_CONDITION_ERROR_XHX,
"9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08",
),
(
"SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo",
),
(
"SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo",
),
("CSV(172800)", sources.EVALUATE_CONDITION_ERROR_CSV, median_time + delay_48h),
]
# TX1 Transaction was made 48h ago...
# update TX1 transaction in alice tx history
transactions_repo.update(
Transaction(
"testcurrency",
alice.key.pubkey, # alice history
tx1_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time - delay_48h,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey, # do not care
bob.key.pubkey, # do not care
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# update TX1 transaction in bob tx history
transactions_repo.update(
Transaction(
"testcurrency",
bob.key.pubkey, # bob history
tx1_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time - delay_48h,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey, # do not care
bob.key.pubkey, # do not care
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# TX2 Transaction was made 24h ago...
# update TX2 transaction in alice tx history
transactions_repo.update(
Transaction(
"testcurrency",
alice.key.pubkey, # alice history
tx2_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time - delay_24h,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey, # do not care
bob.key.pubkey, # do not care
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# update TX2 transaction in bob tx history
transactions_repo.update(
Transaction(
"testcurrency",
bob.key.pubkey, # bob history
tx2_hash,
20,
"15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67",
median_time - delay_24h,
"H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
alice.key.pubkey, # do not care
bob.key.pubkey, # do not care
1565,
1,
"",
0,
Transaction.VALIDATED,
)
)
# alice can get back the source from tx1 without the password after 48h
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx1_condition,
[alice.key.pubkey],
[],
tx1_hash,
)
assert result is True
assert _errors == [
(
"XHX(9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08)",
sources.EVALUATE_CONDITION_ERROR_XHX,
"9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08",
),
(
"SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7",
),
(
"SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7",
),
]
# bob can spend tx2 without the password after 24h
(
result,
_errors,
) = application_with_one_connection.sources_service.evaluate_condition(
application_with_one_connection.currency,
tx2_condition,
[bob.key.pubkey],
[],
tx2_hash,
)
assert result is True
assert _errors == [
(
"XHX(9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08)",
sources.EVALUATE_CONDITION_ERROR_XHX,
"9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08",
),
(
"SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo",
),
(
"SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)",
sources.EVALUATE_CONDITION_ERROR_SIG,
"F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo",
),
]
...@@ -16,7 +16,7 @@ async def test_run_only_once(): ...@@ -16,7 +16,7 @@ async def test_run_only_once():
callback(name) callback(name)
task_runner = TaskRunner() task_runner = TaskRunner()
calls = {'A': 0, 'B': 0, 'C': 0} calls = {"A": 0, "B": 0, "C": 0}
def incrementer(name): def incrementer(name):
nonlocal calls nonlocal calls
...@@ -52,7 +52,7 @@ async def test_cancel_once(application): ...@@ -52,7 +52,7 @@ async def test_cancel_once(application):
cancel_once_task(self, self.some_long_task) cancel_once_task(self, self.some_long_task)
task_runner = TaskRunner() task_runner = TaskRunner()
calls = {'A': 0, 'B': 0} calls = {"A": 0, "B": 0}
def incrementer(name): def incrementer(name):
nonlocal calls nonlocal calls
...@@ -87,7 +87,7 @@ async def test_cancel_once_two_times(application): ...@@ -87,7 +87,7 @@ async def test_cancel_once_two_times(application):
cancel_once_task(self, self.some_long_task) cancel_once_task(self, self.some_long_task)
task_runner = TaskRunner() task_runner = TaskRunner()
calls = {'A': 0, 'B': 0, 'C': 0, 'D': 0} calls = {"A": 0, "B": 0, "C": 0, "D": 0}
def incrementer(name): def incrementer(name):
nonlocal calls nonlocal calls
...@@ -100,7 +100,9 @@ async def test_cancel_once_two_times(application): ...@@ -100,7 +100,9 @@ async def test_cancel_once_two_times(application):
application.loop.call_soon(lambda: task_runner.some_long_task("B", incrementer)) application.loop.call_soon(lambda: task_runner.some_long_task("B", incrementer))
application.loop.call_later(1.5, lambda: task_runner.cancel_long_task()) application.loop.call_later(1.5, lambda: task_runner.cancel_long_task())
application.loop.call_later(2, lambda: task_runner.some_long_task("C", incrementer)) application.loop.call_later(2, lambda: task_runner.some_long_task("C", incrementer))
application.loop.call_later(2.1, lambda: task_runner.some_long_task("D", incrementer)) application.loop.call_later(
2.1, lambda: task_runner.some_long_task("D", incrementer)
)
application.loop.call_later(3.5, lambda: task_runner.cancel_long_task()) application.loop.call_later(3.5, lambda: task_runner.cancel_long_task())
await exec_test() await exec_test()
assert calls["A"] == 0 assert calls["A"] == 0
...@@ -130,7 +132,7 @@ async def test_two_runners(): ...@@ -130,7 +132,7 @@ async def test_two_runners():
def cancel_long_task(self): def cancel_long_task(self):
cancel_once_task(self, self.some_long_task) cancel_once_task(self, self.some_long_task)
calls = {'A': 0, 'B': 0, 'C': 0} calls = {"A": 0, "B": 0, "C": 0}
def incrementer(name): def incrementer(name):
nonlocal calls nonlocal calls
......
#!/usr/bin/env bash
# Ubuntu 18.04+
sudo apt-get install curl qt5-qmake qtbase5-dev qttools5-dev-tools libqt5svg5-dev libdbus-1-dev libdbus-glib-1-dev autoconf automake libtool libsodium23
\ No newline at end of file
#!/bin/bash
wget https://duniter.org/en/files/licence_g1.txt
sed "s/:date.*//g" -i licence_g1.txt
sed "s/:modified.*//g" -i licence_g1.txt
pandoc -s licence_g1.txt -o src/sakia/g1_licence.html
rm licence_g1.txt
#!/bin/bash
wget https://duniter.org/en/files/license_g1.txt
sed "s/:date.*//g" -i license_g1.txt
sed "s/:modified.*//g" -i license_g1.txt
md-to-html -i license_g1.txt -o src/sakia/g1_license.html
rm license_g1.txt
...@@ -18,7 +18,7 @@ def generate_pro(): ...@@ -18,7 +18,7 @@ def generate_pro():
"sakia-ts-{0}".format(int(time.time())))) "sakia-ts-{0}".format(int(time.time()))))
for root, dirs, files in os.walk(src): for root, dirs, files in os.walk(src):
for f in files: for f in files:
if f.endswith('.py') and not f.endswith('_uic.py'): if f.endswith('.py'):
sources.append(os.path.join(root, f)) sources.append(os.path.join(root, f))
else: else:
continue continue
......