Skip to content

Commit 06c4337

Browse files
committed
Expand unit tests to cover complex struct array parameters.
1 parent 5b0b427 commit 06c4337

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

ci/LDKSwift/Tests/LDKSwiftTests/LDKSwiftTest.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class LDKSwiftTest: XCTestCase {
7070
let channel_manager = channel_manager_constructor.channelManager;
7171
let cmPersister = TestChannelManagerPersister(channelManager: channel_manager)
7272

73+
let txdata = [C2Tuple_usizeTransactionZ.new(a: 2, b: Self.hexStringToBytes(hexString: "020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff03530101ffffffff0200f2052a0100000017a9149e6d815a46cd349527961f58cc20d41d15fcb99e870000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000")!)]
74+
let header = Self.hexStringToBytes(hexString: "f5591ea0b69ae3edc0de11497ffb0fdd91f769ede96c5d662c805364e9bf8b2243e8e5b9d1833eff7cb19abd9fc9da3cd26fe84d718bbf8a336966ae4f7dea6a81372961ffff7f200400000001020000")
75+
channel_manager.as_Confirm().transactions_confirmed(header: header, txdata: txdata, height: 525)
76+
7377
channel_manager_constructor.chain_sync_completed(persister: cmPersister)
7478
channel_manager_constructor.interrupt()
7579
}
@@ -133,4 +137,28 @@ class LDKSwiftTest: XCTestCase {
133137
Bindings.setLogThreshold(severity: .DEBUG)
134138
}
135139

140+
private class func hexStringToBytes(hexString: String) -> [UInt8]? {
141+
let hexStr = hexString.dropFirst(hexString.hasPrefix("0x") ? 2 : 0)
142+
143+
guard hexStr.count % 2 == 0 else { return nil }
144+
145+
var newData = [UInt8]()
146+
147+
var indexIsEven = true
148+
for i in hexStr.indices {
149+
if indexIsEven {
150+
let byteRange = i...hexStr.index(after: i)
151+
guard let byte = UInt8(hexStr[byteRange], radix: 16) else { return nil }
152+
newData.append(byte)
153+
}
154+
indexIsEven.toggle()
155+
}
156+
return newData
157+
}
158+
159+
private class func bytesToHexString(bytes: [UInt8]) -> String {
160+
let format = "%02hhx" // "%02hhX" (uppercase)
161+
return bytes.map { String(format: format, $0) }.joined()
162+
}
163+
136164
}

0 commit comments

Comments
 (0)