This repository was archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
Add offset and length to pycurl #95
Merged
todofixthis
merged 7 commits into
iotaledger-archive:develop
from
mlouielu:add_pycurl_offset_length
Jan 13, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ef183f1
Add offset and length to pycurl
mlouielu 1043297
Change curl import
mlouielu 9287e8c
Add docstring and tweak test cases
mlouielu 358d4b0
Add ISS source code link
mlouielu fb98b22
Add squeeze length and test case
mlouielu 0245bc8
Fix absorb docstring
mlouielu b28b9d8
Add blank line in the end
mlouielu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,165 @@ | ||
| # coding=utf-8 | ||
| from __future__ import absolute_import, division, print_function, \ | ||
| unicode_literals | ||
|
|
||
| from unittest import TestCase | ||
|
|
||
| from iota import TryteString | ||
| from iota.crypto import Curl | ||
|
|
||
|
|
||
| class TestCurl(TestCase): | ||
| """ | ||
| This is the test case for CURL-P hash function used in IOTA | ||
| """ | ||
| def test_correct_first(self): | ||
| """Test the inp tryte string will get the correct output""" | ||
| inp = ( | ||
| 'EMIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJ' | ||
| 'FGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH' | ||
| ) | ||
|
|
||
| trits = TryteString(inp).as_trits() | ||
|
|
||
| curl = Curl() | ||
| curl.absorb(trits) | ||
| trits_out = [] | ||
| curl.squeeze(trits_out) | ||
|
|
||
| trits_out = TryteString.from_trits(trits_out) | ||
|
|
||
| self.assertEqual( | ||
| trits_out, | ||
| 'AQBOPUMJMGVHFOXSMUAGZNACKUTISDPBSILMRAGIG' | ||
| 'RXXS9JJTLIKZUW9BCJWKSTFBDSBLNVEEGVGAMSSM') | ||
|
|
||
| def test_input_length_greater_than_243(self): | ||
| """Test input trytes length greater than hash length should work""" | ||
| inp = ( | ||
| 'G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJB' | ||
| 'VBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ' | ||
| '9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA' | ||
| ) | ||
|
|
||
| trits = TryteString(inp).as_trits() | ||
|
|
||
| curl = Curl() | ||
| curl.absorb(trits) | ||
| trits_out = [] | ||
| curl.squeeze(trits_out) | ||
|
|
||
| trits_out = TryteString.from_trits(trits_out) | ||
|
|
||
| self.assertEqual( | ||
| trits_out, | ||
| 'RWCBOLRFANOAYQWXXTFQJYQFAUTEEBSZWTIRSSDR' | ||
| 'EYGCNFRLHQVDZXYXSJKCQFQLJMMRHYAZKRRLQZDKR') | ||
|
|
||
| def test_input_without_offset(self): | ||
| """Test input without offset should work""" | ||
| inp = ( | ||
| 'G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJB' | ||
| 'VBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ' | ||
| '9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA' | ||
| ) | ||
|
|
||
| trits = TryteString(inp).as_trits() | ||
|
|
||
| curl = Curl() | ||
| curl.absorb(trits, 0, length=486) | ||
| curl.absorb(trits, 0, length=243) | ||
| trits_out = [] | ||
| curl.squeeze(trits_out) | ||
|
|
||
| trits_out = TryteString.from_trits(trits_out) | ||
|
|
||
| self.assertEqual( | ||
| trits_out, | ||
| 'OTYHXEXJLCSMEY9LYCC9ASJXMORTLAYQEHRS9DAH' | ||
| '9NR9DXLXYDGOVOBEL9LWRITLWPHPYPZDKXVPAPKUA') | ||
|
|
||
| def test_input_with_offset(self): | ||
| """Test input with offset should work""" | ||
| inp = ( | ||
| 'G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJB' | ||
| 'VBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ' | ||
| '9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA' | ||
| ) | ||
|
|
||
| trits = TryteString(inp).as_trits() | ||
|
|
||
| curl = Curl() | ||
| curl.absorb(trits, 243, length=486) | ||
| curl.absorb(trits, 0, length=243) | ||
| trits_out = [] | ||
| curl.squeeze(trits_out) | ||
|
|
||
| trits_out = TryteString.from_trits(trits_out) | ||
|
|
||
| self.assertEqual( | ||
| trits_out, | ||
| 'ZWNF9YOCAKC9CXQFYZDKXSSAZOCAZLEVEB9OZDJQG' | ||
| 'WEULHUDY9RAWAT9GIUXTTUSYJEGNGQDVJCGTQLN9') | ||
|
|
||
| def test_squeeze_with_offset(self): | ||
| """Test squeeze with offset, this only used in ISS | ||
| GitHub IRI ISS: https://github.com/iotaledger/iri/blob/dev/src/main/java/com/iota/iri/hash/ISS.java#L83 | ||
| """ | ||
| inp = ( | ||
| 'CDLFODMOGMQAWXDURDXTUAOO9BFESHYGZLBUWIIHPTLNZCUNHZAAXSUPUIBW' | ||
| 'IRLOVKCVWJSWEKRJQZUVRDZGZRNANUNCSGANCJWVHMZMVNJVUAZNFZKDAIVV' | ||
| 'LSMIM9SVGUHYECTGGIXTAMXXO9FIXUMQFZCGRQWAOWJPBTXNNQIRSTZEEAJV' | ||
| 'FSXWTHWBQJCWQNYYMHSPCYRA99ITVILYJPMFGOGOUOZUVABK9HMGABSORCVD' | ||
| 'FNGLMPJ9NFKBWCZMFPIWEAGRWPRNLLG9VYUUVLCTEWKGWQIRIJKERZWC9LVR' | ||
| 'XJEXNHBNUGEGGLMWGERKYFB9YEZCLXLKKMCGLRKQOGASDOUDYEDJLMV9BHPG' | ||
| 'GCXQIUVUOFFXKEIIINLVWLRYHHLKXPLSTWKIKNEJWEDFQQFXQVEHGRCIJC9T' | ||
| 'GVQNPPKGCFGPJNWSCPQZDDSIGAVZEIVYJDVPUOCTEMKTZFGXNGPQCOIBD9MX' | ||
| 'YTHJTX' | ||
| ) | ||
|
|
||
|
|
||
| d = [0] * 243 | ||
| trits = TryteString(inp).as_trits() | ||
| curl = Curl() | ||
|
|
||
| for i in range(6): | ||
| curl.reset() | ||
| curl.absorb(trits, i * 243, (i + 1) * 243) | ||
| curl.squeeze(trits, i * 243) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test looks very specific. Is it mimicking a real-world use case? Unit tests also serve as documentation; if you add some comments explaining what real-world situation this test is simulating, it will help users to better understand what they can accomplish with the library.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only use in ISS and ISSInplace, add the source code link in docstring. |
||
|
|
||
| curl.reset() | ||
| curl.absorb(trits) | ||
| curl.squeeze(d) | ||
|
|
||
| trits_out = TryteString.from_trits(d) | ||
|
|
||
| self.assertEqual( | ||
| trits_out, | ||
| 'TAWDGNSEAD9ZRGBBVRVEKQYYVDOKHYQ9KEIYJKFT' | ||
| 'BQEYZDWZVMRFJQQGTMPHBZOGPIJCCVWLZVDKLAQVI') | ||
|
|
||
| def test_squeeze_with_486_length_should_work(self): | ||
| """ | ||
| Test squeeze with 486 length should work as well, no one use this | ||
| in real situation | ||
| """ | ||
| inp = ( | ||
| 'EMIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJ' | ||
| 'FGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH' | ||
| ) | ||
|
|
||
| trits = TryteString(inp).as_trits() | ||
|
|
||
| curl = Curl() | ||
| curl.absorb(trits) | ||
| trits_out = [] | ||
| curl.squeeze(trits_out, length=486) | ||
|
|
||
| trits_out = TryteString.from_trits(trits_out) | ||
|
|
||
| self.assertEqual( | ||
| trits_out, | ||
| 'AQBOPUMJMGVHFOXSMUAGZNACKUTISDPBSILMRAGIG' | ||
| 'RXXS9JJTLIKZUW9BCJWKSTFBDSBLNVEEGVGAMSSMQ' | ||
| 'GSJWCCFQRHWKTSMVPWWCEGOMCNWFYWDZBEDBLXIFB' | ||
| 'HOTCKUMCANLSXXTNKSYNBMOSDDEYFTDOYIKDRJM') | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍