Skip to content

feat: add comprehensive validation for contract creation#708

Open
Xaxxoo wants to merge 1 commit into
SoroScan:mainfrom
Xaxxoo:feat/contract-validation-590
Open

feat: add comprehensive validation for contract creation#708
Xaxxoo wants to merge 1 commit into
SoroScan:mainfrom
Xaxxoo:feat/contract-validation-590

Conversation

@Xaxxoo
Copy link
Copy Markdown

@Xaxxoo Xaxxoo commented Jun 1, 2026

Closes #590

Summary

  • Adds validate_contract_id to TrackedContractSerializer:
    • Strips surrounding whitespace before checking.
    • Enforces the ^C[A-Z2-7]{55}$ Base32 regex with a clear, human-readable error message.
    • On create, checks for an existing TrackedContract with the same contract_id and returns a descriptive duplicate error instead of a raw database integrity error.
    • On update, the duplicate check is skipped so a PATCH/PUT to the same contract does not fail.
  • Adds validate_network: rejects unrecognised network values and lists the valid choices (mainnet, testnet, futurenet) in the error message.
  • Exposes the network field in TrackedContractSerializer.Meta.fields (it was previously missing from the API response entirely).

Test plan

  • test_valid_contract_id_passes — valid Base32 address passes
  • test_invalid_prefix_rejected_by_serializer — G-prefix address rejected with Base32 message
  • test_wrong_length_rejected_by_serializer — 55-char and 57-char addresses rejected
  • test_invalid_charset_rejected_by_serializer0 in address rejected
  • test_leading_whitespace_stripped_and_validated — stripped address that becomes invalid is rejected
  • test_duplicate_contract_id_rejected — second registration of same address gives "already registered" error
  • test_duplicate_check_skipped_on_update — updating an existing contract with its own contract_id passes
  • test_valid_networks_accepted — mainnet, testnet, futurenet all pass
  • test_invalid_network_rejected — "devnet" rejected with valid-choices message
  • test_empty_network_rejected — empty string rejected
  • test_error_message_mentions_base32 — error message is informative
  • test_network_error_lists_valid_choices — error message lists valid options
  • test_network_field_present_in_serialized_output — network field appears in response

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.
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 1, 2026

@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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Contract Creation Validation

1 participant