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

Pocket Integration #127

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2430517
Updated carthage dependencies
pabelnl Oct 14, 2019
598da52
added PocketNetworkClient
pabelnl Oct 14, 2019
307d89b
added proper tests for Pocket Network
pabelnl Oct 14, 2019
062aaab
Updated pocket tests, added dependency to podspec, updated PocketNetw…
pabelnl Oct 25, 2019
f5d735c
Merge branch 'master' into pocket-imp
pabelnl Oct 25, 2019
1bd0925
Add cocoapods to CI script
keefertaylor Oct 28, 2019
defa857
Update Gemfile
keefertaylor Oct 28, 2019
6f8939d
HomeBrew script updates
keefertaylor Oct 28, 2019
35a8017
Update .travis.yml
keefertaylor Oct 28, 2019
aae7054
Split travis into jobs
keefertaylor Nov 2, 2019
acce7af
Update .travis.yml
keefertaylor Nov 2, 2019
7d551af
Update .travis.yml
keefertaylor Nov 2, 2019
767de8e
Update .travis.yml
keefertaylor Nov 2, 2019
be044b6
Update .travis.yml
keefertaylor Nov 2, 2019
04199ce
fix test
keefertaylor Nov 2, 2019
a2d7c95
re-enable carthage build
keefertaylor Nov 2, 2019
a57ba6e
Try to speed up cocoapods build
keefertaylor Nov 2, 2019
66f33a1
disable carthage for debugging
keefertaylor Nov 2, 2019
abb2c63
fix test
keefertaylor Nov 3, 2019
abfbc85
try to speed up travis further
keefertaylor Nov 3, 2019
45426e8
re-enable carthage
keefertaylor Nov 3, 2019
47ac72d
Update OriginationOperationTest.swift
keefertaylor Nov 3, 2019
c1e5480
Reverse order
keefertaylor Nov 3, 2019
d73653d
updated cartfile.resolved
pabelnl Nov 26, 2019
16438f9
Merge branch 'master' into pocket-imp
pabelnl Nov 28, 2019
75ee32f
added build script to retrieve the pocket dev id from a environment v…
pabelnl Dec 31, 2019
a53ab89
added ci configuration file fortesting, updated pocket network tests
pabelnl Dec 31, 2019
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
1 change: 1 addition & 0 deletions Cartfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ github "keefertaylor/TezosCrypto" ~> 2.1
github "mxcl/PromiseKit" ~> 6.8
github "keefertaylor/Base58Swift" ~> 2.1
github "keefertaylor/MnemonicKit" ~> 1.3
github "pokt-network/pocket-swift-core-carthage"
pabelnl marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
github "Quick/Nimble" "v8.0.4"
github "Quick/Quick" "v2.2.0"
github "RNCryptor/RNCryptor" "5.1.0"
github "ReactiveX/RxSwift" "4.5.0"
github "attaswift/BigInt" "v3.1.0"
github "attaswift/SipHash" "v1.2.2"
github "jedisct1/swift-sodium" "0.8.0"
github "jimisaacs/SwiftKeychainWrapper" "65c16da7399dd539322203558160fa349a1e27d3"
github "keefertaylor/Base58Swift" "2.1.9"
github "keefertaylor/MnemonicKit" "1.3.10"
github "keefertaylor/TezosCrypto" "2.1.5"
github "krzyzanowskim/CryptoSwift" "0.14.0"
github "mxcl/PromiseKit" "6.12.0"
github "pokt-network/pocket-swift-core-carthage" "0.0.1"
200 changes: 200 additions & 0 deletions Tests/TezosKit/PocketNetworkClientTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
// Copyright Keefer Taylor, 2019.

@testable import TezosKit
import XCTest

class PocketNetworkClientTest: XCTestCase {
public var networkClient: NetworkClient?
public let fakeURLSession = FakeURLSession()
public let callbackQueue: DispatchQueue = DispatchQueue(label: "callbackQueue")
public var pocket_dev_id = ""
// Setup
public override func setUp() {
super.setUp()

if let path = Bundle(for: type(of: self)).path(forResource: "ci_config", ofType: "json") {
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
let jsonResult = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves)
if let jsonResult = jsonResult as? Dictionary<String, AnyObject>, let dev_id = jsonResult["POCKET_DEV_ID"] as? String {
self.pocket_dev_id = dev_id
}
} catch {
print("Failed to retrieve the Pocket DevID with error: \(error)")
XCTFail()
}
}
// Initialize PocketNetwork Client
networkClient = PocketNetworkClient(
devID: self.pocket_dev_id,
netID: "MAINNET",
callbackQueue: callbackQueue,
responseHandler: RPCResponseHandler()
)
}
// test
public func testRetrieveNetworkVersion() {
let expectation = XCTestExpectation(description: "Completion is Called")
// RPC endpoint will resolve to a valid URL.
let header = Header.contentTypeApplicationJSON
let rpc = RPC(endpoint: "/network/version", headers: [header], responseAdapterClass: StringResponseAdapter.self, payload: nil)

networkClient?.send(rpc, completion: { (result) in
switch result {
case .failure:
XCTFail()
case .success:
expectation.fulfill()
}
})

wait(for: [expectation], timeout: 10)
}
public func testCallbackOnCorrectQueueForBadURL() {
let expectation = XCTestExpectation(description: "Completion is Called")
// RPC endpoint will not resolve to a valid URL.
let rpc = RPC(endpoint: "/ /\"test", responseAdapterClass: StringResponseAdapter.self)
networkClient?.send(rpc) { _ in
if #available(iOS 10, OSX 10.12, *) {
dispatchPrecondition(condition: .onQueue(self.callbackQueue))
}
expectation.fulfill()
}
wait(for: [expectation], timeout: 10)
}
public func testCallbackOnCorrectQueue() {
let expectation = XCTestExpectation(description: "Completion is Called")
let rpc = RPC(endpoint: "/test", responseAdapterClass: StringResponseAdapter.self)
networkClient?.send(rpc) { _ in
if #available(iOS 10, OSX 10.12, *) {
dispatchPrecondition(condition: .onQueue(self.callbackQueue))
}
expectation.fulfill()
}
wait(for: [expectation], timeout: 10)
}
public func testBadEndpointCompletesWithURL() {
let expectation = XCTestExpectation(description: "Completion is Called")
// RPC endpoint will not resolve to a valid URL.
let rpc = RPC(endpoint: "/ /\"test", responseAdapterClass: StringResponseAdapter.self)
networkClient?.send(rpc) { result in
switch result {
case .failure:
expectation.fulfill()
case .success:
XCTFail()
}
}
wait(for: [expectation], timeout: 20)
}
public func testBadHTTPResponseCompletesWithError() {
// Fake URL session has data but has an HTTP error code.
fakeURLSession.urlResponse = HTTPURLResponse(
url: URL(string: "http://keefertaylor.com")!,
statusCode: 400,
httpVersion: nil,
headerFields: nil
)
fakeURLSession.data = "SomeString".data(using: .utf8)
let expectation = XCTestExpectation(description: "Completion is Called")
let rpc = RPC(endpoint: "/test", responseAdapterClass: StringResponseAdapter.self)
networkClient?.send(rpc) { result in
switch result {
case .failure:
expectation.fulfill()
case .success:
XCTFail()
}
}
wait(for: [expectation], timeout: 20)
}
public func testErrorCompletesWithError() {
// Valid HTTP response and data, but error is returned.
fakeURLSession.urlResponse = HTTPURLResponse(
url: URL(string: "http://keefertaylor.com")!,
statusCode: 200,
httpVersion: nil,
headerFields: nil
)
fakeURLSession.data = "Result".data(using: .utf8)
fakeURLSession.error = TezosKitError(kind: .unknown, underlyingError: nil)
// Expectation
let expectation = XCTestExpectation(description: "Completion is Called")
let rpc = RPC(endpoint: "/test", responseAdapterClass: StringResponseAdapter.self)
networkClient?.send(rpc) { result in
switch result {
case .failure:
expectation.fulfill()
case .success:
XCTFail()
}
}
wait(for: [expectation], timeout: 20)
}
public func testNilDataCompletesWithError() {
// Valid HTTP response, but returned data is nil.
fakeURLSession.urlResponse = HTTPURLResponse(
url: URL(string: "http://keefertaylor.com")!,
statusCode: 200,
httpVersion: nil,
headerFields: nil
)
// Expectation
let expectation = XCTestExpectation(description: "Completion is Called")
let rpc = RPC(endpoint: "/test", responseAdapterClass: StringResponseAdapter.self)
networkClient?.send(rpc) { result in
switch result {
case .failure:
expectation.fulfill()
case .success:
XCTFail()
}
}
wait(for: [expectation], timeout: 10)
}
public func testInocrrectDataCompletesWithError() {
// Response is a string but RPC attempts to decode to an int.
fakeURLSession.urlResponse = HTTPURLResponse(
url: URL(string: "http://keefertaylor.com")!,
statusCode: 200,
httpVersion: nil,
headerFields: nil
)
// Expectation
let expectation = XCTestExpectation(description: "Completion is Called")
let rpc = RPC(endpoint: "/test", responseAdapterClass: IntegerResponseAdapter.self)
networkClient?.send(rpc) { result in
switch result {
case .failure:
expectation.fulfill()
case .success:
XCTFail()
}
}
wait(for: [expectation], timeout: 10)
}
public func testRequestCompletesWithResultAndNoError() {
// A valid response with not HTTP error.
let expectedString = "Expected!"
fakeURLSession.urlResponse = HTTPURLResponse(
url: URL(string: "http://keefertaylor.com")!,
statusCode: 200,
httpVersion: nil,
headerFields: nil
)
fakeURLSession.data = expectedString.data(using: .utf8)
// Expectation
let expectation = XCTestExpectation(description: "Completion is Called")
let rpc = RPC(endpoint: "/test", responseAdapterClass: StringResponseAdapter.self)
networkClient?.send(rpc) { result in
switch result {
case .failure:
XCTFail()
case .success(let data):
XCTAssertEqual(data, expectedString)
expectation.fulfill()
}
}
wait(for: [expectation], timeout: 10)
}
}
11 changes: 6 additions & 5 deletions TezosKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ Pod::Spec.new do |s|
s.ios.deployment_target = "10.0"
s.osx.deployment_target = "10.14"
s.default_subspecs = 'TezosKitCore', 'TezosKitPromises'

s.subspec 'TezosKitCore' do |ss|
ss.source_files = "TezosKit/**/*.swift"
ss.frameworks = 'Foundation'

ss.ios.deployment_target = '10.0'
ss.osx.deployment_target = '10.14'

ss.dependency "BigInt", "~> 3.1"
ss.dependency "MnemonicKit", "~> 1.3"
ss.dependency "TezosCrypto", "~> 2.1"
ss.dependency "Base58Swift", "~> 2.1"
ss.dependency "PocketSwift-Core"
end

s.subspec 'TezosKitPromises' do |ss|
ss.source_files = "Extensions/PromiseKit/*.swift"
ss.frameworks = 'Foundation'

ss.ios.deployment_target = '10.0'
ss.osx.deployment_target = '10.14'

Expand All @@ -42,5 +43,5 @@ Pod::Spec.new do |s|

s.test_spec "Tests" do |test_spec|
test_spec.source_files = ["Tests/*.swift", "Tests/TezosKit/*.swift", "Tests/Extensions/PromiseKit/*.swift"]
end
end
end
Loading