当前位置: 首页>>代码示例>>Python>>正文


Python Builder.audit方法代码示例

本文整理汇总了Python中dataserv_client.builder.Builder.audit方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.audit方法的具体用法?Python Builder.audit怎么用?Python Builder.audit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dataserv_client.builder.Builder的用法示例。


在下文中一共展示了Builder.audit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_builder_audit

# 需要导入模块: from dataserv_client.builder import Builder [as 别名]
# 或者: from dataserv_client.builder.Builder import audit [as 别名]
    def test_builder_audit(self):
        # generate shards for testing
        bucket = Builder(addresses["epsilon"], my_shard_size, my_max_size, debug=True)
        bucket.build(self.store_path)

        # audit
        audit_results = bucket.audit(b"storj", self.store_path, height)
        result0 = fixtures["test_builder_audit"]["result0"]
        result1 = fixtures["test_builder_audit"]["result1"]
        self.assertEqual(audit_results[0], _to_bytes(result0))
        self.assertEqual(audit_results[1], _to_bytes(result1))

        # audit full
        expected = fixtures["test_builder_audit"]["expected"]
        audit_results = bucket.full_audit(b"storj", self.store_path,
                                          height)
        self.assertEqual(audit_results, expected)
开发者ID:lockthenlock,项目名称:dataserv-client,代码行数:19,代码来源:test_builder.py

示例2: test_builder_audit

# 需要导入模块: from dataserv_client.builder import Builder [as 别名]
# 或者: from dataserv_client.builder.Builder import audit [as 别名]
    def test_builder_audit(self):
        bucket = Builder(addresses["epsilon"], my_shard_size, 0,
                         my_min_free_size)

        # check last confirmed bitcoin hash
        btc_block = bucket.btc_last_confirmed_block()

        self.assertTrue(btc_block['confirmations']>=
                        common.DEFAULT_MIN_CONFIRMATIONS)
        self.assertTrue(btc_block['is_orphan']==False)

        index = btc_block['block_no']

        block_pos = index % common.DEFAULT_FULL_AUDIT
        block_size = common.DEFAULT_BLOCK_SIZE
        
        # create empty files to skip to btc_index
        seeds = bucket.build_seeds(block_pos * block_size)
        for seed in seeds:
            path = os.path.join(self.store_path, seed)
            open(path,'w').close()

        # generate shards for audit
        shard_size = my_shard_size * (block_pos + 1) * block_size
        bucket = Builder(addresses["epsilon"], my_shard_size, shard_size,
                         my_min_free_size)
        bucket.build(self.store_path)

        # audit possible
        good_hash = bucket.audit(self.store_path, 
                                 btc_block['block_no'], 
                                 btc_block['blockhash'])
        self.assertTrue(good_hash)

        seeds = bucket.build_seeds((block_pos + 1) * block_size)

        # copy a bad file for a bad audit
        path1 = os.path.join(self.store_path, seeds[-2])
        path2 = os.path.join(self.store_path, seeds[-1])
        shutil.copyfile(path1, path2)
        bad_hash = bucket.audit(self.store_path,
                                btc_block['block_no'],
                                btc_block['blockhash'])

        self.assertFalse(good_hash==bad_hash)

        # write some bad data
        with open(path2, "a") as f:
            f.write("bad data is bad\n")

        # audit failed because last shard has bad data
        self.assertFalse(bucket.audit(self.store_path,
                                      btc_block['block_no'],
                                      btc_block['blockhash']))

        # remove last shard
        os.remove(path2)

        # audit failed because last shard missing
        self.assertFalse(bucket.audit(self.store_path,
                                      btc_block['block_no'],
                                      btc_block['blockhash']))

        # build last shard again
        bucket = Builder(addresses["epsilon"], my_shard_size, shard_size,
                         my_min_free_size)
        bucket.build(self.store_path)

        # audit possible
        good_hash = bucket.audit(self.store_path,
                                 btc_block['block_no'],
                                 btc_block['blockhash'])
        self.assertTrue(good_hash)

        # remove first shard of that block
        path1 = os.path.join(self.store_path, seeds[-80])
        os.remove(path1)

        # audit failed because first shard missing
        self.assertFalse(bucket.audit(self.store_path,
                                      btc_block['block_no'],
                                      btc_block['blockhash']))
开发者ID:StorjOld,项目名称:dataserv-client,代码行数:84,代码来源:test_builder.py


注:本文中的dataserv_client.builder.Builder.audit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。