2020-05-23 00:02:00 +00:00
|
|
|
"""
|
|
|
|
This file is part of nucypher.
|
|
|
|
|
|
|
|
nucypher is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
nucypher is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
|
2021-06-25 20:43:41 +00:00
|
|
|
|
2020-05-23 00:02:00 +00:00
|
|
|
import datetime
|
2022-01-11 21:51:44 +00:00
|
|
|
import os
|
2021-06-25 20:43:41 +00:00
|
|
|
|
2020-05-23 00:02:00 +00:00
|
|
|
import maya
|
2021-11-30 05:08:49 +00:00
|
|
|
from nucypher_core import EncryptedKeyFrag
|
2021-09-29 19:28:35 +00:00
|
|
|
|
2022-01-11 21:51:44 +00:00
|
|
|
from nucypher.config.constants import TEMPORARY_DOMAIN
|
2022-02-02 19:34:05 +00:00
|
|
|
from nucypher.policy.payment import SubscriptionManagerPayment
|
2022-01-11 21:51:44 +00:00
|
|
|
from tests.constants import TEST_PROVIDER_URI
|
2020-05-23 00:02:00 +00:00
|
|
|
|
2022-01-11 21:51:44 +00:00
|
|
|
shares = 3
|
|
|
|
policy_end_datetime = maya.now() + datetime.timedelta(days=35)
|
2020-05-23 00:02:00 +00:00
|
|
|
|
|
|
|
|
2022-01-11 21:51:44 +00:00
|
|
|
def check(policy, bob, ursulas):
|
2020-05-23 00:02:00 +00:00
|
|
|
|
2022-01-11 21:51:44 +00:00
|
|
|
# Check the generated treasure map is decryptable by Bob.
|
|
|
|
treasure_map = bob._decrypt_treasure_map(policy.treasure_map, policy.publisher_verifying_key)
|
2021-08-15 05:00:50 +00:00
|
|
|
|
2021-10-29 07:15:18 +00:00
|
|
|
# The number of actual destinations is exactly equal to shares.
|
2021-08-15 21:46:27 +00:00
|
|
|
assert len(treasure_map.destinations) == shares
|
2020-05-23 00:02:00 +00:00
|
|
|
|
2021-10-07 03:59:30 +00:00
|
|
|
# Let's look at the destinations.
|
2022-01-11 21:51:44 +00:00
|
|
|
for ursula in ursulas:
|
2021-12-25 20:56:36 +00:00
|
|
|
if ursula.canonical_address in treasure_map.destinations:
|
|
|
|
kfrag_kit = treasure_map.destinations[ursula.canonical_address]
|
2021-11-01 20:31:11 +00:00
|
|
|
assert isinstance(kfrag_kit, EncryptedKeyFrag)
|
2022-01-11 21:51:44 +00:00
|
|
|
# TODO: try to decrypt?
|
|
|
|
|
|
|
|
|
|
|
|
def test_decentralized_grant_subscription_manager(blockchain_alice, blockchain_bob, blockchain_ursulas):
|
|
|
|
payment_method = SubscriptionManagerPayment(provider=TEST_PROVIDER_URI, network=TEMPORARY_DOMAIN)
|
|
|
|
blockchain_alice.payment_method = payment_method
|
|
|
|
policy = blockchain_alice.grant(bob=blockchain_bob,
|
|
|
|
label=os.urandom(16),
|
|
|
|
threshold=2,
|
|
|
|
shares=shares,
|
|
|
|
expiration=policy_end_datetime)
|
|
|
|
check(policy=policy, bob=blockchain_bob, ursulas=blockchain_ursulas)
|