Skip to content

chore(swift-sdk): swift-sdk test updated#3479

Open
ZocoLini wants to merge 1 commit intov3.1-devfrom
chore/swift-sdk-tests
Open

chore(swift-sdk): swift-sdk test updated#3479
ZocoLini wants to merge 1 commit intov3.1-devfrom
chore/swift-sdk-tests

Conversation

@ZocoLini
Copy link
Copy Markdown
Collaborator

@ZocoLini ZocoLini commented Apr 10, 2026

So, I worked on getting the tests in scope, working and updated the script to do what it is supposed to do

  • Moved all test files into swift-sdk/Tests
  • Updated run_tests.sh script
  • Removed tests that tested no longer available API
  • Removed tests that tested some exposed functions called swift_dash_* that we are not using in our unified sdk
  • Fixed bugs in Platform wrappers detected by the tests that survived the purge

Todo in incoming PRs

  • For some reason we have like 3 or 4 different Network enums with variants that don't match, I will work on unifying them making dashcore generate the FFI Network so every library uses the same wrapper. I am mentioning this because the issue with the Platform wrappers was related to the Network parameter missing in function calls and it caught my attention when trying to figure out which one I should use for the swift wrappers
  • Include the tests in the CI
  • Create some tests to verify the SPVClient and some KeyWallet operations I wrapped in the past

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Added network parameter to wallet creation methods (fromSeed and fromMnemonic) with testnet as default.
    • Introduced named network constants (mainnet, testnet, regtest, devnet, local).
  • Refactor

    • Reorganized test infrastructure and consolidated test targets.
    • Updated error codes and FFI signatures for consistency.
    • Linked SystemConfiguration framework to the SDK target.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

This PR restructures the Swift SDK test infrastructure by consolidating the separate SwiftTests package into the main packages/swift-sdk/Package.swift, removes legacy mock C implementations and headers, updates PlatformWallet FFI function signatures to accept explicit network parameters, adds network constants to DashSDKNetwork, expands error codes in PlatformWalletFFIError, and adds SystemConfiguration framework linking.

Changes

Cohort / File(s) Summary
Package Configuration
packages/swift-sdk/Package.swift, packages/swift-sdk/SwiftTests/Package.swift
Added test target SwiftDashSDKTests to main package manifest; added SystemConfiguration linker setting to SwiftDashSDK target; removed separate SwiftTests/Package.swift.
PlatformWallet FFI Signatures
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletFFI.swift
Updated FFI function signatures: added network: Network parameter to wallet creation functions (platform_wallet_info_create_from_seed, platform_wallet_info_create_from_mnemonic); removed network parameter from identity manager functions (platform_wallet_info_get_identity_manager, platform_wallet_info_set_identity_manager).
PlatformWallet API Updates
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift
Added optional network: Network = .testnet parameter to public factory methods fromSeed(_:) and fromMnemonic(_:passphrase:); updated internal FFI calls to pass network parameter.
Type System Enhancements
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift, packages/swift-sdk/Sources/SwiftDashSDK/SwiftDashSDK.swift
Added code: PlatformWalletFFIResult field to PlatformWalletFFIError struct; expanded error code constants with new codes (ErrorSerialization, ErrorDeserialization, ErrorMemoryAllocation, ErrorUnknown, ErrorUtf8Conversion); added network constants to DashSDKNetwork extension (.mainnet, .testnet, .regtest, .devnet, .local).
Removed Mock C Implementation
packages/swift-sdk/SwiftTests/Sources/SwiftDashSDKMock/..., packages/swift-sdk/SwiftTests/SwiftDashSDK.h, packages/swift-sdk/SwiftTests/TEST_FIX_SUMMARY.md
Deleted entire mock C FFI implementation (SwiftDashSDKMock.c, SwiftDashSDK.h), header files, and test fixture documentation.
Removed Old Test Suite
packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/*
Removed legacy test files including SDKTests.swift, IdentityTests.swift, DataContractTests.swift, DocumentTests.swift, TokenTests.swift, ContactRequestTests.swift, EstablishedContactTests.swift, ManagedIdentityTests.swift, MemoryManagementTests.swift, PlatformWalletIntegrationTests.swift, PlatformWalletTypesTests.swift, IdentityManagerTests.swift, SwiftConstants.swift, and run_tests.sh script.
New Test Suite
packages/swift-sdk/Tests/SwiftDashSDKTests/IdentityManagerTests.swift, packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletIntegrationTests.swift, packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletTypesTests.swift
Added new test files validating IdentityManager initialization, PlatformWallet integration workflows, and wallet type conversions (including network-specific identity manager retrieval and wallet stress testing).
Test Infrastructure Updates
packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletTests.swift, packages/swift-sdk/Tests/SwiftDashSDKTests/WalletSerializationTests.swift, packages/swift-sdk/run_tests.sh
Removed testWalletDeinit test; updated wallet serialization tests to remove explicit network parameters from wallet creation calls; added new test runner script.
Removed Example Code
packages/swift-sdk/example/SwiftSDKExample.swift
Deleted example implementation class demonstrating SDK usage patterns for identity, data contract, and document operations.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • dashpay/platform#3222: Touches Swift SDK test scaffolding and SwiftDashSDK mock implementation including changes to SDK version handling.

Suggested reviewers

  • shumkov
  • QuantumExplorer

Poem

🐰 Hop, hop! The tests take flight,
From SwiftTests to the light,
Network paths now crystal clear,
FFI signatures shed their fear,
One package strong, tests unified bright!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The PR title 'chore(swift-sdk): swift-sdk test updated' is partially related to the changeset but is vague and overly generic. While the PR does involve Swift SDK test updates, the title does not clearly convey the main changes: moving tests, updating scripts, removing obsolete tests, and fixing bugs in Platform wrappers. The phrase 'test updated' is non-descriptive. Consider a more specific title such as 'chore(swift-sdk): reorganize tests and fix platform wrapper bugs' or 'chore(swift-sdk): migrate tests to new structure and update scripts' to better reflect the primary intent and scope.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/swift-sdk-tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added this to the v3.1.0 milestone Apr 10, 2026
@ZocoLini ZocoLini marked this pull request as ready for review April 10, 2026 22:19
@thepastaclaw
Copy link
Copy Markdown
Collaborator

thepastaclaw commented Apr 10, 2026

✅ Review complete (commit dab130e)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift (2)

71-93: ⚠️ Potential issue | 🟠 Major

Misleading per-network caching when FFI doesn't support it.

The identityManagers dictionary caches by PlatformNetwork, but the FFI function platform_wallet_info_get_identity_manager (per context snippet at PlatformWalletFFI.swift:26-38) doesn't accept a network parameter—it returns the same manager for all networks. This creates a misleading API where callers expect network isolation that doesn't exist.

Consider either:

  1. Removing the network parameter and caching a single manager, or
  2. Documenting that network-specific managers are a planned future feature
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift`
around lines 71 - 93, The getIdentityManager(for network: PlatformNetwork)
method currently caches IdentityManager instances per PlatformNetwork but the
FFI call platform_wallet_info_get_identity_manager (see PlatformWalletFFI.swift)
returns a single global manager, so remove the misleading per-network behavior
by changing getIdentityManager to not take a network parameter, replace the
identityManagers dictionary with a single cached property (e.g.,
identityManager: IdentityManager?), call
platform_wallet_info_get_identity_manager once to populate that single cache
(use the existing managerHandle/error handling and IdentityManager(handle:)),
update any callers to use the new parameterless getter, and remove any
network-based caching logic to ensure the API reflects the FFI capability.

18-48: ⚠️ Potential issue | 🟠 Major

Inconsistent Network types used in the same class.

fromSeed and fromMnemonic use Network (alias for DashSDKNetwork), while getIdentityManager and setIdentityManager use PlatformNetwork. These are different enums with different raw values (see issue in PlatformWalletTypes.swift), which will cause confusion and potential bugs when users work with both APIs.

Consider unifying to a single network type throughout this class.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift`
around lines 18 - 48, The class mixes two different enums (Network and
PlatformNetwork) causing inconsistency; update the class to use a single network
type (preferably Network, the alias for DashSDKNetwork) throughout: change the
signatures and internal usage of getIdentityManager and setIdentityManager to
accept Network instead of PlatformNetwork, and update any FFI calls inside those
methods to pass the network raw value expected by the C layer (map or cast to
the FFI/platform enum as needed), or vice versa if you choose
PlatformNetwork—ensure all methods (fromSeed, fromMnemonic, getIdentityManager,
setIdentityManager) reference the same enum and add conversion logic where the
FFI requires the other enum type so rawValue alignment is preserved.
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift (1)

101-110: ⚠️ Potential issue | 🟠 Major

Network enum values mismatch with DashSDKNetwork.

PlatformNetwork defines:

  • devnet = 2, local = 3

But DashSDKNetwork (in SwiftDashSDK.swift) and the Rust FFI (packages/rs-sdk-ffi/src/types.rs) define:

  • regtest = 2, devnet = 3, local = 4

This inconsistency will cause incorrect network selection when PlatformNetwork values are passed to FFI calls expecting DashSDKNetwork values. The PR objectives mention unifying multiple Network enums as a follow-up, but this discrepancy could cause bugs in the meantime.

🔧 Suggested fix to align with DashSDKNetwork
 public enum PlatformNetwork: UInt32 {
     case mainnet = 0
     case testnet = 1
-    case devnet = 2
-    case local = 3
+    case regtest = 2
+    case devnet = 3
+    case local = 4

     var ffiValue: NetworkType {
         NetworkType(self.rawValue)
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift`
around lines 101 - 110, PlatformNetwork's raw values don't match the
FFI/DashSDKNetwork ordering; update the enum to align with DashSDKNetwork by
inserting a regtest case and shifting devnet and local values (so: mainnet=0,
testnet=1, regtest=2, devnet=3, local=4) in the PlatformNetwork declaration and
ensure the ffiValue mapping (var ffiValue: NetworkType) continues to convert
using NetworkType(self.rawValue); adjust any code that constructs
PlatformNetwork from integers if present.
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletFFI.swift (1)

26-38: ⚠️ Potential issue | 🟠 Major

FFI identity manager functions are network-agnostic, incompatible with per-network caching in Swift wrapper.

platform_wallet_info_get_identity_manager and platform_wallet_info_set_identity_manager lack network parameters. The Rust PlatformWalletInfo struct stores a single identity_manager field shared across all networks. The Swift wrapper's getIdentityManager(for:) caches managers per network but calls the FFI function without network context—receiving the same manager handle regardless of which network is requested. This causes testMultipleNetworkIdentityManagers to fail, as it expects different handles for different networks but receives identical handles.

Either implement network-specific managers in the Rust FFI layer, or redesign the Swift wrapper to acknowledge that a single shared manager serves all networks.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletFFI.swift`
around lines 26 - 38, The FFI functions
platform_wallet_info_get_identity_manager and
platform_wallet_info_set_identity_manager are network-agnostic but the Swift
wrapper's getIdentityManager(for:) caches managers per-network, causing
identical handles to be returned for different networks; fix by either (A)
adding a network parameter to the FFI signatures and underlying Rust
PlatformWalletInfo to store per-network identity managers so
platform_wallet_info_get_identity_manager/set_identity_manager accept a network
identifier and return/set network-specific handles, or (B) change the Swift
wrapper (getIdentityManager(for:), any per-network cache) to treat the identity
manager as global/shared (remove per-network caching and use a single cached
manager handle), and update related code/comments/tests (e.g.,
testMultipleNetworkIdentityManagers) to reflect the chosen behavior.
🧹 Nitpick comments (5)
packages/swift-sdk/Tests/SwiftDashSDKTests/IdentityManagerTests.swift (1)

4-16: Consider adding tearDown() to clean up resources.

If IdentityManager holds FFI handles or other resources, adding a tearDown() method to set identityManager = nil ensures proper cleanup between tests.

♻️ Suggested addition
     override func setUp() {
         super.setUp()

         do {
             identityManager = try IdentityManager.create()
         } catch {
             XCTFail("Failed to set up test: \(error)")
         }
     }
+
+    override func tearDown() {
+        identityManager = nil
+        super.tearDown()
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/swift-sdk/Tests/SwiftDashSDKTests/IdentityManagerTests.swift` around
lines 4 - 16, Tests lack a tearDown to release resources held by
IdentityManager; add an override func tearDown() in the IdentityManagerTests
class that clears the identityManager reference (e.g., set identityManager =
nil) and calls super.tearDown() so any FFI handles or other resources get
cleaned between tests after using IdentityManager.create().
packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletTypesTests.swift (1)

52-59: Clarify the expected behavior for odd-length hex strings.

The comment notes the implementation "treats this as 1 byte," but actually it parses "12" (first 2 chars) and silently drops the trailing "3". This truncation behavior may be intentional but could mask bugs if callers accidentally pass odd-length strings.

Consider documenting this behavior more explicitly or updating the implementation to return nil for odd-length inputs if strict validation is preferred.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletTypesTests.swift`
around lines 52 - 59, The test and implementation are ambiguous about how
Data(hexString:) handles odd-length hex strings—currently it silently truncates
the last nibble (parses "12" and drops "3"). Update the behavior and tests to be
explicit: either (A) make Data.init(hexString:) perform strict validation and
return nil for odd-length inputs (adjust or replace
testDataFromOddLengthHexString to assert nil), or (B) document the truncation
behavior in the Data(hexString:) initializer and update
testDataFromOddLengthHexString to assert the exact parsed result (e.g., that
"123" yields Data([0x12]) and not just non-nil). Locate the logic in the
Data(hexString:) extension/initializer and the test
testDataFromOddLengthHexString to apply the change and ensure unit tests reflect
the chosen behavior.
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift (1)

37-51: ErrorMemoryAllocation is not handled in the switch statement.

The constant ErrorMemoryAllocation = 11 is defined but the PlatformWalletError.init(result:error:) switch (lines 71-96) doesn't have a case for it, causing memory allocation errors to fall through to .unknown. Consider adding a dedicated case if this error type should be distinguished.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift`
around lines 37 - 51, The init switch in PlatformWalletError.init(result:error:)
currently maps result codes but omits the ErrorMemoryAllocation (11) constant,
so memory allocation errors fall through to .unknown; update the switch to
handle ErrorMemoryAllocation by mapping it to a distinct PlatformWalletError
case (e.g., .memoryAllocation) or add that enum case to PlatformWalletError if
it doesn't exist, and ensure the case uses the provided error string (error)
like the other cases for consistent messaging.
packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletIntegrationTests.swift (2)

85-100: Inconsistent error type assertions.

The invalid seed test (lines 93-99) properly validates the specific PlatformWalletError.invalidParameter case, but the invalid mnemonic test (lines 87-89) only checks that the error is PlatformWalletError without verifying which case. Consider making both assertions consistent for better test coverage.

♻️ Proposed fix
     // Test invalid mnemonic
     XCTAssertThrowsError(try PlatformWallet.fromMnemonic("invalid mnemonic phrase")) { error in
-        XCTAssertTrue(error is PlatformWalletError)
+        if case PlatformWalletError.invalidParameter = error {
+            // Expected
+        } else {
+            XCTFail("Expected invalidParameter error, got \(error)")
+        }
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletIntegrationTests.swift`
around lines 85 - 100, In testWalletCreationErrorHandling update the invalid
mnemonic assertion to mirror the seed test by checking for the specific
PlatformWalletError case instead of only asserting the error type; modify the
XCTAssertThrowsError closure around PlatformWallet.fromMnemonic("invalid
mnemonic phrase") to pattern-match the thrown error and assert it equals the
expected PlatformWalletError.invalidParameter (or the appropriate specific case)
so both PlatformWallet.fromMnemonic and PlatformWallet.fromSeed checks
consistently validate the exact PlatformWalletError case.

79-81: Redundant assertion adds no value.

If execution reaches line 80, the stress test has already completed successfully. The XCTAssertTrue(true, ...) is a no-op.

♻️ Proposed fix
         XCTAssertGreaterThanOrEqual(count, 0)
     }
-
-    // If this completes without crashing, memory management is working
-    XCTAssertTrue(true, "Stress test completed")
+    // Test passes if loop completes without crashing - memory management is working
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletIntegrationTests.swift`
around lines 79 - 81, The test contains a no-op assertion XCTAssertTrue(true,
"Stress test completed") which adds no value; remove that line from the test
(the one calling XCTAssertTrue(true, ...)) in PlatformWalletIntegrationTests so
the test simply completes without the redundant assertion, or replace it with a
meaningful assertion if there is an actual post-condition to verify.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletIntegrationTests.swift`:
- Around line 39-47: The test passes only because
IDENTITY_MANAGER_STORAGE.insert() generates unique handles, but
getIdentityManager() / platform_wallet_info_get_identity_manager() are returning
clones of the same underlying identity_manager for different networks—masking
that the wallet is single-network. Fix by enforcing a single-network invariant
in the wrapper: update getIdentityManager(for:) to check the requested Network
against the wallet's configured network (e.g., compare requestedNetwork to
wallet.network) and either return the existing identity_manager handle stored on
the wallet (do not call IDENTITY_MANAGER_STORAGE.insert() to fabricate new
handles) or throw/reject when networks differ; alternatively, if true
multi-network support is desired, extend
platform_wallet_info_get_identity_manager() and the underlying wallet to accept
a Network parameter and return distinct per-network identity_manager instances.
Ensure references: getIdentityManager,
platform_wallet_info_get_identity_manager, IDENTITY_MANAGER_STORAGE.insert, and
identity_manager are updated accordingly.

---

Outside diff comments:
In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift`:
- Around line 71-93: The getIdentityManager(for network: PlatformNetwork) method
currently caches IdentityManager instances per PlatformNetwork but the FFI call
platform_wallet_info_get_identity_manager (see PlatformWalletFFI.swift) returns
a single global manager, so remove the misleading per-network behavior by
changing getIdentityManager to not take a network parameter, replace the
identityManagers dictionary with a single cached property (e.g.,
identityManager: IdentityManager?), call
platform_wallet_info_get_identity_manager once to populate that single cache
(use the existing managerHandle/error handling and IdentityManager(handle:)),
update any callers to use the new parameterless getter, and remove any
network-based caching logic to ensure the API reflects the FFI capability.
- Around line 18-48: The class mixes two different enums (Network and
PlatformNetwork) causing inconsistency; update the class to use a single network
type (preferably Network, the alias for DashSDKNetwork) throughout: change the
signatures and internal usage of getIdentityManager and setIdentityManager to
accept Network instead of PlatformNetwork, and update any FFI calls inside those
methods to pass the network raw value expected by the C layer (map or cast to
the FFI/platform enum as needed), or vice versa if you choose
PlatformNetwork—ensure all methods (fromSeed, fromMnemonic, getIdentityManager,
setIdentityManager) reference the same enum and add conversion logic where the
FFI requires the other enum type so rawValue alignment is preserved.

In
`@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletFFI.swift`:
- Around line 26-38: The FFI functions platform_wallet_info_get_identity_manager
and platform_wallet_info_set_identity_manager are network-agnostic but the Swift
wrapper's getIdentityManager(for:) caches managers per-network, causing
identical handles to be returned for different networks; fix by either (A)
adding a network parameter to the FFI signatures and underlying Rust
PlatformWalletInfo to store per-network identity managers so
platform_wallet_info_get_identity_manager/set_identity_manager accept a network
identifier and return/set network-specific handles, or (B) change the Swift
wrapper (getIdentityManager(for:), any per-network cache) to treat the identity
manager as global/shared (remove per-network caching and use a single cached
manager handle), and update related code/comments/tests (e.g.,
testMultipleNetworkIdentityManagers) to reflect the chosen behavior.

In
`@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift`:
- Around line 101-110: PlatformNetwork's raw values don't match the
FFI/DashSDKNetwork ordering; update the enum to align with DashSDKNetwork by
inserting a regtest case and shifting devnet and local values (so: mainnet=0,
testnet=1, regtest=2, devnet=3, local=4) in the PlatformNetwork declaration and
ensure the ffiValue mapping (var ffiValue: NetworkType) continues to convert
using NetworkType(self.rawValue); adjust any code that constructs
PlatformNetwork from integers if present.

---

Nitpick comments:
In
`@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift`:
- Around line 37-51: The init switch in PlatformWalletError.init(result:error:)
currently maps result codes but omits the ErrorMemoryAllocation (11) constant,
so memory allocation errors fall through to .unknown; update the switch to
handle ErrorMemoryAllocation by mapping it to a distinct PlatformWalletError
case (e.g., .memoryAllocation) or add that enum case to PlatformWalletError if
it doesn't exist, and ensure the case uses the provided error string (error)
like the other cases for consistent messaging.

In `@packages/swift-sdk/Tests/SwiftDashSDKTests/IdentityManagerTests.swift`:
- Around line 4-16: Tests lack a tearDown to release resources held by
IdentityManager; add an override func tearDown() in the IdentityManagerTests
class that clears the identityManager reference (e.g., set identityManager =
nil) and calls super.tearDown() so any FFI handles or other resources get
cleaned between tests after using IdentityManager.create().

In
`@packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletIntegrationTests.swift`:
- Around line 85-100: In testWalletCreationErrorHandling update the invalid
mnemonic assertion to mirror the seed test by checking for the specific
PlatformWalletError case instead of only asserting the error type; modify the
XCTAssertThrowsError closure around PlatformWallet.fromMnemonic("invalid
mnemonic phrase") to pattern-match the thrown error and assert it equals the
expected PlatformWalletError.invalidParameter (or the appropriate specific case)
so both PlatformWallet.fromMnemonic and PlatformWallet.fromSeed checks
consistently validate the exact PlatformWalletError case.
- Around line 79-81: The test contains a no-op assertion XCTAssertTrue(true,
"Stress test completed") which adds no value; remove that line from the test
(the one calling XCTAssertTrue(true, ...)) in PlatformWalletIntegrationTests so
the test simply completes without the redundant assertion, or replace it with a
meaningful assertion if there is an actual post-condition to verify.

In `@packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletTypesTests.swift`:
- Around line 52-59: The test and implementation are ambiguous about how
Data(hexString:) handles odd-length hex strings—currently it silently truncates
the last nibble (parses "12" and drops "3"). Update the behavior and tests to be
explicit: either (A) make Data.init(hexString:) perform strict validation and
return nil for odd-length inputs (adjust or replace
testDataFromOddLengthHexString to assert nil), or (B) document the truncation
behavior in the Data(hexString:) initializer and update
testDataFromOddLengthHexString to assert the exact parsed result (e.g., that
"123" yields Data([0x12]) and not just non-nil). Locate the logic in the
Data(hexString:) extension/initializer and the test
testDataFromOddLengthHexString to apply the change and ensure unit tests reflect
the chosen behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3a0b7f49-cc75-4b45-9455-dd96a52db433

📥 Commits

Reviewing files that changed from the base of the PR and between bb4c91d and dab130e.

📒 Files selected for processing (31)
  • packages/swift-sdk/Package.swift
  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift
  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletFFI.swift
  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift
  • packages/swift-sdk/Sources/SwiftDashSDK/SwiftDashSDK.swift
  • packages/swift-sdk/SwiftTests/Package.swift
  • packages/swift-sdk/SwiftTests/Sources/SwiftDashSDKMock/SwiftDashSDK.h
  • packages/swift-sdk/SwiftTests/Sources/SwiftDashSDKMock/SwiftDashSDKMock.c
  • packages/swift-sdk/SwiftTests/SwiftDashSDK.h
  • packages/swift-sdk/SwiftTests/TEST_FIX_SUMMARY.md
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/ContactRequestTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/DataContractTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/DocumentTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/EstablishedContactTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/IdentityManagerTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/IdentityTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/ManagedIdentityTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/MemoryManagementTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/PlatformWalletIntegrationTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/PlatformWalletTypesTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/SDKTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/SwiftConstants.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/TokenTests.swift
  • packages/swift-sdk/SwiftTests/run_tests.sh
  • packages/swift-sdk/Tests/SwiftDashSDKTests/IdentityManagerTests.swift
  • packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletIntegrationTests.swift
  • packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletTests.swift
  • packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletTypesTests.swift
  • packages/swift-sdk/Tests/SwiftDashSDKTests/WalletSerializationTests.swift
  • packages/swift-sdk/example/SwiftSDKExample.swift
  • packages/swift-sdk/run_tests.sh
💤 Files with no reviewable changes (21)
  • packages/swift-sdk/SwiftTests/TEST_FIX_SUMMARY.md
  • packages/swift-sdk/Tests/SwiftDashSDKTests/PlatformWalletTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/EstablishedContactTests.swift
  • packages/swift-sdk/SwiftTests/Package.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/DocumentTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/ManagedIdentityTests.swift
  • packages/swift-sdk/SwiftTests/run_tests.sh
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/SwiftConstants.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/IdentityManagerTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/ContactRequestTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/IdentityTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/MemoryManagementTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/SDKTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/PlatformWalletIntegrationTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/TokenTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/DataContractTests.swift
  • packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/PlatformWalletTypesTests.swift
  • packages/swift-sdk/SwiftTests/Sources/SwiftDashSDKMock/SwiftDashSDK.h
  • packages/swift-sdk/example/SwiftSDKExample.swift
  • packages/swift-sdk/SwiftTests/SwiftDashSDK.h
  • packages/swift-sdk/SwiftTests/Sources/SwiftDashSDKMock/SwiftDashSDKMock.c

@github-actions
Copy link
Copy Markdown
Contributor

✅ DashSDKFFI.xcframework built for this PR.

SwiftPM (host the zip at a stable URL, then use):

.binaryTarget(
  name: "DashSDKFFI",
  url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
  checksum: "3d52b9502667ea0cc1be668dbd335b0ab4a342a33b6b092dc684e8a2e2a75a82"
)

Xcode manual integration:

  • Download 'DashSDKFFI.xcframework' artifact from the run link above.
  • Drag it into your app target (Frameworks, Libraries & Embedded Content) and set Embed & Sign.
  • If using the Swift wrapper package, point its binaryTarget to the xcframework location or add the package and place the xcframework at the expected path.

Copy link
Copy Markdown
Collaborator

@thepastaclaw thepastaclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR mostly cleans up the Swift package/test layout and aligns parts of the Platform Wallet bridge with the current Rust FFI, but two wrapper changes still leave the Swift API out of sync with the actual platform-wallet ABI. The most serious issue is the new networked wallet-creation API: it now forwards the unified SDK network enum directly into the platform-wallet FFI even though that FFI uses a different network enum layout and valid value set. Separately, the Swift layer still exposes per-network identity-manager methods even though the FFI calls are now wallet-global, so the local cache can diverge from the Rust backend state.

Reviewed commit: dab130e

🔴 1 blocking | 🟡 1 suggestion(s)

1 additional finding

🟡 suggestion: The Swift API still pretends identity managers are network-scoped after the FFI removed network scoping

packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift (lines 71-109)

getIdentityManager(for:) / setIdentityManager(_:for:) still cache managers under separate PlatformNetwork keys, but this PR removed the network argument from the actual FFI calls. On the Rust side, platform_wallet_info_get_identity_manager and platform_wallet_info_set_identity_manager now operate on the wallet's single stored identity_manager, so the Swift cache is manufacturing per-network separation that no longer exists in the backend. That means one call can update the wallet-global manager while another network key continues returning a stale cached wrapper, and the new testMultipleNetworkManagers tests can still pass because they compare handle identity rather than verifying backend isolation. The wrapper should either restore explicit network scoping in the FFI or collapse this Swift API/cache to a single wallet-global manager so callers cannot observe inconsistent per-network state.

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift`:
- [BLOCKING] lines 18-58: Wallet creation now sends the wrong network enum into the platform-wallet FFI
  The new `network:` overloads are typed as `SwiftDashSDK.Network` (`DashSDKNetwork`) and pass that value straight into `platform_wallet_info_create_from_seed` / `platform_wallet_info_create_from_mnemonic`. That is not the same enum the platform-wallet FFI expects. `DashSDKNetwork` uses `mainnet=0, testnet=1, regtest=2, devnet=3, local=4` in `packages/rs-sdk-ffi/src/types.rs`, while the Rust platform-wallet side uses `dashcore::Network`, whose discriminants are `Dash=0, Testnet=1, Devnet=2, Regtest=3` (see the checked-out dash-network dependency at `~/.cargo/git/checkouts/rust-dashcore-a35422abb966ea16/6affdaa/dash-network/src/lib.rs`). So `.regtest` now creates a devnet wallet, `.devnet` creates a regtest wallet, and `.local` passes an invalid discriminant across the FFI boundary. Before this PR the Swift bridge used `PlatformNetwork.ffiValue`, which matched the platform-wallet network layout. The fix here is to keep using the platform-wallet network enum/mapping for these entry points instead of reusing the unified SDK enum directly.
- [SUGGESTION] lines 71-109: The Swift API still pretends identity managers are network-scoped after the FFI removed network scoping
  `getIdentityManager(for:)` / `setIdentityManager(_:for:)` still cache managers under separate `PlatformNetwork` keys, but this PR removed the network argument from the actual FFI calls. On the Rust side, `platform_wallet_info_get_identity_manager` and `platform_wallet_info_set_identity_manager` now operate on the wallet's single stored `identity_manager`, so the Swift cache is manufacturing per-network separation that no longer exists in the backend. That means one call can update the wallet-global manager while another network key continues returning a stale cached wrapper, and the new `testMultipleNetworkManagers` tests can still pass because they compare handle identity rather than verifying backend isolation. The wrapper should either restore explicit network scoping in the FFI or collapse this Swift API/cache to a single wallet-global manager so callers cannot observe inconsistent per-network state.

Comment on lines 18 to 58
@@ -25,6 +25,7 @@ public class PlatformWallet {

let result = seed.withUnsafeBytes { seedPtr in
platform_wallet_info_create_from_seed(
network,
seedPtr.baseAddress?.assumingMemoryBound(to: UInt8.self),
seed.count,
&handle,
@@ -40,14 +41,19 @@ public class PlatformWallet {
}

/// Create a new Platform Wallet from a BIP39 mnemonic phrase
public static func fromMnemonic(_ mnemonic: String, passphrase: String? = nil) throws -> PlatformWallet {
public static func fromMnemonic(
_ mnemonic: String,
passphrase: String? = nil,
network: Network = .testnet
) throws -> PlatformWallet {
var handle: Handle = NULL_HANDLE
var error = PlatformWalletFFIError()

let mnemonicCStr = (mnemonic as NSString).utf8String
let passphraseCStr = passphrase != nil ? (passphrase! as NSString).utf8String : nil

let result = platform_wallet_info_create_from_mnemonic(
network,
mnemonicCStr,
passphraseCStr,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Blocking: Wallet creation now sends the wrong network enum into the platform-wallet FFI

The new network: overloads are typed as SwiftDashSDK.Network (DashSDKNetwork) and pass that value straight into platform_wallet_info_create_from_seed / platform_wallet_info_create_from_mnemonic. That is not the same enum the platform-wallet FFI expects. DashSDKNetwork uses mainnet=0, testnet=1, regtest=2, devnet=3, local=4 in packages/rs-sdk-ffi/src/types.rs, while the Rust platform-wallet side uses dashcore::Network, whose discriminants are Dash=0, Testnet=1, Devnet=2, Regtest=3 (see the checked-out dash-network dependency at ~/.cargo/git/checkouts/rust-dashcore-a35422abb966ea16/6affdaa/dash-network/src/lib.rs). So .regtest now creates a devnet wallet, .devnet creates a regtest wallet, and .local passes an invalid discriminant across the FFI boundary. Before this PR the Swift bridge used PlatformNetwork.ffiValue, which matched the platform-wallet network layout. The fix here is to keep using the platform-wallet network enum/mapping for these entry points instead of reusing the unified SDK enum directly.

source: ['codex']

🤖 Fix this with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift`:
- [BLOCKING] lines 18-58: Wallet creation now sends the wrong network enum into the platform-wallet FFI
  The new `network:` overloads are typed as `SwiftDashSDK.Network` (`DashSDKNetwork`) and pass that value straight into `platform_wallet_info_create_from_seed` / `platform_wallet_info_create_from_mnemonic`. That is not the same enum the platform-wallet FFI expects. `DashSDKNetwork` uses `mainnet=0, testnet=1, regtest=2, devnet=3, local=4` in `packages/rs-sdk-ffi/src/types.rs`, while the Rust platform-wallet side uses `dashcore::Network`, whose discriminants are `Dash=0, Testnet=1, Devnet=2, Regtest=3` (see the checked-out dash-network dependency at `~/.cargo/git/checkouts/rust-dashcore-a35422abb966ea16/6affdaa/dash-network/src/lib.rs`). So `.regtest` now creates a devnet wallet, `.devnet` creates a regtest wallet, and `.local` passes an invalid discriminant across the FFI boundary. Before this PR the Swift bridge used `PlatformNetwork.ffiValue`, which matched the platform-wallet network layout. The fix here is to keep using the platform-wallet network enum/mapping for these entry points instead of reusing the unified SDK enum directly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, I will ignore this since I am working on a Network unification PR, in case that is possible

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.

2 participants