Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite library #12

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open

Rewrite library #12

wants to merge 62 commits into from

Conversation

sterliakov
Copy link

@sterliakov sterliakov commented May 16, 2022

This is part of VeChain hackathon submission.

  • Added ABI v2 functionality;
  • Improved test suite;
  • Add more public methods for convenient library usage;
  • Code made consistent;
  • Documentation built.

Core changes

  • Fully mypy-compatible code, including TypedDict for data static validation;
  • Consistent naming policy (no camelCase methods exposed, validate and is_valid with consistent meaning);
  • Documentation ready for RTD publishing, added examples and missing docstrings, building uses custom plugins (see docs/source/ext files docstrings for explanation);
  • Properties for data attributes access;
  • ABIv2 struct support;
  • Enhanced Event and Function interface:
    • decoding methods now return custom namedtuples instead of dictionaries, providing dot.access by name, numeric index[access] and to_dict method to convert to {name: value} dictionary);
    • Added methods to encode and decode other data (function can now both encode and decode inputs and outputs; event can encode data or everything together);
    • Solidity binding to create functions and events directly from solidity code.
  • Moderate backwards compatibility (see at the end of README);
  • Strict code style;
  • Unified RLP ScalarKind and BaseWrapper interface: they both provide serialize and deserialize public methods;
  • Consistent validation of hex strings, hex numbers and addresses;
  • Certificate verify and encode are now methods instead of module-level functions, because they were taking a single argument, Certificate instance, and thus are perfect methods.
  • HDNode subclasses can now override constants;
  • Almost 100% coverage (-5 lines, 3 of them are for python 3.11 and 2 remaining run in workflows, but not locally - installing solidity happens only once per version);
  • Clean pytest code with fixtures.

Current docs

Hosted on RTD

I suggest that the library maintainer will create ReadTheDocs account and deploy docs. All configuration is already done (see .readthedocs.yaml). Then link in README should be updated.

Why so much about style?

Because library code will be read a lot, so consistent code formatting eases the process. Why black? Because it formats everything with the same rules, so any contributor will not add his own style to the project codebase. And flake8 ensures that no bad naming policy and no invalid/missing documentation will be present in repository.

Why mypy was chosen as a reference type checker?

Because it is de-facto standard in python ecosystem, the tool is maintained by python core team. It is most likely included in our users pipeline.

Why properties?

Because it is python. While not enforced by pep8, properties are great way in python to express some calculated attributes of object, hiding the internals from end user. selector or id of something is not a function - you don't try to call it, you try to access it. Thus, properties are semantically more suitable.

Why supporting ancient bip-utils?

Because we support python 3.6 and it is the latest version available for 3.6. Remember, that python 3.6 is End Of Life more than a year, right? And bip_utils 2.0.0 introduced major backwards incompatible changes. It would be great to drop 3.6 support and upgrade dependencies unconditionally, and I'm ready to work on that given maintainer's confirmation.

Coverage with tox

Name                           Stmts   Miss Branch BrPart  Cover   Missing
--------------------------------------------------------------------------
thor_devkit/__init__.py            3      0      0      0   100%
thor_devkit/abi.py               357      3    160      1    99%   52, 709-710
thor_devkit/bloom.py              46      0     10      0   100%
thor_devkit/certificate.py        73      1     16      1    98%   29
thor_devkit/cry/__init__.py        5      0      0      0   100%
thor_devkit/cry/address.py        28      0      6      0   100%
thor_devkit/cry/blake2b.py        10      0      4      0   100%
thor_devkit/cry/hdnode.py         87      0      6      0   100%
thor_devkit/cry/keccak.py         10      0      4      0   100%
thor_devkit/cry/keystore.py       92      0     12      0   100%
thor_devkit/cry/mnemonic.py       43      0      8      0   100%
thor_devkit/cry/secp256k1.py      59      0     12      0   100%
thor_devkit/cry/utils.py          62      0     26      0   100%
thor_devkit/exceptions.py         15      0      8      0   100%
thor_devkit/rlp.py               162      0     68      0   100%
thor_devkit/transaction.py       203      1     58      1    99%   37
thor_devkit/validation.py         63      0     28      0   100%
--------------------------------------------------------------------------
TOTAL                           1318      5    426      3    99%

Impact

Closes #10
Closes #11

@laalaguer
Copy link
Contributor

Thanks for the submission! Nice work. I will take a look at it page by page.

@laalaguer
Copy link
Contributor

By the way, can you squash the commits together so I can start make comments on it?

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ABIv2 "Tuple" Type Upgrade bip_utils to version 2.1.0 due to backward incompatibility
2 participants