Skip to content

Commit

Permalink
Merge pull request #939 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.6.11
  • Loading branch information
Alexander Lisovik authored Jul 3, 2023
2 parents 9b831af + b4ad15e commit 84b09a1
Show file tree
Hide file tree
Showing 72 changed files with 752 additions and 326 deletions.
2 changes: 1 addition & 1 deletion Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
Expand Down
10 changes: 8 additions & 2 deletions Example/IntegrationTests/Auth/AuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ final class AuthTests: XCTestCase {

func makeClients(prefix: String, iatProvider: IATProvider) -> (PairingClient, AuthClient) {
let logger = ConsoleLogger(suffix: prefix, loggingLevel: .debug)
let keychain = KeychainStorageMock()
let relayClient = RelayClient(relayHost: InputConfig.relayHost, projectId: InputConfig.projectId, keychainStorage: keychain, socketFactory: DefaultSocketFactory(), logger: logger)
let keyValueStorage = RuntimeKeyValueStorage()
let keychain = KeychainStorageMock()
let relayClient = RelayClientFactory.create(
relayHost: InputConfig.relayHost,
projectId: InputConfig.projectId,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
socketFactory: DefaultSocketFactory(),
logger: logger)

let networkingClient = NetworkingClientFactory.create(
relayClient: relayClient,
Expand Down
11 changes: 9 additions & 2 deletions Example/IntegrationTests/Chat/ChatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ final class ChatTests: XCTestCase {
func makeClient(prefix: String, account: Account) -> ChatClient {
let keyserverURL = URL(string: "https://keys.walletconnect.com")!
let logger = ConsoleLogger(suffix: prefix, loggingLevel: .debug)
let keychain = KeychainStorageMock()
let relayClient = RelayClient(relayHost: InputConfig.relayHost, projectId: InputConfig.projectId, keychainStorage: keychain, socketFactory: DefaultSocketFactory(), logger: logger)
let keyValueStorage = RuntimeKeyValueStorage()
let keychain = KeychainStorageMock()
let relayClient = RelayClientFactory.create(
relayHost: InputConfig.relayHost,
projectId: InputConfig.projectId,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
socketFactory: DefaultSocketFactory(),
logger: logger)

let networkingInteractor = NetworkingClientFactory.create(
relayClient: relayClient,
logger: logger,
Expand Down
2 changes: 1 addition & 1 deletion Example/IntegrationTests/History/HistoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class HistoryTests: XCTestCase {
}

private func makeRelayClient(prefix: String, keychain: KeychainStorageProtocol) -> RelayClient {
return RelayClient(
return RelayClientFactory.create(
relayHost: InputConfig.relayHost,
projectId: InputConfig.projectId,
keyValueStorage: RuntimeKeyValueStorage(),
Expand Down
27 changes: 16 additions & 11 deletions Example/IntegrationTests/Pairing/PairingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import WalletConnectNetworking
import WalletConnectEcho
@testable import WalletConnectPush
@testable import WalletConnectPairing
@testable import WalletConnectSync

final class PairingTests: XCTestCase {

Expand All @@ -21,15 +22,15 @@ final class PairingTests: XCTestCase {

private var publishers = [AnyCancellable]()

func makeClientDependencies(prefix: String) -> (PairingClient, NetworkInteracting, KeychainStorageProtocol, KeyValueStorage) {
func makeClientDependencies(prefix: String) -> (PairingClient, NetworkInteracting, SyncClient, KeychainStorageProtocol, KeyValueStorage) {
let keychain = KeychainStorageMock()
let keyValueStorage = RuntimeKeyValueStorage()

let relayLogger = ConsoleLogger(suffix: prefix + " [Relay]", loggingLevel: .debug)
let pairingLogger = ConsoleLogger(suffix: prefix + " [Pairing]", loggingLevel: .debug)
let networkingLogger = ConsoleLogger(suffix: prefix + " [Networking]", loggingLevel: .debug)

let relayClient = RelayClient(
let relayClient = RelayClientFactory.create(
relayHost: InputConfig.relayHost,
projectId: InputConfig.projectId,
keyValueStorage: RuntimeKeyValueStorage(),
Expand All @@ -49,27 +50,30 @@ final class PairingTests: XCTestCase {
keychainStorage: keychain,
networkingClient: networkingClient)

let syncClient = SyncClientFactory.create(networkInteractor: networkingClient, bip44: DefaultBIP44Provider(), keychain: keychain)

let clientId = try! networkingClient.getClientId()
networkingLogger.debug("My client id is: \(clientId)")

return (pairingClient, networkingClient, keychain, keyValueStorage)
return (pairingClient, networkingClient, syncClient, keychain, keyValueStorage)
}

func makeDappClients() {
let prefix = "🤖 Dapp: "
let (pairingClient, networkingInteractor, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let (pairingClient, networkingInteractor, syncClient, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let pushLogger = ConsoleLogger(suffix: prefix + " [Push]", loggingLevel: .debug)
appPairingClient = pairingClient
appPushClient = DappPushClientFactory.create(metadata: AppMetadata(name: name, description: "", url: "", icons: [""]),
logger: pushLogger,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
networkInteractor: networkingInteractor)
logger: pushLogger,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
networkInteractor: networkingInteractor,
syncClient: syncClient)
}

func makeWalletClients() {
let prefix = "🐶 Wallet: "
let (pairingClient, networkingInteractor, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let (pairingClient, networkingInteractor, syncClient, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let pushLogger = ConsoleLogger(suffix: prefix + " [Push]", loggingLevel: .debug)
walletPairingClient = pairingClient
let echoClient = EchoClientFactory.create(projectId: "",
Expand All @@ -84,12 +88,13 @@ final class PairingTests: XCTestCase {
groupKeychainStorage: KeychainStorageMock(),
networkInteractor: networkingInteractor,
pairingRegisterer: pairingClient,
echoClient: echoClient)
echoClient: echoClient,
syncClient: syncClient)
}

func makeWalletPairingClient() {
let prefix = "🐶 Wallet: "
let (pairingClient, _, _, _) = makeClientDependencies(prefix: prefix)
let (pairingClient, _, _, _, _) = makeClientDependencies(prefix: prefix)
walletPairingClient = pairingClient
}

Expand Down
50 changes: 34 additions & 16 deletions Example/IntegrationTests/Push/PushTests.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Foundation
import XCTest
import WalletConnectUtils
import Web3
@testable import WalletConnectKMS
import WalletConnectRelay
import Combine
import WalletConnectNetworking
import WalletConnectEcho
@testable import WalletConnectPush
@testable import WalletConnectPairing
@testable import WalletConnectSync
import WalletConnectIdentity
import WalletConnectSigner

Expand All @@ -21,21 +23,30 @@ final class PushTests: XCTestCase {

var pairingStorage: PairingStorage!

let pk = try! EthereumPrivateKey()

var privateKey: Data {
return Data(pk.rawPrivateKey)
}

var account: Account {
return Account("eip155:1:" + pk.address.hex(eip55: true))!
}

private var publishers = [AnyCancellable]()

func makeClientDependencies(prefix: String) -> (PairingClient, NetworkInteracting, KeychainStorageProtocol, KeyValueStorage) {
func makeClientDependencies(prefix: String) -> (PairingClient, NetworkInteracting, SyncClient, KeychainStorageProtocol, KeyValueStorage) {
let keychain = KeychainStorageMock()
let keyValueStorage = RuntimeKeyValueStorage()

let relayLogger = ConsoleLogger(suffix: prefix + " [Relay]", loggingLevel: .debug)
let pairingLogger = ConsoleLogger(suffix: prefix + " [Pairing]", loggingLevel: .debug)
let networkingLogger = ConsoleLogger(suffix: prefix + " [Networking]", loggingLevel: .debug)

let relayClient = RelayClient(
let relayClient = RelayClientFactory.create(
relayHost: InputConfig.relayHost,
projectId: InputConfig.projectId,
keyValueStorage: RuntimeKeyValueStorage(),
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
socketFactory: DefaultSocketFactory(),
logger: relayLogger)
Expand All @@ -52,26 +63,29 @@ final class PushTests: XCTestCase {
keychainStorage: keychain,
networkingClient: networkingClient)

let syncClient = SyncClientFactory.create(networkInteractor: networkingClient, bip44: DefaultBIP44Provider(), keychain: keychain)

let clientId = try! networkingClient.getClientId()
networkingLogger.debug("My client id is: \(clientId)")
return (pairingClient, networkingClient, keychain, keyValueStorage)
return (pairingClient, networkingClient, syncClient, keychain, keyValueStorage)
}

func makeDappClients() {
let prefix = "🦄 Dapp: "
let (pairingClient, networkingInteractor, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let (pairingClient, networkingInteractor, syncClient, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let pushLogger = ConsoleLogger(suffix: prefix + " [Push]", loggingLevel: .debug)
dappPairingClient = pairingClient
dappPushClient = DappPushClientFactory.create(metadata: AppMetadata(name: "GM Dapp", description: "", url: "https://gm-dapp-xi.vercel.app/", icons: []),
logger: pushLogger,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
networkInteractor: networkingInteractor)
networkInteractor: networkingInteractor,
syncClient: syncClient)
}

func makeWalletClients() {
let prefix = "🦋 Wallet: "
let (pairingClient, networkingInteractor, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let (pairingClient, networkingInteractor, syncClient, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let pushLogger = ConsoleLogger(suffix: prefix + " [Push]", loggingLevel: .debug)
walletPairingClient = pairingClient
let echoClient = EchoClientFactory.create(projectId: "",
Expand All @@ -86,7 +100,8 @@ final class PushTests: XCTestCase {
groupKeychainStorage: KeychainStorageMock(),
networkInteractor: networkingInteractor,
pairingRegisterer: pairingClient,
echoClient: echoClient)
echoClient: echoClient,
syncClient: syncClient)
}

override func setUp() {
Expand All @@ -99,7 +114,8 @@ final class PushTests: XCTestCase {

let uri = try! await dappPairingClient.create()
try! await walletPairingClient.pair(uri: uri)
try! await dappPushClient.propose(account: Account.stub(), topic: uri.topic)
try! await walletPushClient.enableSync(account: account, onSign: sign)
try! await dappPushClient.propose(account: account, topic: uri.topic)

walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in
Task(priority: .high) { try! await walletPushClient.approve(id: id, onSign: sign) }
Expand All @@ -121,7 +137,7 @@ final class PushTests: XCTestCase {

let uri = try! await dappPairingClient.create()
try! await walletPairingClient.pair(uri: uri)
try! await dappPushClient.propose(account: Account.stub(), topic: uri.topic)
try! await dappPushClient.propose(account: account, topic: uri.topic)

walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in
Task(priority: .high) { try! await walletPushClient.reject(id: id) }
Expand All @@ -141,7 +157,8 @@ final class PushTests: XCTestCase {
func testWalletCreatesSubscription() async {
let expectation = expectation(description: "expects to create push subscription")
let metadata = AppMetadata(name: "GM Dapp", description: "", url: "https://gm-dapp-xi.vercel.app/", icons: [])
try! await walletPushClient.subscribe(metadata: metadata, account: Account.stub(), onSign: sign)
try! await walletPushClient.enableSync(account: account, onSign: sign)
try! await walletPushClient.subscribe(metadata: metadata, account: account, onSign: sign)
walletPushClient.subscriptionsPublisher
.first()
.sink { [unowned self] subscriptions in
Expand All @@ -152,12 +169,12 @@ final class PushTests: XCTestCase {
wait(for: [expectation], timeout: InputConfig.defaultTimeout)
}


func testDeletePushSubscription() async {
let expectation = expectation(description: "expects to delete push subscription")
let uri = try! await dappPairingClient.create()
try! await walletPairingClient.pair(uri: uri)
try! await dappPushClient.propose(account: Account.stub(), topic: uri.topic)
try! await walletPushClient.enableSync(account: account, onSign: sign)
try! await dappPushClient.propose(account: account, topic: uri.topic)
var subscriptionTopic: String!

walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in
Expand Down Expand Up @@ -185,7 +202,8 @@ final class PushTests: XCTestCase {
let expectation = expectation(description: "expects to create and update push subscription")
let metadata = AppMetadata(name: "GM Dapp", description: "", url: "https://gm-dapp-xi.vercel.app/", icons: [])
let updateScope: Set<String> = ["alerts"]
try! await walletPushClient.subscribe(metadata: metadata, account: Account.stub(), onSign: sign)
try! await walletPushClient.enableSync(account: account, onSign: sign)
try! await walletPushClient.subscribe(metadata: metadata, account: account, onSign: sign)
walletPushClient.subscriptionsPublisher
.first()
.sink { [unowned self] subscriptions in
Expand All @@ -212,7 +230,8 @@ final class PushTests: XCTestCase {
let pushMessage = PushMessage.stub()

let metadata = AppMetadata(name: "GM Dapp", description: "", url: "https://gm-dapp-xi.vercel.app/", icons: [])
try! await walletPushClient.subscribe(metadata: metadata, account: Account.stub(), onSign: sign)
try! await walletPushClient.enableSync(account: account, onSign: sign)
try! await walletPushClient.subscribe(metadata: metadata, account: account, onSign: sign)
var subscription: PushSubscription!
walletPushClient.subscriptionsPublisher
.first()
Expand All @@ -239,7 +258,6 @@ final class PushTests: XCTestCase {

private extension PushTests {
func sign(_ message: String) -> SigningResult {
let privateKey = Data(hex: "305c6cde3846927892cd32762f6120539f3ec74c9e3a16b9b798b1e85351ae2a")
let signer = MessageSignerFactory(signerFactory: DefaultSignerFactory()).create(projectId: InputConfig.projectId)
return .signed(try! signer.sign(message: message, privateKey: privateKey, type: .eip191))
}
Expand Down
7 changes: 3 additions & 4 deletions Example/IntegrationTests/Sign/SignClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ final class SignClientTests: XCTestCase {
static private func makeClientDelegate(name: String) -> ClientDelegate {
let logger = ConsoleLogger(suffix: name, loggingLevel: .debug)
let keychain = KeychainStorageMock()
let relayClient = RelayClient(
let keyValueStorage = RuntimeKeyValueStorage()
let relayClient = RelayClientFactory.create(
relayHost: InputConfig.relayHost,
projectId: InputConfig.projectId,
keyValueStorage: RuntimeKeyValueStorage(),
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
socketFactory: DefaultSocketFactory(),
socketConnectionType: .automatic,
logger: logger
)
let keyValueStorage = RuntimeKeyValueStorage()

let networkingClient = NetworkingClientFactory.create(
relayClient: relayClient,
Expand Down
8 changes: 7 additions & 1 deletion Example/IntegrationTests/Sync/SyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ final class SyncTests: XCTestCase {
let kms = KeyManagementService(keychain: keychain)
let derivationService = SyncDerivationService(syncStorage: syncSignatureStore, bip44: DefaultBIP44Provider(), kms: kms)
let logger = ConsoleLogger(suffix: suffix, loggingLevel: .debug)
let relayClient = RelayClient(relayHost: InputConfig.relayHost, projectId: InputConfig.projectId, keychainStorage: keychain, socketFactory: DefaultSocketFactory(), logger: logger)
let relayClient = RelayClientFactory.create(
relayHost: InputConfig.relayHost,
projectId: InputConfig.projectId,
keyValueStorage: RuntimeKeyValueStorage(),
keychainStorage: keychain,
socketFactory: DefaultSocketFactory(),
logger: logger)
let networkingInteractor = NetworkingClientFactory.create(
relayClient: relayClient,
logger: logger,
Expand Down
12 changes: 11 additions & 1 deletion Example/RelayIntegrationTests/RelayClientEndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ final class RelayClientEndToEndTests: XCTestCase {
socketConnectionType: .manual,
logger: logger
)
let relayClient = RelayClient(dispatcher: dispatcher, logger: logger, keyValueStorage: RuntimeKeyValueStorage(), clientIdStorage: clientIdStorage)
let keychain = KeychainStorageMock()
let keyValueStorage = RuntimeKeyValueStorage()
let relayClient = RelayClientFactory.create(
relayHost: InputConfig.relayHost,
projectId: InputConfig.projectId,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
socketFactory: DefaultSocketFactory(),
socketConnectionType: .manual,
logger: logger
)
let clientId = try! relayClient.getClientId()
logger.debug("My client id is: \(clientId)")

Expand Down
2 changes: 1 addition & 1 deletion Example/WalletApp/ApplicationLayer/EthKeyStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EthKeyStore {
let privateKey: EthereumPrivateKey

var address: String {
return privateKey.address.hex(eip55: false)
return privateKey.address.hex(eip55: true)
}

var privateKeyRaw: Data {
Expand Down
Loading

0 comments on commit 84b09a1

Please sign in to comment.