本文整理汇总了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)
示例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']))