-
Notifications
You must be signed in to change notification settings - Fork 8
Pocket Integration #127
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
Open
pabelnl
wants to merge
27
commits into
keefertaylor:master
Choose a base branch
from
pokt-network:pocket-imp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pocket Integration #127
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2430517
Updated carthage dependencies
pabelnl 598da52
added PocketNetworkClient
pabelnl 307d89b
added proper tests for Pocket Network
pabelnl 062aaab
Updated pocket tests, added dependency to podspec, updated PocketNetw…
pabelnl f5d735c
Merge branch 'master' into pocket-imp
pabelnl 1bd0925
Add cocoapods to CI script
keefertaylor defa857
Update Gemfile
keefertaylor 6f8939d
HomeBrew script updates
keefertaylor 35a8017
Update .travis.yml
keefertaylor aae7054
Split travis into jobs
keefertaylor acce7af
Update .travis.yml
keefertaylor 7d551af
Update .travis.yml
keefertaylor 767de8e
Update .travis.yml
keefertaylor be044b6
Update .travis.yml
keefertaylor 04199ce
fix test
keefertaylor a2d7c95
re-enable carthage build
keefertaylor a57ba6e
Try to speed up cocoapods build
keefertaylor 66f33a1
disable carthage for debugging
keefertaylor abb2c63
fix test
keefertaylor abfbc85
try to speed up travis further
keefertaylor 45426e8
re-enable carthage
keefertaylor 47ac72d
Update OriginationOperationTest.swift
keefertaylor c1e5480
Reverse order
keefertaylor d73653d
updated cartfile.resolved
pabelnl 16438f9
Merge branch 'master' into pocket-imp
pabelnl 75ee32f
added build script to retrieve the pocket dev id from a environment v…
pabelnl a53ab89
added ci configuration file fortesting, updated pocket network tests
pabelnl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.