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

Add ChannelDef model

parent d18e9465
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!18Update Bindings
import Foundation
public struct ChannelDef: Equatable {
public init(
name: String,
description: String,
salt: Data,
pubKey: Data
) {
self.name = name
self.description = description
self.salt = salt
self.pubKey = pubKey
}
public var name: String
public var description: String
public var salt: Data
public var pubKey: Data
}
extension ChannelDef: Codable {
enum CodingKeys: String, CodingKey {
case name = "Name"
case description = "Description"
case salt = "Salt"
case pubKey = "PubKey"
}
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 ChannelDefTests: XCTestCase {
func testCoding() throws {
let name = "My broadcast channel"
let description = "A broadcast channel for me to test things"
let saltB64 = "gpUqW7N22sffMXsvPLE7BA=="
let pubKeyB64 = "LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1DZ0NJUUN2YkZVckJKRFpqT3Y0Y0MvUHZZdXNvQkFtUTFkb3Znb044aHRuUjA2T3F3SURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0="
let jsonString = """
{
"Name": "\(name)",
"Description": "\(description)",
"Salt": "\(saltB64)",
"PubKey": "\(pubKeyB64)"
}
"""
let jsonData = jsonString.data(using: .utf8)!
let model = try ChannelDef.decode(jsonData)
XCTAssertNoDifference(model, ChannelDef(
name: name,
description: description,
salt: Data(base64Encoded: saltB64)!,
pubKey: Data(base64Encoded: pubKeyB64)!
))
let encodedModel = try model.encode()
let decodedModel = try ChannelDef.decode(encodedModel)
XCTAssertNoDifference(decodedModel, model)
}
}
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