nucypher/tests/acceptance/characters/test_decentralized_grant.py

56 lines
2.0 KiB
Python
Raw Normal View History

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/>.
"""
2020-05-23 00:02:00 +00:00
import datetime
2020-05-23 00:02:00 +00:00
import maya
import pytest
from nucypher_core import EncryptedKeyFrag
2021-05-18 20:21:48 +00:00
from nucypher.crypto.utils import keccak_digest
2020-05-23 00:02:00 +00:00
def test_decentralized_grant(blockchain_alice, blockchain_bob, blockchain_ursulas):
2020-05-23 00:02:00 +00:00
# Setup the policy details
shares = 3
2021-03-13 14:27:58 +00:00
policy_end_datetime = maya.now() + datetime.timedelta(days=35)
2020-05-23 00:02:00 +00:00
label = b"this_is_the_path_to_which_access_is_being_granted"
# Create the Policy, Granting access to Bob
policy = blockchain_alice.grant(bob=blockchain_bob,
label=label,
threshold=2,
shares=shares,
2020-05-23 00:02:00 +00:00
rate=int(1e18), # one ether
expiration=policy_end_datetime)
treasure_map = blockchain_bob._decrypt_treasure_map(policy.treasure_map,
policy.publisher_verifying_key)
2021-10-29 07:15:18 +00:00
# The number of actual destinations is exactly equal to shares.
assert len(treasure_map.destinations) == shares
2020-05-23 00:02:00 +00:00
# Let's look at the destinations.
for ursula in blockchain_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]
# TODO: try to decrypt?
assert isinstance(kfrag_kit, EncryptedKeyFrag)