test(dpp): add deserialization failure tests and fix stale test structs#3128
test(dpp): add deserialization failure tests and fix stale test structs#3128thepastaclaw wants to merge 4 commits intodashpay:v3.1-devfrom
Conversation
📝 WalkthroughWalkthroughTest improvements across error handling and state transition modules, adding round-trip serialization/deserialization validation and expanding deserialization test coverage with new edge case scenarios. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 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 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)
packages/rs-dpp/src/state_transition/serialization.rs (1)
433-511: Optional: drop therandom-identitiesfeature gate by not requiring a fullIdentity.Both
deserialize_truncated_bytes_should_failanddeserialize_corrupted_bytes_should_not_panicuseIdentity::random_identityexclusively to obtainidentity.id(). TheIdentifier::random()helper inplatform_valuehas norandom-identitiesdependency and would produce an equally validIdentifier. Removing the full identity construction lets these tests run in every CI configuration.♻️ Proposed simplification for both tests
- #[test] - #[cfg(feature = "random-identities")] + #[test] fn deserialize_truncated_bytes_should_fail() { - let platform_version = PlatformVersion::latest(); - let identity = Identity::random_identity(5, Some(5), platform_version) - .expect("expected a random identity"); let transition = IdentityCreditWithdrawalTransitionV0 { - identity_id: identity.id(), + identity_id: platform_value::Identifier::random(), amount: 5000000,Apply the same substitution to
deserialize_corrupted_bytes_should_not_panic.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/rs-dpp/src/state_transition/serialization.rs` around lines 433 - 511, Tests deserialize_truncated_bytes_should_fail and deserialize_corrupted_bytes_should_not_panic are gated on the random-identities feature only to obtain identity.id(); replace that by generating a lightweight Identifier via Identifier::random() (from platform_value) and use its value for identity_id in IdentityCreditWithdrawalTransitionV0 so the tests no longer need the random-identities feature; remove the #[cfg(feature = "random-identities")] annotation from both test functions and update imports to include platform_value::Identifier (or the crate path used) so Identity::random_identity(...) calls and the feature gate can be dropped while keeping IdentityCreditWithdrawalTransitionV0, StateTransition, serialize_to_bytes and deserialize_from_bytes usage unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/rs-dpp/src/state_transition/serialization.rs`:
- Around line 433-511: Tests deserialize_truncated_bytes_should_fail and
deserialize_corrupted_bytes_should_not_panic are gated on the random-identities
feature only to obtain identity.id(); replace that by generating a lightweight
Identifier via Identifier::random() (from platform_value) and use its value for
identity_id in IdentityCreditWithdrawalTransitionV0 so the tests no longer need
the random-identities feature; remove the #[cfg(feature = "random-identities")]
annotation from both test functions and update imports to include
platform_value::Identifier (or the crate path used) so
Identity::random_identity(...) calls and the feature gate can be dropped while
keeping IdentityCreditWithdrawalTransitionV0, StateTransition,
serialize_to_bytes and deserialize_from_bytes usage unchanged.
3c69e75 to
bbc9c34
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
PastaPastaPasta
left a comment
There was a problem hiding this comment.
seems useful to have over not
520c287 to
07ae804
Compare
Summary
Add negative deserialization tests, fix stale test struct definitions, and complete discarded error round-trips in rs-dpp.
Changes
C-08: Complete discarded round-trips in error serialization tests
unsupported_protocol_version_error.rsandunsupported_version_error.rshad tests that serialized aConsensusErrorbut assigned the result to_cbor(discarding it). The commented-out deserialization used an old Value-based API.PlatformDeserializableround-trip: serialize → deserialize → assert equality.C-14: Fix stale IdentityCreditWithdrawalTransition test structs
protocol_version,transition_type,revision) that don't exist in the actualIdentityCreditWithdrawalTransitionV0.identity_id,amount,core_fee_per_byte,pooling,output_script,nonce,user_fee_increase,signature_public_key_id,signature.C-10: Add negative deserialization tests for StateTransition
deserialize_empty_bytes_should_fail— empty slice returns Errdeserialize_single_byte_should_fail— single 0xFF byte returns Errdeserialize_truncated_bytes_should_fail— truncated to half, minus last byte, first byte onlydeserialize_corrupted_bytes_should_not_panic— bit-flip in middle of payloaddeserialize_many_empty_list— empty vec returns Ok(vec![])deserialize_many_with_invalid_entry— invalid bytes returns Errdeserialize_many_with_valid_entries— round-trip 3 valid transitionsTesting
All 487 tests pass with
cargo test -p dpp --features random-identities,state-transition-signing.Summary by CodeRabbit
Validation
What was tested
Results
Environment
dashpay/platform