From e2fb2d3ecba8730302a7711a0b5d88ba6118039d Mon Sep 17 00:00:00 2001 From: llbartekll Date: Wed, 4 Dec 2024 09:03:40 +0100 Subject: [PATCH 01/17] add bundle id query param --- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- Sources/WalletConnectRelay/RelayClientFactory.swift | 7 +++---- Sources/WalletConnectRelay/RelayURLFactory.swift | 5 ++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Example/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 6e9c421e..4e6022e8 100644 --- a/Example/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Example/ExampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/attaswift/BigInt.git", "state": { "branch": null, - "revision": "793a7fac0bfc318e85994bf6900652e827aef33e", - "version": "5.4.1" + "revision": "114343a705df4725dfe7ab8a2a326b8883cfd79c", + "version": "5.5.1" } }, { diff --git a/Sources/WalletConnectRelay/RelayClientFactory.swift b/Sources/WalletConnectRelay/RelayClientFactory.swift index 812eb7d1..325a8871 100644 --- a/Sources/WalletConnectRelay/RelayClientFactory.swift +++ b/Sources/WalletConnectRelay/RelayClientFactory.swift @@ -56,11 +56,10 @@ public struct RelayClientFactory { relayHost: relayHost, projectId: projectId ) - let socket = socketFactory.create(with: relayUrlFactory.create()) + let bundleId = Bundle.main.bundleIdentifier + let socket = socketFactory.create(with: relayUrlFactory.create(bundleId: bundleId)) + socket.request.addValue(EnvironmentInfo.userAgent, forHTTPHeaderField: "User-Agent") - if let bundleId = Bundle.main.bundleIdentifier { - socket.request.addValue(bundleId, forHTTPHeaderField: "Origin") - } do { let authToken = try socketAuthenticator.createAuthToken(url: "wss://" + relayHost) diff --git a/Sources/WalletConnectRelay/RelayURLFactory.swift b/Sources/WalletConnectRelay/RelayURLFactory.swift index 163eb310..21f0009b 100644 --- a/Sources/WalletConnectRelay/RelayURLFactory.swift +++ b/Sources/WalletConnectRelay/RelayURLFactory.swift @@ -12,13 +12,16 @@ class RelayUrlFactory { self.projectId = projectId } - func create() -> URL { + func create(bundleId: String?) -> URL { var components = URLComponents() components.scheme = "wss" components.host = relayHost components.queryItems = [ URLQueryItem(name: "projectId", value: projectId) ] + if let bundleId = Bundle.main.bundleIdentifier { + components.queryItems?.append(URLQueryItem(name: "bundleId", value: bundleId)) + } return components.url! } } From 17a026ea91b701cb7a8eea530d9aa0c4b0344640 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 5 Dec 2024 11:05:32 +0100 Subject: [PATCH 02/17] solve leaking continuation issue update relay e2e test --- .../RelayClientEndToEndTests.swift | 80 +++++++------------ Sources/WalletConnectRelay/Dispatching.swift | 24 ++++-- 2 files changed, 47 insertions(+), 57 deletions(-) diff --git a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift index ca3e2e6f..00797e3c 100644 --- a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift +++ b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift @@ -44,12 +44,11 @@ final class RelayClientEndToEndTests: XCTestCase { relayHost: InputConfig.relayHost, projectId: InputConfig.projectId ) - let socket = WebSocket(url: urlFactory.create()) - let webSocketFactory = WebSocketFactoryMock(webSocket: socket) +// let socket = WebSocket(url: urlFactory.create(bundleId: nil)) let networkMonitor = NetworkMonitor() - - let socketStatusProvider = SocketStatusProvider(socket: socket, logger: logger) - let socketConnectionHandler = AutomaticSocketConnectionHandler(socket: socket, subscriptionsTracker: SubscriptionsTracker(logger: logger), logger: logger, socketStatusProvider: socketStatusProvider, clientIdAuthenticator: socketAuthenticator) +// +// let socketStatusProvider = SocketStatusProvider(socket: socket, logger: logger) +// let socketConnectionHandler = AutomaticSocketConnectionHandler(socket: socket, subscriptionsTracker: SubscriptionsTracker(logger: logger), logger: logger, socketStatusProvider: socketStatusProvider, clientIdAuthenticator: socketAuthenticator) let keychain = KeychainStorageMock() let relayClient = RelayClientFactory.create( @@ -58,7 +57,7 @@ final class RelayClientEndToEndTests: XCTestCase { keyValueStorage: keyValueStorage, keychainStorage: keychain, socketFactory: DefaultSocketFactory(), - socketConnectionType: .manual, + socketConnectionType: .automatic, networkMonitor: networkMonitor, logger: logger ) @@ -74,38 +73,29 @@ final class RelayClientEndToEndTests: XCTestCase { super.tearDown() } -// func testSubscribe() { -// relayA = makeRelayClient(prefix: "") -// -// do { -// try relayA.connect() -// } catch { -// XCTFail("Failed to connect: \(error)") -// } -// -// let subscribeExpectation = expectation(description: "subscribe call succeeds") -// subscribeExpectation.assertForOverFulfill = true -// relayA.socketConnectionStatusPublisher.sink { [weak self] status in -// guard let self = self else {return} -// if status == .connected { -// Task(priority: .high) { try await self.relayA.subscribe(topic: "ecb78f2df880c43d3418ddbf871092b847801932e21765b250cc50b9e96a9131") } -// subscribeExpectation.fulfill() -// } -// }.store(in: &publishers) -// -// wait(for: [subscribeExpectation], timeout: InputConfig.defaultTimeout) -// } + func testConnect() async { + let randomTopic = String.randomTopic() + relayA = makeRelayClient(prefix: "⚽️ A ") + + let expectation = expectation(description: "RelayA publishes message successfully") + + Task { + do { + try await self.relayA.subscribe(topic: randomTopic) + expectation.fulfill() // Mark the expectation as fulfilled upon success + } catch { + XCTFail("Publish failed with error: \(error)") + } + } + + // Wait for the expectation with a timeout + wait(for: [expectation], timeout: 20.0) // Set the timeout duration in seconds + } - func testEndToEndPayload() { + func testEndToEndPayload() async throws { relayA = makeRelayClient(prefix: "⚽️ A ") relayB = makeRelayClient(prefix: "🏀 B ") - do { - try relayA.connect() - try relayB.connect() - } catch { - XCTFail("Failed to connect: \(error)") - } let randomTopic = String.randomTopic() let payloadA = "A" let payloadB = "B" @@ -120,8 +110,7 @@ final class RelayClientEndToEndTests: XCTestCase { expectationA.assertForOverFulfill = false expectationB.assertForOverFulfill = false - relayA.messagePublisher.sink { [weak self] topic, payload, _, _ in - guard let self = self else { return } + relayA.messagePublisher.sink { topic, payload, _, _ in (subscriptionATopic, subscriptionAPayload) = (topic, payload) expectationA.fulfill() }.store(in: &publishers) @@ -136,22 +125,11 @@ final class RelayClientEndToEndTests: XCTestCase { expectationB.fulfill() }.store(in: &publishers) - relayA.socketConnectionStatusPublisher.sink { [weak self] status in - guard let self = self else { return } - guard status == .connected else { return } - Task(priority: .high) { - try await self.relayA.subscribe(topic: randomTopic) - try await self.relayA.publish(topic: randomTopic, payload: payloadA, tag: 0, prompt: false, ttl: 60) - } - }.store(in: &publishers) + try await self.relayA.subscribe(topic: randomTopic) + try await self.relayA.publish(topic: randomTopic, payload: payloadA, tag: 0, prompt: false, ttl: 60) + + try await self.relayB.subscribe(topic: randomTopic) - relayB.socketConnectionStatusPublisher.sink { [weak self] status in - guard let self = self else { return } - guard status == .connected else { return } - Task(priority: .high) { - try await self.relayB.subscribe(topic: randomTopic) - } - }.store(in: &publishers) wait(for: [expectationA, expectationB], timeout: InputConfig.defaultTimeout) diff --git a/Sources/WalletConnectRelay/Dispatching.swift b/Sources/WalletConnectRelay/Dispatching.swift index 118bf7cf..9cf55e92 100644 --- a/Sources/WalletConnectRelay/Dispatching.swift +++ b/Sources/WalletConnectRelay/Dispatching.swift @@ -76,12 +76,18 @@ final class Dispatcher: NSObject, Dispatching { // Start the connection process if not already connected Task { do { + // Check for task cancellation + try Task.checkCancellation() + // Await the connection handler to establish the connection try await socketConnectionHandler.handleInternalConnect() - + logger.debug("internal connect successful, will try to send a socket frame") // If successful, send the message send(string, completion: completion) + } catch is CancellationError { + logger.debug("Task was cancelled") + completion(CancellationError()) } catch { logger.debug("failed to handle internal connect") // If an error occurs during connection, complete with that error @@ -92,16 +98,22 @@ final class Dispatcher: NSObject, Dispatching { func protectedSend(_ string: String) async throws { - var isResumed = false - return try await withCheckedThrowingContinuation { continuation in + return try await withUnsafeThrowingContinuation { continuation in + var isResumed = false + let syncQueue = DispatchQueue(label: "com.walletconnect.sdk.dispatcher.protectedSend") + protectedSend(string) { error in - if !isResumed { + syncQueue.sync { + guard !isResumed else { + return + } + isResumed = true + if let error = error { continuation.resume(throwing: error) } else { - continuation.resume(returning: ()) + continuation.resume() } - isResumed = true } } } From 579b8f4181e020649aca17a3aa9ce3566a24e763 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 5 Dec 2024 12:09:14 +0100 Subject: [PATCH 03/17] add env vars --- Configuration.xcconfig | 4 ++ .../RelayClientEndToEndTests.swift | 45 ++++++++++++++----- Example/Shared/Tests/InputConfig.swift | 16 +++++++ 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/Configuration.xcconfig b/Configuration.xcconfig index 37814dca..b25a330d 100644 --- a/Configuration.xcconfig +++ b/Configuration.xcconfig @@ -26,5 +26,9 @@ EXPLORER_HOST = explorer-api.walletconnect.com // pimloco bundler url including api key // PIMLICO_BUNDLER_URL = PIMLICO_BUNDLER_URL +// BUNDLE_ID_PRESENT_PROJECT_ID = BUNDLE_ID_PRESENT_PROJECT_ID + +// BUNDLE_ID_NOT_PRESENT_PROJECT_ID = BUNDLE_ID_PRESENT_PROJECT_ID + // rpc url // RPC_URL = RPC_URL diff --git a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift index 00797e3c..3df6a1e3 100644 --- a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift +++ b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift @@ -32,18 +32,18 @@ final class RelayClientEndToEndTests: XCTestCase { private var relayA: RelayClient! private var relayB: RelayClient! - func makeRelayClient(prefix: String) -> RelayClient { + func makeRelayClient(prefix: String, projectId: String = InputConfig.projectId) -> RelayClient { let keyValueStorage = RuntimeKeyValueStorage() let logger = ConsoleLogger(prefix: prefix, loggingLevel: .debug) let clientIdStorage = ClientIdStorage(defaults: keyValueStorage, keychain: KeychainStorageMock(), logger: logger) - let socketAuthenticator = ClientIdAuthenticator( - clientIdStorage: clientIdStorage, - logger: ConsoleLoggerMock() - ) - let urlFactory = RelayUrlFactory( - relayHost: InputConfig.relayHost, - projectId: InputConfig.projectId - ) +// let socketAuthenticator = ClientIdAuthenticator( +// clientIdStorage: clientIdStorage, +// logger: ConsoleLoggerMock() +// ) +// let urlFactory = RelayUrlFactory( +// relayHost: InputConfig.relayHost, +// projectId: InputConfig.projectId +// ) // let socket = WebSocket(url: urlFactory.create(bundleId: nil)) let networkMonitor = NetworkMonitor() // @@ -73,9 +73,30 @@ final class RelayClientEndToEndTests: XCTestCase { super.tearDown() } - func testConnect() async { + // test_bundleId_present - configured in the cloud to include bundleId for whitelisted apps + func testConnectProjectBundleIdPresent() async { let randomTopic = String.randomTopic() - relayA = makeRelayClient(prefix: "⚽️ A ") + relayA = makeRelayClient(prefix: "⚽️ X ", projectId: InputConfig.bundleIdPresentProjectId) + + let expectation = expectation(description: "RelayA publishes message successfully") + + Task { + do { + try await self.relayA.subscribe(topic: randomTopic) + expectation.fulfill() // Mark the expectation as fulfilled upon success + } catch { + XCTFail("Publish failed with error: \(error)") + } + } + + // Wait for the expectation with a timeout + await fulfillment(of: [expectation], timeout: 20.0) // Set the timeout duration in seconds + } + + // test_bundleId_not_present - configured in the cloud to not include bundleId for whitelisted apps + func testConnectProjectBundleIdNotPresent() async { + let randomTopic = String.randomTopic() + relayA = makeRelayClient(prefix: "⚽️ X ", projectId: InputConfig.bundleIdNotPresentProjectId) let expectation = expectation(description: "RelayA publishes message successfully") @@ -89,7 +110,7 @@ final class RelayClientEndToEndTests: XCTestCase { } // Wait for the expectation with a timeout - wait(for: [expectation], timeout: 20.0) // Set the timeout duration in seconds + await fulfillment(of: [expectation], timeout: 20.0) // Set the timeout duration in seconds } func testEndToEndPayload() async throws { diff --git a/Example/Shared/Tests/InputConfig.swift b/Example/Shared/Tests/InputConfig.swift index 761e1978..70babf71 100644 --- a/Example/Shared/Tests/InputConfig.swift +++ b/Example/Shared/Tests/InputConfig.swift @@ -42,6 +42,22 @@ struct InputConfig { return projectId } + static var bundleIdPresentProjectId: String { + guard let projectId = config(for: "BUNDLE_ID_PRESENT_PROJECT_ID"), !projectId.isEmpty else { + fatalError("BUNDLE_ID_PRESENT_PROJECT_ID is either not defined or empty in Configuration.xcconfig") + } + + return projectId + } + + static var bundleIdNotPresentProjectId: String { + guard let projectId = config(for: "BUNDLE_ID_NOT_PRESENT_PROJECT_ID"), !projectId.isEmpty else { + fatalError("BUNDLE_ID_NOT_PRESENT_PROJECT_ID is either not defined or empty in Configuration.xcconfig") + } + + return projectId + } + static var defaultTimeout: TimeInterval { return 45 } From 9e1b451130bd07e5381ef4488e96311ee6b4905a Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 5 Dec 2024 12:13:13 +0100 Subject: [PATCH 04/17] update test config --- .../xcschemes/RelayIntegrationTests.xcscheme | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/RelayIntegrationTests.xcscheme b/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/RelayIntegrationTests.xcscheme index 07d7e4e0..6ee56600 100644 --- a/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/RelayIntegrationTests.xcscheme +++ b/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/RelayIntegrationTests.xcscheme @@ -31,6 +31,16 @@ value = "$(PROJECT_ID)" isEnabled = "YES"> + + + + Date: Thu, 5 Dec 2024 12:19:44 +0100 Subject: [PATCH 05/17] savepoint --- Configuration.xcconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Configuration.xcconfig b/Configuration.xcconfig index b25a330d..c88b1b03 100644 --- a/Configuration.xcconfig +++ b/Configuration.xcconfig @@ -28,7 +28,7 @@ EXPLORER_HOST = explorer-api.walletconnect.com // BUNDLE_ID_PRESENT_PROJECT_ID = BUNDLE_ID_PRESENT_PROJECT_ID -// BUNDLE_ID_NOT_PRESENT_PROJECT_ID = BUNDLE_ID_PRESENT_PROJECT_ID +// BUNDLE_ID_NOT_PRESENT_PROJECT_ID = BUNDLE_ID_NOT_PRESENT_PROJECT_ID // rpc url // RPC_URL = RPC_URL From 4128f5905f07565487fc236334bc2859d3c216c4 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 5 Dec 2024 12:31:15 +0100 Subject: [PATCH 06/17] clean test --- .../RelayClientEndToEndTests.swift | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift index 3df6a1e3..35f93877 100644 --- a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift +++ b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift @@ -35,20 +35,8 @@ final class RelayClientEndToEndTests: XCTestCase { func makeRelayClient(prefix: String, projectId: String = InputConfig.projectId) -> RelayClient { let keyValueStorage = RuntimeKeyValueStorage() let logger = ConsoleLogger(prefix: prefix, loggingLevel: .debug) - let clientIdStorage = ClientIdStorage(defaults: keyValueStorage, keychain: KeychainStorageMock(), logger: logger) -// let socketAuthenticator = ClientIdAuthenticator( -// clientIdStorage: clientIdStorage, -// logger: ConsoleLoggerMock() -// ) -// let urlFactory = RelayUrlFactory( -// relayHost: InputConfig.relayHost, -// projectId: InputConfig.projectId -// ) -// let socket = WebSocket(url: urlFactory.create(bundleId: nil)) let networkMonitor = NetworkMonitor() -// -// let socketStatusProvider = SocketStatusProvider(socket: socket, logger: logger) -// let socketConnectionHandler = AutomaticSocketConnectionHandler(socket: socket, subscriptionsTracker: SubscriptionsTracker(logger: logger), logger: logger, socketStatusProvider: socketStatusProvider, clientIdAuthenticator: socketAuthenticator) + let keychain = KeychainStorageMock() let relayClient = RelayClientFactory.create( From 06148081cc2e61ec627af79f6c2daef46d714e27 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 5 Dec 2024 14:31:59 +0100 Subject: [PATCH 07/17] test --- Sources/ReownAppKitUI/Modifiers/Conditional.swift | 1 + Sources/ReownAppKitUI/Modifiers/Shimmer.swift | 1 + Sources/WalletConnectRelay/Dispatching.swift | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/ReownAppKitUI/Modifiers/Conditional.swift b/Sources/ReownAppKitUI/Modifiers/Conditional.swift index 4a0767fa..83b611f7 100644 --- a/Sources/ReownAppKitUI/Modifiers/Conditional.swift +++ b/Sources/ReownAppKitUI/Modifiers/Conditional.swift @@ -1,4 +1,5 @@ import SwiftUI +import UIKit extension View { /// Applies the given transform if the given condition evaluates to `true`. diff --git a/Sources/ReownAppKitUI/Modifiers/Shimmer.swift b/Sources/ReownAppKitUI/Modifiers/Shimmer.swift index 2744c923..0d6802df 100644 --- a/Sources/ReownAppKitUI/Modifiers/Shimmer.swift +++ b/Sources/ReownAppKitUI/Modifiers/Shimmer.swift @@ -1,4 +1,5 @@ import SwiftUI +import UIKit public struct ShimmerBackground: ViewModifier { private let animation: Animation diff --git a/Sources/WalletConnectRelay/Dispatching.swift b/Sources/WalletConnectRelay/Dispatching.swift index 9cf55e92..ea3bb34d 100644 --- a/Sources/WalletConnectRelay/Dispatching.swift +++ b/Sources/WalletConnectRelay/Dispatching.swift @@ -78,10 +78,10 @@ final class Dispatcher: NSObject, Dispatching { do { // Check for task cancellation try Task.checkCancellation() - + // Await the connection handler to establish the connection try await socketConnectionHandler.handleInternalConnect() - + logger.debug("internal connect successful, will try to send a socket frame") // If successful, send the message send(string, completion: completion) From 6e4cb459a9fda76f5e24c8f5fb89de4fbcb5e03f Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 5 Dec 2024 14:41:18 +0100 Subject: [PATCH 08/17] test --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7faf5e64..d1e20e7f 100755 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ build_all: set -o pipefail && env NSUnbufferedIO=YES \ xcodebuild \ -scheme "WalletConnect-Package" \ - -destination "platform=iOS Simulator,name=iPhone 14" \ + -destination "platform=iOS Simulator,name=iPhone 14,OS=latest" \ -derivedDataPath DerivedDataCache \ -clonedSourcePackagesDirPath ../SourcePackagesCache \ RELAY_HOST='$(RELAY_HOST)' \ From d4ecc2e85afb2b109493f7e3385ef3e483450fc7 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 6 Dec 2024 08:45:21 +0100 Subject: [PATCH 09/17] test --- .../xcshareddata/xcschemes/BuildAll.xcscheme | 17 +-- .../xcschemes/WalletConnect.xcscheme | 114 +----------------- Makefile | 4 +- Package.resolved | 22 +--- .../ReownAppKitUI/Modifiers/Conditional.swift | 1 - Sources/ReownAppKitUI/Modifiers/Shimmer.swift | 1 - 6 files changed, 11 insertions(+), 148 deletions(-) diff --git a/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/BuildAll.xcscheme b/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/BuildAll.xcscheme index 2c44051d..6cba7647 100644 --- a/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/BuildAll.xcscheme +++ b/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/BuildAll.xcscheme @@ -64,10 +64,10 @@ + buildForRunning = "NO" + buildForProfiling = "NO" + buildForArchiving = "NO" + buildForAnalyzing = "NO"> - - - - diff --git a/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/WalletConnect.xcscheme b/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/WalletConnect.xcscheme index b4856e3a..d5864bb9 100644 --- a/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/WalletConnect.xcscheme +++ b/Example/ExampleApp.xcodeproj/xcshareddata/xcschemes/WalletConnect.xcscheme @@ -6,20 +6,6 @@ parallelizeBuildables = "YES" buildImplicitDependencies = "YES"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Makefile b/Makefile index d1e20e7f..abeac010 100755 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ build_all: set -o pipefail && env NSUnbufferedIO=YES \ xcodebuild \ -scheme "WalletConnect-Package" \ - -destination "platform=iOS Simulator,name=iPhone 14,OS=latest" \ + -destination "platform=iOS Simulator,name=iPhone 16" \ -derivedDataPath DerivedDataCache \ -clonedSourcePackagesDirPath ../SourcePackagesCache \ RELAY_HOST='$(RELAY_HOST)' \ @@ -32,7 +32,7 @@ build_all: xcodebuild \ -project "Example/ExampleApp.xcodeproj" \ -scheme "BuildAll" \ - -destination "platform=iOS Simulator,name=iPhone 14" \ + -destination "platform=iOS Simulator,name=iPhone 16" \ -derivedDataPath DerivedDataCache \ -clonedSourcePackagesDirPath ../SourcePackagesCache \ RELAY_HOST='$(RELAY_HOST)' \ diff --git a/Package.resolved b/Package.resolved index 64598b06..76976ae4 100644 --- a/Package.resolved +++ b/Package.resolved @@ -28,15 +28,6 @@ "version": "1.0.0" } }, - { - "package": "swift-dotenv", - "repositoryURL": "https://github.com/thebarndog/swift-dotenv.git", - "state": { - "branch": null, - "revision": "f6e7ca817d35eeccb20b62c87ee75963b01b29dc", - "version": "2.0.1" - } - }, { "package": "swift-qrcode-generator", "repositoryURL": "https://github.com/dagronf/swift-qrcode-generator", @@ -46,15 +37,6 @@ "version": "1.0.3" } }, - { - "package": "swift-snapshot-testing", - "repositoryURL": "https://github.com/pointfreeco/swift-snapshot-testing", - "state": { - "branch": null, - "revision": "f29e2014f6230cf7d5138fc899da51c7f513d467", - "version": "1.10.0" - } - }, { "package": "SwiftImageReadWrite", "repositoryURL": "https://github.com/dagronf/SwiftImageReadWrite", @@ -66,10 +48,10 @@ }, { "package": "CoinbaseWalletSDK", - "repositoryURL": "https://github.com/WalletConnect/wallet-mobile-sdk", + "repositoryURL": "https://github.com/MobileWalletProtocol/wallet-mobile-sdk", "state": { "branch": null, - "revision": "b6dfb7d6b8447c7c5b238a10443a1ac28223f38f", + "revision": "84b3d3f25a2e3b140ec12bb0d22c35b58f817d44", "version": "1.0.0" } } diff --git a/Sources/ReownAppKitUI/Modifiers/Conditional.swift b/Sources/ReownAppKitUI/Modifiers/Conditional.swift index 83b611f7..4a0767fa 100644 --- a/Sources/ReownAppKitUI/Modifiers/Conditional.swift +++ b/Sources/ReownAppKitUI/Modifiers/Conditional.swift @@ -1,5 +1,4 @@ import SwiftUI -import UIKit extension View { /// Applies the given transform if the given condition evaluates to `true`. diff --git a/Sources/ReownAppKitUI/Modifiers/Shimmer.swift b/Sources/ReownAppKitUI/Modifiers/Shimmer.swift index 0d6802df..2744c923 100644 --- a/Sources/ReownAppKitUI/Modifiers/Shimmer.swift +++ b/Sources/ReownAppKitUI/Modifiers/Shimmer.swift @@ -1,5 +1,4 @@ import SwiftUI -import UIKit public struct ShimmerBackground: ViewModifier { private let animation: Animation From 752e25f5160e2366b613ed633c1e84bdb16609e3 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 6 Dec 2024 09:10:35 +0100 Subject: [PATCH 10/17] test --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index abeac010..4999906d 100755 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ build_all: set -o pipefail && env NSUnbufferedIO=YES \ xcodebuild \ -scheme "WalletConnect-Package" \ - -destination "platform=iOS Simulator,name=iPhone 16" \ + -destination "platform=iOS Simulator,name=iPhone 15,OS=17.5" \ -derivedDataPath DerivedDataCache \ -clonedSourcePackagesDirPath ../SourcePackagesCache \ RELAY_HOST='$(RELAY_HOST)' \ @@ -32,7 +32,7 @@ build_all: xcodebuild \ -project "Example/ExampleApp.xcodeproj" \ -scheme "BuildAll" \ - -destination "platform=iOS Simulator,name=iPhone 16" \ + -destination "platform=iOS Simulator,name=iPhone 15,OS=17.5" \ -derivedDataPath DerivedDataCache \ -clonedSourcePackagesDirPath ../SourcePackagesCache \ RELAY_HOST='$(RELAY_HOST)' \ From 9288ca5fd48e6a0c4e1050cd49312f0e72111d3e Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 6 Dec 2024 10:08:55 +0100 Subject: [PATCH 11/17] update test plan --- Example/RelayIntegrationTests.xctestplan | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Example/RelayIntegrationTests.xctestplan b/Example/RelayIntegrationTests.xctestplan index b4026d55..16c3ca70 100644 --- a/Example/RelayIntegrationTests.xctestplan +++ b/Example/RelayIntegrationTests.xctestplan @@ -4,7 +4,24 @@ "id" : "3D7BF967-0C62-49DD-ABA1-BDDEE678ED85", "name" : "Configuration 1", "options" : { - + "environmentVariableEntries" : [ + { + "key" : "RELAY_HOST", + "value" : "$(RELAY_HOST)" + }, + { + "key" : "PROJECT_ID", + "value" : "$(PROJECT_ID)" + }, + { + "key" : "BUNDLE_ID_NOT_PRESENT_PROJECT_ID", + "value" : "$(BUNDLE_ID_NOT_PRESENT_PROJECT_ID)" + }, + { + "key" : "BUNDLE_ID_PRESENT_PROJECT_ID", + "value" : "$(BUNDLE_ID_PRESENT_PROJECT_ID)" + } + ] } } ], From 10ac7564ecd6b6ad079456131eaedf2d622f4c68 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 6 Dec 2024 10:52:50 +0100 Subject: [PATCH 12/17] test --- Example/RelayIntegrationTests.xctestplan | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Example/RelayIntegrationTests.xctestplan b/Example/RelayIntegrationTests.xctestplan index 16c3ca70..c43f7a5d 100644 --- a/Example/RelayIntegrationTests.xctestplan +++ b/Example/RelayIntegrationTests.xctestplan @@ -28,6 +28,14 @@ "defaultOptions" : { "codeCoverage" : false, "environmentVariableEntries" : [ + { + "key" : "BUNDLE_ID_NOT_PRESENT_PROJECT_ID", + "value" : "$(BUNDLE_ID_NOT_PRESENT_PROJECT_ID)" + }, + { + "key" : "BUNDLE_ID_PRESENT_PROJECT_ID", + "value" : "$(BUNDLE_ID_PRESENT_PROJECT_ID)" + }, { "key" : "RELAY_HOST", "value" : "$(RELAY_HOST)" From d735c61c6987044549c6a2c47c75cd19aa170c49 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 6 Dec 2024 11:11:35 +0100 Subject: [PATCH 13/17] test --- run_tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run_tests.sh b/run_tests.sh index b6b1911d..3133bcc1 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -88,6 +88,8 @@ else update_xctestrun --key "CAST_HOST" --value "$CAST_HOST" --target "$XCTESTRUN" update_xctestrun --key "EXPLORER_HOST" --value "$EXPLORER_HOST" --target "$XCTESTRUN" update_xctestrun --key "JS_CLIENT_API_HOST" --value "$JS_CLIENT_API_HOST" --target "$XCTESTRUN" + update_xctestrun --key "BUNDLE_ID_NOT_PRESENT_PROJECT_ID" --value "$BUNDLE_ID_NOT_PRESENT_PROJECT_ID" --target "$XCTESTRUN" + update_xctestrun --key "BUNDLE_ID_PRESENT_PROJECT_ID" --value "$BUNDLE_ID_PRESENT_PROJECT_ID" --target "$XCTESTRUN" ( set -x From 4f54c9c31d34a6496dfdc09ef000117946f6cc8d Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 6 Dec 2024 11:34:00 +0100 Subject: [PATCH 14/17] update script --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 090b11b3..a66c8cdb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,11 @@ jobs: - name: Run Relay integration tests if: matrix.type == 'relay-tests' shell: bash - run: make relay_tests RELAY_HOST=relay.walletconnect.com PROJECT_ID=${{ secrets.PROJECT_ID }} + run: make relay_tests \ + RELAY_HOST=relay.walletconnect.com \ + PROJECT_ID=${{ secrets.PROJECT_ID }} \ + BUNDLE_ID_PRESENT_PROJECT_ID=${{ secrets.BUNDLE_ID_PRESENT_PROJECT_ID }} \ + BUNDLE_ID_NOT_PRESENT_PROJECT_ID=${{ secrets.BUNDLE_ID_NOT_PRESENT_PROJECT_ID }} - name: Publish Test Report uses: mikepenz/action-junit-report@v3 From a58ce2ac5e261769c8833dee1f4dcbade09faf3f Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 6 Dec 2024 11:57:47 +0100 Subject: [PATCH 15/17] savepoint --- .../RelayClientEndToEndTests.swift | 2 +- .../SubscriptionsTracker.swift | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift index 35f93877..941d0278 100644 --- a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift +++ b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift @@ -70,7 +70,7 @@ final class RelayClientEndToEndTests: XCTestCase { Task { do { - try await self.relayA.subscribe(topic: randomTopic) + try await self.relayA.publish(topic: randomTopic, payload: "", tag: 0, prompt: false, ttl: 60) expectation.fulfill() // Mark the expectation as fulfilled upon success } catch { XCTFail("Publish failed with error: \(error)") diff --git a/Sources/WalletConnectRelay/SubscriptionsTracker.swift b/Sources/WalletConnectRelay/SubscriptionsTracker.swift index aa67a91c..e8a5ef9e 100644 --- a/Sources/WalletConnectRelay/SubscriptionsTracker.swift +++ b/Sources/WalletConnectRelay/SubscriptionsTracker.swift @@ -8,7 +8,6 @@ protocol SubscriptionsTracking { func getTopics() -> [String] } - public final class SubscriptionsTracker: SubscriptionsTracking { private var subscriptions: [String: String] = [:] private let concurrentQueue = DispatchQueue(label: "com.walletconnect.sdk.subscriptions_tracker", attributes: .concurrent) @@ -20,7 +19,8 @@ public final class SubscriptionsTracker: SubscriptionsTracking { func setSubscription(for topic: String, id: String) { logger.debug("Setting subscription for topic: \(topic) with id: \(id)") - concurrentQueue.async(flags: .barrier) { [unowned self] in + concurrentQueue.async(flags: .barrier) { [weak self] in + guard let self = self else { return } self.subscriptions[topic] = id self.logger.debug("Subscription set: \(self.subscriptions)") } @@ -29,8 +29,9 @@ public final class SubscriptionsTracker: SubscriptionsTracking { func getSubscription(for topic: String) -> String? { logger.debug("Getting subscription for topic: \(topic)") var result: String? - concurrentQueue.sync { [unowned self] in - result = subscriptions[topic] + concurrentQueue.sync { [weak self] in + guard let self = self else { return } + result = self.subscriptions[topic] self.logger.debug("Retrieved subscription: \(String(describing: result)) for topic: \(topic)") } return result @@ -38,7 +39,8 @@ public final class SubscriptionsTracker: SubscriptionsTracking { func removeSubscription(for topic: String) { logger.debug("Removing subscription for topic: \(topic)") - concurrentQueue.async(flags: .barrier) { [unowned self] in + concurrentQueue.async(flags: .barrier) { [weak self] in + guard let self = self else { return } self.subscriptions[topic] = nil self.logger.debug("Subscription removed for topic: \(topic). Current subscriptions: \(self.subscriptions)") } @@ -47,8 +49,9 @@ public final class SubscriptionsTracker: SubscriptionsTracking { func isSubscribed() -> Bool { logger.debug("Checking if there are any active subscriptions") var result = false - concurrentQueue.sync { [unowned self] in - result = !subscriptions.isEmpty + concurrentQueue.sync { [weak self] in + guard let self = self else { return } + result = !self.subscriptions.isEmpty self.logger.debug("Is subscribed: \(result)") } return result @@ -57,13 +60,15 @@ public final class SubscriptionsTracker: SubscriptionsTracking { func getTopics() -> [String] { logger.debug("Getting all subscription topics") var topics: [String] = [] - concurrentQueue.sync { [unowned self] in - topics = Array(subscriptions.keys) + concurrentQueue.sync { [weak self] in + guard let self = self else { return } + topics = Array(self.subscriptions.keys) self.logger.debug("Retrieved topics: \(topics)") } return topics } } + #if DEBUG final class SubscriptionsTrackerMock: SubscriptionsTracking { var isSubscribedReturnValue: Bool = false @@ -90,4 +95,3 @@ final class SubscriptionsTrackerMock: SubscriptionsTracking { } } #endif - From c9ad51b3b6f092f0791ad760dec617ac90a6112e Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 6 Dec 2024 12:01:05 +0100 Subject: [PATCH 16/17] test --- .../RelayClientEndToEndTests.swift | 35 ++++--------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift index 941d0278..a7fcb4c5 100644 --- a/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift +++ b/Example/RelayIntegrationTests/RelayClientEndToEndTests.swift @@ -62,43 +62,20 @@ final class RelayClientEndToEndTests: XCTestCase { } // test_bundleId_present - configured in the cloud to include bundleId for whitelisted apps - func testConnectProjectBundleIdPresent() async { + func testConnectProjectBundleIdPresent() async throws { let randomTopic = String.randomTopic() relayA = makeRelayClient(prefix: "⚽️ X ", projectId: InputConfig.bundleIdPresentProjectId) - - let expectation = expectation(description: "RelayA publishes message successfully") - - Task { - do { - try await self.relayA.publish(topic: randomTopic, payload: "", tag: 0, prompt: false, ttl: 60) - expectation.fulfill() // Mark the expectation as fulfilled upon success - } catch { - XCTFail("Publish failed with error: \(error)") - } - } - - // Wait for the expectation with a timeout - await fulfillment(of: [expectation], timeout: 20.0) // Set the timeout duration in seconds + try await self.relayA.publish(topic: randomTopic, payload: "", tag: 0, prompt: false, ttl: 60) + sleep(1) } // test_bundleId_not_present - configured in the cloud to not include bundleId for whitelisted apps - func testConnectProjectBundleIdNotPresent() async { + func testConnectProjectBundleIdNotPresent() async throws{ let randomTopic = String.randomTopic() relayA = makeRelayClient(prefix: "⚽️ X ", projectId: InputConfig.bundleIdNotPresentProjectId) - let expectation = expectation(description: "RelayA publishes message successfully") - - Task { - do { - try await self.relayA.subscribe(topic: randomTopic) - expectation.fulfill() // Mark the expectation as fulfilled upon success - } catch { - XCTFail("Publish failed with error: \(error)") - } - } - - // Wait for the expectation with a timeout - await fulfillment(of: [expectation], timeout: 20.0) // Set the timeout duration in seconds + try await self.relayA.publish(topic: randomTopic, payload: "", tag: 0, prompt: false, ttl: 60) + sleep(1) } func testEndToEndPayload() async throws { From b9eaa0eda31902b647e861ee4dc7098ab8322125 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 6 Dec 2024 11:14:56 +0000 Subject: [PATCH 17/17] Set User Agent --- Sources/WalletConnectRelay/PackageConfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WalletConnectRelay/PackageConfig.json b/Sources/WalletConnectRelay/PackageConfig.json index 4a72d855..48f893bf 100644 --- a/Sources/WalletConnectRelay/PackageConfig.json +++ b/Sources/WalletConnectRelay/PackageConfig.json @@ -1 +1 @@ -{"version": "1.0.7"} +{"version": "1.1.0"}