mirror of https://github.com/nucypher/nucypher.git
Test started being fixed (unfinished yet)
parent
9d9cdb9df1
commit
baf964e83e
|
@ -4,26 +4,19 @@ from base64 import b64encode
|
|||
import maya
|
||||
import pytest
|
||||
|
||||
from nucypher.characters.control.controllers import JSONRPCController, AliceJSONController, BobJSONController, \
|
||||
EnricoJSONController
|
||||
from nucypher.characters.lawful import Enrico
|
||||
|
||||
|
||||
#
|
||||
# HTTP
|
||||
#
|
||||
from nucypher.crypto.powers import DecryptingPower
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def alice_web_controller_test_client(federated_alice):
|
||||
web_controller = federated_alice.make_web_controller(crash_on_error=True)
|
||||
def alice_web_controller_test_client(blockchain_alice):
|
||||
web_controller = blockchain_alice.make_web_controller(crash_on_error=True)
|
||||
yield web_controller.test_client()
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def bob_web_controller_test_client(federated_bob):
|
||||
web_controller = federated_bob.make_web_controller(crash_on_error=True)
|
||||
def bob_web_controller_test_client(blockchain_bob):
|
||||
web_controller = blockchain_bob.make_web_controller(crash_on_error=True)
|
||||
yield web_controller.test_client()
|
||||
|
||||
|
||||
|
@ -35,8 +28,8 @@ def enrico_web_controller_test_client(capsule_side_channel):
|
|||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def enrico_web_controller_from_alice(federated_alice, random_policy_label):
|
||||
enrico = Enrico.from_alice(federated_alice, random_policy_label)
|
||||
def enrico_web_controller_from_alice(blockchain_alice, random_policy_label):
|
||||
enrico = Enrico.from_alice(blockchain_alice, random_policy_label)
|
||||
web_controller = enrico.make_web_controller(crash_on_error=True)
|
||||
yield web_controller.test_client()
|
||||
|
||||
|
@ -46,14 +39,14 @@ def enrico_web_controller_from_alice(federated_alice, random_policy_label):
|
|||
#
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def alice_rpc_test_client(federated_alice):
|
||||
rpc_controller = federated_alice.make_rpc_controller(crash_on_error=True)
|
||||
def alice_rpc_test_client(blockchain_alice):
|
||||
rpc_controller = blockchain_alice.make_rpc_controller(crash_on_error=True)
|
||||
yield rpc_controller.test_client()
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def bob_rpc_controller(federated_bob):
|
||||
rpc_controller = federated_bob.make_rpc_controller(crash_on_error=True)
|
||||
def bob_rpc_controller(blockchain_bob):
|
||||
rpc_controller = blockchain_bob.make_rpc_controller(crash_on_error=True)
|
||||
yield rpc_controller.test_client()
|
||||
|
||||
|
||||
|
@ -69,62 +62,66 @@ def enrico_rpc_controller_test_client(capsule_side_channel):
|
|||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def enrico_rpc_controller_from_alice(federated_alice, random_policy_label):
|
||||
enrico = Enrico.from_alice(federated_alice, random_policy_label)
|
||||
def enrico_rpc_controller_from_alice(blockchain_alice, random_policy_label):
|
||||
enrico = Enrico.from_alice(blockchain_alice, random_policy_label)
|
||||
rpc_controller = enrico.make_rpc_controller(crash_on_error=True)
|
||||
yield rpc_controller.test_client()
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def create_policy_control_request(federated_bob):
|
||||
def create_policy_control_request(blockchain_bob):
|
||||
method_name = 'create_policy'
|
||||
bob_pubkey_enc = federated_bob.public_keys(DecryptingPower)
|
||||
bob_pubkey_enc = blockchain_bob.public_keys(DecryptingPower)
|
||||
params = {
|
||||
'bob_encrypting_key': bytes(bob_pubkey_enc).hex(),
|
||||
'bob_verifying_key': bytes(federated_bob.stamp).hex(),
|
||||
'bob_verifying_key': bytes(blockchain_bob.stamp).hex(),
|
||||
'label': b64encode(bytes(b'test')).decode(),
|
||||
'm': 2,
|
||||
'n': 3,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=3)).iso8601(),
|
||||
'value': 3 * 3 * 10 ** 16,
|
||||
'first_period_reward': 4242
|
||||
}
|
||||
return method_name, params
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def grant_control_request(federated_bob):
|
||||
def grant_control_request(blockchain_bob):
|
||||
method_name = 'grant'
|
||||
bob_pubkey_enc = federated_bob.public_keys(DecryptingPower)
|
||||
bob_pubkey_enc = blockchain_bob.public_keys(DecryptingPower)
|
||||
params = {
|
||||
'bob_encrypting_key': bytes(bob_pubkey_enc).hex(),
|
||||
'bob_verifying_key': bytes(federated_bob.stamp).hex(),
|
||||
'bob_verifying_key': bytes(blockchain_bob.stamp).hex(),
|
||||
'label': 'test',
|
||||
'm': 2,
|
||||
'n': 3,
|
||||
'expiration': (maya.now() + datetime.timedelta(days=3)).iso8601(),
|
||||
'value': 3 * 3 * 10 ** 16,
|
||||
'first_period_reward': 4242
|
||||
}
|
||||
return method_name, params
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def join_control_request(federated_bob, enacted_federated_policy):
|
||||
def join_control_request(blockchain_bob, enacted_blockchain_policy):
|
||||
method_name = 'join_policy'
|
||||
|
||||
params = {
|
||||
'label': enacted_federated_policy.label.decode(),
|
||||
'alice_verifying_key': bytes(enacted_federated_policy.alice.stamp).hex(),
|
||||
'label': enacted_blockchain_policy.label.decode(),
|
||||
'alice_verifying_key': bytes(enacted_blockchain_policy.alice.stamp).hex(),
|
||||
}
|
||||
return method_name, params
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def retrieve_control_request(federated_bob, enacted_federated_policy, capsule_side_channel):
|
||||
def retrieve_control_request(blockchain_bob, enacted_blockchain_policy, capsule_side_channel):
|
||||
method_name = 'retrieve'
|
||||
message_kit, data_source = capsule_side_channel()
|
||||
|
||||
params = {
|
||||
'label': enacted_federated_policy.label.decode(),
|
||||
'policy_encrypting_key': bytes(enacted_federated_policy.public_key).hex(),
|
||||
'alice_verifying_key': bytes(enacted_federated_policy.alice.stamp).hex(),
|
||||
'label': enacted_blockchain_policy.label.decode(),
|
||||
'policy_encrypting_key': bytes(enacted_blockchain_policy.public_key).hex(),
|
||||
'alice_verifying_key': bytes(enacted_blockchain_policy.alice.stamp).hex(),
|
||||
'message_kit': b64encode(message_kit.to_bytes()).decode(),
|
||||
}
|
||||
return method_name, params
|
||||
|
|
|
@ -251,11 +251,12 @@ def idle_blockchain_policy(blockchain_alice, blockchain_bob, token_economics):
|
|||
Creates a Policy, in a manner typical of how Alice might do it, with a unique label
|
||||
"""
|
||||
random_label = generate_random_label()
|
||||
expiration = maya.now().add(days=token_economics.minimum_locked_periods//2)
|
||||
days = token_economics.minimum_locked_periods // 2
|
||||
expiration = maya.now().add(days=days)
|
||||
policy = blockchain_alice.create_policy(blockchain_bob,
|
||||
label=random_label,
|
||||
m=2, n=3,
|
||||
value=20*100,
|
||||
value=3*days*100,
|
||||
expiration=expiration)
|
||||
return policy
|
||||
|
||||
|
@ -263,13 +264,14 @@ def idle_blockchain_policy(blockchain_alice, blockchain_bob, token_economics):
|
|||
@pytest.fixture(scope="module")
|
||||
def enacted_blockchain_policy(idle_blockchain_policy, blockchain_ursulas):
|
||||
# Alice has a policy in mind and knows of enough qualified Ursulas; she crafts an offer for them.
|
||||
deposit = NON_PAYMENT(b"0000000")
|
||||
contract_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
|
||||
# value and expiration were set when creating idle_blockchain_policy already
|
||||
# cannot set them again
|
||||
# deposit = NON_PAYMENT(b"0000000")
|
||||
# contract_end_datetime = maya.now() + datetime.timedelta(days=5)
|
||||
network_middleware = MockRestMiddleware()
|
||||
|
||||
idle_blockchain_policy.make_arrangements(network_middleware,
|
||||
value=deposit,
|
||||
expiration=contract_end_datetime,
|
||||
ursulas=list(blockchain_ursulas))
|
||||
|
||||
idle_blockchain_policy.enact(network_middleware) # REST call happens here, as does population of TreasureMap.
|
||||
|
|
Loading…
Reference in New Issue