Skip to content

Validate token contract exists before group creation#112

Open
WuXieSec wants to merge 1 commit intosorosave-protocol:mainfrom
WuXieSec:feat/validate-token-exists
Open

Validate token contract exists before group creation#112
WuXieSec wants to merge 1 commit intosorosave-protocol:mainfrom
WuXieSec:feat/validate-token-exists

Conversation

@WuXieSec
Copy link
Copy Markdown

This PR adds validation to ensure the provided token address is a valid Stellar asset contract, as requested in #62.

Changes:

  • Call token contract's symbol() to verify it exists
  • Return InvalidToken error if contract call fails
  • Add InvalidToken variant to ContractError enum
  • Add test coverage for both valid and invalid tokens

Why this matters:
Without validation, groups could be created with:

  • Invalid addresses
  • Non-existent contracts
  • Non-token contracts

This would cause failures later when trying to transfer tokens during contributions and payouts.

Implementation:
Uses try_symbol() to safely check if the token contract exists and implements the token interface. If the call fails, we reject the group creation immediately.

Test coverage:

  • Valid token contract → group creation succeeds
  • Invalid/non-existent address → InvalidToken error

Closes #62

Changes:
- Call token contract's symbol() to verify it exists
- Return InvalidToken error if contract call fails
- Add InvalidToken variant to ContractError enum
- Add test coverage for both valid and invalid tokens

This prevents groups from being created with invalid or
non-existent token addresses, ensuring all groups use
valid Stellar asset contracts.

Closes sorosave-protocol#62
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.

Validate token contract exists before group creation

1 participant