diff --git a/Example/IntegrationTests/Auth/AuthTests.swift b/Example/IntegrationTests/Auth/AuthTests.swift index a90de5067..54e6ed19e 100644 --- a/Example/IntegrationTests/Auth/AuthTests.swift +++ b/Example/IntegrationTests/Auth/AuthTests.swift @@ -76,7 +76,7 @@ final class AuthTests: XCTestCase { let uri = try! await appPairingClient.create() try! await appAuthClient.request(RequestParams.stub(), topic: uri.topic) - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) walletAuthClient.authRequestPublisher.sink { _ in requestExpectation.fulfill() }.store(in: &publishers) @@ -88,7 +88,7 @@ final class AuthTests: XCTestCase { let uri = try! await appPairingClient.create() try! await appAuthClient.request(RequestParams.stub(), topic: uri.topic) - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) walletAuthClient.authRequestPublisher.sink { [unowned self] request in Task(priority: .high) { let signerFactory = DefaultSignerFactory() @@ -126,7 +126,7 @@ final class AuthTests: XCTestCase { resources: nil ), topic: uri.topic) - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) walletAuthClient.authRequestPublisher.sink { [unowned self] request in Task(priority: .high) { let signature = CacaoSignature(t: .eip1271, s: eip1271Signature) @@ -147,7 +147,7 @@ final class AuthTests: XCTestCase { let uri = try! await appPairingClient.create() try! await appAuthClient.request(RequestParams.stub(), topic: uri.topic) - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) walletAuthClient.authRequestPublisher.sink { [unowned self] request in Task(priority: .high) { let signature = CacaoSignature(t: .eip1271, s: eip1271Signature) @@ -168,7 +168,7 @@ final class AuthTests: XCTestCase { let uri = try! await appPairingClient.create() try! await appAuthClient.request(RequestParams.stub(), topic: uri.topic) - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) walletAuthClient.authRequestPublisher.sink { [unowned self] request in Task(priority: .high) { try! await walletAuthClient.reject(requestId: request.0.id) @@ -189,7 +189,7 @@ final class AuthTests: XCTestCase { let uri = try! await appPairingClient.create() try! await appAuthClient.request(RequestParams.stub(), topic: uri.topic) - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) walletAuthClient.authRequestPublisher.sink { [unowned self] request in Task(priority: .high) { let invalidSignature = "438effc459956b57fcd9f3dac6c675f9cee88abf21acab7305e8e32aa0303a883b06dcbd956279a7a2ca21ffa882ff55cc22e8ab8ec0f3fe90ab45f306938cfa1b" diff --git a/Example/IntegrationTests/Pairing/PairingTests.swift b/Example/IntegrationTests/Pairing/PairingTests.swift index 24cdcaf24..54d436c60 100644 --- a/Example/IntegrationTests/Pairing/PairingTests.swift +++ b/Example/IntegrationTests/Pairing/PairingTests.swift @@ -120,7 +120,7 @@ final class PairingTests: XCTestCase { let uri = try! await appPairingClient.create() - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) try! await appPushClient.propose(account: Account.stub(), topic: uri.topic) @@ -131,7 +131,7 @@ final class PairingTests: XCTestCase { let expectation = expectation(description: "expects ping response") makeWalletClients() let uri = try! await appPairingClient.create() - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) try! await walletPairingClient.ping(topic: uri.topic) walletPairingClient.pingResponsePublisher .sink { topic in @@ -152,7 +152,7 @@ final class PairingTests: XCTestCase { let uri = try! await appPairingClient.create() - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) try! await appPushClient.propose(account: Account.stub(), topic: uri.topic) diff --git a/Example/IntegrationTests/Push/PushTests.swift b/Example/IntegrationTests/Push/PushTests.swift index a58c1ed54..700f893ef 100644 --- a/Example/IntegrationTests/Push/PushTests.swift +++ b/Example/IntegrationTests/Push/PushTests.swift @@ -121,7 +121,7 @@ final class PushTests: XCTestCase { let expectation = expectation(description: "expects dapp to receive error response") let uri = try! await dappPairingClient.create() - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) try! await walletPushClient.enableSync(account: account, onSign: sign) try! await dappPushClient.propose(account: account, topic: uri.topic) @@ -144,7 +144,7 @@ final class PushTests: XCTestCase { let expectation = expectation(description: "expects dapp to receive error response") let uri = try! await dappPairingClient.create() - try! await walletPairingClient.pair(uri: uri) + try? await walletPairingClient.pair(uri: uri) try! await dappPushClient.propose(account: account, topic: uri.topic) walletPushClient.requestPublisher.sink { [unowned self] (id, _, _) in @@ -180,7 +180,7 @@ final class PushTests: XCTestCase { 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 walletPairingClient.pair(uri: uri) try! await walletPushClient.enableSync(account: account, onSign: sign) try! await dappPushClient.propose(account: account, topic: uri.topic) var subscriptionTopic: String! diff --git a/Tests/AuthTests/WalletRequestSubscriberTests.swift b/Tests/AuthTests/WalletRequestSubscriberTests.swift index 2508ae587..1fba88977 100644 --- a/Tests/AuthTests/WalletRequestSubscriberTests.swift +++ b/Tests/AuthTests/WalletRequestSubscriberTests.swift @@ -57,7 +57,7 @@ class WalletRequestSubscriberTests: XCTestCase { pairingRegisterer.subject.send(payload) wait(for: [messageExpectation], timeout: defaultTimeout) - XCTAssertTrue(pairingRegisterer.isActivateCalled) + XCTAssertTrue(pairingRegisterer.isReceivedCalled) XCTAssertEqual(requestPayload, expectedPayload) XCTAssertEqual(requestId, expectedRequestId) } diff --git a/Tests/TestingUtils/Mocks/PairingRegistererMock.swift b/Tests/TestingUtils/Mocks/PairingRegistererMock.swift index 6aa18183f..3c21567c6 100644 --- a/Tests/TestingUtils/Mocks/PairingRegistererMock.swift +++ b/Tests/TestingUtils/Mocks/PairingRegistererMock.swift @@ -7,6 +7,7 @@ public class PairingRegistererMock: PairingRegisterer where Reque public let subject = PassthroughSubject, Never>() public var isActivateCalled: Bool = false + public var isReceivedCalled: Bool = false public func register(method: ProtocolMethod) -> AnyPublisher, Never> where RequestParams: Decodable, RequestParams: Encodable { subject.eraseToAnyPublisher() as! AnyPublisher, Never> @@ -21,6 +22,6 @@ public class PairingRegistererMock: PairingRegisterer where Reque } public func setReceived(pairingTopic: String) { - + isReceivedCalled = true } } diff --git a/Tests/TestingUtils/NetworkingInteractorMock.swift b/Tests/TestingUtils/NetworkingInteractorMock.swift index 175e6aed0..8764e7675 100644 --- a/Tests/TestingUtils/NetworkingInteractorMock.swift +++ b/Tests/TestingUtils/NetworkingInteractorMock.swift @@ -15,6 +15,7 @@ public class NetworkingInteractorMock: NetworkInteracting { private(set) var didRespondError = false private(set) var didCallSubscribe = false private(set) var didCallUnsubscribe = false + private(set) var didCallHandleHistoryRequest = false private(set) var didRespondOnTopic: String? private(set) var lastErrorCode = -1 @@ -90,6 +91,10 @@ public class NetworkingInteractorMock: NetworkInteracting { subscriptions.append(topic) didCallSubscribe = true } + + public func handleHistoryRequest(topic: String, request: JSONRPC.RPCRequest) { + didCallHandleHistoryRequest = true + } func didSubscribe(to topic: String) -> Bool { subscriptions.contains { $0 == topic } diff --git a/Tests/WalletConnectPairingTests/WalletPairServiceTests.swift b/Tests/WalletConnectPairingTests/WalletPairServiceTests.swift index facccf6b4..4f88e9c94 100644 --- a/Tests/WalletConnectPairingTests/WalletPairServiceTests.swift +++ b/Tests/WalletConnectPairingTests/WalletPairServiceTests.swift @@ -11,12 +11,14 @@ final class WalletPairServiceTestsTests: XCTestCase { var networkingInteractor: NetworkingInteractorMock! var storageMock: WCPairingStorageMock! var cryptoMock: KeyManagementServiceMock! + var rpcHistory: RPCHistory! override func setUp() { networkingInteractor = NetworkingInteractorMock() storageMock = WCPairingStorageMock() cryptoMock = KeyManagementServiceMock() - service = WalletPairService(networkingInteractor: networkingInteractor, kms: cryptoMock, pairingStorage: storageMock) + rpcHistory = RPCHistoryFactory.createForNetwork(keyValueStorage: RuntimeKeyValueStorage()) + service = WalletPairService(networkingInteractor: networkingInteractor, kms: cryptoMock, pairingStorage: storageMock, history: rpcHistory) } func testPairWhenNetworkNotConnectedThrows() async { @@ -25,13 +27,18 @@ final class WalletPairServiceTestsTests: XCTestCase { await XCTAssertThrowsErrorAsync(try await service.pair(uri)) } - func testPairOnSameURIWhenRequestReceivedThrows() async { + func testPairOnSameUriPresentsRequest() async { + let rpcRequest = RPCRequest(method: "session_propose", id: 1234) + let uri = WalletConnectURI.stub() try! await service.pair(uri) var pairing = storageMock.getPairing(forTopic: uri.topic) pairing?.receivedRequest() storageMock.setPairing(pairing!) - await XCTAssertThrowsErrorAsync(try await service.pair(uri)) + try! rpcHistory.set(rpcRequest, forTopic: uri.topic, emmitedBy: .local) + + try! await service.pair(uri) + XCTAssertTrue(networkingInteractor.didCallHandleHistoryRequest) } func testPair() async {