Skip to content

<test>(sdk): raise unit-test coverage 54.6% -> 69.9% (pure-Java, no node)#959

Open
kyonRay wants to merge 1 commit into
FISCO-BCOS:release-3.9.0from
kyonRay:test/raise-unit-coverage
Open

<test>(sdk): raise unit-test coverage 54.6% -> 69.9% (pure-Java, no node)#959
kyonRay wants to merge 1 commit into
FISCO-BCOS:release-3.9.0from
kyonRay:test/raise-unit-coverage

Conversation

@kyonRay

@kyonRay kyonRay commented Jun 23, 2026

Copy link
Copy Markdown
Member

What

Adds offline (no live node) JUnit4 unit tests that substantially raise the unit-test coverage tracked by Codecov.

Unit-only JaCoCo (the CI/Codecov-visible metric — .codecov.yml ignores the integration-test dirs):

metric before after
instruction 54.57% 69.87%
line 56.24% 68.22%
branch 67.79%
method 76.07%

26 new test files, all passing offline under Java 8. No production code is modified.

How

The biggest "uncovered" chunks were the generated precompiled and auth contract wrappers and their high-level *Service classes — which looked integration-only but are actually pure-Java once instantiated. The tests:

  • instantiate wrappers/services with a mocked Client (Mockito) + a real new CryptoSuite(CryptoType.ECDSA_TYPE) keypair — no BcosSDK.build / Client.build / network;
  • drive the getXxxInput/getXxxOutput decoders via ABI round-trips (encode known args with the SDK's own FunctionEncoder, set them on a TransactionReceipt, decode, assert);
  • drive read paths by stubbing client.call(...) with ABI-encoded outputs;
  • cover pure-Java codec/model/util classes (ContractLoader, ContractCodec, AbiTypes, ABIDefinition, TransactionReceipt, JsonTransactionResponse, StringUtils, CryptoSuite, …) directly.

Notable package gains

contract/auth/contracts 6.7% → 88.2%, precompiled/crud 6.8% → 67%, precompiled/consensus 12.5% → 66%, precompiled/balance 20% → 72%, precompiled/bfs 36% → 74%, transaction/tools 36% → 89%, utils → 95%, model → 93%.

Scope / what is intentionally not covered

The remaining gap is genuinely node/JNI-dependent and not unit-testable: ClientImpl JSON-RPC, live transaction submission (native TransactionBuilderJniObj signing), and the eventsub/filter push loops. Those are exercised by the integrationTest suite instead.

🤖 Generated with Claude Code

… 69.9%

Adds offline (no live node) JUnit4 unit tests that drive the generated
precompiled and auth contract wrappers, their high-level Service classes, and
several pure-Java codec/model/util classes. The wrappers are exercised via a
mocked Client (Mockito) plus ABI round-trips (encode known args with the SDK's
own FunctionEncoder, feed to the getXxxInput/getXxxOutput decoders) and stubbed
client.call(...) outputs, so no chain or JNI transaction signing is required.

Unit-only JaCoCo (verifiable in CI/Codecov, which ignores integration-test
dirs): instruction 54.57% -> 69.87%, line 56.24% -> 68.22%, branch -> 67.79%,
method -> 76.07%. Notable package gains: contract/auth/contracts 6.7% -> 88.2%,
precompiled/crud 6.8% -> 67%, consensus 12.5% -> 66%, balance 20% -> 72%,
bfs 36% -> 74%, transaction/tools 36% -> 89%.

Test-only change; no production code modified.
Copilot AI review requested due to automatic review settings June 23, 2026 09:31
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release-3.9.0@401fb58). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-3.9.0     #959   +/-   ##
================================================
  Coverage                 ?   63.95%           
  Complexity               ?     4550           
================================================
  Files                    ?      430           
  Lines                    ?    17592           
  Branches                 ?     1962           
================================================
  Hits                     ?    11251           
  Misses                   ?     5591           
  Partials                 ?      750           
Flag Coverage Δ
unittest 63.95% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants