-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address some comments from ChiaMineJP.
- Loading branch information
1 parent
e92f68f
commit e4bce12
Showing
5 changed files
with
109 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import io | ||
import unittest | ||
|
||
from clvm import to_sexp_f | ||
from clvm.object_cache import ObjectCache, treehash, serialized_length | ||
from clvm.serialize import sexp_from_stream | ||
|
||
from clvm_tools.binutils import assemble | ||
|
||
TEXT = b"the quick brown fox jumps over the lazy dogs" | ||
|
||
|
||
def obj_from_hex(h): | ||
b = bytes.fromhex(h) | ||
f = io.BytesIO(b) | ||
return sexp_from_stream(f, to_sexp_f) | ||
|
||
|
||
class ObjectCacheTest(unittest.TestCase): | ||
def check(self, obj_text, expected_hash, expected_length): | ||
obj = assemble(obj_text) | ||
th = ObjectCache(treehash) | ||
self.assertEqual(th.get(obj).hex(), expected_hash) | ||
sl = ObjectCache(serialized_length) | ||
self.assertEqual(sl.get(obj), expected_length) | ||
|
||
def test_various(self): | ||
self.check( | ||
"0x00", | ||
"47dc540c94ceb704a23875c11273e16bb0b8a87aed84de911f2133568115f254", | ||
1, | ||
) | ||
|
||
self.check( | ||
"0", "4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a", 1 | ||
) | ||
|
||
self.check( | ||
"foo", "0080b50a51ecd0ccfaaa4d49dba866fe58724f18445d30202bafb03e21eef6cb", 4 | ||
) | ||
|
||
self.check( | ||
"(foo . bar)", | ||
"c518e45ae6a7b4146017b7a1d81639051b132f1f5572ce3088a3898a9ed1280b", | ||
9, | ||
) | ||
|
||
self.check( | ||
"(this is a longer test of a deeper tree)", | ||
"0a072d7d860d77d8e290ced0fdb29a271198ca3db54d701c45d831e3aae6422c", | ||
47, | ||
) |