Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-lsvk committed Aug 17, 2023
1 parent ef75976 commit 12518f1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
12 changes: 6 additions & 6 deletions Example/IntegrationTests/Auth/AuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions Example/IntegrationTests/Pairing/PairingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

Expand Down
6 changes: 3 additions & 3 deletions Example/IntegrationTests/Push/PushTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion Tests/AuthTests/WalletRequestSubscriberTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/TestingUtils/Mocks/PairingRegistererMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class PairingRegistererMock<RequestParams>: PairingRegisterer where Reque
public let subject = PassthroughSubject<RequestSubscriptionPayload<RequestParams>, Never>()

public var isActivateCalled: Bool = false
public var isReceivedCalled: Bool = false

public func register<RequestParams>(method: ProtocolMethod) -> AnyPublisher<RequestSubscriptionPayload<RequestParams>, Never> where RequestParams: Decodable, RequestParams: Encodable {
subject.eraseToAnyPublisher() as! AnyPublisher<RequestSubscriptionPayload<RequestParams>, Never>
Expand All @@ -21,6 +22,6 @@ public class PairingRegistererMock<RequestParams>: PairingRegisterer where Reque
}

public func setReceived(pairingTopic: String) {

isReceivedCalled = true
}
}
5 changes: 5 additions & 0 deletions Tests/TestingUtils/NetworkingInteractorMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }
Expand Down
13 changes: 10 additions & 3 deletions Tests/WalletConnectPairingTests/WalletPairServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 12518f1

Please sign in to comment.