mirror of https://github.com/nucypher/nucypher.git
Separating blockchain Alice from regular ole' Alice. Style touch-ups.
parent
d8a5a4a110
commit
a88052c9a2
|
@ -442,7 +442,8 @@ class TreasureMap:
|
||||||
self.m = map_in_the_clear[0]
|
self.m = map_in_the_clear[0]
|
||||||
self.node_ids = self.node_id_splitter.repeat(map_in_the_clear[1:], as_set=True)
|
self.node_ids = self.node_id_splitter.repeat(map_in_the_clear[1:], as_set=True)
|
||||||
else:
|
else:
|
||||||
raise self.InvalidPublicSignature("This TreasureMap does not contain the correct signature from Alice to Bob.")
|
raise self.InvalidPublicSignature(
|
||||||
|
"This TreasureMap does not contain the correct signature from Alice to Bob.")
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return bytes(self) == bytes(other)
|
return bytes(self) == bytes(other)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from apistar.test import TestClient
|
||||||
|
|
||||||
from nucypher.characters import Ursula
|
from nucypher.characters import Ursula
|
||||||
from nucypher.crypto.api import keccak_digest
|
from nucypher.crypto.api import keccak_digest
|
||||||
from nucypher.crypto.powers import SigningPower, EncryptingPower
|
from nucypher.crypto.powers import SigningPower, EncryptingPower, CryptoPower
|
||||||
from tests.utilities import _ALL_URSULAS
|
from tests.utilities import _ALL_URSULAS
|
||||||
from umbral.fragments import KFrag
|
from umbral.fragments import KFrag
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ def test_grant(alice, bob, three_agents):
|
||||||
_token_agent, _miner_agent, policy_agent = three_agents
|
_token_agent, _miner_agent, policy_agent = three_agents
|
||||||
|
|
||||||
policy_agent.blockchain.wait_for_receipt = MockPolicyCreation.wait_for_receipt
|
policy_agent.blockchain.wait_for_receipt = MockPolicyCreation.wait_for_receipt
|
||||||
|
|
||||||
policy_agent.contract.functions.createPolicy = MockPolicyCreation
|
policy_agent.contract.functions.createPolicy = MockPolicyCreation
|
||||||
|
|
||||||
policy = alice.grant(bob, label, m=2, n=n,
|
policy = alice.grant(bob, label, m=2, n=n,
|
||||||
|
|
|
@ -46,7 +46,8 @@ def test_bob_already_knows_all_nodes_in_treasure_map(enacted_federated_policy, u
|
||||||
|
|
||||||
|
|
||||||
@pytest_twisted.inlineCallbacks
|
@pytest_twisted.inlineCallbacks
|
||||||
def test_bob_can_follow_treasure_map_even_if_he_only_knows_of_one_node(enacted_federated_policy, bob,
|
def test_bob_can_follow_treasure_map_even_if_he_only_knows_of_one_node(enacted_federated_policy,
|
||||||
|
bob,
|
||||||
ursulas):
|
ursulas):
|
||||||
"""
|
"""
|
||||||
Similar to above, but this time, we'll show that if Bob can connect to a single node, he can
|
Similar to above, but this time, we'll show that if Bob can connect to a single node, he can
|
||||||
|
@ -82,12 +83,13 @@ def test_bob_can_follow_treasure_map_even_if_he_only_knows_of_one_node(enacted_f
|
||||||
assert len(bob._known_nodes) == 1
|
assert len(bob._known_nodes) == 1
|
||||||
|
|
||||||
# Now, we'll start his learning loop.
|
# Now, we'll start his learning loop.
|
||||||
bob.start_learning()
|
bob.start_learning_loop()
|
||||||
|
|
||||||
# ...and block until the unknown_nodes have all been found.
|
# ...and block until the unknown_nodes have all been found.
|
||||||
yield threads.deferToThread(bob.block_until_nodes_are_known, unknown_nodes)
|
yield threads.deferToThread(bob.block_until_nodes_are_known, unknown_nodes)
|
||||||
|
|
||||||
# ...and he now has no more unknown_nodes.
|
# ...and he now has no more unknown_nodes.
|
||||||
|
print(len(bob._known_nodes))
|
||||||
assert len(bob._known_nodes) == len(treasure_map)
|
assert len(bob._known_nodes) == len(treasure_map)
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,9 +106,9 @@ def test_bob_can_issue_a_work_order_to_a_specific_ursula(enacted_federated_polic
|
||||||
# We pick up our story with Bob already having followed the treasure map above, ie:
|
# We pick up our story with Bob already having followed the treasure map above, ie:
|
||||||
hrac, treasure_map = enacted_federated_policy.hrac(), enacted_federated_policy.treasure_map
|
hrac, treasure_map = enacted_federated_policy.hrac(), enacted_federated_policy.treasure_map
|
||||||
bob.treasure_maps[hrac] = treasure_map
|
bob.treasure_maps[hrac] = treasure_map
|
||||||
bob.start_learning()
|
bob.start_learning_loop()
|
||||||
|
|
||||||
bob.follow_treasure_map(hrac, block=True)
|
bob.follow_treasure_map(hrac, block=True, timeout=1000)
|
||||||
|
|
||||||
assert len(bob._known_nodes) == len(ursulas)
|
assert len(bob._known_nodes) == len(ursulas)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import logging
|
||||||
from os.path import abspath, dirname
|
from os.path import abspath, dirname
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -86,13 +87,12 @@ def enacted_federated_policy(idle_federated_policy, ursulas):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def idle_blockchain_policy(alice, bob):
|
def idle_blockchain_policy(blockchain_alice, bob):
|
||||||
"""
|
"""
|
||||||
Creates a Policy, in a manner typical of how Alice might do it, with a unique uri (soon to be "label" - see #183)
|
Creates a Policy, in a manner typical of how Alice might do it, with a unique uri (soon to be "label" - see #183)
|
||||||
"""
|
"""
|
||||||
n = int(constants.NUMBER_OF_URSULAS_IN_NETWORK)
|
|
||||||
random_label = b'label://' + os.urandom(32)
|
random_label = b'label://' + os.urandom(32)
|
||||||
policy = alice.create_policy(bob, label=random_label, m=3, n=n)
|
policy = blockchain_alice.create_policy(bob, label=random_label, m=2, n=3)
|
||||||
return policy
|
return policy
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,12 +115,8 @@ def enacted_blockchain_policy(idle_blockchain_policy, ursulas):
|
||||||
#
|
#
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def alice(ursulas, three_agents):
|
def alice(ursulas):
|
||||||
token_agent, miner_agent, policy_agent = three_agents
|
|
||||||
etherbase, alice, bob, *everyone_else = token_agent.blockchain.interface.w3.eth.accounts
|
|
||||||
|
|
||||||
alice = Alice(network_middleware=MockRestMiddleware(),
|
alice = Alice(network_middleware=MockRestMiddleware(),
|
||||||
policy_agent=policy_agent,
|
|
||||||
known_nodes=ursulas,
|
known_nodes=ursulas,
|
||||||
federated_only=True,
|
federated_only=True,
|
||||||
abort_on_learning_error=True)
|
abort_on_learning_error=True)
|
||||||
|
@ -129,6 +125,21 @@ def alice(ursulas, three_agents):
|
||||||
return alice
|
return alice
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def blockchain_alice(mining_ursulas, three_agents):
|
||||||
|
token_agent, miner_agent, policy_agent = three_agents
|
||||||
|
etherbase, alice_address, bob_address, *everyone_else = token_agent.blockchain.interface.w3.eth.accounts
|
||||||
|
|
||||||
|
alice = Alice(network_middleware=MockRestMiddleware(),
|
||||||
|
policy_agent=policy_agent,
|
||||||
|
known_nodes=mining_ursulas,
|
||||||
|
abort_on_learning_error=True,
|
||||||
|
checksum_address=alice_address)
|
||||||
|
# alice.recruit = lambda *args, **kwargs: [u._ether_address for u in ursulas]
|
||||||
|
|
||||||
|
return alice
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def bob():
|
def bob():
|
||||||
_bob = Bob(network_middleware=MockRestMiddleware(),
|
_bob = Bob(network_middleware=MockRestMiddleware(),
|
||||||
|
|
|
@ -3,8 +3,10 @@ import asyncio
|
||||||
import pytest
|
import pytest
|
||||||
from kademlia.utils import digest
|
from kademlia.utils import digest
|
||||||
|
|
||||||
|
from nucypher.characters import Ursula
|
||||||
from nucypher.crypto.api import keccak_digest
|
from nucypher.crypto.api import keccak_digest
|
||||||
from tests.utilities import MockRestMiddleware
|
from nucypher.crypto.powers import CryptoPower, SigningPower
|
||||||
|
from tests.utilities import MockRestMiddleware, MockArrangement
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('testerchain')
|
@pytest.mark.usefixtures('testerchain')
|
||||||
|
|
Loading…
Reference in New Issue