[TM-329] Consider lengths during unpack
Description
All binary data in Michelson encoding is prefixed with its length, and sometimes we ignore this length and parse as many bytes as reasonable with regard to the type we parse (e.g. Address has fixed length). But this is obviously wrong and if that length in the prefix does not match against how many bytes we are going to consume, then we have to fail.
After committing a fix, I noticed some refactorings which can be made, so this MR even reached fixing another issue.
Related issue(s)
https://issues.serokell.io/issue/TM-329
Resolves #19 (closed).
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
-
If I added new functionality, I added tests covering it. -
If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
-
Documentation
Stylistic guide (mandatory)
-
My commits comply with the following policy. -
My code complies with the style guide.
Edited by Konstantin Ivanov