Skip to content
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

[CI] Explorer host injection #1195

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/actions/run_tests_without_building/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Example/ExampleApp.xcodeproj/IntegrationTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"key" : "RELAY_HOST",
"value" : "$(RELAY_HOST)"
},
{
"key" : "EXPLORER_HOST",
"value" : "$(EXPLORER_HOST)"
},
{
"key" : "GM_DAPP_HOST",
"value" : "$(GM_DAPP_HOST)"
Expand Down
32 changes: 24 additions & 8 deletions Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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<String> = ["8529aae8-cb26-4d49-922e-eb099044bebe"]
expectation.assertForOverFulfill = false

var updateScope: Set<String>!
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 {
Expand All @@ -184,25 +191,34 @@ 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()
}
}
}.store(in: &publishers)

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)
Expand Down
4 changes: 4 additions & 0 deletions Example/Shared/Tests/InputConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions NotifyTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"key" : "RELAY_HOST",
"value" : "$(RELAY_HOST)"
},
{
"key" : "EXPLORER_HOST",
"value" : "$(EXPLORER_HOST)"
},
{
"key" : "GM_DAPP_HOST",
"value" : "$(GM_DAPP_HOST)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")!
Expand All @@ -20,7 +20,8 @@ public struct NotifyClientFactory {
pairingRegisterer: pairingRegisterer,
pushClient: pushClient,
crypto: crypto,
notifyHost: notifyHost
notifyHost: notifyHost,
explorerHost: explorerHost
)
}

Expand All @@ -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<NotifySubscription>(storage: keyValueStorage, identifier: NotifyStorageIdntifiers.notifySubscription)
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sources/WalletConnectNotify/Notify+Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ extension Notify {
let environment: APNSEnvironment
let crypto: CryptoProvider
let notifyHost: String
let explorerHost: String
}
}
14 changes: 11 additions & 3 deletions Sources/WalletConnectNotify/Notify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}()

Expand All @@ -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)
}

}
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

(
Expand Down
Loading