diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/swift-algorand-sdk.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/swift-algorand-sdk.xcscheme
index a625d20..f39cc17 100644
--- a/.swiftpm/xcode/xcshareddata/xcschemes/swift-algorand-sdk.xcscheme
+++ b/.swiftpm/xcode/xcshareddata/xcschemes/swift-algorand-sdk.xcscheme
@@ -48,6 +48,20 @@
ReferencedContainer = "container:">
+
+
+
+
(for request: CustomRequest,
+ json: String? = nil,
with mock: CustomRequest.ResponseType,
file: StaticString = #filePath,
line: UInt = #line,
comparing compare: @escaping(CustomRequest.ResponseType?, CustomRequest.ResponseType?) -> Void)
where CustomRequest: swift_algorand_sdk.Request {
- MockURLProtocol.response(for: request, with: mock)
+ if let json = json,
+ let url = Bundle.module.url(forResource: json, withExtension: "json"),
+ let data = try? Data(contentsOf: url) {
+ MockURLProtocol.response(for: request, with: data)
+ } else {
+ MockURLProtocol.response(for: request, with: mock)
+ }
let expectation = XCTestExpectation(description: "Performing request for \(request.self)")
request.execute { response in
compare(response.data, mock)
@@ -26,11 +33,13 @@ extension XCTestCase {
wait(for: [expectation], timeout: 1)
}
func assertSuccessfulResponse(for request: CustomRequest,
+ json: String? = nil,
with mock: CustomRequest.ResponseType,
file: StaticString = #filePath,
line: UInt = #line)
where CustomRequest: swift_algorand_sdk.Request, CustomRequest.ResponseType: Equatable {
assertSuccessfulResponse(for: request,
+ json: json,
with: mock,
file: file,
line: line,
@@ -116,11 +125,19 @@ final class MockURLProtocol: URLProtocol {
with mock: CustomRequest.ResponseType)
where CustomRequest: swift_algorand_sdk.Request {
let encoder = JSONEncoder()
+ let data = try? encoder.encode(mock)
+ self.response(for: request, with: data)
+ }
+
+ static func response(for request: CustomRequest,
+ with data: Data?)
+ where CustomRequest: swift_algorand_sdk.Request {
+
MockURLProtocol.responseType = MockURLProtocol.ResponseType
.success(HTTPURLResponse(url: URL(string: "https://something.useless")!,
statusCode: 200,
httpVersion: nil, headerFields: nil)!,
- try? encoder.encode(mock))
+ data)
}
}
diff --git a/Tests/swift-algorand-sdkTests/mocks/algod/versions.json b/Tests/swift-algorand-sdkTests/mocks/algod/versions.json
new file mode 100644
index 0000000..89853d4
--- /dev/null
+++ b/Tests/swift-algorand-sdkTests/mocks/algod/versions.json
@@ -0,0 +1,16 @@
+{
+ "genesis_hash_b64": "123",
+ "genesis_id": "1234",
+ "versions": [
+ "1.0",
+ "2.0"
+ ],
+ "build": {
+ "branch": "theBranch",
+ "build_number": 123,
+ "channel": "theChannel",
+ "commit_hash": "theCommitHash",
+ "major": 123,
+ "minor": 123
+ }
+}