feat: Introduce Environment constants for Sandbox and Production#33
Conversation
📝 WalkthroughWalkthroughRenames ChangesEnvironment Refactor and Module-Level Property
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_api_base.py (1)
81-83: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winEscape the regex in
pytest.raises(match=...).
match=is a regex, so the.in"Invalid environment. ..."currently matches any character. Escaping the pattern (or usingre.escape) makes the assertion exact and fixes the Ruff warning.Proposed fix
- with pytest.raises(ValueError, match="Invalid environment. Valid options are: 'sandbox', 'production'"): + with pytest.raises( + ValueError, + match=r"Invalid environment\. Valid options are: 'sandbox', 'production'", + ): shade.environment = "invalid"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_api_base.py` around lines 81 - 83, The pytest.raises match in test_invalid_assignment_raises_value_error uses a regex pattern, so the unescaped punctuation in the expected error string can match too broadly. Update the assertion in test_invalid_assignment_raises_value_error to escape the full message (for example via re.escape) so the ValueError check is exact and aligns with the Ruff warning.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/test_api_base.py`:
- Around line 81-83: The pytest.raises match in
test_invalid_assignment_raises_value_error uses a regex pattern, so the
unescaped punctuation in the expected error string can match too broadly. Update
the assertion in test_invalid_assignment_raises_value_error to escape the full
message (for example via re.escape) so the ValueError check is exact and aligns
with the Ruff warning.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 97bf6fa1-36e0-45c4-992b-5d48005a37ad
📒 Files selected for processing (4)
src/shade/__init__.pysrc/shade/config.pysrc/shade/gateway.pytests/test_api_base.py
codebestia
left a comment
There was a problem hiding this comment.
LGTM!
Thank you for your contribution.
Description
This PR introduces a formalized
Environmentenum in the SDK to handle the resolution of Horizon URLs, network passphrases, and Shade backend base URLs. This ensures that the HTTP client and Stellar layer can automatically resolve the correct settings for staging and live environments without requiring manual user mapping.Changes
MAINNETandTESTNETconstants withSANDBOXandPRODUCTIONinshade/config.py.SANDBOXto prevent accidental production interactions. Exposedshade.environmentinshade/__init__.pyto allow developers to set the environment globally.parse_environment()to allow users to set the environment using string shorthands like"sandbox"and"production". Invalid strings raise aValueError.Acceptance Criteria Met
shade.environment = "production"resolves to the mainnet Horizon URL and production API base.shade.environment = "sandbox"resolves to the testnet Horizon URL and staging API base.ValueErrorwith the list of valid options.SANDBOXto protect developers.Environmentwithout separate configuration.Closes #3
Summary by CodeRabbit
New Features
environmentsetting that can be read and updated at the module level.Gatewaynow accepts either an environment name or environment value, making configuration easier.Bug Fixes