Handle geth --dev process as a fixture to stop when finished. Additional test bug fixes, found missing assertions.

pull/1040/head
Kieran R. Prasch 2019-05-31 09:15:47 -07:00 committed by Kieran Prasch
parent f9d9346c0f
commit e74ba944f8
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
4 changed files with 27 additions and 15 deletions

View File

@ -350,8 +350,8 @@ class NuCypherGethDevProcess(NuCypherGethProcess):
def start(self, timeout: int = 30, extra_delay: int = 1): def start(self, timeout: int = 30, extra_delay: int = 1):
self.log.info("STARTING GETH DEV NOW") self.log.info("STARTING GETH DEV NOW")
BaseGethProcess.start(self) # <--- START GETH BaseGethProcess.start(self) # <--- START GETH
time.sleep(extra_delay) # give it a second
self.wait_for_ipc(timeout=timeout) self.wait_for_ipc(timeout=timeout)
time.sleep(extra_delay)
class NuCypherGethDevnetProcess(NuCypherGethProcess): class NuCypherGethDevnetProcess(NuCypherGethProcess):

View File

@ -107,11 +107,10 @@ def test_ganache_web3_client():
assert interface.is_local assert interface.is_local
def test_geth_EIP_191_client_signature_integration(): def test_geth_EIP_191_client_signature_integration(geth_dev_node):
# Start a geth process # Start a geth process
geth = NuCypherGethDevProcess() blockchain = Blockchain.connect(provider_process=geth_dev_node, sync=False)
blockchain = Blockchain.connect(provider_process=geth, sync=False)
# Sign a message (RPC) and verify it. # Sign a message (RPC) and verify it.
etherbase = blockchain.interface.accounts[0] etherbase = blockchain.interface.accounts[0]

View File

@ -32,6 +32,7 @@ from umbral.signing import Signer
from nucypher.blockchain.economics import TokenEconomics, SlashingEconomics from nucypher.blockchain.economics import TokenEconomics, SlashingEconomics
from nucypher.blockchain.eth.agents import NucypherTokenAgent from nucypher.blockchain.eth.agents import NucypherTokenAgent
from nucypher.blockchain.eth.clients import NuCypherGethDevProcess
from nucypher.blockchain.eth.deployers import (NucypherTokenDeployer, from nucypher.blockchain.eth.deployers import (NucypherTokenDeployer,
MinerEscrowDeployer, MinerEscrowDeployer,
PolicyManagerDeployer, PolicyManagerDeployer,
@ -438,12 +439,13 @@ def blockchain_ursulas(three_agents, ursula_decentralized_test_config):
for ursula_to_learn_about in _ursulas: for ursula_to_learn_about in _ursulas:
ursula_to_teach.remember_node(ursula_to_learn_about) ursula_to_teach.remember_node(ursula_to_learn_about)
# TODO: #1035 - Move non-staking Ursulas to a new fixture
# This one is not going to stake # This one is not going to stake
_non_staking_ursula = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config, _non_staking_ursula = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config,
ether_addresses=[the_last_ursula], ether_addresses=[the_last_ursula],
stake=False) stake=False)
# _ursulas.extend(_non_staking_ursula) _ursulas.extend(_non_staking_ursula)
yield _ursulas yield _ursulas
@ -546,3 +548,14 @@ def _mock_ursula_reencrypts(ursula, corrupt_cfrag: bool = False):
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def mock_ursula_reencrypts(): def mock_ursula_reencrypts():
return _mock_ursula_reencrypts return _mock_ursula_reencrypts
@pytest.fixture(scope='session')
def geth_dev_node():
geth = NuCypherGethDevProcess()
try:
yield geth
finally:
if geth.is_running:
geth.stop()
assert not geth.is_running

View File

@ -48,11 +48,11 @@ def test_emit_warning_upon_new_version(ursula_federated_test_config, caplog):
ursula_config=ursula_federated_test_config, ursula_config=ursula_federated_test_config,
quantity=2, quantity=2,
know_each_other=True) know_each_other=True)
learner = lonely_ursula_maker().pop() learner = lonely_ursula_maker().pop()
teacher, new_node = lonely_ursula_maker() teacher, new_node = lonely_ursula_maker()
new_node.TEACHER_VERSION = learner.LEARNER_VERSION + 1 new_node.TEACHER_VERSION = learner.LEARNER_VERSION + 1
learner._current_teacher_node = teacher learner._current_teacher_node = teacher
warnings = [] warnings = []
@ -62,25 +62,25 @@ def test_emit_warning_upon_new_version(ursula_federated_test_config, caplog):
warnings.append(event) warnings.append(event)
globalLogPublisher.addObserver(warning_trapper) globalLogPublisher.addObserver(warning_trapper)
learner.learn_from_teacher_node() learner.learn_from_teacher_node()
assert len(warnings) == 1 assert len(warnings) == 1
#TODO: Why no assert? Is this in progress? assert warnings[0]['log_format'] == learner.unknown_version_message.format(new_node,
warnings[0]['log_format'] == learner.unknown_version_message.format(new_node, new_node.TEACHER_VERSION, new_node.TEACHER_VERSION,
learner.LEARNER_VERSION) learner.LEARNER_VERSION)
# Now let's go a little further: make the version totally unrecognizable. # Now let's go a little further: make the version totally unrecognizable.
crazy_bytes_representation = int(learner.LEARNER_VERSION + 1).to_bytes(2, crazy_bytes_representation = int(learner.LEARNER_VERSION + 1).to_bytes(2, byteorder="big") \
byteorder="big") + b"totally unintelligible nonsense" + b"totally unintelligible nonsense"
Response = namedtuple("MockResponse", ("content", "status_code")) Response = namedtuple("MockResponse", ("content", "status_code"))
response = Response(content=crazy_bytes_representation, status_code=200) response = Response(content=crazy_bytes_representation, status_code=200)
learner.network_middleware.get_nodes_via_rest = lambda *args, **kwargs: response learner.network_middleware.get_nodes_via_rest = lambda *args, **kwargs: response
learner.learn_from_teacher_node() learner.learn_from_teacher_node()
assert len(warnings) == 2 assert len(warnings) == 2
# TODO: Why no assert? Is this in progress? assert warnings[1]['log_format'] == learner.unknown_version_message.format(new_node,
warnings[1]['log_format'] == learner.unknown_version_message.format(new_node, new_node.TEACHER_VERSION, new_node.TEACHER_VERSION,
learner.LEARNER_VERSION) learner.LEARNER_VERSION)
globalLogPublisher.removeObserver(warning_trapper) globalLogPublisher.removeObserver(warning_trapper)