|
| 1 | +# Repository Guidelines |
| 2 | + |
| 3 | +<!-- wallet-context:start --> |
| 4 | +> About this codebase |
| 5 | +> This repository contains the codebase for a cryptocurrency wallet compatible with the Polkadot ecosystem (and related networks). |
| 6 | +> It uses dependencies available in the iOS ecosystem (e.g., SoraFoundation, SoraKeystore, FearlessKeys) and has an Android counterpart in soramitsu/fearless-Android. |
| 7 | +<!-- wallet-context:end --> |
| 8 | +
|
| 9 | +## Project Structure & Modules |
| 10 | +- `fearless/`: App sources, split by features/modules. |
| 11 | +- `fearlessTests/`, `fearlessIntegrationTests/`: Unit/integration tests. |
| 12 | +- `fearless.xcworkspace`, `fearless.xcodeproj`: Xcode workspace/project files. |
| 13 | +- `Pods/`, `Podfile`, `Podfile.lock`: CocoaPods dependencies. |
| 14 | +- `Jenkinsfile`: CI pipeline configuration. |
| 15 | +- Config files: `.swiftlint.yml`, `.swiftformat`, `.periphery.yml`. |
| 16 | + |
| 17 | +## Build, Test, and Dev Commands |
| 18 | +- Install dependencies: `pod install` |
| 19 | +- Build (Debug, simulator): |
| 20 | + - `xcodebuild -workspace fearless.xcworkspace -scheme fearless -configuration Debug -destination 'platform=iOS Simulator,OS=latest,name=iPhone 15' build` |
| 21 | +- Run unit tests (on simulator): |
| 22 | + - `xcodebuild -workspace fearless.xcworkspace -scheme fearless.tests -destination 'platform=iOS Simulator,OS=latest,name=iPhone 15' test` |
| 23 | +- Lint/format: |
| 24 | + - `swiftlint` (uses `.swiftlint.yml`) |
| 25 | + - `swiftformat .` (uses `.swiftformat`) |
| 26 | + - CI matrix: `bash scripts/test-matrix.sh` runs tests for Debug and Release |
| 27 | + |
| 28 | +Example destinations |
| 29 | +- iPhone 15: `-destination 'platform=iOS Simulator,OS=latest,name=iPhone 15'` |
| 30 | +- iPhone 14 Pro: `-destination 'platform=iOS Simulator,OS=latest,name=iPhone 14 Pro'` |
| 31 | +- iPad Pro (11-inch) 4th gen: `-destination 'platform=iOS Simulator,OS=latest,name=iPad Pro (11-inch) (4th generation)'` |
| 32 | + |
| 33 | +Tip: list available destinations with `xcodebuild -showsdks` and `xcrun simctl list devices`. |
| 34 | + |
| 35 | +CI note |
| 36 | +- Jenkins is configured to run tests on each build. For deterministic local parity, use `scripts/test-matrix.sh` before opening a PR. |
| 37 | + |
| 38 | +## Coding Style & Naming |
| 39 | +- Language: Swift; follow Swift API design guidelines. |
| 40 | +- Formatting: SwiftFormat; linting with SwiftLint. |
| 41 | +- Files: one main type per file; names in PascalCase; avoid long files. |
| 42 | +- Packages/Modules: keep dependencies explicit; prefer dependency injection to singletons. |
| 43 | +- Avoid force‑unwraps; handle errors explicitly with clear user messaging. |
| 44 | + |
| 45 | +## Testing Guidelines |
| 46 | +- Framework: XCTest; tests live in `fearlessTests/` and `fearlessIntegrationTests/`. |
| 47 | +- Naming: mirror the class under test, e.g., `AccountRepositoryTests.swift`; test methods `testX_whenY_thenZ`. |
| 48 | +- Coverage: maintain/raise coverage for changed code. |
| 49 | +- New code policy: whenever you add a function, add at least one unit test covering it. |
| 50 | + |
| 51 | +## Commit & Pull Requests |
| 52 | +- Commits: concise, imperative subjects; reference issues (`#123`). Conventional Commit prefixes (`feat:`, `fix:`, `refactor:`) encouraged. |
| 53 | +- Before PR: ensure build + tests pass locally; `swiftlint`/`swiftformat` are clean. |
| 54 | +- PR checklist: clear description, linked issue, screenshots/video for UI, steps to test, risk/rollback notes. |
| 55 | +- CI must be green (Jenkins or equivalent). |
| 56 | + |
| 57 | +## Security & Configuration |
| 58 | +- Never commit secrets or private keys. Use Keychain/secure storage at runtime; use CI secrets for pipelines. |
| 59 | +- Do not alter seed handling, signing, or cryptography without maintainer approval. |
| 60 | +- Runtime registries and chain/type sources must be aligned with the current Polkadot SDK release; coordinate updates with maintainers. |
| 61 | +- Use `*.xcconfig` and environment variables for private values; avoid hardcoding secrets in `Info.plist`. |
| 62 | + |
| 63 | +## Dependencies & Versioning |
| 64 | +- Prefer conservative upgrades (patch/minor). Pin major bumps to separate PRs with clear testing notes. |
| 65 | +- Summarize upstream changes (link release notes) and provide a rollback plan. |
| 66 | +- If aligning to a Polkadot SDK release, ensure iOS utils/runtime dependencies are pinned accordingly (e.g., fearless-utils‑ios or equivalent). |
| 67 | + |
| 68 | +## Preferred Tasks for Agents |
| 69 | +- Keep build green: fix warnings, flaky tests, and broken CI when root cause is clear. |
| 70 | +- Code hygiene: remove dead code; improve naming; tighten access control. |
| 71 | +- Tooling: enforce SwiftLint/SwiftFormat; update configs when safe. |
| 72 | +- Tests: add missing unit tests around changed code; stabilize integration tests. |
| 73 | +- Docs: keep README/ROADMAP/this guide accurate; small updates are welcome. |
| 74 | + |
| 75 | +## Out of Scope (without prior approval) |
| 76 | +- Feature/UI/UX changes. |
| 77 | +- Protocol, staking, or on‑chain logic changes. |
| 78 | +- Wallet/account management, seeds, encryption, or secure storage changes. |
| 79 | +- Adding telemetry/analytics. |
| 80 | + |
| 81 | +## Communication & Escalation |
| 82 | +- Use GitHub issues/PRs for decisions and traceability. |
| 83 | +- See `CONTRIBUTING.md` for community channels and expectations. |
| 84 | +- When in doubt, open an issue and wait for maintainer guidance. |
| 85 | + |
| 86 | +## Sources of Truth |
| 87 | +- Roadmap (Aha!): https://soramitsucoltd.aha.io/shared/97bc3006ee3c1baa0598863615cf8d14 |
| 88 | +- Dev status board: https://soramitsucoltd.aha.io/shared/343e5db57d53398e3f26d0048158c4a2 |
| 89 | +- Issues: https://github.com/soramitsu/fearless-iOS/issues |
| 90 | +- Contributing: ./CONTRIBUTING.md |
| 91 | +- Roadmap (repo): ./ROADMAP.md |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +By following these guidelines, agents help keep Fearless Wallet iOS healthy, predictable, and aligned with the published roadmap while minimizing risk to users. |
| 96 | + |
| 97 | +## Build & Archive — End‑to‑End Checklist |
| 98 | + |
| 99 | +The project mixes CocoaPods and Swift Package Manager. Follow these steps in order. |
| 100 | + |
| 101 | +1) Prerequisites (local dev) |
| 102 | +- Xcode 15.4+ (Xcode 18 SDK supported; CI pins 15.x when available for SPM/IrohaCrypto stability) |
| 103 | +- CocoaPods: `brew install cocoapods` (or `gem install cocoapods`) |
| 104 | +- SwiftFormat, SwiftLint (optional for local): `brew install swiftformat swiftlint` |
| 105 | + |
| 106 | +2) Install Pods (always open the workspace) |
| 107 | +- From repo root: `pod install` |
| 108 | +- Open: `open fearless.xcworkspace` |
| 109 | + |
| 110 | +3) Resolve SPM packages |
| 111 | +- CLI: `xcodebuild -resolvePackageDependencies -workspace fearless.xcworkspace -scheme fearless` |
| 112 | +- Xcode GUI: File → Packages → Reset Package Caches → Resolve Package Versions (if needed) |
| 113 | + |
| 114 | +4) Build & test on Simulator (no signing) |
| 115 | +- Build: `xcodebuild -workspace fearless.xcworkspace -scheme fearless -configuration Debug -destination 'platform=iOS Simulator,OS=latest,name=iPhone 15' build` |
| 116 | +- Tests: `bash scripts/test-matrix.sh` (runs Debug + Release simulator tests using `fearless.tests` by default) |
| 117 | + |
| 118 | +5) Archive (two options) |
| 119 | +- Development archive (local testing without Distribution certs): |
| 120 | + - In Xcode target ‘fearless’ → Signing & Capabilities (Dev config): set Automatic + Apple Development + your team/profile. |
| 121 | + - Then: `xcodebuild -workspace fearless.xcworkspace -scheme fearless -configuration Dev -destination 'generic/platform=iOS' -archivePath "$PWD/build/fearless.xcarchive" clean archive` |
| 122 | +- Ad‑hoc archive (CI/Release parity): |
| 123 | + - Requirements on the machine: Apple Distribution certificate for team `YLWWUD25VZ` + ad‑hoc profile `fearlesswallet-dev-adhoc` installed. |
| 124 | + - Project Dev config must be Manual + Apple Distribution + `jp.co.soramitsu.fearlesswallet.dev` + `PROVISIONING_PROFILE_SPECIFIER=fearlesswallet-dev-adhoc`. |
| 125 | + |
| 126 | +6) Private pods (FearlessKeys) |
| 127 | +- The pod `FearlessKeys` is private. To allow `pod install` on CI/local without prompting: |
| 128 | + - Provide a GitHub Personal Access Token with repo read access (recommended env var: `GH_PAT_READ`). |
| 129 | + - Preconfigure git on the agent: `git config --global url."https://${GH_PAT_READ}@github.com/".insteadOf "https://github.com/"` (or run `scripts/secrets/setup-private-pods.sh` which does this for you and writes `.env.private` with `INCLUDE_FEARLESS_KEYS=1`). |
| 130 | + - Alternatively, write a `~/.netrc` with GitHub credentials (read-only). |
| 131 | + |
| 132 | +7) IrohaCrypto + SPM stability (Xcode 16/18) |
| 133 | +- The SPM package `shared-features-spm` must be pinned to a revision that works with Xcode 16/18 (`3ad0fe9…`). We now enforce this automatically via `scripts/deps/enforce-ssf-pin.sh` in CI (`bootstrap.sh`), local dev (`dev-setup.sh`), and tests (`test-matrix.sh`). |
| 134 | +- Dependency-contract validation is centralized in: |
| 135 | + - `scripts/deps/check-dependency-contracts.sh` |
| 136 | +- Native crypto stability now uses dedicated contract scripts: |
| 137 | + - `scripts/deps/prepare-native-crypto-checkout.sh` |
| 138 | + - `scripts/deps/apply-native-crypto-package-contract.sh` |
| 139 | + - `scripts/deps/apply-native-crypto-modulemap-contract.sh` |
| 140 | + - `scripts/deps/verify-native-crypto-package-state.sh` |
| 141 | +- Additional required `shared-features-spm` compatibility fixes (BigInt dep, Web3 Data.bytes, AddressFactory type usage, scrypt guard) are applied by `scripts/spm-shared-features-fixes.sh`. |
| 142 | + |
| 143 | +8) Web3 duplication |
| 144 | +- The project uses `soramitsu/web3-swift@7.7.7`. Do not add another Web3 source; duplicate packages will cause resolver failure. |
| 145 | + |
| 146 | +## CI Build Requirements (Jenkins) |
| 147 | + |
| 148 | +- CocoaPods available on agents (or handled in a shared pipeline step). If Pods are installed elsewhere, our Jenkinsfile guards will skip `pod install` gracefully. |
| 149 | +- Environment variables: |
| 150 | + - `GH_PAT_READ` (optional): GitHub PAT for private pods (`FearlessKeys`). |
| 151 | + - `DEVELOPER_DIR` (optional): Jenkinsfile auto‑pins to Xcode 15.x if present for SPM stability; otherwise default Xcode is used. |
| 152 | +- Private keys in PRs: |
| 153 | + - PR builds do NOT require private keys. The Jenkinsfile detects PR context (`CHANGE_ID`) and temporarily comments out the `pod 'FearlessKeys'` line before `pod install`, then restores the file. This prevents private repo access and allows PRs to build without secrets. |
| 154 | + - Trusted branches (develop/master/release): Jenkins sets `INCLUDE_FEARLESS_KEYS=1` and, if `GH_PAT_READ` is present, rewrites GitHub URLs to use the token so `pod install` can fetch `FearlessKeys`. |
| 155 | +- Steps performed before archive: |
| 156 | + - Clean SPM caches; resolve packages if the workspace exists. |
| 157 | + - Configure GitHub token (if provided) and run `pod install --repo-update` when `pod` is available. |
| 158 | + - Prepare the native crypto checkout against the repo-owned contract when required by the resolved package state. |
| 159 | +- Fastlane lane archives Dev as Ad‑hoc with mapping: |
| 160 | + - `jp.co.soramitsu.fearlesswallet.dev` → `fearlesswallet-dev-adhoc` |
| 161 | + - Ensure the Apple Distribution cert for `YLWWUD25VZ` is installed on the CI keychain. |
| 162 | + |
| 163 | +## Common Build Failures & Fixes |
| 164 | + |
| 165 | +- “No profile … matching ‘fearlesswallet-dev-adhoc’”: install the ad‑hoc profile (and Distribution certificate) on the machine, or switch PR builds to Development signing. |
| 166 | +- “Missing package product ‘MPQRCoreSDK’”: resolve SPM; reset SPM caches; ensure network access for binary targets. |
| 167 | +- “umbrella header … IrohaCrypto-umbrella.h not found”: use the pinned `shared-features-spm` revision and run the dedicated native crypto contract scripts / verifier. |
| 168 | +- “multiple similar targets ‘Web3’ …”: dedupe to `soramitsu/web3-swift@7.7.7` only. |
| 169 | +- “pod install” fails cloning FearlessKeys: supply `GH_PAT_READ` or gate that pod in CI. |
| 170 | +- “Ambiguous type ‘MetaAccountModel’ / ‘ChainAccountResponse’ in tests”: tests include `fearlessTests/Helper/TestTypeAliases.swift` to resolve ambiguity to app models. If you add conflicting SDK types, keep this shim or qualify uses (`fearless.MetaAccountModel`). |
| 171 | +- “JSONRPCEngine conformance missing in tests”: `fearlessTests/Common/Services/ChainRegistry/MockConnection.swift` provides a test engine conforming to the current `JSONRPCEngine` protocol. If the protocol changes upstream, adjust this file accordingly. |
| 172 | + |
| 173 | +## Troubleshooting Raw Archive Output |
| 174 | + |
| 175 | +- To bypass xcpretty and see the actual error: |
| 176 | + - `set -o pipefail; xcodebuild -workspace fearless.xcworkspace -scheme fearless -configuration Dev -destination 'generic/platform=iOS' -archivePath "$PWD/build/fearless.xcarchive" clean archive | tee build/archive.raw.log` |
| 177 | + - Then: `tail -n 300 build/archive.raw.log` |
0 commit comments