本文整理汇总了Python中sawtooth_validator.state.merkle.MerkleDatabase.hash方法的典型用法代码示例。如果您正苦于以下问题:Python MerkleDatabase.hash方法的具体用法?Python MerkleDatabase.hash怎么用?Python MerkleDatabase.hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sawtooth_validator.state.merkle.MerkleDatabase
的用法示例。
在下文中一共展示了MerkleDatabase.hash方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_merkle_trie_root_advance
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import hash [as 别名]
def test_merkle_trie_root_advance(self):
value = {"name": "foo", "value": 1}
orig_root = self.trie.get_merkle_root()
new_root = self.trie.set(MerkleDatabase.hash("foo"),
value)
with self.assertRaises(KeyError):
self.trie.get(MerkleDatabase.hash("foo"))
self.trie.set_merkle_root(new_root)
self.assertEqual(self.trie.get(MerkleDatabase.hash("foo")),
value)
示例2: test_merkle_trie_delete
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import hash [as 别名]
def test_merkle_trie_delete(self):
value = {"name": "bar", "value": 1}
new_root = self.trie.set(MerkleDatabase.hash("bar"), value)
self.trie.set_merkle_root(new_root)
self.assertEqual(self.trie.get(MerkleDatabase.hash("bar")),
value)
del_root = self.trie.delete(MerkleDatabase.hash("bar"))
self.trie.set_merkle_root(del_root)
with self.assertRaises(KeyError):
self.trie.get(MerkleDatabase.hash("bar"))
示例3: test_merkle_trie_update
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import hash [as 别名]
def test_merkle_trie_update(self):
value = ''.join(random.choice(string.ascii_lowercase)
for _ in range(512))
keys = []
for i in range(1000):
key = ''.join(random.choice(string.ascii_lowercase)
for _ in range(10))
keys.append(key)
hash = MerkleDatabase.hash(key)
new_root = self.trie.set(hash, {key: value})
self.trie.set_merkle_root(new_root)
set_items = {}
for key in random.sample(keys, 50):
hash = MerkleDatabase.hash(key)
thing = {key: 5.0}
set_items[hash] = thing
update_root = self.trie.update(set_items)
self.trie.set_merkle_root(update_root)
for address in set_items:
self.assertEqual(self.trie.get(address),
set_items[address])
示例4: _hash
# 需要导入模块: from sawtooth_validator.state.merkle import MerkleDatabase [as 别名]
# 或者: from sawtooth_validator.state.merkle.MerkleDatabase import hash [as 别名]
def _hash(key):
return MerkleDatabase.hash(key.encode())