Skip to content
Snippets Groups Projects
Commit d18e9465 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add BroadcastReport model

parent 71ba6b7f
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!18Update Bindings
import Foundation
public struct BroadcastReport: Equatable {
public init(
roundId: Int,
ephId: [Int]
) {
self.roundId = roundId
self.ephId = ephId
}
public var roundId: Int
public var ephId: [Int]
}
extension BroadcastReport: Codable {
enum CodingKeys: String, CodingKey {
case roundId = "RoundID"
case ephId = "EphID"
}
public static func decode(_ data: Data) throws -> Self {
try JSONDecoder().decode(Self.self, from: data)
}
public func encode() throws -> Data {
try JSONEncoder().encode(self)
}
}
import CustomDump
import XCTest
@testable import ElixxirDAppsSDK
final class BroadcastReportTests: XCTestCase {
func testCoding() throws {
let roundId: Int = 42
let ephId: [Int] = [0, 0, 0, 0, 0, 0, 24, 61]
let jsonString = """
{
"RoundID": \(roundId),
"EphID": [\(ephId.map { "\($0)" }.joined(separator: ", "))]
}
"""
let jsonData = jsonString.data(using: .utf8)!
let report = try BroadcastReport.decode(jsonData)
XCTAssertNoDifference(report, BroadcastReport(
roundId: roundId,
ephId: ephId
))
let encodedReport = try report.encode()
let decodedReport = try BroadcastReport.decode(encodedReport)
XCTAssertNoDifference(decodedReport, report)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment