fix(models): distinguish DepositPreauth validation errors in ledger_entry request - #358
Open
soloking1412 wants to merge 1 commit into
Open
fix(models): distinguish DepositPreauth validation errors in ledger_entry request#358soloking1412 wants to merge 1 commit into
soloking1412 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
High Level Overview of Change
Fixes two related validation bugs in
DepositPreauth::get_errors()(theledger_entryrequest selector,src/models/requests/ledger_entry.rs):ExpectedOneOferror for both "neitherauthorizednorauthorized_credentialsset" and "both set" — two states that need opposite remediation (add a field vs. remove one). These are now split into distinct arms.authorized_credentialsraisedInvalidValue, while every other site in the codebase that detects duplicate credentials (validate_credential_ids, theDepositPreauthtransaction model, theDepositPreauthledger object model) raisesValueEqualsValue. Callers that match onValueEqualsValueto categorize "duplicate credential" errors silently fell through to their default arm for this one request type.Context of Change
Both inconsistencies were found during review of #154 (XLS-70 Credentials support); neither was introduced by that PR. Filed as #333 and #334.
Type of Change
Before / After
authorized: None, authorized_credentials: NoneExpectedOneOf(["authorized", "authorized_credentials"])authorized: Some, authorized_credentials: SomeExpectedOneOf(["authorized", "authorized_credentials"])InvalidFieldCombination { field: "authorized", other_fields: ["authorized_credentials"] }(issuer, credential_type)pair inauthorized_credentialsInvalidValue { field: "authorized_credentials", expected: "unique issuer and credential_type pairs", .. }ValueEqualsValue { field1: "authorized_credentials", field2: "authorized_credentials (duplicate entry)" }, matching every other duplicate-credential check in the codebaseInvalidFieldCombinationwas chosen overValueEqualsValuefor the mutually-exclusive-fields case becauseValueEqualsValueis used elsewhere in this codebase strictly for "these two fields hold the same value" (e.g.account == authorize), not "these two fields are both present" —InvalidFieldCombinationalready carries that second meaning at the sibling ledger-object and transaction validators.Test Plan
cargo test --release(1314 passed, up from 1313). Updatedtest_deposit_preauth_rejects_duplicate_authorized_credentials,test_deposit_preauth_rejects_case_variant_duplicate_credentials, andtest_deposit_preauth_rejects_authorized_and_credentialsto assert on the specific error variant instead of onlyis_err(). Addedtest_deposit_preauth_rejects_neither_authorized_nor_credentials, which previously had no coverage.cargo clippy --all-targetsandcargo fmt --checkare clean on the changed file.Closes #333
Closes #334