Skip to content

feat(tokens): achieve 80%+ unit test coverage for tokens service#1499

Open
Rozerxshashank wants to merge 2 commits intohyperledger-labs:mainfrom
Rozerxshashank:fix/issue-1487-coverage-increase
Open

feat(tokens): achieve 80%+ unit test coverage for tokens service#1499
Rozerxshashank wants to merge 2 commits intohyperledger-labs:mainfrom
Rozerxshashank:fix/issue-1487-coverage-increase

Conversation

@Rozerxshashank
Copy link
Copy Markdown
Contributor

Fixes: #1487

I’ve spent some time digging into the token/services/tokens package and managed to push our unit test coverage from a pretty low 30% all the way up to 81.1%.

The main goal here wasn't just to bump up the numbers, but to make sure the core services are actually reliable. Here’s a breakdown of what I worked on:

  • Better Mocks: I built out a much more robust mocking setup in mocks_test.go for the Vault, QueryEngine, TMS, and Network. I also added a couple of helpers (buildTestTMS, buildTestNetwork) that make it way easier to spin up isolated tests without a ton of boilerplate.
  • Deeper Service Testing: I tackled the harder-to-reach logic in PruneInvalidUnspentTokens and CacheRequest. This includes covering those tricky parsing paths like Auditor flags and Graph Hiding that were previously untested.
  • Database & Transactions: I expanded the tests for DBStorage to make sure we’re correctly handling the full transaction lifecycle: specifically things like Commits, Rollbacks, and how we notify other components.
  • Bug Squashing: While writing these tests, I actually found and fixed a few potential nil-pointer issues in the service layer that could have popped up in edge cases.

Verification Results

  • Test Status: All tests in token/services/tokens are passing (go test -v).
  • Final Coverage: 81.1% of statements.

@Rozerxshashank Rozerxshashank force-pushed the fix/issue-1487-coverage-increase branch from a42c070 to 6e5fd7f Compare April 8, 2026 13:58
@Rozerxshashank
Copy link
Copy Markdown
Contributor Author

Hi @adecaro , This PR is to the Fabric Token SDK! I’ve been working on increasing the unit test coverage for the token/services/tokens package, and I’ve successfully brought it from roughly 30% up to 81.1% .

@adecaro adecaro self-requested a review April 9, 2026 05:43
@adecaro adecaro self-assigned this Apr 9, 2026
@adecaro adecaro added this to the Q2/26 milestone Apr 9, 2026
@adecaro adecaro force-pushed the fix/issue-1487-coverage-increase branch from 2470faa to e3220e6 Compare April 9, 2026 05:43
@adecaro
Copy link
Copy Markdown
Contributor

adecaro commented Apr 9, 2026

Hi @Rozerxshashank , great effort. I'll review ASAP. Thanks a lot 🙏

@adecaro
Copy link
Copy Markdown
Contributor

adecaro commented Apr 9, 2026

Hi @Rozerxshashank , please, use counterfeiter for the mocks. We use it almost everywhere. Thanks 🙏

@Rozerxshashank Rozerxshashank force-pushed the fix/issue-1487-coverage-increase branch 3 times, most recently from ff9b8ce to 28fdcec Compare April 10, 2026 14:09
Signed-off-by: Shashank <yshashank959@gmail.com>
Signed-off-by: Shashank <yshashank959@gmail.com>
@Rozerxshashank Rozerxshashank force-pushed the fix/issue-1487-coverage-increase branch from 28fdcec to 136ae89 Compare April 10, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unit-test: token/services/tokens

2 participants