-
Notifications
You must be signed in to change notification settings - Fork 57
fix(swift-example-app): make Platform Sync "Clear" actually clear synced data #3959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09333ba
fix(swift-example-app): make Platform Sync "Clear" actually clear syn…
llbartekll 8d3ca39
fix(swift-example-app): fail closed and scope platform Clear to activ…
llbartekll 7ee5034
fix(swift-sdk): drop stale platform-address sync completions after Clear
llbartekll 93f3bf0
fix(swift-sdk): clear retained platform-address published state on reset
llbartekll d1b0222
fix(swift-example-app): zero platform-address rows in place instead o…
llbartekll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...swift-sdk/SwiftExampleApp/SwiftExampleAppTests/PlatformBalanceSyncServiceClearTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import SwiftData | ||
| import XCTest | ||
| @testable import SwiftDashSDK | ||
| @testable import SwiftExampleApp | ||
|
|
||
| @MainActor | ||
| final class PlatformBalanceSyncServiceClearTests: XCTestCase { | ||
|
|
||
| /// The Platform Sync "Clear" button must delete BOTH platform-address | ||
| /// SwiftData stores — the cached per-address balances | ||
| /// (`PersistentPlatformAddress`) and the network-scoped sync-state | ||
| /// watermark (`PersistentPlatformAddressesSyncState`) — so the UI | ||
| /// reads zero and the next sync is a full rescan rather than a ~2s | ||
| /// incremental resume (the reported "Clear didn't work" symptom). | ||
| /// | ||
| /// The Rust-side watermark reset is skipped here because no wallet | ||
| /// manager is configured (the `if let walletManager` guard short- | ||
| /// circuits); that path is covered by the platform-wallet Rust unit | ||
| /// test (`reset_sync_state_clears_watermark_and_seed`) and manual | ||
| /// simulator verification. | ||
| func testClearLocalStateWipesPlatformAddressRows() async throws { | ||
| let container = try DashModelContainer.createInMemory() | ||
| let context = ModelContext(container) | ||
| let walletId = Data(repeating: 0x44, count: 32) | ||
|
|
||
| context.insert( | ||
| PersistentPlatformAddress( | ||
| address: "yTestPlatformAddr", | ||
| addressType: 0, | ||
| addressHash: Data(repeating: 0x01, count: 20), | ||
| accountIndex: 0, | ||
| addressIndex: 0, | ||
| derivationPath: "m/9'/1'/17'/0'/0'/0", | ||
| balance: 294_627_247_940, | ||
| walletId: walletId | ||
| ) | ||
| ) | ||
| context.insert( | ||
| PersistentPlatformAddressesSyncState( | ||
| walletId: Self.syncStateScopeId(for: .testnet), | ||
| network: .testnet, | ||
| syncHeight: 10, | ||
| syncTimestamp: 20, | ||
| lastKnownRecentBlock: 30 | ||
| ) | ||
| ) | ||
| try context.save() | ||
|
|
||
| // Sanity: both rows present before the clear. | ||
| XCTAssertEqual(try fetch(PersistentPlatformAddress.self, in: container).count, 1) | ||
| XCTAssertEqual(try fetch(PersistentPlatformAddressesSyncState.self, in: container).count, 1) | ||
|
|
||
| let service = PlatformBalanceSyncService() | ||
| await service.clearLocalState(modelContext: context) | ||
|
|
||
| XCTAssertTrue( | ||
| try fetch(PersistentPlatformAddress.self, in: container).isEmpty, | ||
| "cached per-address balances must be deleted" | ||
| ) | ||
| XCTAssertTrue( | ||
| try fetch(PersistentPlatformAddressesSyncState.self, in: container).isEmpty, | ||
| "the sync-state watermark must be deleted so the next sync is a full rescan" | ||
| ) | ||
| } | ||
|
|
||
| private static func syncStateScopeId(for network: Network) -> Data { | ||
| var data = Data("platform-sync:\(network.networkName)".utf8.prefix(32)) | ||
| if data.count < 32 { | ||
| data.append(Data(repeating: 0, count: 32 - data.count)) | ||
| } | ||
| return data | ||
| } | ||
|
|
||
| private func fetch<T: PersistentModel>(_ type: T.Type, in container: ModelContainer) throws -> [T] { | ||
| try ModelContext(container).fetch(FetchDescriptor<T>()) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.