Unused blocks, formatting, spelling - responses to the latest batch of RFCs.

pull/1741/head
jMyles 2020-09-06 22:37:37 -07:00
parent 8dead4d333
commit 64d76046ca
6 changed files with 30 additions and 45 deletions

View File

@ -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

View File

@ -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.")

View File

@ -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

View File

@ -15,32 +15,23 @@ You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
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__()

View File

@ -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

View File

@ -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