Skip to content

Commit

Permalink
add tests for client module
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Nov 18, 2020
1 parent 6fe4642 commit 29632e4
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Sources/TonClientSwift/Client/TonClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Foundation

public final class TSDKClientModule {

public let module: String = "client"
private let binding: TSDKBindingModule
public let config: TSDKClientConfig
public var abi: TSDKAbiModule
Expand All @@ -31,4 +32,31 @@ public final class TSDKClientModule {
public func destroy() {
binding.destroyContext()
}

public func get_api_reference(_ handler: @escaping (TSDKBindingResponse<TSDKResultOfGetApiReference, TSDKClientError, TSDKDefault>) -> Void) {
let method: String = "get_api_reference"
binding.requestLibraryAsync(methodName(module, method)) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfGetApiReference, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
BindingStore.responseQueue.async { handler(response) }
}
}

public func version(_ handler: @escaping (TSDKBindingResponse<TSDKResultOfVersion, TSDKClientError, TSDKDefault>) -> Void) {
let method: String = "version"
binding.requestLibraryAsync(methodName(module, method)) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfVersion, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
BindingStore.responseQueue.async { handler(response) }
}
}

public func build_info(_ handler: @escaping (TSDKBindingResponse<TSDKResultOfBuildInfo, TSDKClientError, TSDKDefault>) -> Void) {
let method: String = "build_info"
binding.requestLibraryAsync(methodName(module, method)) { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKResultOfBuildInfo, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
BindingStore.responseQueue.async { handler(response) }
}
}
}
51 changes: 51 additions & 0 deletions Tests/TonClientSwiftTests/ClientTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// File.swift
//
//
// Created by Oleh Hudeichuk on 19.11.2020.
//

import XCTest
import class Foundation.Bundle
@testable import TonClientSwift
@testable import CTonSDK

final class ClientTests: XCTestCase {

func testGet_api_reference() throws {
testAsyncMethods { (client, group) in
group.enter()
client.get_api_reference { (response) in
XCTAssertTrue(response.result?.api != nil)
group.leave()
}
group.wait()
}
}

func testVersion() throws {
testAsyncMethods { (client, group) in
group.enter()
client.version { (response) in
XCTAssertTrue(response.result?.version != nil)
if response.finished {
group.leave()
}
}
group.wait()
}
}

func testBuild_info() throws {
testAsyncMethods { (client, group) in
group.enter()
client.build_info { (response) in
XCTAssertTrue(response.result?.build_number != nil)
if response.finished {
group.leave()
}
}
group.wait()
}
}
}

0 comments on commit 29632e4

Please sign in to comment.