mirror of https://github.com/nucypher/nucypher.git
repairs a p2p validity test that implements /ping. Linting.
parent
1f83e2c5ab
commit
d06bb7af9a
|
@ -1,9 +1,10 @@
|
|||
import datetime
|
||||
import maya
|
||||
import os
|
||||
from getpass import getpass
|
||||
from pathlib import Path
|
||||
|
||||
import maya
|
||||
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.signers.base import Signer
|
||||
from nucypher.characters.lawful import Alice, Bob
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
import base64
|
||||
import datetime
|
||||
import json
|
||||
import maya
|
||||
import os
|
||||
import shutil
|
||||
from getpass import getpass
|
||||
from pathlib import Path
|
||||
|
||||
import maya
|
||||
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.blockchain.eth.signers import Signer
|
||||
from nucypher.characters.lawful import Alice, Bob
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import base64
|
||||
import json
|
||||
import maya
|
||||
import msgpack
|
||||
import os
|
||||
import shutil
|
||||
from timeit import default_timer as timer
|
||||
|
||||
import maya
|
||||
import msgpack
|
||||
from nucypher_core import EncryptedTreasureMap, MessageKit
|
||||
from nucypher_core.umbral import PublicKey
|
||||
from timeit import default_timer as timer
|
||||
|
||||
from nucypher.blockchain.eth import domains
|
||||
from nucypher.characters.lawful import Bob
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import datetime
|
||||
|
||||
import maya
|
||||
import pytest
|
||||
from eth_account._utils.signing import to_standard_signature_bytes
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
import pytest
|
||||
|
||||
|
@ -97,24 +92,8 @@ def test_interactive_select_config_file(
|
|||
assert config_path.exists()
|
||||
|
||||
mock_stdin.line(str(user_input))
|
||||
result = select_config_file(emitter=test_emitter,
|
||||
config_class=config_class,
|
||||
config_root=temp_dir_path)
|
||||
|
||||
captured = capsys.readouterr()
|
||||
for filename, account in accounts:
|
||||
assert account.address in captured.out
|
||||
assert mock_stdin.empty()
|
||||
|
||||
table_data = captured.out.split('\n')
|
||||
table_addresses = [row.split()[1] for row in table_data[6:-2]] # escape extra lines printed before table
|
||||
|
||||
# TODO: Finish this test
|
||||
# for index, (filename, account) in enumerate(accounts):
|
||||
# assert False
|
||||
#
|
||||
# selection = config.filepath
|
||||
# assert isinstance(result, str)
|
||||
# result = Path(result)
|
||||
# assert result.exists()
|
||||
# assert result == selection
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
|
||||
|
||||
import json
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import shutil
|
||||
|
||||
from nucypher.config.base import BaseConfiguration
|
||||
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
|
||||
|
||||
|
||||
import datetime
|
||||
from functools import partial
|
||||
|
||||
|
|
|
@ -6,8 +6,9 @@ from nucypher.acumen.nicknames import Nickname
|
|||
from nucypher.acumen.perception import FleetSensor
|
||||
from nucypher.characters.unlawful import Vladimir
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
|
||||
from nucypher.network.middleware import RestMiddleware
|
||||
from tests.constants import MOCK_ETH_PROVIDER_URI
|
||||
from tests.utils.middleware import MockRestMiddleware
|
||||
from tests.utils.middleware import EvilMiddleWare, MockRestMiddleware
|
||||
|
||||
|
||||
def test_all_ursulas_know_about_all_other_ursulas(ursulas, test_registry):
|
||||
|
@ -99,10 +100,11 @@ def test_vladimir_illegal_interface_key_does_not_propagate(ursulas):
|
|||
# assert vladimir not in other_ursula.known_nodes
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("monkeypatch_get_staking_provider_from_operator")
|
||||
def test_alice_refuses_to_select_node_unless_ursula_is_valid(
|
||||
alice, idle_policy, ursulas
|
||||
):
|
||||
|
||||
Vladimir.network_middleware = EvilMiddleWare(eth_endpoint=MOCK_ETH_PROVIDER_URI)
|
||||
target = list(ursulas)[2]
|
||||
# First, let's imagine that Alice has sampled a Vladimir while making this policy.
|
||||
vladimir = Vladimir.from_target_ursula(target,
|
||||
|
@ -117,6 +119,9 @@ def test_alice_refuses_to_select_node_unless_ursula_is_valid(
|
|||
alice.known_nodes.record_node(vladimir)
|
||||
alice.known_nodes.record_fleet_state()
|
||||
|
||||
# unmock the ping endpoint on mock rest middleware for this test.
|
||||
MockRestMiddleware.ping = RestMiddleware.ping
|
||||
|
||||
with pytest.raises(vladimir.InvalidNode):
|
||||
idle_policy._ping_node(
|
||||
address=vladimir.checksum_address,
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ def _determine_good_serials(start, end):
|
|||
for i in range(start, end):
|
||||
try:
|
||||
NotAPublicKey.from_int(i).i_want_to_be_a_real_boy()
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
continue
|
||||
else:
|
||||
good_serials.append(i)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from pathlib import Path
|
||||
|
||||
import maya
|
||||
import os
|
||||
import pytest
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
|
||||
import builtins
|
||||
|
||||
import pytest
|
||||
|
||||
from nucypher.exceptions import DevelopmentInstallationRequired
|
||||
|
@ -49,7 +50,7 @@ def test_use_vladimir_without_development_installation(import_mocker, mocker):
|
|||
del EvilMiddleWare
|
||||
|
||||
with import_mocker:
|
||||
from nucypher.characters.unlawful import Vladimir # Import OK
|
||||
from nucypher.characters.unlawful import Vladimir # Import OK
|
||||
with pytest.raises(DevelopmentInstallationRequired, match=message): # Expect lazy failure
|
||||
Vladimir.from_target_ursula(target_ursula=mocker.Mock())
|
||||
|
||||
|
@ -63,7 +64,8 @@ def test_get_pyevm_backend_without_development_installation(import_mocker):
|
|||
del constants
|
||||
|
||||
with import_mocker:
|
||||
from nucypher.blockchain.eth.providers import _get_pyevm_test_backend # Import OK
|
||||
from nucypher.blockchain.eth.providers import (
|
||||
_get_pyevm_test_backend, # Import OK
|
||||
)
|
||||
with pytest.raises(DevelopmentInstallationRequired, match=message): # Expect lazy failure
|
||||
_get_pyevm_test_backend()
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ from nucypher.blockchain.eth.actors import Operator
|
|||
from nucypher.blockchain.eth.agents import ContractAgency
|
||||
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
|
||||
from nucypher.crypto.ferveo import dkg
|
||||
from nucypher.crypto.powers import TransactingPower
|
||||
from nucypher.network.nodes import Teacher
|
||||
|
|
|
@ -4,11 +4,7 @@ import unittest
|
|||
|
||||
from eth_utils import keccak
|
||||
|
||||
from nucypher.crypto.utils import (
|
||||
secure_random_range,
|
||||
secure_random,
|
||||
keccak_digest
|
||||
)
|
||||
from nucypher.crypto.utils import keccak_digest, secure_random, secure_random_range
|
||||
|
||||
|
||||
class TestCrypto(unittest.TestCase):
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
|
||||
from tests.constants import TESTERCHAIN_CHAIN_ID, TEMPORARY_DOMAIN
|
||||
from tests.constants import TEMPORARY_DOMAIN, TESTERCHAIN_CHAIN_ID
|
||||
from tests.utils.registry import MockRegistrySource
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import PropertyMock
|
|||
|
||||
import pytest
|
||||
from hexbytes import HexBytes
|
||||
from web3.exceptions import TransactionNotFound, TimeExhausted
|
||||
from web3.exceptions import TimeExhausted, TransactionNotFound
|
||||
|
||||
from tests.mock.interfaces import MockEthereumClient
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
|
||||
from unittest.mock import Mock, MagicMock
|
||||
from unittest.mock import MagicMock, Mock
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
|
||||
|
||||
import pytest
|
||||
from web3.gas_strategies import time_based
|
||||
|
||||
from constant_sorrow.constants import ALL_OF_THEM
|
||||
from web3.gas_strategies import time_based
|
||||
|
||||
from nucypher.blockchain.eth.interfaces import BlockchainInterface
|
||||
from nucypher.utilities.gas_strategies import WEB3_GAS_STRATEGIES
|
||||
|
|
|
@ -3,7 +3,7 @@ import pytest
|
|||
|
||||
import nucypher
|
||||
from nucypher.cli.main import ENTRY_POINTS, nucypher_cli
|
||||
from nucypher.config.constants import USER_LOG_DIR, DEFAULT_CONFIG_ROOT
|
||||
from nucypher.config.constants import DEFAULT_CONFIG_ROOT, USER_LOG_DIR
|
||||
|
||||
|
||||
def test_echo_nucypher_version(click_runner):
|
||||
|
|
|
@ -6,7 +6,7 @@ from statistics import median
|
|||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from constant_sorrow.constants import SLOW, MEDIUM, FAST, FASTEST
|
||||
from constant_sorrow.constants import FAST, FASTEST, MEDIUM, SLOW
|
||||
from requests.exceptions import ConnectionError
|
||||
from web3 import Web3
|
||||
|
||||
|
@ -15,11 +15,10 @@ from nucypher.utilities.datafeeds import (
|
|||
EtherchainGasPriceDatafeed,
|
||||
EthereumGasPriceDatafeed,
|
||||
UpvestGasPriceDatafeed,
|
||||
ZoltuGasPriceDatafeed
|
||||
ZoltuGasPriceDatafeed,
|
||||
)
|
||||
from nucypher.utilities.gas_strategies import construct_datafeed_median_strategy
|
||||
|
||||
|
||||
etherchain_json = {
|
||||
"safeLow": "99.0",
|
||||
"standard": "105.0",
|
||||
|
@ -204,7 +203,6 @@ def test_zoltu():
|
|||
|
||||
def test_datafeed_median_gas_price_strategy():
|
||||
|
||||
mock_etherchain_gas_price = 1000
|
||||
mock_upvest_gas_price = 2000
|
||||
mock_zoltu_gas_price = 4000
|
||||
mock_rpc_gas_price = 42
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from nucypher.blockchain.eth.decorators import InvalidChecksumAddress, validate_checksum_address
|
||||
from nucypher.blockchain.eth.decorators import (
|
||||
InvalidChecksumAddress,
|
||||
validate_checksum_address,
|
||||
)
|
||||
|
||||
|
||||
def test_validate_checksum_address(get_random_checksum_address):
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
|
||||
import itertools
|
||||
|
||||
import pytest
|
||||
from web3 import Web3
|
||||
|
||||
from nucypher.utilities.gas_strategies import (
|
||||
construct_fixed_price_gas_strategy,
|
||||
max_price_gas_strategy_wrapper,
|
||||
GasStrategyError
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ from io import StringIO
|
|||
from json.encoder import py_encode_basestring_ascii
|
||||
|
||||
import pytest
|
||||
from twisted.logger import Logger as TwistedLogger, formatEvent, jsonFileLogObserver
|
||||
from twisted.logger import Logger as TwistedLogger
|
||||
from twisted.logger import formatEvent, jsonFileLogObserver
|
||||
|
||||
from nucypher.utilities.logging import Logger
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@ from unittest.mock import Mock
|
|||
|
||||
import pytest
|
||||
from requests import HTTPError
|
||||
from web3.types import RPCResponse, RPCError, RPCEndpoint
|
||||
from web3.types import RPCEndpoint, RPCError, RPCResponse
|
||||
|
||||
from nucypher.blockchain.middleware.retry import (
|
||||
RetryRequestMiddleware,
|
||||
AlchemyRetryRequestMiddleware,
|
||||
InfuraRetryRequestMiddleware
|
||||
InfuraRetryRequestMiddleware,
|
||||
RetryRequestMiddleware,
|
||||
)
|
||||
from tests.constants import RPC_TOO_MANY_REQUESTS, RPC_SUCCESSFUL_RESPONSE
|
||||
from tests.constants import RPC_SUCCESSFUL_RESPONSE, RPC_TOO_MANY_REQUESTS
|
||||
|
||||
RETRY_REQUEST_CLASSES = (RetryRequestMiddleware, AlchemyRetryRequestMiddleware, InfuraRetryRequestMiddleware)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from eth_typing import ChecksumAddress
|
||||
from typing import List
|
||||
|
||||
from eth_typing import ChecksumAddress
|
||||
|
||||
from nucypher.blockchain.eth.registry import ContractRegistry
|
||||
from nucypher.characters.lawful import Ursula
|
||||
from nucypher.config.characters import (
|
||||
|
|
|
@ -161,6 +161,12 @@ class NodeIsDownMiddleware(MockRestMiddleware):
|
|||
def all_nodes_down(self):
|
||||
self.client.ports_that_are_down = set(MOCK_KNOWN_URSULAS_CACHE)
|
||||
|
||||
def ping(self, node, *args, **kwargs):
|
||||
if node.rest_interface.port in self.client.ports_that_are_down:
|
||||
raise ConnectionRefusedError
|
||||
else:
|
||||
return Response(node.rest_interface.host, status=200)
|
||||
|
||||
|
||||
class EvilMiddleWare(MockRestMiddleware):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue