2020-05-23 00:02:00 +00:00
|
|
|
import datetime
|
2023-04-28 08:39:42 +00:00
|
|
|
import os
|
2023-09-14 17:00:24 +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
|
|
|
|
2023-10-28 13:59:19 +00:00
|
|
|
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
|
2022-02-02 19:34:05 +00:00
|
|
|
from nucypher.policy.payment import SubscriptionManagerPayment
|
2022-02-12 13:56:46 +00:00
|
|
|
from tests.constants import TEST_ETH_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?
|
|
|
|
|
|
|
|
|
2023-10-01 18:52:48 +00:00
|
|
|
def test_grant_subscription_manager(alice, bob, ursulas):
|
2023-09-14 17:00:24 +00:00
|
|
|
pre_payment_method = SubscriptionManagerPayment(
|
2023-10-28 13:59:19 +00:00
|
|
|
blockchain_endpoint=TEST_ETH_PROVIDER_URI, domain=TEMPORARY_DOMAIN_NAME
|
2023-09-14 17:00:24 +00:00
|
|
|
)
|
|
|
|
alice.pre_payment_method = pre_payment_method
|
2022-11-30 11:46:51 +00:00
|
|
|
policy = alice.grant(
|
|
|
|
bob=bob,
|
|
|
|
label=os.urandom(16),
|
|
|
|
threshold=2,
|
|
|
|
shares=shares,
|
|
|
|
expiration=policy_end_datetime,
|
|
|
|
)
|
|
|
|
check(policy=policy, bob=bob, ursulas=ursulas)
|