2 // LDKExperimentTest.swift
5 // Created by Arik Sosman on 7/27/21.
9 @testable import LDKCHeaders
10 @testable import LDKSwift
12 class LDKExperimentTest: XCTestCase {
14 override func setUpWithError() throws {
15 // Put setup code here. This method is called before the invocation of each test method in the class.
18 override func tearDownWithError() throws {
19 // Put teardown code here. This method is called after the invocation of each test method in the class.
22 func testExample() throws {
23 // This is an example of a functional test case.
24 // Use XCTAssert and related functions to verify your tests produce the correct results.
27 func testVersionSanity() throws {
28 check_get_ldk_version()
29 check_get_ldk_bindings_version()
33 func testExtendedActivity() {
34 // for i in 0...(1 << 7) {
35 for i in 0..<1 { // only do one test run initially
36 let nice_close = (i & (1 << 0)) != 0;
37 let use_km_wrapper = (i & (1 << 1)) != 0;
38 let use_manual_watch = (i & (1 << 2)) != 0;
39 let reload_peers = (i & (1 << 3)) != 0;
40 let break_cross_refs = (i & (1 << 4)) != 0;
41 let nio_peer_handler = true // (i & (1 << 5)) != 0;
42 let use_chan_manager_constructor = true // (i & (1 << 6)) != 0;
44 if (break_cross_refs && !reload_peers) {
45 // There are no cross refs to break without reloading peers.
49 if (use_chan_manager_constructor && (use_manual_watch || !nio_peer_handler)) {
50 // ChannelManagerConstructor requires a ChainMonitor as the Watch and creates a NioPeerHandler for us.
54 print("Running test with flags \(i)");
55 try? SimulationRunner.do_test(nice_close: nice_close, use_km_wrapper: use_km_wrapper, use_manual_watch: use_manual_watch, reload_peers: reload_peers, break_cross_peer_refs: break_cross_refs, nio_peer_handler: nio_peer_handler, use_chan_manager_constructor: use_chan_manager_constructor)
58 // avoid early termination
60 print("Press enter to stop running test.")
61 let keyboard = FileHandle.standardInput
62 let inputData = keyboard.availableData
63 let strData = String(data: inputData, encoding: String.Encoding.utf8)!
68 fileprivate class SimulationRunner {
70 class func do_test(nice_close: Bool, use_km_wrapper: Bool, use_manual_watch: Bool, reload_peers: Bool, break_cross_peer_refs: Bool, nio_peer_handler: Bool, use_chan_manager_constructor: Bool) throws {
72 let instance = do_test_run(nice_close: nice_close, use_km_wrapper: use_km_wrapper, use_manual_watch: use_manual_watch, reload_peers: reload_peers, break_cross_peer_refs: break_cross_peer_refs, nio_peer_handler: nio_peer_handler, use_chan_manager_constructor: use_chan_manager_constructor)
76 class func do_test_run(nice_close: Bool, use_km_wrapper: Bool, use_manual_watch: Bool, reload_peers: Bool, break_cross_peer_refs: Bool, nio_peer_handler: Bool, use_chan_manager_constructor: Bool) -> HumanObjectPeerTestInstance {
78 let instance = HumanObjectPeerTestInstance(nice_close: nice_close, use_km_wrapper: use_km_wrapper, use_manual_watch: use_manual_watch, reload_peers: reload_peers, break_cross_peer_refs: break_cross_peer_refs, use_nio_peer_handler: nio_peer_handler, use_filter: !nio_peer_handler, use_chan_manager_constructor: use_chan_manager_constructor)
80 instance.do_test_message_handler()
88 func testPerformanceExample() throws {
89 // This is an example of a performance test case.
91 // Put the code you want to measure the time of here.