Skip to content

Validate supported position token symbols#374

Open
silentgeckoaudit3801 wants to merge 6 commits into
Quantarq:mainfrom
silentgeckoaudit3801:fix/token-symbol-validation-230
Open

Validate supported position token symbols#374
silentgeckoaudit3801 wants to merge 6 commits into
Quantarq:mainfrom
silentgeckoaudit3801:fix/token-symbol-validation-230

Conversation

@silentgeckoaudit3801

Copy link
Copy Markdown

Summary

  • add a SQLAlchemy CheckConstraint for supported Position.token_symbol values
  • add an Alembic migration for the Postgres check constraint
  • validate position and extra-deposit token symbols at the Pydantic boundary, normalizing supported lowercase input to uppercase
  • add tests for DOGE rejection and model constraint coverage

Validation

  • Static API validation confirmed the model constraint, migration head, Pydantic validators, and DOGE rejection tests are present
  • Compare is 0 commits behind upstream main

Closes #230

def test_position_form_data_normalizes_supported_token_symbol():
form = PositionFormData(
wallet_id="GABC",
token_symbol="usdc",
multiplier="2",
)

assert form.token_symbol == "USDC"
multiplier="2",
)

assert form.token_symbol == "USDC"
with pytest.raises(ValidationError):
PositionFormData(
wallet_id="GABC",
token_symbol="DOGE",

def test_extra_deposit_data_rejects_unsupported_token_symbol():
with pytest.raises(ValidationError):
AddPositionDepositData(amount="50", token_symbol="DOGE")
sql = str(constraint.sqltext)

for token in SUPPORTED_POSITION_TOKENS:
assert token in sql

for token in SUPPORTED_POSITION_TOKENS:
assert token in sql
assert "DOGE" not in sql No newline at end of file
multiplier: float

@field_validator("token_symbol")
def validate_token_symbol(cls, value: str) -> str:
transaction_hash: Optional[str] = None

@field_validator("token_symbol")
def validate_deposit_token_symbol(cls, value: str) -> str:
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.

CHECK constraint on token_symbol

2 participants