示例#1
0
 def application_cancel(self, record_identifier, application_type,
                        wait=None):
     outputs = [Addressing.application_address(record_identifier),
                Addressing.record_address(record_identifier)]
     inputs = outputs + [Addressing.agent_address(self.public_key),
                         Addressing.record_address(record_identifier)]
     return self._send_txn(
         SupplyChainPayload.APPLICATION_CANCEL,
         ApplicationCancelPayload(
             record_identifier=record_identifier,
             applicant=self._public_key,
             type=application_type),
         inputs=inputs, outputs=outputs, wait=wait)
示例#2
0
 def application_accept(self, record_identifier,
                        applicant, application_type,
                        timestamp=None, wait=None):
     outputs = [Addressing.application_address(record_identifier),
                Addressing.record_address(record_identifier)]
     inputs = outputs + [Addressing.agent_address(self.public_key),
                         Addressing.record_address(record_identifier)]
     return self._send_txn(
         SupplyChainPayload.APPLICATION_ACCEPT,
         ApplicationAcceptPayload(
             record_identifier=record_identifier,
             applicant=applicant,
             type=application_type,
             timestamp=timestamp or time.time()),
         inputs=inputs, outputs=outputs, wait=wait)
示例#3
0
    def _record_create(self, state, originator, data):
        txn_data = RecordCreatePayload()
        txn_data.ParseFromString(data)

        agent_addr = Addressing.agent_address(originator)
        record_addr = Addressing.record_address(txn_data.identifier)

        state_items = self._get(state, [agent_addr, record_addr])

        agents = state_items.get(agent_addr, None)
        records = state_items.get(record_addr, RecordContainer())

        # check that the agent exists
        if self._find_agent(agents, originator) is None:
            raise InvalidTransaction("Agent is not registered.")

        # check that the record does not exists
        record = self._find_record(records, txn_data.identifier)
        if record is not None:
            raise InvalidTransaction("Record already exists.")

        # create the new record
        record = records.entries.add()
        record.identifier = txn_data.identifier
        record.creation_time = txn_data.creation_time
        owner = record.owners.add()
        owner.agent_identifier = originator
        owner.start_time = txn_data.creation_time
        custodian = record.custodians.add()
        custodian.agent_identifier = originator
        custodian.start_time = txn_data.creation_time
        record.final = False

        # send back the updated agents list
        self._set(state, [(record_addr, records)])
示例#4
0
    def test_record_finalize(self):
        """
        Test if the supplychain processor can finalize a record.
        """
        try:
            validator = self.validator
            factory = self.factory

            record_id = "serial number"
            record_addr = Addressing.record_address(record_id)
            agent_pub_key = factory.public_key

            # 1. -> Send a set transaction
            #    <- Expect a state get request
            validator.send(
                factory.finalize_record_tp_process_request(record_id))

            # test for record existance
            received = self.expect_get([record_addr])

            record = factory.create_record(record_id)
            factory.add_agent_record(record.owners, agent_pub_key)
            factory.add_agent_record(record.custodians, agent_pub_key)
            self.respond_get(received, [(record_addr, record)])

            # Update record
            record.final = True
            received = self.expect_set([(record_addr, record)])
            self.respond_set(received, [record_addr])

            self.expect_ok()
        except Exception:
            LOGGER.exception("test_record_finalize exception")
            raise
示例#5
0
    def _record_finalize(self, state, originator, data):
        txn_data = RecordFinalizePayload()
        txn_data.ParseFromString(data)

        record_addr = Addressing.record_address(txn_data.identifier)

        state_items = self._get(state, [record_addr])

        records = state_items.get(record_addr, RecordContainer())

        # check that the record does not exists
        record = self._find_record(records, txn_data.identifier)
        if record is None:
            raise InvalidTransaction("Record does not exists.")

        owner = record.owners[len(record.owners) - 1]
        if owner.agent_identifier != originator:
            raise InvalidTransaction(
                "Record can only be finalized by owner.")

        custodian = record.custodians[len(record.custodians) - 1]
        if custodian.agent_identifier != originator:
            raise InvalidTransaction(
                "Application can only be finalized when the owner is the " +
                "custodian.")

        # Mark the record as final
        record.final = True

        # send back the updated agents list
        self._set(state, [(record_addr, records)])
示例#6
0
    def _record_create(self, state, originator, data):
        txn_data = RecordCreatePayload()
        txn_data.ParseFromString(data)

        agent_addr = Addressing.agent_address(originator)
        record_addr = Addressing.record_address(txn_data.identifier)

        state_items = self._get(state, [agent_addr, record_addr])

        agents = state_items.get(agent_addr, None)
        records = state_items.get(record_addr, RecordContainer())

        # check that the agent exists
        if self._find_agent(agents, originator) is None:
            raise InvalidTransaction("Agent is not registered.")

        # check that the record does not exists
        record = self._find_record(records, txn_data.identifier)
        if record is not None:
            raise InvalidTransaction("Record already exists.")

        # create the new record
        record = records.entries.add()
        record.identifier = txn_data.identifier
        record.creation_time = txn_data.creation_time
        owner = record.owners.add()
        owner.agent_identifier = originator
        owner.start_time = txn_data.creation_time
        custodian = record.custodians.add()
        custodian.agent_identifier = originator
        custodian.start_time = txn_data.creation_time
        record.final = False

        # send back the updated agents list
        self._set(state, [(record_addr, records)])
    def test_record_finalize(self):
        """
        Test if the supplychain processor can finalize a record.
        """
        try:
            validator = self.validator
            factory = self.factory

            record_id = "serial number"
            record_addr = Addressing.record_address(record_id)
            agent_pub_key = factory.public_key

            # 1. -> Send a set transaction
            #    <- Expect a state get request
            validator.send(
                factory.finalize_record_tp_process_request(
                    record_id))

            # test for record existance
            received = self.expect_get([record_addr])

            record = factory.create_record(record_id)
            factory.add_agent_record(record.owners, agent_pub_key)
            factory.add_agent_record(record.custodians, agent_pub_key)
            self.respond_get(received, [(record_addr, record)])

            # Update record
            record.final = True
            received = self.expect_set([(record_addr, record)])
            self.respond_set(received, [record_addr])

            self.expect_ok()
        except Exception:
            LOGGER.exception("test_record_finalize exception")
            raise
示例#8
0
    def _record_finalize(self, state, originator, data):
        txn_data = RecordFinalizePayload()
        txn_data.ParseFromString(data)

        record_addr = Addressing.record_address(txn_data.identifier)

        state_items = self._get(state, [record_addr])

        records = state_items.get(record_addr, RecordContainer())

        # check that the record does not exists
        record = self._find_record(records, txn_data.identifier)
        if record is None:
            raise InvalidTransaction("Record does not exists.")

        owner = record.owners[len(record.owners) - 1]
        if owner.agent_identifier != originator:
            raise InvalidTransaction("Record can only be finalized by owner.")

        custodian = record.custodians[len(record.custodians) - 1]
        if custodian.agent_identifier != originator:
            raise InvalidTransaction(
                "Application can only be finalized when the owner is the " +
                "custodian.")

        # Mark the record as final
        record.final = True

        # send back the updated agents list
        self._set(state, [(record_addr, records)])
示例#9
0
 def record_finalize(self, record_identifier, wait=None):
     addrs = [Addressing.record_address(record_identifier)]
     return self._send_txn(
         SupplyChainPayload.RECORD_FINALIZE,
         RecordFinalizePayload(identifier=record_identifier),
         addrs,
         addrs,
         wait=wait)
示例#10
0
    def _application_accept(self, state, originator, data):
        txn_data = ApplicationAcceptPayload()
        txn_data.ParseFromString(data)

        record_addr = Addressing.record_address(txn_data.record_identifier)
        application_addr = Addressing.application_address(
            txn_data.record_identifier)

        state_items = self._get(state, [application_addr, record_addr])

        # check that the application exists
        applications = state_items.get(application_addr, None)
        application = self._find_application(applications, txn_data.applicant,
                                             txn_data.record_identifier,
                                             txn_data.type)
        if application is None:
            raise InvalidTransaction("Application does not exists.")

        # check that the recorf exists
        records = state_items.get(record_addr, None)
        record = self._find_record(records, application.record_identifier)
        if record is None:
            raise InvalidTransaction("Record does not exists.")

        if record.final:
            raise InvalidTransaction("Record is final, no updates can be " +
                                     "made.")

        # verify the txn signer is qualified to accept the application
        if application.type == Application.OWNER:
            owner = record.owners[len(record.owners) - 1]
            if owner.agent_identifier != originator:
                raise InvalidTransaction(
                    "Application can only be accepted by owner.")
        elif application.type == Application.CUSTODIAN:
            custodian = record.custodians[len(record.custodians) - 1]
            if custodian.agent_identifier != originator:
                raise InvalidTransaction(
                    "Application can only be accepted by custodian.")
        else:
            raise InvalidTransaction("Invalid application type.")

        # update the application
        application.status = Application.ACCEPTED

        # update the record
        if application.type == Application.OWNER:
            agent_record = record.owners.add()
        elif application.type == Application.CUSTODIAN:
            agent_record = record.custodians.add()
        agent_record.agent_identifier = application.applicant
        agent_record.start_time = txn_data.timestamp

        # send back the updated application list
        self._set(state, [(application_addr, applications),
                          (record_addr, records)])
示例#11
0
    def _application_accept(self, state, originator, data):
        txn_data = ApplicationAcceptPayload()
        txn_data.ParseFromString(data)

        record_addr = Addressing.record_address(txn_data.record_identifier)
        application_addr = Addressing.application_address(
            txn_data.record_identifier)

        state_items = self._get(state, [application_addr, record_addr])

        # check that the application exists
        applications = state_items.get(application_addr, None)
        application = self._find_application(
            applications, txn_data.applicant, txn_data.record_identifier,
            txn_data.type)
        if application is None:
            raise InvalidTransaction("Application does not exists.")

        # check that the recorf exists
        records = state_items.get(record_addr, None)
        record = self._find_record(records, application.record_identifier)
        if record is None:
            raise InvalidTransaction("Record does not exists.")

        if record.final:
            raise InvalidTransaction("Record is final, no updates can be " +
                                     "made.")

        # verify the txn signer is qualified to accept the application
        if application.type == Application.OWNER:
            owner = record.owners[len(record.owners) - 1]
            if owner.agent_identifier != originator:
                raise InvalidTransaction(
                    "Application can only be accepted by owner.")
        elif application.type == Application.CUSTODIAN:
            custodian = record.custodians[len(record.custodians) - 1]
            if custodian.agent_identifier != originator:
                raise InvalidTransaction(
                    "Application can only be accepted by custodian.")
        else:
            raise InvalidTransaction("Invalid application type.")

        # update the application
        application.status = Application.ACCEPTED

        # update the record
        if application.type == Application.OWNER:
            agent_record = record.owners.add()
        elif application.type == Application.CUSTODIAN:
            agent_record = record.custodians.add()
        agent_record.agent_identifier = application.applicant
        agent_record.start_time = txn_data.timestamp

        # send back the updated application list
        self._set(state, [(application_addr, applications),
                          (record_addr, records)])
示例#12
0
 def application_cancel(self,
                        record_identifier,
                        application_type,
                        wait=None):
     outputs = [
         Addressing.application_address(record_identifier),
         Addressing.record_address(record_identifier)
     ]
     inputs = outputs + [
         Addressing.agent_address(self.public_key),
         Addressing.record_address(record_identifier)
     ]
     return self._send_txn(SupplyChainPayload.APPLICATION_CANCEL,
                           ApplicationCancelPayload(
                               record_identifier=record_identifier,
                               applicant=self._public_key,
                               type=application_type),
                           inputs=inputs,
                           outputs=outputs,
                           wait=wait)
示例#13
0
    def record_get(self, public_key):
        address = Addressing.record_address(public_key)
        result = self._send_get("state/{}".format(address))

        try:
            data = self._get_result_data(result)
            records = _decode_record_container(data)
            return next((record for record in records.entries
                         if record.identifier == public_key), None)
        except BaseException:
            return None
示例#14
0
    def record_create(self, record_identifier, creation_time=None, wait=None):
        outputs = [Addressing.record_address(record_identifier)]
        inputs = outputs + \
            [Addressing.agent_address(self._public_key)]

        return self._send_txn(
            SupplyChainPayload.RECORD_CREATE,
            RecordCreatePayload(
                identifier=record_identifier,
                creation_time=creation_time or int(time.time())),
            inputs=inputs, outputs=outputs, wait=wait)
示例#15
0
    def record_get(self, public_key):
        address = Addressing.record_address(public_key)
        result = self._send_get("state/{}".format(address))

        try:
            data = self._get_result_data(result)
            records = _decode_record_container(data)
            return next((record for record in records.entries
                         if record.identifier == public_key), None)
        except BaseException:
            return None
示例#16
0
    def finalize_record_tp_process_request(self,
                                           record_id):
        record_addr = Addressing.record_address(record_id)
        agent_pub_key = self.public_key
        agent_addr = Addressing.agent_address(agent_pub_key)
        inputs = [agent_addr, record_addr]
        outputs = [agent_addr, record_addr]

        return self.create_tp_process_request(
            SupplyChainPayload.RECORD_FINALIZE,
            RecordFinalizePayload(identifier=record_id),
            inputs, outputs)
示例#17
0
    def record_create(self, record_identifier, creation_time=None, wait=None):
        outputs = [Addressing.record_address(record_identifier)]
        inputs = outputs + \
            [Addressing.agent_address(self._public_key)]

        return self._send_txn(SupplyChainPayload.RECORD_CREATE,
                              RecordCreatePayload(identifier=record_identifier,
                                                  creation_time=creation_time
                                                  or int(time.time())),
                              inputs=inputs,
                              outputs=outputs,
                              wait=wait)
示例#18
0
 def application_create(self, record_identifier, application_type,
                        terms="", creation_time=None, wait=None):
     outputs = [Addressing.application_address(record_identifier)]
     inputs = outputs + [Addressing.agent_address(self.public_key),
                         Addressing.record_address(record_identifier)]
     return self._send_txn(
         SupplyChainPayload.APPLICATION_CREATE,
         ApplicationCreatePayload(
             record_identifier=record_identifier,
             creation_time=creation_time or int(time.time()),
             type=application_type,
             terms=terms),
         inputs=inputs, outputs=outputs, wait=wait)
    def test_application_accept(self):
        """
        Test if the supplychain processor can create a application.
        """
        try:
            validator = self.validator
            factory = self.factory

            applicant_id = "applicant pub key"

            record_id = "serial number"
            record_addr = Addressing.record_address(record_id)
            agent_pub_key = factory.public_key
            application_addr = Addressing.application_address(record_id)
            timestamp = int(time.time())

            # 1. -> Send a set transaction
            #    <- Expect a state get request
            validator.send(
                factory.create_application_accept_tp_process_request(
                    record_id,
                    applicant_id,
                    Application.OWNER,
                    timestamp))

            # test for application and record existance
            received = self.expect_get([application_addr, record_addr])
            application = factory.create_application(
                record_id,
                applicant_id,
                Application.OWNER,
                Application.OPEN)
            record = factory.create_record(record_id)
            factory.add_agent_record(record.owners, agent_pub_key)

            self.respond_get(received,
                             [(application_addr, application),
                              (record_addr, record)])

            # Update record and application
            application.status = Application.ACCEPTED
            factory.add_agent_record(record.owners, applicant_id, timestamp)
            received = self.expect_set(
                [(application_addr, application),
                 (record_addr, record)])
            self.respond_set(received,
                             [application_addr, record_addr])
            self.expect_ok()
        except Exception:
            LOGGER.exception("test_application_accept exception")
            raise
    def test_create_application(self):
        """
        Test if the supplychain processor can create a application.
        """
        try:
            validator = self.validator
            factory = self.factory

            record_id = "serial number"
            record_addr = Addressing.record_address(record_id)
            agent_pub_key = factory.public_key
            agent_addr = Addressing.agent_address(agent_pub_key)
            application_addr = Addressing.application_address(record_id)
            timestamp = int(time.time())
            terms = "Please take this."

            # 1. -> Send a set transaction
            #    <- Expect a state get request
            validator.send(factory.create_application_tp_process_request(
                agent_pub_key,
                record_id,
                timestamp,
                Application.OWNER,
                terms))

            # test for record existance
            received = self.expect_get(
                [agent_addr, application_addr, record_addr])

            agent = factory.create_agent(agent_pub_key)
            record = factory.create_record(record_id)
            self.respond_get(received,
                             [(agent_addr, agent),
                              (application_addr, None),
                              (record_addr, record)])

            # Expect test for existance
            application = factory.create_application(
                record_id,
                agent_pub_key,
                Application.OWNER,
                Application.OPEN,
                timestamp,
                terms)
            received = self.expect_set([(application_addr, application)])
            self.respond_set(received, [application_addr])

            self.expect_ok()
        except Exception:
            LOGGER.exception("test_create_application exception")
            raise
示例#21
0
    def create_record_tp_process_request(self,
                                         identifier,
                                         timestamp):
        record_addr = Addressing.record_address(identifier)
        agent_pub_key = self.public_key
        agent_addr = Addressing.agent_address(agent_pub_key)
        inputs = [agent_addr, record_addr]
        outputs = [agent_addr, record_addr]

        return self.create_tp_process_request(
            SupplyChainPayload.RECORD_CREATE,
            RecordCreatePayload(identifier=identifier,
                                creation_time=timestamp),
            inputs, outputs)
示例#22
0
 def application_accept(self,
                        record_identifier,
                        applicant_public_key,
                        application_type,
                        timestamp=None,
                        wait=None):
     outputs = [
         Addressing.application_address(record_identifier),
         Addressing.record_address(record_identifier)
     ]
     inputs = outputs + [
         Addressing.agent_address(self.public_key),
         Addressing.record_address(record_identifier)
     ]
     return self._send_txn(SupplyChainPayload.APPLICATION_ACCEPT,
                           ApplicationAcceptPayload(
                               record_identifier=record_identifier,
                               applicant=applicant_public_key,
                               type=application_type,
                               timestamp=timestamp or int(time.time())),
                           inputs=inputs,
                           outputs=outputs,
                           wait=wait)
示例#23
0
    def create_application_cancel_tp_process_request(self,
                                                     record_id,
                                                     applicant_id,
                                                     application_type):
        record_addr = Addressing.record_address(record_id)
        agent_pub_key = self.public_key
        agent_addr = Addressing.agent_address(agent_pub_key)
        application_addr = Addressing.application_address(record_id)
        inputs = [agent_addr, application_addr, record_addr]
        outputs = [application_addr]

        return self.create_tp_process_request(
            SupplyChainPayload.APPLICATION_CANCEL,
            ApplicationCancelPayload(record_identifier=record_id,
                                     applicant=applicant_id,
                                     type=application_type),
            inputs, outputs)
示例#24
0
    def test_create_application(self):
        """
        Test if the supplychain processor can create a application.
        """
        try:
            validator = self.validator
            factory = self.factory

            record_id = "serial number"
            record_addr = Addressing.record_address(record_id)
            agent_pub_key = factory.public_key
            agent_addr = Addressing.agent_address(agent_pub_key)
            application_addr = Addressing.application_address(record_id)
            timestamp = int(time.time())
            terms = "Please take this."

            # 1. -> Send a set transaction
            #    <- Expect a state get request
            validator.send(
                factory.create_application_tp_process_request(
                    agent_pub_key, record_id, timestamp, Application.OWNER,
                    terms))

            # test for record existance
            received = self.expect_get(
                [agent_addr, application_addr, record_addr])

            agent = factory.create_agent(agent_pub_key)
            record = factory.create_record(record_id)
            self.respond_get(received, [(agent_addr, agent),
                                        (application_addr, None),
                                        (record_addr, record)])

            # Expect test for existance
            application = factory.create_application(record_id, agent_pub_key,
                                                     Application.OWNER,
                                                     Application.OPEN,
                                                     timestamp, terms)
            received = self.expect_set([(application_addr, application)])
            self.respond_set(received, [application_addr])

            self.expect_ok()
        except Exception:
            LOGGER.exception("test_create_application exception")
            raise
示例#25
0
    def _application_create(self, state, originator, data):
        txn_data = ApplicationCreatePayload()
        txn_data.ParseFromString(data)

        agent_addr = Addressing.agent_address(originator)
        record_addr = Addressing.record_address(txn_data.record_identifier)
        application_addr = Addressing.application_address(
            txn_data.record_identifier)
        state_items = self._get(state,
                                [agent_addr, application_addr, record_addr])

        # check that the agent and record exists
        agents = state_items.get(agent_addr, None)
        if self._find_agent(agents, originator) is None:
            raise InvalidTransaction("Agent is not registered.")

        records = state_items.get(record_addr, None)
        record = self._find_record(records, txn_data.record_identifier)
        if record is None:
            raise InvalidTransaction("Record does not exist.")

        if record.final:
            raise InvalidTransaction("Record is final, no updates can be " +
                                     "proposed.")

        # check that the application does not exists
        applications = state_items.get(application_addr,
                                       ApplicationContainer())
        application = self._find_application(
            applications, originator, txn_data.record_identifier,
            txn_data.type)
        if application is not None:
            raise InvalidTransaction("Application already exists.")

        # create the new application
        application = applications.entries.add()
        application.record_identifier = txn_data.record_identifier
        application.applicant = originator
        application.creation_time = txn_data.creation_time
        application.type = txn_data.type
        application.status = Application.OPEN
        application.terms = txn_data.terms

        # send back the updated application list
        self._set(state, [(application_addr, applications)])
示例#26
0
    def _application_create(self, state, originator, data):
        txn_data = ApplicationCreatePayload()
        txn_data.ParseFromString(data)

        agent_addr = Addressing.agent_address(originator)
        record_addr = Addressing.record_address(txn_data.record_identifier)
        application_addr = Addressing.application_address(
            txn_data.record_identifier)
        state_items = self._get(state,
                                [agent_addr, application_addr, record_addr])

        # check that the agent and record exists
        agents = state_items.get(agent_addr, None)
        if self._find_agent(agents, originator) is None:
            raise InvalidTransaction("Agent is not registered.")

        records = state_items.get(record_addr, None)
        record = self._find_record(records, txn_data.record_identifier)
        if record is None:
            raise InvalidTransaction("Record does not exist.")

        if record.final:
            raise InvalidTransaction("Record is final, no updates can be " +
                                     "proposed.")

        # check that the application does not exists
        applications = state_items.get(application_addr,
                                       ApplicationContainer())
        application = self._find_application(applications, originator,
                                             txn_data.record_identifier,
                                             txn_data.type)
        if application is not None:
            raise InvalidTransaction("Application already exists.")

        # create the new application
        application = applications.entries.add()
        application.record_identifier = txn_data.record_identifier
        application.applicant = originator
        application.creation_time = txn_data.creation_time
        application.type = txn_data.type
        application.status = Application.OPEN
        application.terms = txn_data.terms

        # send back the updated application list
        self._set(state, [(application_addr, applications)])
示例#27
0
    def create_application_accept_tp_process_request(self,
                                                     record_id,
                                                     applicant_id,
                                                     application_type,
                                                     timestamp=0):
        record_addr = Addressing.record_address(record_id)
        agent_pub_key = self.public_key
        agent_addr = Addressing.agent_address(agent_pub_key)
        inputs = [agent_addr, record_addr]
        outputs = [record_addr]

        return self.create_tp_process_request(
            SupplyChainPayload.APPLICATION_ACCEPT,
            ApplicationAcceptPayload(record_identifier=record_id,
                                     applicant=applicant_id,
                                     type=application_type,
                                     timestamp=timestamp),
            inputs, outputs)
示例#28
0
    def test_application_accept(self):
        """
        Test if the supplychain processor can create a application.
        """
        try:
            validator = self.validator
            factory = self.factory

            applicant_id = "applicant pub key"

            record_id = "serial number"
            record_addr = Addressing.record_address(record_id)
            agent_pub_key = factory.public_key
            application_addr = Addressing.application_address(record_id)
            timestamp = int(time.time())

            # 1. -> Send a set transaction
            #    <- Expect a state get request
            validator.send(
                factory.create_application_accept_tp_process_request(
                    record_id, applicant_id, Application.OWNER, timestamp))

            # test for application and record existance
            received = self.expect_get([application_addr, record_addr])
            application = factory.create_application(record_id, applicant_id,
                                                     Application.OWNER,
                                                     Application.OPEN)
            record = factory.create_record(record_id)
            factory.add_agent_record(record.owners, agent_pub_key)

            self.respond_get(received, [(application_addr, application),
                                        (record_addr, record)])

            # Update record and application
            application.status = Application.ACCEPTED
            factory.add_agent_record(record.owners, applicant_id, timestamp)
            received = self.expect_set([(application_addr, application),
                                        (record_addr, record)])
            self.respond_set(received, [application_addr, record_addr])
            self.expect_ok()
        except Exception:
            LOGGER.exception("test_application_accept exception")
            raise
示例#29
0
    def create_application_tp_process_request(self,
                                              agent_pub_key,
                                              record_id,
                                              timestamp,
                                              application_type,
                                              terms=None):
        record_addr = Addressing.record_address(record_id)
        agent_pub_key = self.public_key
        agent_addr = Addressing.agent_address(agent_pub_key)
        inputs = [agent_addr, record_addr]
        outputs = [record_addr]

        return self.create_tp_process_request(
            SupplyChainPayload.APPLICATION_CREATE,
            ApplicationCreatePayload(record_identifier=record_id,
                                     creation_time=timestamp,
                                     type=application_type,
                                     terms=terms),
            inputs, outputs)
    def test_record_create(self):
        """
        Test if the supplychain processor can create a record.
        """
        try:
            validator = self.validator
            factory = self.factory

            record_identifier = 'serial number'
            record_addr = Addressing.record_address(record_identifier)
            agent_pub_key = factory.public_key
            agent_addr = Addressing.agent_address(agent_pub_key)
            record_timestamp = int(time.time())

            # 1. -> Send a set transaction
            #    <- Expect a state get request
            validator.send(factory.create_record_tp_process_request(
                record_identifier, record_timestamp))

            # test for record existance
            received = self.expect_get([agent_addr, record_addr])
            agent = factory.create_agent(agent_pub_key)
            self.respond_get(received,
                             [(agent_addr, agent),
                              (record_addr, None)])

            # Expect create Record
            record = factory.create_record(record_identifier,
                                           record_timestamp)
            factory.add_agent_record(record.owners,
                                     agent_pub_key,
                                     record_timestamp)
            factory.add_agent_record(record.custodians,
                                     agent_pub_key,
                                     record_timestamp)
            received = self.expect_set([(record_addr, record)])
            self.respond_set(received, [record_addr])

            self.expect_ok()
        except Exception:
            LOGGER.exception("test_record_create exception")
            raise
示例#31
0
 def application_create(self,
                        record_identifier,
                        application_type,
                        terms="",
                        creation_time=None,
                        wait=None):
     outputs = [Addressing.application_address(record_identifier)]
     inputs = outputs + [
         Addressing.agent_address(self.public_key),
         Addressing.record_address(record_identifier)
     ]
     return self._send_txn(
         SupplyChainPayload.APPLICATION_CREATE,
         ApplicationCreatePayload(record_identifier=record_identifier,
                                  creation_time=creation_time
                                  or int(time.time()),
                                  type=application_type,
                                  terms=terms),
         inputs=inputs,
         outputs=outputs,
         wait=wait)
示例#32
0
    def test_record_create(self):
        """
        Test if the supplychain processor can create a record.
        """
        try:
            validator = self.validator
            factory = self.factory

            record_identifier = 'serial number'
            record_addr = Addressing.record_address(record_identifier)
            agent_pub_key = factory.public_key
            agent_addr = Addressing.agent_address(agent_pub_key)
            record_timestamp = int(time.time())

            # 1. -> Send a set transaction
            #    <- Expect a state get request
            validator.send(
                factory.create_record_tp_process_request(
                    record_identifier, record_timestamp))

            # test for record existance
            received = self.expect_get([agent_addr, record_addr])
            agent = factory.create_agent(agent_pub_key)
            self.respond_get(received, [(agent_addr, agent),
                                        (record_addr, None)])

            # Expect create Record
            record = factory.create_record(record_identifier, record_timestamp)
            factory.add_agent_record(record.owners, agent_pub_key,
                                     record_timestamp)
            factory.add_agent_record(record.custodians, agent_pub_key,
                                     record_timestamp)
            received = self.expect_set([(record_addr, record)])
            self.respond_set(received, [record_addr])

            self.expect_ok()
        except Exception:
            LOGGER.exception("test_record_create exception")
            raise
示例#33
0
 def record_finalize(self, record_identifier, wait=None):
     addrs = [Addressing.record_address(record_identifier)]
     return self._send_txn(
         SupplyChainPayload.RECORD_FINALIZE,
         RecordFinalizePayload(identifier=record_identifier),
         addrs, addrs, wait=wait)