test(framework): stabilize test fixtures and fix resource leaks#19
test(framework): stabilize test fixtures and fix resource leaks#19
Conversation
change RocksDB iterator exception checks to use Assert.assertThrows for clearer intent and stricter failure behavior when expected exceptions are not thrown.
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
📝 WalkthroughWalkthroughThe pull request updates a GitHub Actions workflow to improve PR handling by switching from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
framework/src/test/java/org/tron/keystore/CredentialsTest.java (1)
37-45: UseAssert.assertThrowsinstead of try/catch for this negative-path test.JUnit 4.13.2 (configured in
build.gradle) supportsAssert.assertThrows(), which makes the expected exception contract explicit and simplifies failure behavior.♻️ Proposed refactor
`@Test` public void testCreateFromSM2() { - try { - Credentials.create(SM2.fromNodeId(ByteUtil.hexToBytes("fffffffffff" - + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - + "fffffffffffffffffffffffffffffffffffffff"))); - Assert.fail("Expected IllegalArgumentException"); - } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); - } + Assert.assertThrows(IllegalArgumentException.class, () -> + Credentials.create(SM2.fromNodeId(ByteUtil.hexToBytes("fffffffffff" + + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + + "fffffffffffffffffffffffffffffffffffffff")))); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@framework/src/test/java/org/tron/keystore/CredentialsTest.java` around lines 37 - 45, Replace the try/catch in the testCreateFromSM2 method with a direct Assert.assertThrows call: use Assert.assertThrows(IllegalArgumentException.class, () -> Credentials.create(SM2.fromNodeId(ByteUtil.hexToBytes("fffffffffff" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffffffffffffffffffffffffff")))); so the test explicitly expects IllegalArgumentException from Credentials.create and removes the manual try/catch/Assert.fail pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@framework/src/test/java/org/tron/keystore/CredentialsTest.java`:
- Around line 37-45: Replace the try/catch in the testCreateFromSM2 method with
a direct Assert.assertThrows call: use
Assert.assertThrows(IllegalArgumentException.class, () ->
Credentials.create(SM2.fromNodeId(ByteUtil.hexToBytes("fffffffffff" +
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
+ "fffffffffffffffffffffffffffffffffffffff")))); so the test explicitly expects
IllegalArgumentException from Credentials.create and removes the manual
try/catch/Assert.fail pattern.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 853a3d32-d58a-4af6-a455-fe5a61405449
📒 Files selected for processing (4)
.github/workflows/pr-reviewer.ymlframework/src/test/java/org/tron/core/db/DBIteratorTest.javaframework/src/test/java/org/tron/keystore/CredentialsTest.javaframework/src/test/java/org/tron/keystroe/CredentialsTest.java
💤 Files with no reviewable changes (1)
- framework/src/test/java/org/tron/keystroe/CredentialsTest.java
Summary
DBIteratorTestby properly closing iteratorsCredentialsTestcoverage fromkeystroe(typo package) intokeystoreCredentialsTestfixtures with dynamic temp file generationTest plan
./gradlew :framework:test --tests "org.tron.core.db.DBIteratorTest"./gradlew :framework:test --tests "org.tron.keystore.CredentialsTest"org.tron.keystroe.CredentialsTesthas no unique coverage🤖 Generated with Claude Code
Summary by cubic
Stabilizes keystore tests and fixes RocksDB iterator leaks to make the framework tests reliable. Also updates the reviewer auto-assign workflow with the correct event and permissions.
Bug Fixes
Assert.assertThrowsinorg.tron.core.db.DBIteratorTest.Refactors
org.tron.keystroe.CredentialsTestand merge coverage intoorg.tron.keystore.CredentialsTest.SignInterfacewith fixed addresses; assert Base58Check address, equals, and hashCode.Assertand drop legacyTestCase/SpringAssert.Written for commit 276716e. Summary will update on new commits.
Summary by CodeRabbit
Release Notes