예제 #1
0
    def test_ipns(self, mocked_ipfs_client, _):
        """
        Test storage: upload, download, create_new_ipns_link, etc
        """

        credentials = {
            "gas_payer":
            "0x1413862C2B7054CDbfdc181B83962CB0FC11fD92",
            "gas_payer_priv":
            "28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5"
        }
        pub_key = b"2dbc2c2c86052702e7c219339514b2e8bd4687ba1236c478ad41b43330b08488c12c8c1797aa181f3a4596a1bd8a0c18344ea44d6655f61fa73e56e743f79e0d"
        job = Job(credentials=credentials,
                  escrow_manifest=Manifest({
                      'task_bid_price': 9,
                      'request_type': 'image_label_binary',
                      'job_total_tasks': 10
                  }))
        name = 'abc'

        mocked_ipfs_client.key.list.side_effect = MI.key_list
        mocked_ipfs_client.key.gen.side_effect = MI.key_gen
        mocked_ipfs_client.name.publish.side_effect = MI.publish
        mocked_ipfs_client.add_bytes.side_effect = MI.add_bytes
        mocked_ipfs_client.resolve.side_effect = MI.resolve
        mocked_ipfs_client.cat.side_effect = MI.cat

        ipns_id = create_new_ipns_link(name)

        # Upload 1
        (hash_, manifest_url) = upload(job.serialized_manifest, pub_key, name)
        manifest_dict = download(ipns_id, job.gas_payer_priv)
        dl_equals_up = manifest_dict == job.serialized_manifest
        link_exist = ipns_link_exists(name)
        ipns_urls_match = ipns_id == get_ipns_link(name).split('/')[-1]
        self.assertTrue(dl_equals_up)
        self.assertTrue(link_exist)
        self.assertTrue(ipns_urls_match)

        # Upload 2
        data2 = dict(
            Manifest({
                'task_bid_price': 999999,
                'request_type': 'image_label_binary',
                'job_total_tasks': 30010
            }).serialize())
        (hash_, manifest_url) = upload(data2, pub_key, name)
        manifest_dict = download(ipns_id, job.gas_payer_priv)
        dl_equals_up = manifest_dict == data2
        link_exist = ipns_link_exists(name)
        ipns_urls_match = ipns_id == get_ipns_link(name).split('/')[-1]
        self.assertTrue(dl_equals_up)
        self.assertTrue(link_exist)
        self.assertTrue(ipns_urls_match)
예제 #2
0
    def test_download(self):
        credentials = {
            "gas_payer": "0x1413862C2B7054CDbfdc181B83962CB0FC11fD92",
            "gas_payer_priv": "28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5",
        }
        pub_key = b"2dbc2c2c86052702e7c219339514b2e8bd4687ba1236c478ad41b43330b08488c12c8c1797aa181f3a4596a1bd8a0c18344ea44d6655f61fa73e56e743f79e0d"
        job = Job(credentials=credentials, escrow_manifest=manifest)
        (_, manifest_url) = upload(job.serialized_manifest, pub_key)
        manifest_dict = download(manifest_url, job.gas_payer_priv)
        self.assertEqual(manifest_dict, job.serialized_manifest)

        job = Job(credentials=credentials, escrow_manifest=manifest)
        (_, manifest_url) = upload(job.serialized_manifest, pub_key)
        manifest_dict = download(manifest_url, job.gas_payer_priv)
        self.assertEqual(manifest_dict, job.serialized_manifest)
예제 #3
0
파일: job.py 프로젝트: bxabi/hmt-escrow
    def final_results(self, priv_key: bytes, gas: int = GAS_LIMIT) -> Dict:
        """Retrieves the final results stored by the Reputation Oracle.

        >>> credentials = {
        ... 	"gas_payer": "0x1413862C2B7054CDbfdc181B83962CB0FC11fD92",
        ... 	"gas_payer_priv": "28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5"
        ... }
        >>> rep_oracle_pub_key = b"2dbc2c2c86052702e7c219339514b2e8bd4687ba1236c478ad41b43330b08488c12c8c1797aa181f3a4596a1bd8a0c18344ea44d6655f61fa73e56e743f79e0d"
        >>> job = Job(credentials, manifest)
        >>> job.launch(rep_oracle_pub_key)
        True
        >>> job.setup()
        True

        Getting final results succeeds after payout.
        >>> payouts = [("0x852023fbb19050B8291a335E5A83Ac9701E7B4E6", Decimal('100.0'))]
        >>> job.bulk_payout(payouts, {'results': 0}, rep_oracle_pub_key)
        True
        >>> rep_oracle_priv_key = "28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5"
        >>> job.final_results(rep_oracle_priv_key)
        {'results': 0}

        Args:
            priv_key (bytes): the private key of the the job requester or their agent.

        Returns:
            bool: returns True if IPFS download with the private key succeeds.

        """
        final_results_url = self.job_contract.functions.getFinalResultsUrl(
        ).call({
            'from': self.gas_payer,
            'gas': gas
        })
        return download(final_results_url, priv_key)
예제 #4
0
파일: job.py 프로젝트: bxabi/hmt-escrow
    def intermediate_results(self,
                             priv_key: bytes,
                             gas: int = GAS_LIMIT) -> Dict:
        """Reputation Oracle retrieves the intermediate results stored by the Recording Oracle.

        >>> credentials = {
        ... 	"gas_payer": "0x1413862C2B7054CDbfdc181B83962CB0FC11fD92",
        ... 	"gas_payer_priv": "28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5"
        ... }
        >>> rep_oracle_pub_key = b"2dbc2c2c86052702e7c219339514b2e8bd4687ba1236c478ad41b43330b08488c12c8c1797aa181f3a4596a1bd8a0c18344ea44d6655f61fa73e56e743f79e0d"
        >>> job = Job(credentials, manifest)
        >>> job.launch(rep_oracle_pub_key)
        True
        >>> job.setup()
        True

        Trying to download the results with the wrong key fails.
        >>> results = {"results": True}
        >>> job.store_intermediate_results(results, rep_oracle_pub_key)
        True
        >>> rep_oracle_false_priv_key = b"486a0621e595dd7fcbe5608cbbeec8f5a8b5cabe7637f11eccfc7acd408c3a0e"
        >>> job.intermediate_results(rep_oracle_false_priv_key)
        Traceback (most recent call last):
        p2p.exceptions.DecryptionError: Failed to verify tag

        Args:
            priv_key (bytes): the private key of the Reputation Oracle.

        Returns:
            bool: returns True if IPFS download with the private key succeeds.

        """
        intermediate_results_url = intermediate_url(self.job_contract,
                                                    self.gas_payer)
        return download(intermediate_results_url, priv_key)
예제 #5
0
파일: job.py 프로젝트: bxabi/hmt-escrow
    def manifest(self, priv_key: bytes) -> Dict:
        """Retrieves the initial manifest used to setup a Job.

        >>> credentials = {
        ... 	"gas_payer": "0x1413862C2B7054CDbfdc181B83962CB0FC11fD92",
        ... 	"gas_payer_priv": "28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5"
        ... }
        >>> rep_oracle_pub_key = b"2dbc2c2c86052702e7c219339514b2e8bd4687ba1236c478ad41b43330b08488c12c8c1797aa181f3a4596a1bd8a0c18344ea44d6655f61fa73e56e743f79e0d"
        >>> job = Job(credentials, manifest)
        >>> job.launch(rep_oracle_pub_key)
        True
        >>> job.setup()
        True
        >>> rep_oracle_priv_key = b"28e516f1e2f99e96a48a23cea1f94ee5f073403a1c68e818263f0eb898f1c8e5"
        >>> manifest = job.manifest(rep_oracle_priv_key)
        >>> manifest_amount = int(int(manifest["job_total_tasks"]) * Decimal(manifest["task_bid_price"]))
        >>> manifest_amount == job.amount
        True

        Args:
            priv_key (bytes): the private key used to download the manifest.

        Returns:
            bool: returns True if IPFS download with the private key succeeds.

        """
        return download(self.manifest_url, priv_key)