diff --git a/.github/actions/run_tests_without_building/action.yml b/.github/actions/run_tests_without_building/action.yml index a9639e3db..52c492e93 100644 --- a/.github/actions/run_tests_without_building/action.yml +++ b/.github/actions/run_tests_without_building/action.yml @@ -9,9 +9,13 @@ inputs: required: false default: 'relay.walletconnect.com' notify-endpoint: - description: 'The endpoint of the notify server e.g. cast.walletconnect.com' + description: 'The endpoint of the notify server e.g. notify.walletconnect.com' required: false - default: 'cast.walletconnect.com' + default: 'notify.walletconnect.com' + explorer-endpoint: + description: 'The endpoint of the explorer server e.g. explorer-api.walletconnect.com' + required: false + default: 'explorer-api.walletconnect.com' project-id: description: 'WalletConnect project id' required: true @@ -59,13 +63,13 @@ runs: - name: Run integration tests if: inputs.type == 'integration-tests' shell: bash - run: make integration_tests RELAY_HOST=${{ inputs.relay-endpoint }} PROJECT_ID=${{ inputs.project-id }} CAST_HOST=${{ inputs.notify-endpoint }} GM_DAPP_PROJECT_ID=${{ inputs.gm-dapp-project-id }} GM_DAPP_PROJECT_SECRET=${{ inputs.gm-dapp-project-secret }} GM_DAPP_HOST=${{ inputs.gm-dapp-host }} JS_CLIENT_API_HOST=${{ inputs.js-client-api-host }} + run: make integration_tests RELAY_HOST=${{ inputs.relay-endpoint }} PROJECT_ID=${{ inputs.project-id }} CAST_HOST=${{ inputs.notify-endpoint }} EXPLORER_HOST=${{ inputs.explorer-endpoint }} GM_DAPP_PROJECT_ID=${{ inputs.gm-dapp-project-id }} GM_DAPP_PROJECT_SECRET=${{ inputs.gm-dapp-project-secret }} GM_DAPP_HOST=${{ inputs.gm-dapp-host }} JS_CLIENT_API_HOST=${{ inputs.js-client-api-host }} # Relay Integration tests - name: Run Relay integration tests if: inputs.type == 'relay-tests' shell: bash - run: make relay_tests RELAY_HOST=${{ inputs.relay-endpoint }} PROJECT_ID=${{ inputs.project-id }} CAST_HOST=${{ inputs.notify-endpoint }} + run: make relay_tests RELAY_HOST=${{ inputs.relay-endpoint }} PROJECT_ID=${{ inputs.project-id }} CAST_HOST=${{ inputs.notify-endpoint }} EXPLORER_HOST=${{ inputs.explorer-endpoint }} # Smoke tests - name: Run smoke tests @@ -77,7 +81,7 @@ runs: - name: Run notify tests if: inputs.type == 'notify-tests' shell: bash - run: make notify_tests RELAY_HOST=${{ inputs.relay-endpoint }} PROJECT_ID=${{ inputs.project-id }} CAST_HOST=${{ inputs.notify-endpoint }} GM_DAPP_PROJECT_ID=${{ inputs.gm-dapp-project-id }} GM_DAPP_PROJECT_SECRET=${{ inputs.gm-dapp-project-secret }} GM_DAPP_HOST=${{ inputs.gm-dapp-host }} + run: make notify_tests RELAY_HOST=${{ inputs.relay-endpoint }} PROJECT_ID=${{ inputs.project-id }} CAST_HOST=${{ inputs.notify-endpoint }} EXPLORER_HOST=${{ inputs.explorer-endpoint }} GM_DAPP_PROJECT_ID=${{ inputs.gm-dapp-project-id }} GM_DAPP_PROJECT_SECRET=${{ inputs.gm-dapp-project-secret }} GM_DAPP_HOST=${{ inputs.gm-dapp-host }} - name: Run x-platform protocol tests if: inputs.type == 'x-platform-protocol-tests' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a9b07721..fe39b9775 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,7 +69,7 @@ jobs: - name: Run integration tests if: matrix.type == 'integration-tests' shell: bash - run: make integration_tests RELAY_HOST=relay.walletconnect.com PROJECT_ID=${{ secrets.PROJECT_ID }} CAST_HOST=notify.walletconnect.com GM_DAPP_PROJECT_ID=${{ secrets.GM_DAPP_PROJECT_ID }} GM_DAPP_PROJECT_SECRET=${{ secrets.GM_DAPP_PROJECT_SECRET }} GM_DAPP_HOST=gm.walletconnect.com JS_CLIENT_API_HOST=test-automation-api.walletconnect.com + run: make integration_tests RELAY_HOST=relay.walletconnect.com PROJECT_ID=${{ secrets.PROJECT_ID }} CAST_HOST=notify.walletconnect.com EXPLORER_HOST=explorer-api.walletconnect.com GM_DAPP_PROJECT_ID=${{ secrets.GM_DAPP_PROJECT_ID }} GM_DAPP_PROJECT_SECRET=${{ secrets.GM_DAPP_PROJECT_SECRET }} GM_DAPP_HOST=gm.walletconnect.com JS_CLIENT_API_HOST=test-automation-api.walletconnect.com # Relay Integration tests - name: Run Relay integration tests diff --git a/Example/ExampleApp.xcodeproj/IntegrationTests.xctestplan b/Example/ExampleApp.xcodeproj/IntegrationTests.xctestplan index e3aa93b52..40b79df1d 100644 --- a/Example/ExampleApp.xcodeproj/IntegrationTests.xctestplan +++ b/Example/ExampleApp.xcodeproj/IntegrationTests.xctestplan @@ -15,6 +15,10 @@ "key" : "RELAY_HOST", "value" : "$(RELAY_HOST)" }, + { + "key" : "EXPLORER_HOST", + "value" : "$(EXPLORER_HOST)" + }, { "key" : "GM_DAPP_HOST", "value" : "$(GM_DAPP_HOST)" diff --git a/Example/IntegrationTests/Push/NotifyTests.swift b/Example/IntegrationTests/Push/NotifyTests.swift index a0bfed40e..889af4389 100644 --- a/Example/IntegrationTests/Push/NotifyTests.swift +++ b/Example/IntegrationTests/Push/NotifyTests.swift @@ -84,7 +84,8 @@ final class NotifyTests: XCTestCase { pairingRegisterer: pairingClient, pushClient: pushClient, crypto: DefaultCryptoProvider(), - notifyHost: InputConfig.notifyHost) + notifyHost: InputConfig.notifyHost, + explorerHost: InputConfig.explorerHost) return client } @@ -152,19 +153,25 @@ final class NotifyTests: XCTestCase { func testWalletCreatesAndUpdatesSubscription() async { let expectation = expectation(description: "expects to create and update notify subscription") - let updateScope: Set = ["8529aae8-cb26-4d49-922e-eb099044bebe"] expectation.assertForOverFulfill = false + var updateScope: Set! var didUpdate = false + walletNotifyClientA.subscriptionsPublisher .sink { [unowned self] subscriptions in - guard let subscription = subscriptions.first else { return } + guard + let subscription = subscriptions.first, + let scope = subscription.scope.keys.first + else { return } + let updatedScope = Set(subscription.scope.filter { $0.value.enabled == true }.keys) if !didUpdate { + updateScope = Set([scope]) didUpdate = true Task(priority: .high) { - try await walletNotifyClientA.update(topic: subscription.topic, scope: updateScope) + try await walletNotifyClientA.update(topic: subscription.topic, scope: Set([scope])) } } if updateScope == updatedScope { @@ -184,17 +191,26 @@ final class NotifyTests: XCTestCase { func testNotifyServerSubscribeAndNotifies() async throws { let subscribeExpectation = expectation(description: "creates notify subscription") let messageExpectation = expectation(description: "receives a notify message") - let notifyMessage = NotifyMessage.stub(type: "8529aae8-cb26-4d49-922e-eb099044bebe") + + var notifyMessage: NotifyMessage! var didNotify = false walletNotifyClientA.subscriptionsPublisher .sink { subscriptions in - guard let subscription = subscriptions.first else { return } + guard + let subscription = subscriptions.first, + let scope = subscription.scope.keys.first + else { return } + let notifier = Publisher() if !didNotify { didNotify = true + + let message = NotifyMessage.stub(type: scope) + notifyMessage = message + Task(priority: .high) { - try await notifier.notify(topic: subscription.topic, account: subscription.account, message: notifyMessage) + try await notifier.notify(topic: subscription.topic, account: subscription.account, message: message) subscribeExpectation.fulfill() } } @@ -202,7 +218,7 @@ final class NotifyTests: XCTestCase { walletNotifyClientA.notifyMessagePublisher .sink { [unowned self] notifyMessageRecord in - XCTAssertEqual(notifyMessage, notifyMessageRecord.message) + XCTAssertEqual(notifyMessageRecord.message, notifyMessage) Task(priority: .high) { try await walletNotifyClientA.deleteSubscription(topic: notifyMessageRecord.topic) diff --git a/Example/Shared/Tests/InputConfig.swift b/Example/Shared/Tests/InputConfig.swift index b420b93b8..761e19788 100644 --- a/Example/Shared/Tests/InputConfig.swift +++ b/Example/Shared/Tests/InputConfig.swift @@ -26,6 +26,10 @@ struct InputConfig { return config(for: "CAST_HOST")! } + static var explorerHost: String { + return config(for: "EXPLORER_HOST")! + } + static var relayUrl: String { return "wss://\(relayHost)" } diff --git a/Makefile b/Makefile index 32cdfdd66..68c9b1a0b 100755 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ build_all: RELAY_HOST='$(RELAY_HOST)' \ PROJECT_ID='$(PROJECT_ID)' \ CAST_HOST='$(CAST_HOST)' \ + EXPLORER_HOST='$(EXPLORER_HOST)' \ JS_CLIENT_API_HOST='$(JS_CLIENT_API_HOST)' \ build-for-testing \ | xcbeautify diff --git a/NotifyTests.xctestplan b/NotifyTests.xctestplan index 881dd5fda..fe598450b 100644 --- a/NotifyTests.xctestplan +++ b/NotifyTests.xctestplan @@ -15,6 +15,10 @@ "key" : "RELAY_HOST", "value" : "$(RELAY_HOST)" }, + { + "key" : "EXPLORER_HOST", + "value" : "$(EXPLORER_HOST)" + }, { "key" : "GM_DAPP_HOST", "value" : "$(GM_DAPP_HOST)" diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift index 8fac80ce5..f04b62a14 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift @@ -2,7 +2,7 @@ import Foundation public struct NotifyClientFactory { - public static func create(projectId: String, groupIdentifier: String, networkInteractor: NetworkInteracting, pairingRegisterer: PairingRegisterer, pushClient: PushClient, crypto: CryptoProvider, notifyHost: String) -> NotifyClient { + public static func create(projectId: String, groupIdentifier: String, networkInteractor: NetworkInteracting, pairingRegisterer: PairingRegisterer, pushClient: PushClient, crypto: CryptoProvider, notifyHost: String, explorerHost: String) -> NotifyClient { let logger = ConsoleLogger(prefix: "🔔",loggingLevel: .debug) let keyValueStorage = UserDefaults.standard let keyserverURL = URL(string: "https://keys.walletconnect.com")! @@ -20,7 +20,8 @@ public struct NotifyClientFactory { pairingRegisterer: pairingRegisterer, pushClient: pushClient, crypto: crypto, - notifyHost: notifyHost + notifyHost: notifyHost, + explorerHost: explorerHost ) } @@ -35,7 +36,8 @@ public struct NotifyClientFactory { pairingRegisterer: PairingRegisterer, pushClient: PushClient, crypto: CryptoProvider, - notifyHost: String + notifyHost: String, + explorerHost: String ) -> NotifyClient { let kms = KeyManagementService(keychain: keychainStorage) let subscriptionStore = KeyedDatabase(storage: keyValueStorage, identifier: NotifyStorageIdntifiers.notifySubscription) @@ -48,7 +50,7 @@ public struct NotifyClientFactory { let deleteNotifySubscriptionRequester = DeleteNotifySubscriptionRequester(keyserver: keyserverURL, networkingInteractor: networkInteractor, identityClient: identityClient, webDidResolver: webDidResolver, kms: kms, logger: logger, notifyStorage: notifyStorage) let resubscribeService = NotifyResubscribeService(networkInteractor: networkInteractor, notifyStorage: notifyStorage, logger: logger) - let notifyConfigProvider = NotifyConfigProvider(projectId: projectId) + let notifyConfigProvider = NotifyConfigProvider(projectId: projectId, explorerHost: explorerHost) let notifySubscribeRequester = NotifySubscribeRequester(keyserverURL: keyserverURL, networkingInteractor: networkInteractor, identityClient: identityClient, logger: logger, kms: kms, webDidResolver: webDidResolver, notifyConfigProvider: notifyConfigProvider) diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifyConfig.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifyConfig.swift index b0e88b181..f9579ba6c 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifyConfig.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifyConfig.swift @@ -13,7 +13,7 @@ struct NotifyConfig: Codable { } let id: String let name: String - let homepage: String + let homepage: String? let description: String let dapp_url: String let image_url: ImageUrl? diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifyConfigProvider.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifyConfigProvider.swift index 8b196f592..414d7960d 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifyConfigProvider.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifyConfigProvider.swift @@ -3,11 +3,13 @@ import Foundation actor NotifyConfigProvider { private let projectId: String + private let explorerHost: String private var cache: [String: NotifyConfig] = [:] - init(projectId: String) { + init(projectId: String, explorerHost: String) { self.projectId = projectId + self.explorerHost = explorerHost } func resolveNotifyConfig(appDomain: String) async -> NotifyConfig { @@ -16,7 +18,7 @@ actor NotifyConfigProvider { } do { - let httpClient = HTTPNetworkClient(host: "explorer-api.walletconnect.com") + let httpClient = HTTPNetworkClient(host: explorerHost) let request = NotifyConfigAPI.notifyDApps(projectId: projectId, appDomain: appDomain) let response = try await httpClient.request(NotifyConfigResponse.self, at: request) let config = response.data diff --git a/Sources/WalletConnectNotify/Notify+Config.swift b/Sources/WalletConnectNotify/Notify+Config.swift index c7e699c03..4d1141022 100644 --- a/Sources/WalletConnectNotify/Notify+Config.swift +++ b/Sources/WalletConnectNotify/Notify+Config.swift @@ -7,5 +7,6 @@ extension Notify { let environment: APNSEnvironment let crypto: CryptoProvider let notifyHost: String + let explorerHost: String } } diff --git a/Sources/WalletConnectNotify/Notify.swift b/Sources/WalletConnectNotify/Notify.swift index 039c139d6..2880d2ce5 100644 --- a/Sources/WalletConnectNotify/Notify.swift +++ b/Sources/WalletConnectNotify/Notify.swift @@ -13,7 +13,8 @@ public class Notify { pairingRegisterer: Pair.registerer, pushClient: Push.instance, crypto: config.crypto, - notifyHost: config.notifyHost + notifyHost: config.notifyHost, + explorerHost: config.explorerHost ) }() @@ -22,8 +23,15 @@ public class Notify { private init() { } /// Wallet's configuration method - static public func configure(pushHost: String = "echo.walletconnect.com", groupIdentifier: String, environment: APNSEnvironment, crypto: CryptoProvider, notifyHost: String = "notify.walletconnect.com") { - Notify.config = Notify.Config(pushHost: pushHost, groupIdentifier: groupIdentifier, environment: environment, crypto: crypto, notifyHost: notifyHost) + static public func configure( + pushHost: String = "echo.walletconnect.com", + groupIdentifier: String, + environment: APNSEnvironment, + crypto: CryptoProvider, + notifyHost: String = "notify.walletconnect.com", + explorerHost: String = "explorer-api.walletconnect.com" + ) { + Notify.config = Notify.Config(pushHost: pushHost, groupIdentifier: groupIdentifier, environment: environment, crypto: crypto, notifyHost: notifyHost, explorerHost: explorerHost) } } diff --git a/run_tests.sh b/run_tests.sh index ea5cad206..b6b1911d7 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -86,6 +86,7 @@ else update_xctestrun --key "GM_DAPP_PROJECT_SECRET" --value "$GM_DAPP_PROJECT_SECRET" --target "$XCTESTRUN" update_xctestrun --key "GM_DAPP_HOST" --value "$GM_DAPP_HOST" --target "$XCTESTRUN" 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" (