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

Improve fungible token coverage #113

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tinkerer-shubh
Copy link
Contributor

@tinkerer-shubh tinkerer-shubh commented Mar 14, 2025

Fixes #96

I'm marking this PR as a draft for now because:

One of the goals of this issue was to increase test coverage for the functions, which this PR doesn't address yet. While there are new tests covering edge cases, I think my suggestion that these functions don't need explicit tests isn't the best approach.
I'm also considering that simplifying the YAML file might be a better option.

I'll make this ready for review once I've addressed these points. :) Open to any feedback in the meantime!

(apologies for being all over the place on this one!)

PR Checklist

  • Tests
  • Documentation

* Add tests for allowance TTL handling and edge cases

* Add tests for capped supply functionality

* Create comprehensive coverage documentation

* Set up GitHub Actions workflow for coverage checks
* Add new test files for storage and trait functionality

* Update existing test files in extensions

* Include all necessary test snapshots
Copy link

netlify bot commented Mar 14, 2025

Deploy Preview for delightful-dieffenbachia-2097e0 canceled.

Name Link
🔨 Latest commit 16419f6
🔍 Latest deploy log https://app.netlify.com/sites/delightful-dieffenbachia-2097e0/deploys/67d3d414d8563e0008ec599d

Comment on lines +70 to +85
# Extract branch coverage and verify threshold
if grep -q "TOTAL.*branches" coverage-report.txt; then
BRANCH_COVERAGE=$(grep "TOTAL.*branches" coverage-report.txt | awk '{print $NF}' | sed 's/%//')
echo "Branch coverage: $BRANCH_COVERAGE%"
if (( $(echo "$BRANCH_COVERAGE < 85" | bc -l) )); then
echo "::error::Branch coverage $BRANCH_COVERAGE% is below the target of 85%"
echo "Uncovered branches:"
cat coverage-report.txt | grep -B 1 "\^" || echo "No specific uncovered branches found!"
exit 1
else
echo "Branch coverage meets target: $BRANCH_COVERAGE% ≥ 85%"
fi
else
echo "Branch coverage information not available in this version of cargo-llvm-cov"
BRANCH_COVERAGE="Not available"
fi
Copy link
Contributor Author

@tinkerer-shubh tinkerer-shubh Mar 14, 2025

Choose a reason for hiding this comment

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

Heads up about how this implementation works with cargo-llvm-cov's text reports:

  • We look for "TOTAL.*branches" to find branch coverage info
  • Pull the percentage with awk
  • Spot uncovered code by finding "^" markers

This works fine now, but if cargo-llvm-cov changes its output format, our parsing might break. We should probably:

  1. Document this dependency somewhere
  2. Maybe add a version check for cargo-llvm-cov
  3. Keep an eye on this when we upgrade tools
  4. Consider using LCOV format with a proper parser if we need something more stable

For now though, this approach keeps things simple while getting the job done.

(OR we can just keep the line coverage for now and add branch coverage when it is natively supported in cargo-llvm-cov)

- Improved branch coverage in critical areas like allowance management and extensions
- Reduced uncovered code in error paths

Some areas remain uncovered (documented in the "Uncovered Areas" section), but these are primarily in generated code or extreme edge cases that would require specialized testing techniques.
Copy link
Contributor Author

@tinkerer-shubh tinkerer-shubh Mar 14, 2025

Choose a reason for hiding this comment

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

I added coverage.md mainly to help reviewers understand the reasoning behind the test coverage choices in this PR.

I think we can safely remove this file in the end before the merge - it's just helpful context for the review process.

Also, I'd love feedback on how I’ve set up the test placements in the project structure—just checking to see if they feel right with the rest of it.

Comment on lines +109 to +117
- name: Upload coverage report to Codecov
# Only run if the Codecov token is configured
if: ${{ secrets.CODECOV_TOKEN != '' }}
continue-on-error: true # Don't fail the workflow if Codecov upload fails
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: false # Don't fail even if the Codecov upload fails
Copy link
Contributor Author

@tinkerer-shubh tinkerer-shubh Mar 14, 2025

Choose a reason for hiding this comment

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

I've added an optional Codecov integration that only runs if you have the CODECOV_TOKEN secret set up. It gives nicer visualizations and keeps history longer than GitHub's 14-day artifact storage.

(Totally optional though - the core coverage validation works fine without it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tsk tsk

the workflow infact did not work fine without it. still working on this one!

Copy link
Collaborator

Choose a reason for hiding this comment

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

hey @tinkerer-shubh

  1. Added CODECOV_TOKEN to repo's secrets.
  2. Opened this PR just to test it gets detected and it seems fine (had to make some changes to coverage.yml to make it run).
  3. You can use the config from the Stylus repo

@tinkerer-shubh
Copy link
Contributor Author

Screenshot from 2025-03-14 18-55-42

  • Overall line coverage: 97.85%
  • Overall function coverage: 92.59%
  • Overall region coverage: 91.64%

(I had forgotten to attach the screenshot!)

@tinkerer-shubh
Copy link
Contributor Author

Screenshot from 2025-03-14 18-55-42

  • Overall line coverage: 97.85%
  • Overall function coverage: 92.59%
  • Overall region coverage: 91.64%

(I had forgotten to attach the screenshot!)

I noticed in the screenshot that the coverage report isn't showing branch coverage (it's all '0'). Maybe the script for this is failing? I'll dig into it.

Another option—if we decide to stick with the scripts—is to use region coverage as a proxy for branch coverage. Not exactly the same, but could do the trick!

@tinkerer-shubh tinkerer-shubh marked this pull request as draft March 14, 2025 20:38
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.

Tests coverage
2 participants