def test_make_addresses():
    """Test making the message addresses"""
    related_id = helper.user.id()
    object_id = helper.task.id()
    proposal_id = helper.proposal.id()
    proposal_address = Task().admin.propose.address(object_id, related_id)
    reason = helper.proposal.reason()
    relationship_address = Task().admin.address(object_id, related_id)
    signer_user_id = helper.user.id()
    helper.user.key()

    user_address = User().address(related_id)
    signer_admin_address = Task().admin.address(object_id, signer_user_id)
    User().address(signer_user_id)
    message = Task().admin.confirm.make(
        proposal_id=proposal_id,
        related_id=related_id,
        object_id=object_id,
        reason=reason,
    )

    inputs, outputs = Task().admin.confirm.make_addresses(
        message=message, signer_user_id=signer_user_id)

    assert user_address in inputs
    assert signer_admin_address in inputs
    assert proposal_address in inputs
    assert relationship_address in inputs

    assert proposal_address in outputs
    assert relationship_address in outputs
Beispiel #2
0
def test_make_addresses():
    """Test the make addresses method for the message"""
    name = helper.task.name()
    task_id = helper.task.id()
    task_address = Task().address(task_id)

    next_id = helper.user.id()
    user_address = User().address(next_id)
    signer_user_id = helper.user.id()
    owner_address = Task().owner.address(task_id, next_id)
    admin_address = Task().admin.address(task_id, next_id)
    message = Task().make(
        task_id=task_id, name=name, owners=[next_id], admins=[next_id]
    )

    inputs, outputs = Task().make_addresses(
        message=message, signer_user_id=signer_user_id
    )

    assert task_address in inputs
    assert user_address in inputs
    assert owner_address in inputs
    assert admin_address in inputs

    assert task_address in outputs
    assert user_address in outputs
    assert owner_address in outputs
    assert admin_address in outputs
Beispiel #3
0
def test_create():
    """Test executing the message on the blockchain"""
    proposal, _, task_owner, task_owner_key, _, _ = helper.task.owner.propose.create(
    )

    reason = helper.task.owner.propose.reason()
    message = Task().owner.confirm.make(
        proposal_id=proposal.proposal_id,
        object_id=proposal.object_id,
        related_id=proposal.related_id,
        reason=reason,
    )

    status = Task().owner.confirm.new(
        signer_keypair=task_owner_key,
        signer_user_id=task_owner.next_id,
        message=message,
    )

    assert len(status) == 1
    assert status[0]["status"] == "COMMITTED"

    confirm = Task().owner.confirm.get(object_id=proposal.object_id,
                                       related_id=proposal.related_id)

    assert isinstance(confirm, protobuf.proposal_state_pb2.Proposal)
    assert confirm.proposal_type == protobuf.proposal_state_pb2.Proposal.ADD_TASK_OWNER
    assert confirm.proposal_id == proposal.proposal_id
    assert confirm.object_id == proposal.object_id
    assert confirm.related_id == proposal.related_id
    assert confirm.close_reason == reason
    assert confirm.closer == task_owner.next_id
    assert confirm.status == protobuf.proposal_state_pb2.Proposal.CONFIRMED
    assert Task().owner.exists(object_id=proposal.object_id,
                               related_id=proposal.related_id)
def test_make_addresses():
    """Test making the message addresses"""
    next_id = helper.user.id()
    user_address = User().address(next_id)
    task_id = helper.task.id()
    task_address = Task().address(task_id)
    proposal_id = addresser.proposal.unique_id()
    reason = helper.proposal.reason()
    relationship_address = Task().admin.address(task_id, next_id)
    proposal_address = Task().admin.propose.address(task_id, next_id)
    signer_user_id = helper.user.id()
    message = Task().admin.propose.make(
        proposal_id=proposal_id,
        next_id=next_id,
        task_id=task_id,
        reason=reason,
        metadata=None,
    )

    inputs, outputs = Task().admin.propose.make_addresses(
        message=message, signer_user_id=signer_user_id
    )

    assert relationship_address in inputs
    assert user_address in inputs
    assert task_address in inputs
    assert proposal_address in inputs

    assert proposal_address in outputs
def test_create():
    """Test executing the message on the blockchain"""
    task, _, _ = helper.task.create()
    proposal_id = addresser.proposal.unique_id()
    reason = helper.proposal.reason()
    user, signer_keypair = helper.user.create()
    message = Task().admin.propose.make(
        proposal_id=proposal_id,
        next_id=user.next_id,
        task_id=task.task_id,
        reason=reason,
        metadata=None,
    )

    status = Task().admin.propose.new(
        signer_keypair=signer_keypair, signer_user_id=user.next_id, message=message
    )

    assert len(status) == 1
    assert status[0]["status"] == "COMMITTED"

    proposal = Task().admin.propose.get(object_id=task.task_id, related_id=user.next_id)

    assert isinstance(proposal, protobuf.proposal_state_pb2.Proposal)
    assert proposal.proposal_type == protobuf.proposal_state_pb2.Proposal.ADD_TASK_ADMIN
    assert proposal.proposal_id == proposal_id
    assert proposal.object_id == task.task_id
    assert proposal.related_id == user.next_id
    assert proposal.opener == user.next_id
    assert proposal.open_reason == reason
    def create(self):
        """Create a test task"""
        task_id = self.id()
        name = self.name()
        user, keypair = helper.user.create()
        message = Task().make(task_id=task_id,
                              name=name,
                              owners=[user.next_id],
                              admins=[user.next_id])

        status = Task().new(signer_keypair=keypair,
                            signer_user_id=user.next_id,
                            message=message)

        assert len(status) == 1
        assert status[0]["status"] == "COMMITTED"

        task = Task().get(object_id=message.task_id)

        assert task.task_id == message.task_id
        assert task.name == message.name
        assert Task().owner.exists(object_id=task.task_id,
                                   related_id=user.next_id)
        assert Task().admin.exists(object_id=task.task_id,
                                   related_id=user.next_id)
        return task, user, keypair
Beispiel #7
0
def test_make_addresses():
    """Test making the message addresses"""
    related_id = helper.user.id()
    object_id = helper.task.id()
    proposal_id = helper.proposal.id()
    proposal_address = Task().owner.propose.address(object_id, related_id)
    reason = helper.proposal.reason()
    signer_user_id = helper.user.id()
    signer_admin_address = Task().admin.address(object_id, signer_user_id)
    signer_owner_address = Task().owner.address(object_id, signer_user_id)
    message = Task().owner.reject.make(
        proposal_id=proposal_id,
        related_id=related_id,
        object_id=object_id,
        reason=reason,
    )

    inputs, outputs = Task().owner.reject.make_addresses(
        message=message, signer_user_id=signer_user_id
    )

    assert proposal_address in inputs
    assert signer_admin_address in inputs
    assert signer_owner_address in inputs

    assert proposal_address in outputs
def test_create():
    """Test executing the message on the blockchain"""
    proposal, _, task_admin, task_admin_key, _, _ = helper.task.admin.propose.create(
    )

    reason = helper.task.admin.propose.reason()
    message = Task().admin.reject.make(
        proposal_id=proposal.proposal_id,
        object_id=proposal.object_id,
        related_id=proposal.related_id,
        reason=reason,
    )

    status = Task().admin.reject.new(
        signer_keypair=task_admin_key,
        signer_user_id=task_admin.next_id,
        message=message,
        object_id=proposal.object_id,
        related_id=proposal.related_id,
    )

    assert len(status) == 1
    assert status[0]["status"] == "COMMITTED"

    reject = Task().admin.propose.get(object_id=proposal.object_id,
                                      related_id=proposal.related_id)

    assert isinstance(reject, protobuf.proposal_state_pb2.Proposal)
    assert reject.proposal_type == protobuf.proposal_state_pb2.Proposal.ADD_TASK_ADMIN
    assert reject.proposal_id == proposal.proposal_id
    assert reject.object_id == proposal.object_id
    assert reject.related_id == proposal.related_id
    assert reject.close_reason == reason
    assert reject.closer == task_admin.next_id
    assert reject.status == protobuf.proposal_state_pb2.Proposal.REJECTED
def test_make_addresses():
    """Test making the message addresses"""
    related_id = helper.task.id()
    object_id = helper.role.id()
    proposal_id = helper.proposal.id()
    proposal_address = Role().task.propose.address(object_id, related_id)
    reason = helper.proposal.reason()
    relationship_address = Role().task.address(object_id, related_id)
    signer_user_id = helper.user.id()
    task_owner_address = Task().owner.address(related_id, signer_user_id)
    message = Role().task.confirm.make(
        proposal_id=proposal_id,
        related_id=related_id,
        object_id=object_id,
        reason=reason,
    )

    inputs, outputs = Role().task.confirm.make_addresses(
        message=message, signer_user_id=signer_user_id)

    assert task_owner_address in inputs
    assert proposal_address in inputs
    assert relationship_address in inputs

    assert proposal_address in outputs
    assert relationship_address in outputs
Beispiel #10
0
def test_make_addresses():
    """Test making the message addresses"""
    task_id = helper.task.id()
    task_address = Task().address(task_id)
    role_id = helper.role.id()
    role_address = Role().address(role_id)
    proposal_id = addresser.proposal.unique_id()
    reason = helper.proposal.reason()
    relationship_address = Role().task.address(role_id, task_id)
    proposal_address = Role().task.propose.address(role_id, task_id)
    signer_user_id = helper.user.id()
    role_owner_address = Role().owner.address(role_id, signer_user_id)
    message = Role().task.propose.make(
        proposal_id=proposal_id,
        task_id=task_id,
        role_id=role_id,
        reason=reason,
        metadata=None,
    )

    inputs, outputs = Role().task.propose.make_addresses(
        message=message, signer_user_id=signer_user_id)

    assert relationship_address in inputs
    assert task_address in inputs
    assert role_address in inputs
    assert proposal_address in inputs
    assert role_owner_address in inputs

    assert proposal_address in outputs
async def add_task_owner(request, task_id):
    """Propose add a task owner."""
    log_request(request)
    required_fields = ["id"]
    validate_fields(required_fields, request.json)

    txn_key, txn_user_id = await get_transactor_key(request)
    proposal_id = str(uuid4())
    conn = await create_connection()
    approver = await fetch_relationships("task_admins", "task_id",
                                         task_id).run(conn)
    conn.close()
    batch_list = Task().owner.propose.batch_list(
        signer_keypair=txn_key,
        signer_user_id=txn_user_id,
        proposal_id=proposal_id,
        task_id=task_id,
        next_id=request.json.get("id"),
        reason=request.json.get("reason"),
        metadata=request.json.get("metadata"),
        assigned_approver=approver,
    )
    await send(request.app.config.VAL_CONN, batch_list,
               request.app.config.TIMEOUT)
    return json({"proposal_id": proposal_id})
Beispiel #12
0
def test_create_two_owners():
    """Test creating a task with two admin+owners"""
    user, keypair = helper.user.create()
    user2, _ = helper.user.create()
    name = helper.task.name()
    task_id = helper.task.id()
    message = Task().make(
        task_id=task_id,
        name=name,
        owners=[user.next_id, user2.next_id],
        admins=[user.next_id, user2.next_id],
    )

    status = Task().new(
        signer_keypair=keypair, signer_user_id=user.next_id, message=message
    )

    assert len(status) == 1
    assert status[0]["status"] == "COMMITTED"

    task = Task().get(object_id=task_id)

    assert task.task_id == message.task_id
    assert task.name == message.name
    assert Task().owner.exists(object_id=task.task_id, related_id=user.next_id)
    assert Task().admin.exists(object_id=task.task_id, related_id=user.next_id)
    assert Task().owner.exists(object_id=task.task_id, related_id=user2.next_id)
    assert Task().admin.exists(object_id=task.task_id, related_id=user2.next_id)
    def create(self):
        """A user creates an add task admin proposal
        to add themselves as an admin to a task"""
        task, task_owner, task_owner_key = helper.task.create()
        user, user_key = helper.user.create()
        proposal_id = self.id()
        reason = self.reason()
        message = Task().admin.propose.make(
            proposal_id=proposal_id,
            task_id=task.task_id,
            next_id=user.next_id,
            reason=reason,
            metadata=None,
        )

        status = Task().admin.propose.new(
            signer_keypair=user_key,
            signer_user_id=user.next_id,
            message=message,
            object_id=task.task_id,
            related_id=user.next_id,
        )

        assert len(status) == 1
        assert status[0]["status"] == "COMMITTED"

        proposal = Task().admin.propose.get(
            object_id=task.task_id, related_id=user.next_id
        )

        assert isinstance(proposal, protobuf.proposal_state_pb2.Proposal)
        assert (
            proposal.proposal_type
            == protobuf.proposal_state_pb2.Proposal.ADD_TASK_ADMIN
        )
        assert proposal.proposal_id == proposal_id
        assert proposal.object_id == task.task_id
        assert proposal.related_id == user.next_id
        assert proposal.opener == user.next_id
        assert proposal.open_reason == reason
        return proposal, task, task_owner, task_owner_key, user, user_key
 def message(self):
     """Get a test data CreateTask message"""
     task_id = self.id()
     name = self.name()
     next_id = helper.user.id()
     message = Task().make(task_id=task_id,
                           name=name,
                           owners=[next_id],
                           admins=[next_id])
     assert isinstance(message, protobuf.task_transaction_pb2.CreateTask)
     assert message.task_id == task_id
     assert message.name == name
     return message
Beispiel #15
0
 def reject_add_task_owners(self, key, proposal_id, task_id, next_id,
                            reason):
     """Reject addition of task owner."""
     batch_list = Task().owner.reject.batch_list(
         signer_keypair=key,
         signer_user_id=key.public_key,
         proposal_id=proposal_id,
         object_id=task_id,
         related_id=next_id,
         reason=reason,
     )
     batch_ids = batcher.get_batch_ids(batch_list=batch_list)
     self._client.send_batches(batch_list)
     return self._client.get_statuses(batch_ids, wait=10)
Beispiel #16
0
 def confirm_add_task_admins(self, key, proposal_id, task_id, next_id,
                             reason):
     """Confirm addition of task admin."""
     batch_list = Task().admin.confirm.batch_list(
         signer_keypair=key,
         signer_user_id=key.public_key,
         proposal_id=proposal_id,
         object_id=task_id,
         related_id=next_id,
         reason=reason,
     )
     batch_ids = batcher.get_batch_ids(batch_list=batch_list)
     self._client.send_batches(batch_list)
     return self._client.get_statuses(batch_ids, wait=10)
Beispiel #17
0
 def create_task(self, key, task_id, task_name, admins, owners, metadata):
     """Create a new task."""
     batch_list = Task().batch_list(
         signer_keypair=key,
         signer_user_id=key.public_key,
         task_id=task_id,
         name=task_name,
         admins=admins,
         owners=owners,
         metadata=metadata,
     )
     batch_ids = batcher.get_batch_ids(batch_list=batch_list)
     self._client.send_batches(batch_list)
     return self._client.get_statuses(batch_ids, wait=10)
Beispiel #18
0
def test_make():
    """Test making a message"""
    name = helper.task.name()
    task_id = helper.task.id()
    next_id = helper.user.id()
    message = Task().make(
        task_id=task_id, name=name, owners=[next_id], admins=[next_id]
    )
    assert isinstance(message, protobuf.task_transaction_pb2.CreateTask)
    assert isinstance(message.task_id, str)
    assert isinstance(message.name, str)
    assert message.task_id == task_id
    assert message.name == name
    assert message.owners == [next_id]
    assert message.admins == [next_id]
Beispiel #19
0
 def propose_add_task_owners(self, key, proposal_id, task_id, next_id,
                             reason, metadata):
     """Propose adding a task owner."""
     batch_list = Task().owner.propose.batch_list(
         signer_keypair=key,
         signer_user_id=key.public_key,
         proposal_id=proposal_id,
         task_id=task_id,
         next_id=next_id,
         reason=reason,
         metadata=metadata,
     )
     batch_ids = batcher.get_batch_ids(batch_list=batch_list)
     self._client.send_batches(batch_list)
     return self._client.get_statuses(batch_ids, wait=10)
def test_make():
    """Test making the message"""
    next_id = helper.user.id()
    task_id = helper.task.id()
    proposal_id = addresser.proposal.unique_id()
    reason = helper.proposal.reason()
    message = Task().admin.propose.make(
        proposal_id=proposal_id,
        next_id=next_id,
        task_id=task_id,
        reason=reason,
        metadata=None,
    )
    assert isinstance(message, protobuf.task_transaction_pb2.ProposeAddTaskAdmin)
    assert message.next_id == next_id
    assert message.task_id == task_id
    assert message.reason == reason
Beispiel #21
0
def test_make():
    """Test making the message"""
    related_id = helper.user.id()
    object_id = helper.task.id()
    proposal_id = helper.proposal.id()
    reason = helper.proposal.reason()
    message = Task().owner.reject.make(
        proposal_id=proposal_id,
        related_id=related_id,
        object_id=object_id,
        reason=reason,
    )
    assert isinstance(message, protobuf.proposal_transaction_pb2.UpdateProposal)
    assert message.proposal_id == proposal_id
    assert message.related_id == related_id
    assert message.object_id == object_id
    assert message.reason == reason
Beispiel #22
0
async def add_task_admin(request, task_id):
    """Propose add a task admin."""
    required_fields = ["id"]
    utils.validate_fields(required_fields, request.json)

    txn_key, txn_user_id = await utils.get_transactor_key(request)
    proposal_id = str(uuid4())
    batch_list = Task().admin.propose.batch_list(
        signer_keypair=txn_key,
        signer_user_id=txn_user_id,
        proposal_id=proposal_id,
        task_id=task_id,
        next_id=request.json.get("id"),
        reason=request.json.get("reason"),
        metadata=request.json.get("metadata"),
    )
    await utils.send(request.app.config.VAL_CONN, batch_list,
                     request.app.config.TIMEOUT)
    return json({"proposal_id": proposal_id})
async def create_new_task(request):
    """Create a new task."""
    required_fields = ["name", "administrators", "owners"]
    utils.validate_fields(required_fields, request.json)

    txn_key, txn_user_id = await utils.get_transactor_key(request)
    task_id = str(uuid4())
    batch_list = Task().batch_list(
        signer_keypair=txn_key,
        signer_user_id=txn_user_id,
        task_id=task_id,
        name=request.json.get("name"),
        admins=request.json.get("administrators"),
        owners=request.json.get("owners"),
        metdata=request.json.get("metadata"),
    )
    await utils.send(request.app.config.VAL_CONN, batch_list,
                     request.app.config.TIMEOUT)
    return create_task_response(request, task_id)
Beispiel #24
0
        "APPROVED": Role().task.confirm.batch_list,
    },
    "ADD_ROLE_MEMBER": {
        "REJECTED": Role().member.reject.batch_list,
        "APPROVED": Role().member.confirm.batch_list,
    },
    "ADD_ROLE_OWNER": {
        "REJECTED": Role().owner.reject.batch_list,
        "APPROVED": Role().owner.confirm.batch_list,
    },
    "ADD_ROLE_ADMIN": {
        "REJECTED": Role().admin.reject.batch_list,
        "APPROVED": Role().admin.confirm.batch_list,
    },
    "ADD_TASK_OWNER": {
        "REJECTED": Task().owner.reject.batch_list,
        "APPROVED": Task().owner.confirm.batch_list,
    },
    "ADD_TASK_ADMIN": {
        "REJECTED": Task().admin.reject.batch_list,
        "APPROVED": Task().admin.confirm.batch_list,
    },
    "UPDATE_USER_MANAGER": {
        "REJECTED": User().manager.reject.batch_list,
        "APPROVED": User().manager.confirm.batch_list,
    },
}


@PROPOSALS_BP.get("api/proposals")
@authorized()
Beispiel #25
0
PROPOSAL_TRANSACTION = {
    "ADD_ROLE_TASK": {"REJECTED": Role().task.reject, "APPROVED": Role().task.confirm},
    "ADD_ROLE_MEMBER": {
        "REJECTED": Role().member.reject,
        "APPROVED": Role().member.confirm,
    },
    "ADD_ROLE_OWNER": {
        "REJECTED": Role().owner.reject,
        "APPROVED": Role().owner.confirm,
    },
    "ADD_ROLE_ADMIN": {
        "REJECTED": Role().admin.reject,
        "APPROVED": Role().admin.confirm,
    },
    "ADD_TASK_OWNER": {
        "REJECTED": Task().owner.reject,
        "APPROVED": Task().owner.confirm,
    },
    "ADD_TASK_ADMIN": {
        "REJECTED": Task().admin.reject,
        "APPROVED": Task().admin.confirm,
    },
    "UPDATE_USER_MANAGER": {
        "REJECTED": User().manager.reject,
        "APPROVED": User().manager.confirm,
    },
}


@PROPOSALS_BP.get("api/proposals")
@doc.summary("API Endpoint to get all proposals")
Beispiel #26
0
def test_address():
    """Test the address method and that it is in sync with the addresser"""
    task_id = helper.task.id()
    address1 = Task().address(object_id=task_id)
    address2 = addresser.task.address(task_id)
    assert address1 == address2