Skip to content

test: improve coverage for token/token package (#1348)#1478

Open
nishantbkl3345-ship-it wants to merge 4 commits intohyperledger-labs:mainfrom
nishantbkl3345-ship-it:unit-test-token-package-1348
Open

test: improve coverage for token/token package (#1348)#1478
nishantbkl3345-ship-it wants to merge 4 commits intohyperledger-labs:mainfrom
nishantbkl3345-ship-it:unit-test-token-package-1348

Conversation

@nishantbkl3345-ship-it
Copy link
Copy Markdown

Summary

This PR improves unit test coverage for the token/token package as part of #1348.

What’s included

  • added a new token_test.go file to cover logic in token.go
  • added a few focused tests in quantity_test.go for missing paths (e.g. ToBigInt, type mismatch cases, and edge scenarios)
  • all tests pass locally

Coverage

  • package coverage is now ~93%

Notes

I avoided duplicating existing tests and focused only on uncovered or weakly covered areas, mainly in token.go and a few edge cases in quantity.go.

Let me know if you’d like me to adjust or expand any tests.

Copilot AI review requested due to automatic review settings April 5, 2026 10:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR increases unit test coverage for the token/token package (targeting ~93% coverage) by adding missing tests for core token structs and quantity edge cases.

Changes:

  • Added a new token_test.go covering ID, LedgerToken, and token collection helpers (Sum, ByType, Count, At).
  • Expanded quantity_test.go to cover ToBigInt, type-mismatch panics, non-64 precision paths, and negative decimal input handling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
token/token/token_test.go New unit tests for token identifiers, ledger token equality, and issued/unspent token collection helpers.
token/token/quantity_test.go Additional unit tests covering ToBigInt, panic behavior on type mismatches, BigQuantity path in UInt64ToQuantity, and negative decimal parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

assert.Panics(t, func() { big128.(*token.BigQuantity).Cmp(u64) })

// UInt64Quantity methods panic when given BigQuantity
big128 = token.NewZeroQuantity(128) // fresh instance after mutation
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

The comment "fresh instance after mutation" is misleading here: the preceding Add/Sub/Cmp calls are expected to panic before mutating big128, so there is no mutation to recover from. Consider rewording or removing the comment to reflect what’s actually happening (e.g., "fresh instance" without implying mutation).

Suggested change
big128 = token.NewZeroQuantity(128) // fresh instance after mutation
big128 = token.NewZeroQuantity(128) // fresh instance

Copilot uses AI. Check for mistakes.
@nishantbkl3345-ship-it nishantbkl3345-ship-it force-pushed the unit-test-token-package-1348 branch from 127e5f7 to e60cfb3 Compare April 5, 2026 11:08
@nishantbkl3345-ship-it
Copy link
Copy Markdown
Author

Opened a PR for this here: #1478

@AkramBitar AkramBitar added this to the Q2/26 milestone Apr 6, 2026
@AkramBitar AkramBitar linked an issue Apr 6, 2026 that may be closed by this pull request
@AkramBitar AkramBitar modified the milestones: Q2/26, Q3/26 Apr 6, 2026
@adecaro
Copy link
Copy Markdown
Contributor

adecaro commented Apr 7, 2026

Hi @nishantbkl3345-ship-it , please, rebase and check the linter errors. You can run the linters with make lint and make checks (run both). The makefile contains also entries to install the tools.

Thanks 🙏

@adecaro adecaro self-requested a review April 7, 2026 08:59
@nishantbkl3345-ship-it nishantbkl3345-ship-it force-pushed the unit-test-token-package-1348 branch 2 times, most recently from 0b3e3ac to b63824f Compare April 7, 2026 21:38
@adecaro adecaro force-pushed the unit-test-token-package-1348 branch from f178ac2 to 4651e85 Compare April 9, 2026 05:42
@adecaro
Copy link
Copy Markdown
Contributor

adecaro commented Apr 9, 2026

Hi @nishantbkl3345-ship-it , thanks for submitting this. I'll review ASAP.

@adecaro adecaro force-pushed the unit-test-token-package-1348 branch from b301925 to 91cbc64 Compare April 10, 2026 07:50
Copy link
Copy Markdown
Contributor

@adecaro adecaro left a comment

Choose a reason for hiding this comment

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

LGTM

@adecaro
Copy link
Copy Markdown
Contributor

adecaro commented Apr 10, 2026

Hi @nishantbkl3345-ship-it , please, check again the PR. There are linting issues. We have upgraded golangci-lint version. Thanks 🙏

@nishantbkl3345-ship-it nishantbkl3345-ship-it force-pushed the unit-test-token-package-1348 branch from 8183729 to 0c2b88c Compare April 10, 2026 19:55
…verage

Signed-off-by: Nishant <nishantbkl3345@gmail.com>
@nishantbkl3345-ship-it nishantbkl3345-ship-it force-pushed the unit-test-token-package-1348 branch from 0c2b88c to c6d00c1 Compare April 10, 2026 20:02
@nishantbkl3345-ship-it
Copy link
Copy Markdown
Author

I checked it again with the updated lint setup and pushed a follow-up fix.

I cleaned up the issues in quantity.go and updated the quantity tests to match the current behavior. All tests and lint checks pass locally now.

Signed-off-by: Nishant <nishantbkl3345@gmail.com>
@nishantbkl3345-ship-it nishantbkl3345-ship-it force-pushed the unit-test-token-package-1348 branch from c1a5eb7 to 42d0b33 Compare April 11, 2026 07:56
@adecaro
Copy link
Copy Markdown
Contributor

adecaro commented Apr 12, 2026

Hi @nishantbkl3345-ship-it , please, fix the conflicts. Thanks 🙏

@adecaro
Copy link
Copy Markdown
Contributor

adecaro commented Apr 12, 2026

@nishantbkl3345-ship-it , there is something strange in the PR. There are way too many files changed. Please, have a second look.

@adecaro adecaro self-requested a review April 12, 2026 06:07
Copy link
Copy Markdown
Contributor

@adecaro adecaro left a comment

Choose a reason for hiding this comment

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

Please, double check the PR.

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/token package

4 participants