From c728c1afe0dde15da2973461dbfa45b8006a0524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Tue, 11 Jun 2019 02:33:29 +0200 Subject: [PATCH] Introduce simple PRE lifecycle test with blockchain ursulas --- ...t_ursula_prepares_to_act_as_mining_node.py | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/tests/characters/test_ursula_prepares_to_act_as_mining_node.py b/tests/characters/test_ursula_prepares_to_act_as_mining_node.py index 6cf325ac9..6d51be0e6 100644 --- a/tests/characters/test_ursula_prepares_to_act_as_mining_node.py +++ b/tests/characters/test_ursula_prepares_to_act_as_mining_node.py @@ -14,16 +14,16 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with nucypher. If not, see . """ +import datetime +import maya import pytest from eth_account._utils.signing import to_standard_signature_bytes -from eth_keys.datatypes import Signature as EthSignature -from nucypher.blockchain.eth.clients import Web3Client -from nucypher.characters.lawful import Ursula +from nucypher.characters.lawful import Enrico from nucypher.characters.unlawful import Vladimir from nucypher.crypto.api import verify_eip_191 -from nucypher.crypto.powers import SigningPower, CryptoPower +from nucypher.crypto.powers import SigningPower from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD from nucypher.utilities.sandbox.middleware import MockRestMiddleware from nucypher.utilities.sandbox.ursula import make_federated_ursulas, make_decentralized_ursulas @@ -137,3 +137,34 @@ def test_vladimir_uses_his_own_signing_key(blockchain_alice, blockchain_ursulas) # However, the actual handshake proves him wrong. with pytest.raises(vladimir.InvalidNode): vladimir.verify_node(blockchain_alice.network_middleware, certificate_filepath="doesn't matter") + + +# TODO: Change name of this file +def test_blockchain_ursulas_reencrypt(blockchain_ursulas, blockchain_alice, blockchain_bob, policy_value): + + label = b'bbo' + + # TODO: Investigate issues with wiggle room and additional ursulas during sampling. See also #1061 + # 1 <= N <= 5 : OK + # N == 6 : NotEnoughBlockchainUrsulas: Cannot create policy with 6 arrangements: Selection failed after 5 attempts + # N >= 7 : NotEnoughBlockchainUrsulas: Cannot create policy with 7 arrangements: Cannot create policy with 7 arrangements: 10 stakers are available, need 11 (for wiggle room) + m = n = 5 + expiration = maya.now() + datetime.timedelta(days=5) + + _policy = blockchain_alice.grant(bob=blockchain_bob, + label=label, + m=m, + n=n, + expiration=expiration, + value=policy_value) + + enrico = Enrico.from_alice(blockchain_alice, label) + + message = b"Oh, this isn't even BO. This is beyond BO. It's BBO." + + message_kit, signature = enrico.encrypt_message(message) + + blockchain_bob.join_policy(label, bytes(blockchain_alice.stamp)) + + plaintext = blockchain_bob.retrieve(message_kit, enrico, blockchain_alice.stamp, label) + assert plaintext[0] == message \ No newline at end of file