Skip to content

Commit

Permalink
Add prompt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Feb 15, 2022
1 parent 1e5bbd4 commit 3f7899f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Tests/WalletConnectTests/Mocks/MockedNetworkRelayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class MockedNetworkRelayer: NetworkRelaying {
var onConnect: (() -> ())?
var onMessage: ((String, String) -> ())?
var error: Error?
var prompt = false
func publish(topic: String, payload: String, prompt: Bool, completion: @escaping ((Error?) -> ())) -> Int64 {
self.prompt = prompt
completion(error)
return 0
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/WalletConnectTests/Mocks/SerializerMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import WalletConnectUtils

class SerializerMock: Serializing {
var deserialized: Any!
var serialized: String!
var serialized: String = ""

func serialize(topic: String, encodable: Encodable) throws -> String {
try serialize(json: try encodable.json(), agreementKeys: AgreementSecret(sharedSecret: Data(), publicKey: AgreementPrivateKey().publicKey))
Expand Down
24 changes: 22 additions & 2 deletions Tests/WalletConnectTests/WCRelayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,20 @@ class WalletConnectRelayTests: XCTestCase {
waitForExpectations(timeout: 0.01, handler: nil)
}

func testRequestCompletesWithError() {
//todo
func testPromptOnSessionPayload() {
let topic = "fefc3dc39cacbc562ed58f92b296e2d65a6b07ef08992b93db5b3cb86280635a"
let request = getWCSessionPayloadRequest()
networkRelayer.prompt = false
wcRelay.request(topic: topic, payload: request) { _ in }
XCTAssertTrue(networkRelayer.prompt)
}

func testNoPromptOnSessionUpgrade() {
let topic = "fefc3dc39cacbc562ed58f92b296e2d65a6b07ef08992b93db5b3cb86280635a"
let request = getWCSessionUpgrade()
networkRelayer.prompt = false
wcRelay.request(topic: topic, payload: request) { _ in }
XCTAssertTrue(networkRelayer.prompt)
}
}

Expand All @@ -89,6 +101,14 @@ extension WalletConnectRelayTests {
let wcRequest = WCRequest(id: wcRequestId, method: WCRequest.Method.sessionPayload, params: params)
return wcRequest
}

func getWCSessionUpgrade() -> WCRequest {
let wcRequestId: Int64 = 123456
let sessionUpgradeParams = SessionType.UpgradeParams(permissions: SessionPermissions(blockchain: SessionPermissions.Blockchain(chains: []), jsonrpc: SessionPermissions.JSONRPC(methods: []), notifications: SessionPermissions.Notifications(types: [])))
let params = WCRequest.Params.sessionUpgrade(sessionUpgradeParams)
let wcRequest = WCRequest(id: wcRequestId, method: WCRequest.Method.sessionPayload, params: params)
return wcRequest
}
}

fileprivate let testPayload =
Expand Down

0 comments on commit 3f7899f

Please sign in to comment.