feat: add comprehensive validation for contract creation#708
Open
Xaxxoo wants to merge 1 commit into
Open
Conversation
Closes SoroScan#590 - Add validate_contract_id to TrackedContractSerializer: strips whitespace, enforces the ^C[A-Z2-7]{55}$ Base32 regex with a clear human-readable error, and rejects duplicate contract_id on create with a message explaining the address is already registered. - Add validate_network: rejects unrecognised network values with an error that lists the valid choices (mainnet, testnet, futurenet). - Expose the network field in TrackedContractSerializer.Meta.fields (it was previously omitted from the API response). - Extend test_contract_validation.py with serializer-level tests: valid/invalid address format, wrong length, bad charset, whitespace stripping, duplicate rejection, update bypass, all valid networks, invalid network, error message content, and network in serialized output.
|
@Xaxxoo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #590
Summary
validate_contract_idtoTrackedContractSerializer:^C[A-Z2-7]{55}$Base32 regex with a clear, human-readable error message.TrackedContractwith the samecontract_idand returns a descriptive duplicate error instead of a raw database integrity error.validate_network: rejects unrecognised network values and lists the valid choices (mainnet,testnet,futurenet) in the error message.networkfield inTrackedContractSerializer.Meta.fields(it was previously missing from the API response entirely).Test plan
test_valid_contract_id_passes— valid Base32 address passestest_invalid_prefix_rejected_by_serializer— G-prefix address rejected with Base32 messagetest_wrong_length_rejected_by_serializer— 55-char and 57-char addresses rejectedtest_invalid_charset_rejected_by_serializer—0in address rejectedtest_leading_whitespace_stripped_and_validated— stripped address that becomes invalid is rejectedtest_duplicate_contract_id_rejected— second registration of same address gives "already registered" errortest_duplicate_check_skipped_on_update— updating an existing contract with its owncontract_idpassestest_valid_networks_accepted— mainnet, testnet, futurenet all passtest_invalid_network_rejected— "devnet" rejected with valid-choices messagetest_empty_network_rejected— empty string rejectedtest_error_message_mentions_base32— error message is informativetest_network_error_lists_valid_choices— error message lists valid optionstest_network_field_present_in_serialized_output— network field appears in response