From 9bbcfe399a5e5bf9aa5e33931e90a24e0b5310da Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Wed, 2 Feb 2022 11:20:41 -0800 Subject: [PATCH] Removes PolicyManager shims --- nucypher/policy/policies.py | 21 ++-------- .../characters/test_decentralized_grant.py | 12 ------ .../characters/test_freerider_attacks.py | 38 ------------------- 3 files changed, 4 insertions(+), 67 deletions(-) diff --git a/nucypher/policy/policies.py b/nucypher/policy/policies.py index de974f67b..1dfdaacfa 100644 --- a/nucypher/policy/policies.py +++ b/nucypher/policy/policies.py @@ -209,23 +209,10 @@ class BlockchainPolicy(Policy): def _make_reservoir(self, handpicked_addresses: List[ChecksumAddress]): """Returns a reservoir of staking nodes to create a decentralized policy.""" - - # TODO: This is a shim to provide compatibility between SubscriptionManager and StakingEscrow sampling - # Handles the duration unit difference between PolicyManager (periods) and SubscriptionManager (seconds) - # this can be further abstracted away (into payments?) or removed when - # StakingEscrow periods are fully deprecated. - from nucypher.policy.payment import SubscriptionManagerPayment - duration = self.duration - if isinstance(self.publisher.payment_method, SubscriptionManagerPayment): - economics = self.publisher.economics - expiration = maya.MayaDT(self.expiration) - duration = calculate_period_duration(future_time=expiration, seconds_per_period=economics.seconds_per_period) - duration += 1 - - staker_reservoir = make_decentralized_staker_reservoir(staking_agent=self.publisher.staking_agent, - duration_periods=duration, - include_addresses=handpicked_addresses) - return staker_reservoir + reservoir = make_decentralized_staking_provider_reservoir(application_agent=self.publisher.application_agent, + include_addresses=handpicked_addresses, + pagination_size=self.publisher.application_agent.get_staking_providers_population()) # TODO: Use another size? + return reservoir class EnactedPolicy: diff --git a/tests/acceptance/characters/test_decentralized_grant.py b/tests/acceptance/characters/test_decentralized_grant.py index 2d9a3b80f..32a7aef9d 100644 --- a/tests/acceptance/characters/test_decentralized_grant.py +++ b/tests/acceptance/characters/test_decentralized_grant.py @@ -46,18 +46,6 @@ def check(policy, bob, ursulas): # TODO: try to decrypt? -def test_decentralized_grant_policy_manager(blockchain_alice, blockchain_bob, blockchain_ursulas): - payment_method = PolicyManagerPayment(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, - rate=int(1e18), - expiration=policy_end_datetime) - check(policy=policy, bob=blockchain_bob, ursulas=blockchain_ursulas) - - 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 diff --git a/tests/acceptance/characters/test_freerider_attacks.py b/tests/acceptance/characters/test_freerider_attacks.py index afddc0d93..ee8c3b9ae 100644 --- a/tests/acceptance/characters/test_freerider_attacks.py +++ b/tests/acceptance/characters/test_freerider_attacks.py @@ -28,43 +28,6 @@ from nucypher.policy.payment import PolicyManagerPayment from tests.constants import TEST_PROVIDER_URI -def test_policy_simple_sinpa_policy_manager(blockchain_ursulas, - blockchain_alice, - blockchain_bob, - agency, - testerchain): - """ - Making a Policy without paying. - """ - - # This test only applies to the PolicyManager payment method - blockchain_alice.payment_method = PolicyManagerPayment(provider=TEST_PROVIDER_URI, network=TEMPORARY_DOMAIN) - - amonia = Amonia.from_lawful_alice(blockchain_alice) - - # Setup the policy details - shares = 3 - policy_end_datetime = maya.now() + datetime.timedelta(days=35) - label = b"this_is_the_path_to_which_access_is_being_granted" - - bupkiss_policy = amonia.grant_without_paying(bob=blockchain_bob, - label=label, - threshold=2, - shares=shares, - rate=int(1e18), # one ether - expiration=policy_end_datetime) - - # Enrico becomes - enrico = Enrico(policy_encrypting_key=bupkiss_policy.public_key) - plaintext = b"A crafty campaign" - message_kit = enrico.encrypt_message(plaintext) - - with pytest.raises(Ursula.NotEnoughUrsulas): # Return a more descriptive request error? - blockchain_bob.retrieve_and_decrypt([message_kit], - alice_verifying_key=amonia.stamp.as_umbral_pubkey(), - encrypted_treasure_map=bupkiss_policy.treasure_map) - - def test_try_to_post_free_service_by_hacking_enact(blockchain_ursulas, blockchain_alice, blockchain_bob, @@ -83,7 +46,6 @@ def test_try_to_post_free_service_by_hacking_enact(blockchain_ursulas, label=label, threshold=2, shares=shares, - rate=int(1e18), # one ether expiration=policy_end_datetime) # Enrico becomes