Repository navigation
test(swift-sdk): run SDKMethodTests against the offline mock SDK instead of live testnet - #5009
Conversation
…ead of live testnet testSimpleIdentityFetch and testDirectMethodCall built SDK(network: .testnet), so the required Swift SDK CI job failed on every PR whenever testnet was unreachable or stopped producing blocks (the SDK's stale-block time check refused the response). Unit tests must not touch the network. - Add an internal SDK(mockVectorsDirectory:) initializer over the existing FFI dash_sdk_create_handle_with_mock. The mock has no transport; it replays recorded DAPI responses and still verifies their proofs. - testSimpleIdentityFetch now fetches identity [1; 32] through identityGet from rs-sdk's recorded test_identity_read vectors and checks its id and public keys. - testDirectMethodCall now runs on the mock with a valid private key. The all-zero key it used is not a valid secp256k1 scalar, so signer creation failed and the test returned before calling transferCredits. It now requires the "Invalid to_identity_id" refusal instead of any error. - The live testnet identity read moves to SwiftDashSDKIntegrationTests/Platform/TestnetIdentityFetchTests.swift, skipped unless RUN_TESTNET_TESTS=1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe Swift SDK tests now use an FFI mock and recorded response vectors for method checks. A separate integration test fetches a known identity from testnet when ChangesSwift SDK tests
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The offline tests and opt-in testnet test are ready to merge after normal checks; no concrete merge-blocking issue remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🕓 Queued for automated review — 1st in line, estimated start in ~15 min (commit 0779964)
|
Issue being fixed or feature implemented
The required job "Swift SDK build / Swift SDK build + tests (warnings as errors)" ran two unit tests in
SDKMethodTeststhat builtSDK(network: .testnet). One of them,testSimpleIdentityFetch, read a live testnet identity. On 2026-09-25 testnet Platform stopped producing blocks at height 601636. From about 22:35 UTC, every PR's Swift job failed on that test, including unrelated ones such as #5006 (run 36199315296) and branchfix/dpns-name-pick-survives-sync(run 36198430696):That is the SDK's stale-block time check working as intended. Unit tests must not touch the network (CLAUDE.md,
book/src/contributing/coding-conventions.md), andPackage.swiftalready labels this target "Unit tests (offline, hermetic)".The second test,
testDirectMethodCall, also built a testnet SDK, but it never reached the call it meant to test. Its all-zero private key is not a valid secp256k1 scalar, sodash_sdk_signer_create_from_private_keyfailed and the test printed "Failed to create signer" and returned early, passing without checking anything.What was done?
SDK.init(mockVectorsDirectory:)(internal, inSources/SwiftDashSDK/SDK.swift) wraps the existing FFI constructordash_sdk_create_handle_with_mock. It adds no new FFI. The mock SDK has no transport: its DAPI client answers only from recordedmsg_*.jsonresponses, still verifies their proofs against the recorded quorum keys, and fails any request it has no recording for.SDK(network:)is unchanged. It always goes throughdash_sdk_create_trusted, which falls back to the seed nodes, so Swift previously had no way to reach the mock.testSimpleIdentityFetchnow usesSDK(mockVectorsDirectory:)with rs-sdk's recordedpackages/rs-sdk/tests/vectors/test_identity_readvectors. It fetches identity[1; 32]throughidentityGet, so the recorded response is replayed, its proof is verified, and the result is decoded into the Swift dictionary. It then asserts the id and that public keys are present.testDirectMethodCallnow uses the mock with no vectors and a valid key (0x01repeated 32 times). It fails if signer creation fails, and it requiresSDKError.internalErrorcontainingInvalid to_identity_id, because the FFI refuses"test2"while parsing the identifier. Any other error fails the test, so a network failure can no longer make it pass.SwiftTests/SwiftDashSDKIntegrationTests/Platform/TestnetIdentityFetchTests.swift. It is skipped unlessRUN_TESTNET_TESTS=1is set, and it keeps the original check (SDK(network: .testnet),identityGet("5DbLwAxGBzUzo81VewMUwn4b5P4bpv9FNFybi25XB5Bk")) plus an id assertion. It is a plainXCTestCasebecauseIntegrationTestCasestarts a local devnet.Before / after
swift test --filter SDKMethodTestswhile testnet was halted:Before:
After:
With
RUN_TESTNET_TESTSunset,TestnetIdentityFetchTestsis skipped. WithRUN_TESTNET_TESTS=1, it reads testnet as before.Worth knowing
The
test_identity_readvectors carry GroveDB V0 proofs. They verify because the mock SDK is built for mainnet, whose SDK protocol version floor (min_protocol_version(Mainnet)) is 13. If that floor rises to 14,testSimpleIdentityFetchwill fail until the vectors are regenerated withscripts/generate_test_vectors.sh, as rs-sdk's own identity offline tests already note. That breakage comes from a code change in this repository, not from network state.How Has This Been Tested?
The tests were run on macOS from
packages/swift-sdkwith the branch at7829c84f2a. It was then fast-forwarded onto1f5069590a, which adds #5005, #5006 and #5008. None of those touchpackages/swift-sdk, and #5008'srs-sdk-ffichange is outside the mock path, so the tests were not re-run after the fast-forward.bash build_ios.sh --target tests --profile dev: OK.swift build --build-tests: OK with no warnings, including the integration target, which compiles with-warnings-as-errors.swift test --filter SDKMethodTests: 3 tests, 0 failures. The baseline before the change was 1 failure, the error above.tcp connect error ... Operation not permitted.RUN_TESTNET_TESTS=1 swift test --filter TestnetIdentityFetchTests: passed once testnet was producing blocks again. Without the variable, it is skipped.swift test: 735 tests, 18 skipped, 0 failures. One of three runs had an unrelateddatabase is lockedfailure inDashModelMigrationTests, which passed 3 of 3 times when run on its own.xcodebuild test -project SwiftExampleApp/SwiftExampleApp.xcodeproj -scheme SwiftExampleApp -skip-testing:SwiftExampleAppUITests: 206 passed, 15 skipped, 0 failed.Breaking Changes
None. Test-only change plus one
internalinitializer.Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
0779964/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are doneswift-sdk(packages/swift-sdk/Package.swift,packages/swift-sdk/Sources/SwiftDashSDK/SDK.swift,packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Platform/TestnetIdentityFetchTests.swiftand 1 more) — llbartekll or romchornyiWhen every box is checked the
PR Hygienecheck passes and this can merge.Summary by CodeRabbit