From 1ea14e514b9ceb44661991317751ae5c77eafc46 Mon Sep 17 00:00:00 2001 From: jMyles Date: Fri, 6 Apr 2018 19:26:13 -0700 Subject: [PATCH] Switching to maya for most DT things. --- nkms/policy/models.py | 12 ++++++------ tests/characters/test_alice_can_grant_and_revoke.py | 3 ++- tests/fixtures.py | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/nkms/policy/models.py b/nkms/policy/models.py index 734a37e52..af60f1afc 100644 --- a/nkms/policy/models.py +++ b/nkms/policy/models.py @@ -47,16 +47,16 @@ class Arrangement(BlockchainArrangement): self.kfrag = kfrag self.ursula = ursula - arrangement_delta = datetime.utcnow() - self.expiration - policy_duration = arrangement_delta.hours // 24 + arrangement_delta = maya.now() - self.expiration + policy_duration = arrangement_delta.days - super().__init__(author=self.alice.address, miner=self.ursula.address, + super().__init__(author=self.alice, miner=ursula, value=self.deposit, periods=policy_duration, arrangement_id=self._make_arrangement_id()) def __bytes__(self): return bytes(self.alice.stamp) + bytes( - self.hrac) + self.expiration.isoformat().encode() + bytes( + self.hrac) + self.expiration.iso8601().encode() + bytes( self.deposit) @staticmethod @@ -82,7 +82,7 @@ class Arrangement(BlockchainArrangement): # Publish arrangement to blockchain # TODO Determine actual gas price here # TODO Negotiate the receipt of a KFrag per Ursula - super().publish(gas_price=0) + # super().publish(gas_price=0) def encrypt_payload_for_ursula(self): """ @@ -268,7 +268,7 @@ class Policy(object): for ursula, arrangement, result in found_ursulas: if result.was_accepted: # TODO: Here, we need to assess the result and see if we're actually good to go. kfrag = self.assign_kfrag_to_arrangement(arrangement) - arrangement.activate(kfrag, ursula, result) + arrangement.publish(kfrag, ursula, result) # TODO: What if there weren't enough Arrangements approved to distribute n kfrags? We need to raise NotEnoughQualifiedUrsulas. diff --git a/tests/characters/test_alice_can_grant_and_revoke.py b/tests/characters/test_alice_can_grant_and_revoke.py index 60c9891c3..9a6a61c22 100644 --- a/tests/characters/test_alice_can_grant_and_revoke.py +++ b/tests/characters/test_alice_can_grant_and_revoke.py @@ -10,11 +10,12 @@ from bytestring_splitter import BytestringSplitter from tests.utilities import MockNetworkyStuff from umbral.fragments import KFrag from umbral.keys import UmbralPublicKey +import maya def test_grant(alice, bob, ursulas): networky_stuff = MockNetworkyStuff(ursulas) - policy_end_datetime = datetime.datetime.now() + datetime.timedelta(days=5) + policy_end_datetime = maya.now() + datetime.timedelta(days=5) n = 5 uri = b"this_is_the_path_to_which_access_is_being_granted" policy = alice.grant(bob, uri, networky_stuff, m=3, n=n, diff --git a/tests/fixtures.py b/tests/fixtures.py index 6dcd80dfd..4a4298358 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -13,6 +13,7 @@ from sqlalchemy.engine import create_engine from nkms.keystore import keystore from nkms.keystore.db import Base from umbral import pre +import maya @pytest.fixture(scope="module") @@ -36,7 +37,7 @@ def idle_policy(alice, bob): def enacted_policy(idle_policy, ursulas): # Alice has a policy in mind and knows of enough qualifies Ursulas; she crafts an offer for them. deposit = constants.NON_PAYMENT - contract_end_datetime = datetime.datetime.now() + datetime.timedelta(days=5) + contract_end_datetime = maya.now() + datetime.timedelta(days=5) # contract = Contract(idle_policy.n, deposit, contract_end_datetime) networky_stuff = MockNetworkyStuff(ursulas)