Initial checkin
[ldk-swift-linux] / LDKSwift / Tests / LDKSwiftTests / LDKExperimentTest.swift
1 //
2 //  LDKExperimentTest.swift
3 //  LDKExperimentTest
4 //
5 //  Created by Arik Sosman on 7/27/21.
6 //
7
8 import XCTest
9 @testable import LDKCHeaders
10 @testable import LDKSwift
11
12 class LDKExperimentTest: XCTestCase {
13
14     override func setUpWithError() throws {
15         // Put setup code here. This method is called before the invocation of each test method in the class.
16     }
17
18     override func tearDownWithError() throws {
19         // Put teardown code here. This method is called after the invocation of each test method in the class.
20     }
21
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.
25     }
26     
27     func testVersionSanity() throws {
28         check_get_ldk_version()
29         check_get_ldk_bindings_version()
30         check_platform()
31     }
32     
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;
43             
44             if (break_cross_refs && !reload_peers) {
45                 // There are no cross refs to break without reloading peers.
46                 continue;
47             }
48             
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.
51                 continue;
52             }
53             
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)
56         }
57         
58         // avoid early termination
59         /*
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)!
64         */
65         
66     }
67     
68     fileprivate class SimulationRunner {
69         
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 {
71             
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)
73             
74         }
75         
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 {
77             
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)
79             
80             instance.do_test_message_handler()
81             return instance
82         }
83         
84     }
85     
86     
87
88     func testPerformanceExample() throws {
89         // This is an example of a performance test case.
90         measure {
91             // Put the code you want to measure the time of here.
92         }
93     }
94     
95     
96
97 }