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

refactor: constrain environment associated type bounds to ease mocking #265

Merged
merged 6 commits into from
Sep 6, 2024

Conversation

evilrobot-01
Copy link
Collaborator

The pallet_contracts::Config bound on the associated types within Environment/Ext means that mocking the environment requires taking a dependency on pallet-contracts and requires adding it to the mock runtime. This is overkill for unit tests.

This PR simply constrains the type bounds to the only type currently required - AccountId. This can obviously be refactored in the future as more of the Ext implementation is used.

Also adds a test for the Prepender, which was the original cause of this refactor requirement.

@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2024

Codecov Report

Attention: Patch coverage is 80.35714% with 11 lines in your changes missing coverage. Please review.

Project coverage is 46.23%. Comparing base (f0a0a51) to head (7f447f0).

Files with missing lines Patch % Lines
pallets/api/src/extension.rs 64.70% 6 Missing ⚠️
extension/src/decoding.rs 76.47% 0 Missing and 4 partials ⚠️
extension/src/mock.rs 75.00% 1 Missing ⚠️
@@                 Coverage Diff                 @@
##           frank/extension     #265      +/-   ##
===================================================
+ Coverage            45.50%   46.23%   +0.72%     
===================================================
  Files                   40       40              
  Lines                 3685     3707      +22     
  Branches              3685     3707      +22     
===================================================
+ Hits                  1677     1714      +37     
+ Misses                1954     1938      -16     
- Partials                54       55       +1     
Files with missing lines Coverage Δ
extension/src/environment.rs 100.00% <100.00%> (ø)
extension/src/functions.rs 92.50% <100.00%> (+0.05%) ⬆️
extension/src/lib.rs 94.23% <100.00%> (ø)
runtime/devnet/src/config/api/mod.rs 35.29% <ø> (ø)
extension/src/mock.rs 95.12% <75.00%> (ø)
extension/src/decoding.rs 96.91% <76.47%> (ø)
pallets/api/src/extension.rs 48.33% <64.70%> (+48.33%) ⬆️

extension/src/environment.rs Outdated Show resolved Hide resolved
value.insert(0, version);
value.insert(1, module);
value.insert(2, index);
value.splice(0..0, [version, module, index]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant syntax!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats down to Peter! 🙌

@evilrobot-01 evilrobot-01 merged commit 848b4c3 into frank/extension Sep 6, 2024
10 checks passed
@evilrobot-01 evilrobot-01 deleted the frank/refactor-environment branch September 6, 2024 15:34
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.

4 participants