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

Fix unit test run #410

Merged
merged 7 commits into from
Aug 8, 2022
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
3 changes: 2 additions & 1 deletion .github/actions/ci/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ runs:
-project Example/ExampleApp.xcodeproj \
-scheme WalletConnect \
-clonedSourcePackagesDirPath SourcePackages \
-sdk iphonesimulator"
-destination 'platform=iOS Simulator,name=iPhone 13' \
test"

# Integration tests
- name: Run integration tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private extension ApproveEngine {
)
settlingProposal = proposal

Task(priority: .background) {
Task(priority: .high) {
try? await networkingInteractor.subscribe(topic: sessionTopic)
}
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Tests/AuthTests/Stubs/RequestSubscriptionPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ extension RequestSubscriptionPayload {
let payload = AuthPayload(requestParams: RequestParams.stub(), iat: issueAt)
let params = AuthRequestParams(requester: requester, payloadParams: payload)
let request = RPCRequest(method: "wc_authRequest", params: params, rpcid: id)
return RequestSubscriptionPayload(id: 123, request: request)
return RequestSubscriptionPayload(topic: "123", request: request)
}
}
4 changes: 2 additions & 2 deletions Tests/JSONRPCTests/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import Commons

final class TestIdentifierGenerator: IdentifierGenerator {

var id: RPCID = .right(Int.random())
var id: RPCID = .right(Int64.random())

func next() -> RPCID {
return id
}
}

extension Either where L == String, R == Int {
extension Either where L == String, R == Int64 {

var isString: Bool {
left != nil
Expand Down
20 changes: 10 additions & 10 deletions Tests/JSONRPCTests/RPCRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import TestingUtils

private func makeRequests() -> [RPCRequest] {
return [
RPCRequest(method: String.random(), id: Int.random()),
RPCRequest(method: String.random(), id: Int64.random()),
RPCRequest(method: String.random(), id: String.random()),
RPCRequest(method: String.random(), params: EmptyCodable(), id: Int.random()),
RPCRequest(method: String.random(), params: EmptyCodable(), id: Int64.random()),
RPCRequest(method: String.random(), params: EmptyCodable(), id: String.random()),
RPCRequest(method: String.random(), params: [0, 1, 2], id: Int.random()),
RPCRequest(method: String.random(), params: [0, 1, 2], id: Int64.random()),
RPCRequest(method: String.random(), params: ["0", "1", "2"], id: String.random()),
RPCRequest(method: String.random(), params: [AnyCodable(0), AnyCodable("0")], id: Int.random()),
RPCRequest(method: String.random(), params: [AnyCodable(0), AnyCodable("0")], id: Int64.random()),
RPCRequest(method: String.random(), params: [AnyCodable(0), AnyCodable("0")], id: String.random())
]
}
Expand All @@ -38,21 +38,21 @@ final class RPCRequestTests: XCTestCase {

func testCheckedParamsInit() {
XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0]))
XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0], id: Int.random()))
XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0], id: Int64.random()))
XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: [0], id: String.random()))
XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable()))
XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable(), id: Int.random()))
XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable(), id: Int64.random()))
XCTAssertNoThrow(try RPCRequest(method: "method", checkedParams: EmptyCodable(), id: String.random()))
}

func testCheckedParamsInitFailsWithPrimitives() {
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: 0, id: Int.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: 0, id: Int64.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: 0, id: String.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: "string", id: Int.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: "string", id: Int64.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: "string", id: String.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: Double.pi, id: Int.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: Double.pi, id: Int64.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: Double.pi, id: String.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: true, id: Int.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: true, id: Int64.random()))
XCTAssertThrowsError(try RPCRequest(method: "method", checkedParams: true, id: String.random()))
}

Expand Down
14 changes: 7 additions & 7 deletions Tests/JSONRPCTests/RPCResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import TestingUtils

private func makeResultResponses() -> [RPCResponse] {
return [
RPCResponse(id: Int.random(), result: Int.random()),
RPCResponse(id: Int.random(), result: Bool.random()),
RPCResponse(id: Int.random(), result: String.random()),
RPCResponse(id: Int.random(), result: (1...10).map { String($0) }),
RPCResponse(id: Int.random(), result: EmptyCodable()),
RPCResponse(id: Int64.random(), result: Int.random()),
RPCResponse(id: Int64.random(), result: Bool.random()),
RPCResponse(id: Int64.random(), result: String.random()),
RPCResponse(id: Int64.random(), result: (1...10).map { String($0) }),
RPCResponse(id: Int64.random(), result: EmptyCodable()),
RPCResponse(id: String.random(), result: Int.random())
]
}

private func makeErrorResponses() -> [RPCResponse] {
return [
RPCResponse(id: Int.random(), error: JSONRPCError.stub()),
RPCResponse(id: Int64.random(), error: JSONRPCError.stub()),
RPCResponse(id: String.random(), error: JSONRPCError.stub(data: AnyCodable(Int.random()))),
RPCResponse(id: Int.random(), errorCode: Int.random(), message: String.random(), associatedData: AnyCodable(String.random())),
RPCResponse(id: Int64.random(), errorCode: Int.random(), message: String.random(), associatedData: AnyCodable(String.random())),
RPCResponse(id: String.random(), errorCode: Int.random(), message: String.random(), associatedData: nil)
]
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/TestingUtils/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public extension Int {
}
}

public extension Int64 {
static func random() -> Int64 {
random(in: Int64.min...Int64.max)
}
}

public extension Double {

// Do not use this function when testing Codables: https://bugs.swift.org/browse/SR-7054
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class NetworkingInteractorMock: NetworkInteracting {
}

func subscribe(topic: String) {
didCallSubscribe = true
subscriptions.append(topic)
didCallSubscribe = true
}

func unsubscribe(topic: String) {
Expand Down
2 changes: 0 additions & 2 deletions Tests/WalletConnectSignTests/PairingEngineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ final class PairingEngineTests: XCTestCase {
XCTAssertEqual(publishTopic, topicA)
}

// Flaky test: asserting `topicB` and `sessionTopic` failed once, couldn't reproduce
@MainActor
func testHandleSessionProposeResponse() async {
let uri = try! await engine.create()
let pairing = storageMock.getPairing(forTopic: uri.topic)!
Expand Down
2 changes: 1 addition & 1 deletion Tests/WalletConnectUtilsTests/RPCHistoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class RPCHistoryTests: XCTestCase {
func testSetDuplicateRequest() throws {
let expectedError = RPCHistory.HistoryError.requestDuplicateNotAllowed

let id = Int.random()
let id = Int64.random()
let requestA = RPCRequest.stub(method: "method-1", id: id)
let requestB = RPCRequest.stub(method: "method-2", id: id)
let topic = String.randomTopic()
Expand Down