Skip to content

Commit

Permalink
move serializer tests to integration target
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Feb 11, 2022
1 parent 13c5a77 commit 885d109
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let package = Package(
dependencies: ["WalletConnect", "TestingUtils", "WalletConnectKMS"]),
.testTarget(
name: "IntegrationTests",
dependencies: ["WalletConnect", "TestingUtils"]),
dependencies: ["WalletConnect", "TestingUtils", "WalletConnectKMS"]),
.testTarget(
name: "RelayerTests",
dependencies: ["Relayer", "WalletConnectUtils", "TestingUtils"]),
Expand All @@ -43,7 +43,7 @@ let package = Package(
dependencies: ["WalletConnectKMS", "WalletConnectUtils", "TestingUtils"]),
.target(
name: "TestingUtils",
dependencies: ["WalletConnectUtils"],
dependencies: ["WalletConnectUtils", "WalletConnectKMS"],
path: "Tests/TestingUtils"),
],
swiftLanguageVersions: [.v5]
Expand Down
4 changes: 2 additions & 2 deletions Sources/WalletConnectKMS/Serialiser/Serializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public class Serializer {
}
}

private func deserialize<T: Codable>(message: String, symmetricKey: Data) throws -> T {
func deserialize<T: Codable>(message: String, symmetricKey: Data) throws -> T {
let decryptedData = try decrypt(message: message, symmetricKey: symmetricKey)
return try JSONDecoder().decode(T.self, from: decryptedData)
}

private func encrypt(json: String, agreementKeys: AgreementSecret) throws -> String {
func encrypt(json: String, agreementKeys: AgreementSecret) throws -> String {
let payload = try codec.encode(plainText: json, agreementKeys: agreementKeys)
let iv = payload.iv.toHexString()
let publicKey = payload.publicKey.toHexString()
Expand Down
39 changes: 39 additions & 0 deletions Tests/IntegrationTests/Mocks/SerialiserTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//

import Foundation

import XCTest
@testable import WalletConnectKMS
@testable import WalletConnect
@testable import TestingUtils

final class SerializerTests: XCTestCase {
var serializer: Serializer!
var codec: MockedCodec!
override func setUp() {
codec = MockedCodec()
self.serializer = Serializer(kms: KeyManagementService(keychain: KeychainStorageMock()), codec: codec)
}

override func tearDown() {
serializer = nil
}

func testSerialize() {
codec.encryptionPayload = EncryptionPayload(iv: SerializerTestData.iv,
publicKey: SerializerTestData.publicKey,
mac: SerializerTestData.mac,
cipherText: SerializerTestData.cipherText)
let serializedMessage = try! serializer.encrypt(json: SerializerTestData.pairingApproveJSON, agreementKeys: SerializerTestData.emptyAgreementSecret)
let serializedMessageSample = SerializerTestData.serializedMessage
XCTAssertEqual(serializedMessage, serializedMessageSample)
}

func testDeserialize() {
let serializedMessageSample = SerializerTestData.serializedMessage
codec.decodedJson = SerializerTestData.pairingApproveJSON
let deserializedJSONRPC: WCRequest = try! serializer.deserialize(message: serializedMessageSample, symmetricKey: Data(hex: ""))
XCTAssertEqual(deserializedJSONRPC.params, SerializerTestData.pairingApproveJSONRPCRequest.params)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Foundation
@testable import WalletConnectKMS
@testable import WalletConnect

enum SerializerTestData {
static let emptyAgreementSecret = AgreementSecret(sharedSecret: Data(hex: ""), publicKey: AgreementPrivateKey().publicKey)
Expand Down Expand Up @@ -35,5 +36,23 @@ enum SerializerTestData {
}
}
"""

static let pairingApproveJSONRPCRequest = WCRequest(
id: 0,
jsonrpc: "2.0",
method: WCRequest.Method.pairingApprove,
params: WCRequest.Params.pairingApprove(
PairingType.ApprovalParams(
relay: RelayProtocolOptions(
protocol: "waku",
params: nil),
responder: PairingParticipant(publicKey: "be9225978b6287a02d259ee0d9d1bcb683082d8386b7fb14b58ac95b93b2ef43"),
expiry: 1632742217,
state: PairingState(metadata: AppMetadata(
name: "iOS",
description: nil,
url: nil,
icons: nil))))
)
}

1 change: 1 addition & 0 deletions Tests/WalletConnectKMSTests/CryptoTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import XCTest
@testable import WalletConnectKMS
@testable import TestingUtils

fileprivate extension Error {
var isKeyNotFoundError: Bool {
Expand Down
38 changes: 0 additions & 38 deletions Tests/WalletConnectKMSTests/JSONRPCSerialiserTests.swift

This file was deleted.

0 comments on commit 885d109

Please sign in to comment.