Skip to content

test(framework): consolidate and stabilize CredentialsTest#6614

Open
3for wants to merge 2 commits intotronprotocol:developfrom
3for:credential_test_fix
Open

test(framework): consolidate and stabilize CredentialsTest#6614
3for wants to merge 2 commits intotronprotocol:developfrom
3for:credential_test_fix

Conversation

@3for
Copy link
Copy Markdown
Collaborator

@3for 3for commented Mar 31, 2026

What does this PR do?

This PR cleans up and consolidates CredentialsTest coverage in the framework module.

  • removes the duplicate test under the incorrect package path org.tron.keystroe
  • keeps the test in the correct package org.tron.keystore
  • replaces random key generation with deterministic mocked SignInterface fixtures
  • adds stronger assertions for Credentials.create(...), equals(...), and hashCode()

Why are these changes required?

The previous test setup had two problems:

  1. test coverage was split across two locations, including a typo package path
  2. some assertions depended on random key generation, which made the test intent less explicit and less stable

This change makes the test deterministic, easier to understand, and better aligned with the current Credentials contract:

  • address is derived from getAddress()
  • equality depends on both cryptoEngine and address
  • equal objects must have the same hashCode

This PR has been tested by:

  • Unit Tests
    • ./gradlew framework:test --tests org.tron.keystore.CredentialsTest

Follow up

No follow-up is required.

Extra details

This is a test-only change. No production logic, protocol behavior, or runtime code path is modified.

3for added 2 commits March 31, 2026 11:27
Consolidate the misplaced keystroe CredentialsTest into org.tron.keystore.CredentialsTest.

- remove the duplicate test under the misspelled keystroe package
- add explicit equals behavior coverage for address and cryptoEngine
- normalize assertions to JUnit Assert and remove legacy TestCase usage
Replace random Credentials test setup with deterministic SignInterface mocks
so the suite no longer depends on platform-specific SecureRandom providers or
probabilistic retries.

- remove NativePRNG usage from CredentialsTest
- replace random key generation with fixed address fixtures via mocked SignInterface
- assert create(SignInterface) returns the expected base58check address
- keep equals/hashCode contract coverage with deterministic inputs
Comment on lines +13 to +14
private static final byte[] ADDRESS_1 = ByteUtil.hexToBytes(
"410102030405060708090a0b0c0d0e0f1011121314");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work on the fixture improvement! Just a quick question out of curiosity — the old "TQhZ7...".getBytes() returns 34 UTF-8 bytes rather than a proper 21-byte address, so switching to ByteUtil.hexToBytes("410102...") definitely improves semantic correctness. That said, does this change have any practical impact on the test outcomes, or is it more of a correctness/readability improvement on the fixture side? Just want to make sure I'm not missing anything.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@CodeNinjaEvan Yes, this is mainly a fixture correctness improvement rather than an intended behavioral change.

SignInterface.getAddress() is expected to return raw address bytes, so using a canonical 21-byte TRON address fixture is a better fit for the API contract. The previous Base58 string UTF-8 bytes could still make the test pass because Credentials.create(...) currently just feeds the returned bytes into encode58Check(...) without validating the address shape.

So it would be better to keep the new fixture as-is. It makes the test semantically correct, and it doesn’t materially change the current behavior under test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@CodeNinjaEvan Yes, this is mainly a fixture correctness improvement rather than an intended behavioral change.

SignInterface.getAddress() is expected to return raw address bytes, so using a canonical 21-byte TRON address fixture is a better fit for the API contract. The previous Base58 string UTF-8 bytes could still make the test pass because Credentials.create(...) currently just feeds the returned bytes into encode58Check(...) without validating the address shape.

So it would be better to keep the new fixture as-is. It makes the test semantically correct, and it doesn’t materially change the current behavior under test.

Thanks for clarifying! Makes total sense — keeping the new fixture as-is.

@kuny0707 kuny0707 requested a review from lxcmyf April 6, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants