From 64d76046cafba146e8c09aaa8ba24921d49b513d Mon Sep 17 00:00:00 2001 From: jMyles Date: Sun, 6 Sep 2020 22:37:37 -0700 Subject: [PATCH] Unused blocks, formatting, spelling - responses to the latest batch of RFCs. --- nucypher/blockchain/eth/actors.py | 1 - nucypher/characters/lawful.py | 1 + nucypher/network/nodes.py | 5 +--- nucypher/policy/collections.py | 30 ++++++++----------- .../blockchain/actors/test_staker.py | 29 +++++++++--------- .../learning/test_firstula_circumstances.py | 9 ------ 6 files changed, 30 insertions(+), 45 deletions(-) diff --git a/nucypher/blockchain/eth/actors.py b/nucypher/blockchain/eth/actors.py index 182748190..a80dbdcb3 100644 --- a/nucypher/blockchain/eth/actors.py +++ b/nucypher/blockchain/eth/actors.py @@ -1450,7 +1450,6 @@ class Worker(NucypherTokenActor): self.is_me = is_me - # self._checksum_address = None # Stake Address # TODO - wait, why? Why are we setting this to None when it may have already been set in an outer method? self.__worker_address = worker_address # Agency diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index ffcddb4fd..76e6c71ca 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -898,6 +898,7 @@ class Bob(Character): try: # TODO: This is almost certainly happening in a test. If it does happen in production, it's a bit of a problem. Need to fix #2124 to mitigate. target_nodes = list(nodes._nodes.values())[0:6] + return target_nodes except IndexError: raise self.NotEnoughNodes("There aren't enough nodes on the network to enact this policy. Unless this is day one of the network and nodes are still getting spun up, something is bonkers.") diff --git a/nucypher/network/nodes.py b/nucypher/network/nodes.py index 1eb574156..e2c749989 100644 --- a/nucypher/network/nodes.py +++ b/nucypher/network/nodes.py @@ -441,11 +441,8 @@ class Learner: return self.learning_deferred else: self.log.info("Starting Learning Loop.") - - learner_deferred = self._learning_task.start(interval=self._SHORT_LEARNING_DELAY, - now=now) # TODO: now=now? This block is always False, no? + learner_deferred = self._learning_task.start(interval=self._SHORT_LEARNING_DELAY, now=False) learner_deferred.addErrback(self.handle_learning_errors) - self.learning_deferred = learner_deferred return self.learning_deferred diff --git a/nucypher/policy/collections.py b/nucypher/policy/collections.py index a95a87ded..38d1f7c50 100644 --- a/nucypher/policy/collections.py +++ b/nucypher/policy/collections.py @@ -15,32 +15,23 @@ You should have received a copy of the GNU Affero General Public License along with nucypher. If not, see . """ -import binascii - import json from collections import OrderedDict +from typing import Optional, Tuple + import maya -from bytestring_splitter import BytestringSplitter, VariableLengthBytestring, BytestringSplittingError, \ - BytestringKwargifier -from constant_sorrow.constants import CFRAG_NOT_RETAINED, NO_DECRYPTION_PERFORMED, NOT_SIGNED -from constant_sorrow.constants import CFRAG_NOT_RETAINED -from constant_sorrow.constants import NO_DECRYPTION_PERFORMED -from bytestring_splitter import BytestringSplitter, BytestringSplittingError, VariableLengthBytestring -from constant_sorrow.constants import CFRAG_NOT_RETAINED, NO_DECRYPTION_PERFORMED from cryptography.hazmat.backends.openssl import backend from cryptography.hazmat.primitives import hashes from eth_utils import to_canonical_address, to_checksum_address -from typing import List, Optional, Tuple -from umbral.config import default_params -from umbral.curvebn import CurveBN -from umbral.keys import UmbralPublicKey -from umbral.pre import Capsule +from bytestring_splitter import BytestringKwargifier +from bytestring_splitter import BytestringSplitter, BytestringSplittingError, VariableLengthBytestring +from constant_sorrow.constants import CFRAG_NOT_RETAINED, NO_DECRYPTION_PERFORMED +from constant_sorrow.constants import NOT_SIGNED from nucypher.blockchain.eth.constants import ETH_ADDRESS_BYTE_LENGTH, ETH_HASH_BYTE_LENGTH from nucypher.characters.lawful import Bob, Character -from nucypher.crypto.api import keccak_digest, encrypt_and_sign, verify_eip_191 -from nucypher.crypto.constants import PUBLIC_ADDRESS_LENGTH, KECCAK_DIGEST_LENGTH from nucypher.crypto.api import encrypt_and_sign, keccak_digest +from nucypher.crypto.api import verify_eip_191 from nucypher.crypto.constants import KECCAK_DIGEST_LENGTH, PUBLIC_ADDRESS_LENGTH from nucypher.crypto.kits import UmbralMessageKit from nucypher.crypto.signing import InvalidSignature, Signature, signature_splitter @@ -49,6 +40,10 @@ from nucypher.crypto.utils import (canonical_address_from_umbral_key, get_coordinates_as_bytes, get_signature_recovery_value) from nucypher.network.middleware import RestMiddleware +from umbral.config import default_params +from umbral.curvebn import CurveBN +from umbral.keys import UmbralPublicKey +from umbral.pre import Capsule class TreasureMap: @@ -273,7 +268,8 @@ class SignedTreasureMap(TreasureMap): def __bytes__(self): if self._blockchain_signature is NOT_SIGNED: - raise self.InvalidSignature("Can't cast a DecentralizedTreasureMap to bytes until it has a blockchain signature (otherwise, is it really a 'DecentralizedTreasureMap'?") + raise self.InvalidSignature( + "Can't cast a DecentralizedTreasureMap to bytes until it has a blockchain signature (otherwise, is it really a 'DecentralizedTreasureMap'?") return self._blockchain_signature + super().__bytes__() diff --git a/tests/acceptance/blockchain/actors/test_staker.py b/tests/acceptance/blockchain/actors/test_staker.py index f914f3078..7b37ff885 100644 --- a/tests/acceptance/blockchain/actors/test_staker.py +++ b/tests/acceptance/blockchain/actors/test_staker.py @@ -20,13 +20,11 @@ from eth_tester.exceptions import TransactionFailed from nucypher.blockchain.eth.agents import ContractAgency, StakingEscrowAgent from nucypher.blockchain.eth.token import NU, Stake -from nucypher.crypto.powers import TransactingPower -from tests.constants import FEE_RATE_RANGE, INSECURE_DEVELOPMENT_PASSWORD -from tests.utils.ursula import make_decentralized_ursulas -from nucypher.crypto.powers import TransactingPower from nucypher.blockchain.eth.utils import datetime_at_period +from nucypher.crypto.powers import TransactingPower from tests.constants import FEE_RATE_RANGE, INSECURE_DEVELOPMENT_PASSWORD, DEVELOPMENT_TOKEN_AIRDROP_AMOUNT from tests.utils.blockchain import token_airdrop +from tests.utils.ursula import make_decentralized_ursulas def test_staker_locking_tokens(testerchain, agency, staker, token_economics, mock_transacting_power_activation): @@ -36,7 +34,8 @@ def test_staker_locking_tokens(testerchain, agency, staker, token_economics, moc assert NU(token_economics.minimum_allowed_locked, 'NuNit') < staker.token_balance, "Insufficient staker balance" - staker.initialize_stake(amount=NU(token_economics.minimum_allowed_locked, 'NuNit'), # Lock the minimum amount of tokens + staker.initialize_stake(amount=NU(token_economics.minimum_allowed_locked, 'NuNit'), + # Lock the minimum amount of tokens lock_periods=token_economics.minimum_locked_periods) # Verify that the escrow is "approved" to receive tokens @@ -55,8 +54,8 @@ def test_staker_locking_tokens(testerchain, agency, staker, token_economics, moc @pytest.mark.usefixtures("agency") def test_staker_divides_stake(staker, token_economics): - stake_value = NU(token_economics.minimum_allowed_locked*5, 'NuNit') - new_stake_value = NU(token_economics.minimum_allowed_locked*2, 'NuNit') + stake_value = NU(token_economics.minimum_allowed_locked * 5, 'NuNit') + new_stake_value = NU(token_economics.minimum_allowed_locked * 2, 'NuNit') stake_index = 0 staker.initialize_stake(amount=stake_value, lock_periods=int(token_economics.minimum_locked_periods)) @@ -111,8 +110,10 @@ def test_staker_divides_stake(staker, token_economics): economics=token_economics) assert 4 == len(staker.stakes), 'A new stake was not added after two stake divisions' - assert expected_old_stake == staker.stakes[stake_index + 1].to_stake_info(), 'Old stake values are invalid after two stake divisions' - assert expected_new_stake == staker.stakes[stake_index + 2].to_stake_info(), 'New stake values are invalid after two stake divisions' + assert expected_old_stake == staker.stakes[ + stake_index + 1].to_stake_info(), 'Old stake values are invalid after two stake divisions' + assert expected_new_stake == staker.stakes[ + stake_index + 2].to_stake_info(), 'New stake values are invalid after two stake divisions' assert expected_yet_another_stake.value == staker.stakes[stake_index + 3].value, 'Third stake values are invalid' @@ -224,7 +225,6 @@ def test_staker_merges_stakes(agency, staker, token_economics): def test_staker_manages_restaking(testerchain, test_registry, staker): - # Enable Restaking receipt = staker.enable_restaking() assert receipt['status'] == 1 @@ -240,7 +240,7 @@ def test_staker_manages_restaking(testerchain, test_registry, staker): assert staker.restaking_lock_enabled with pytest.raises((TransactionFailed, ValueError)): - staker.disable_restaking() + staker.disable_restaking() # Wait until terminal period testerchain.time_travel(periods=2) @@ -267,8 +267,10 @@ def test_staker_collects_staking_reward(testerchain, mock_transacting_power_activation(account=staker.checksum_address, password=INSECURE_DEVELOPMENT_PASSWORD) - staker.initialize_stake(amount=NU(token_economics.minimum_allowed_locked, 'NuNit'), # Lock the minimum amount of tokens - lock_periods=int(token_economics.minimum_locked_periods)) # ... for the fewest number of periods + staker.initialize_stake(amount=NU(token_economics.minimum_allowed_locked, 'NuNit'), + # Lock the minimum amount of tokens + lock_periods=int( + token_economics.minimum_locked_periods)) # ... for the fewest number of periods # Get an unused address for a new worker worker_address = testerchain.unassigned_accounts[-1] @@ -353,7 +355,6 @@ def test_staker_manages_winding_down(testerchain, def test_set_min_fee_rate(testerchain, test_registry, staker): - # Check before set _minimum, default, maximum = FEE_RATE_RANGE assert staker.min_fee_rate == default diff --git a/tests/integration/learning/test_firstula_circumstances.py b/tests/integration/learning/test_firstula_circumstances.py index 241149129..9fab3baed 100644 --- a/tests/integration/learning/test_firstula_circumstances.py +++ b/tests/integration/learning/test_firstula_circumstances.py @@ -52,15 +52,6 @@ def test_get_cert_from_running_seed_node(lonely_ursula_maker): network_middleware=RestMiddleware()).pop() assert not any_other_ursula.known_nodes - # def start_lonely_learning_loop(): - # any_other_ursula.log.info( - # "Known nodes when starting learning loop were: {}".format(any_other_ursula.known_nodes)) - # any_other_ursula.start_learning_loop() - # result = any_other_ursula.block_until_specific_nodes_are_known(set([firstula.checksum_address]), - # timeout=2) - # assert result - # - # yield deferToThread(start_lonely_learning_loop) yield deferToThread(any_other_ursula.load_seednodes) assert firstula in any_other_ursula.known_nodes