@@ -12,34 +12,34 @@ import LDKHeaders
12
12
import XCTest
13
13
14
14
public class HumanObjectPeerTestInstance {
15
-
15
+
16
16
private let configuration : Configuration
17
-
17
+
18
18
public class Configuration {
19
19
//
20
20
public var useFilter : Bool = false ;
21
21
public var useRouter : Bool = false ;
22
22
public var shouldRecipientRejectPayment : Bool = false ;
23
-
23
+
24
24
// public var nice_close: Bool = false;
25
25
// public var use_km_wrapper: Bool = false;
26
26
// public var use_manual_watch: Bool = false;
27
27
// public var reload_peers: Bool = false;
28
28
// public var break_cross_peer_refs: Bool = false;
29
29
// public var use_nio_peer_handler: Bool = false;
30
-
30
+
31
31
private class func listCustomizeableProperties( ) -> [ String ] {
32
32
return [ " useFilter " , " useRouter " , " shouldRecipientRejectPayment " ]
33
33
}
34
-
34
+
35
35
public class func combinationCount( ) -> UInt {
36
36
return 1 << self . listCustomizeableProperties ( ) . count
37
37
}
38
-
38
+
39
39
}
40
-
41
-
42
-
40
+
41
+
42
+
43
43
public init ( configuration: Configuration ) {
44
44
self . configuration = configuration
45
45
}
@@ -54,8 +54,7 @@ public class HumanObjectPeerTestInstance {
54
54
var filterAdditions : Set < String >
55
55
let monitors : [ String : ChannelMonitor ]
56
56
private( set) var filter : Filter ?
57
- private( set) var keysInterface : KeysInterface !
58
- private( set) var explicitKeysManager : KeysManager ?
57
+ private( set) var explicitKeysManager : KeysManager !
59
58
private( set) var router : GossipSync !
60
59
private( set) var channelManager : ChannelManager !
61
60
private( set) var peerManager : PeerManager !
@@ -196,18 +195,18 @@ public class HumanObjectPeerTestInstance {
196
195
}
197
196
}
198
197
199
- fileprivate class TestKeysInterface : KeysInterface {
198
+ fileprivate class TestKeysInterface : SignerProvider {
200
199
201
200
weak var master : Peer !
202
- let interface : KeysInterface
201
+ let interface : SignerProvider
203
202
204
- fileprivate init ( master: Peer , underlyingInterface: KeysInterface ) {
203
+ fileprivate init ( master: Peer , underlyingInterface: SignerProvider ) {
205
204
self . master = master
206
205
self . interface = underlyingInterface
207
206
super. init ( )
208
207
}
209
-
210
- override func deriveChannelSigner( channelValueSatoshis: UInt64 , channelKeysId: [ UInt8 ] ) -> Bindings . Sign {
208
+
209
+ override func deriveChannelSigner( channelValueSatoshis: UInt64 , channelKeysId: [ UInt8 ] ) -> Bindings . WriteableEcdsaChannelSigner {
211
210
let ck = self . interface. deriveChannelSigner ( channelValueSatoshis: channelValueSatoshis, channelKeysId: channelKeysId)
212
211
return ck
213
212
}
@@ -230,17 +229,18 @@ public class HumanObjectPeerTestInstance {
230
229
await master. pendingEventTracker. addEvent ( event: event)
231
230
}
232
231
}
233
-
232
+
234
233
override func persistManager( channelManager: Bindings . ChannelManager ) -> Bindings . Result_NoneErrorZ {
235
234
. initWithOk( )
236
235
}
237
-
236
+
238
237
override func persistScorer( scorer: Bindings . WriteableScore ) -> Bindings . Result_NoneErrorZ {
239
238
. initWithOk( )
240
239
}
241
-
240
+
242
241
override func persistGraph( networkGraph: Bindings . NetworkGraph ) -> Bindings . Result_NoneErrorZ {
243
- . initWithOk( )
242
+ let writtenGraph = networkGraph. write ( ) ;
243
+ return Result_NoneErrorZ . initWithOk ( )
244
244
}
245
245
246
246
}
@@ -284,13 +284,11 @@ public class HumanObjectPeerTestInstance {
284
284
let timestamp_seconds = UInt64 ( NSDate ( ) . timeIntervalSince1970)
285
285
let timestamp_nanos = UInt32 ( truncating: NSNumber ( value: timestamp_seconds * 1000 * 1000 ) )
286
286
let keysManager = KeysManager ( seed: keySeed, startingTimeSecs: timestamp_seconds, startingTimeNanos: timestamp_nanos)
287
-
288
- self . keysInterface = keysManager. asKeysInterface ( )
289
287
self . explicitKeysManager = keysManager
290
288
291
289
if master. configuration. useRouter {
292
- let networkGraph = NetworkGraph ( genesisHash : [ UInt8 ] ( repeating : 0 , count : 32 ) , logger: self . logger)
293
- self . router = GossipSync . initWithP2P ( a: P2PGossipSync ( networkGraph: networkGraph, chainAccess : nil , logger: self . logger) )
290
+ let networkGraph = NetworkGraph ( network : . Regtest , logger: self . logger)
291
+ self . router = GossipSync . initWithP2P ( a: P2PGossipSync ( networkGraph: networkGraph, utxoLookup : nil , logger: self . logger) )
294
292
} else {
295
293
self . router = GossipSync . none ( )
296
294
}
@@ -302,16 +300,27 @@ public class HumanObjectPeerTestInstance {
302
300
do {
303
301
// channel manager constructor is mandatory
304
302
305
- let graph = NetworkGraph ( genesisHash: [ UInt8] ( repeating: 0 , count: 32 ) , logger: self . logger)
306
-
307
- self . constructor = ChannelManagerConstructor ( network: . Bitcoin, userConfig: UserConfig . initWithDefault ( ) , currentBlockchainTipHash: [ UInt8] ( repeating: 0 , count: 32 ) , currentBlockchainTipHeight: 0 , keysInterface: self . keysInterface, feeEstimator: self . feeEstimator, chainMonitor: self . chainMonitor!, netGraph: graph, txBroadcaster: self . txBroadcaster, logger: self . logger)
303
+ let graph = NetworkGraph ( network: . Regtest, logger: self . logger)
308
304
309
305
let scoringParams = ProbabilisticScoringParameters . initWithDefault ( )
310
306
let probabalisticScorer = ProbabilisticScorer ( params: scoringParams, networkGraph: graph, logger: self . logger)
311
307
let score = probabalisticScorer. asScore ( )
312
308
let multiThreadedScorer = MultiThreadedLockableScore ( score: score)
313
-
314
- self . constructor? . chainSyncCompleted ( persister: TestChannelManagerPersister ( master: self ) , scorer: multiThreadedScorer)
309
+
310
+ let constructionParameters = ChannelManagerConstructionParameters (
311
+ config: UserConfig . initWithDefault ( ) ,
312
+ entropySource: self . explicitKeysManager. asEntropySource ( ) ,
313
+ nodeSigner: self . explicitKeysManager. asNodeSigner ( ) ,
314
+ signerProvider: self . explicitKeysManager. asSignerProvider ( ) ,
315
+ feeEstimator: self . feeEstimator,
316
+ chainMonitor: self . chainMonitor!,
317
+ txBroadcaster: self . txBroadcaster,
318
+ logger: self . logger,
319
+ scorer: multiThreadedScorer
320
+ )
321
+ self . constructor = ChannelManagerConstructor ( network: . Bitcoin, currentBlockchainTipHash: [ UInt8] ( repeating: 0 , count: 32 ) , currentBlockchainTipHeight: 0 , netGraph: graph, params: constructionParameters)
322
+
323
+ self . constructor? . chainSyncCompleted ( persister: TestChannelManagerPersister ( master: self ) )
315
324
self . channelManager = self . constructor!. channelManager
316
325
self . peerManager = self . constructor!. peerManager
317
326
}
@@ -324,9 +333,20 @@ public class HumanObjectPeerTestInstance {
324
333
325
334
do {
326
335
// channel manager constructor is mandatory
327
- let graph = NetworkGraph ( genesisHash: [ UInt8] ( repeating: 0 , count: 32 ) , logger: self . logger)
328
- self . constructor = ChannelManagerConstructor ( network: . Bitcoin, userConfig: UserConfig . initWithDefault ( ) , currentBlockchainTipHash: [ UInt8] ( repeating: 0 , count: 32 ) , currentBlockchainTipHeight: 0 , keysInterface: self . keysInterface, feeEstimator: self . feeEstimator, chainMonitor: self . chainMonitor!, netGraph: graph, txBroadcaster: self . txBroadcaster, logger: self . logger)
329
- self . constructor? . chainSyncCompleted ( persister: TestChannelManagerPersister ( master: self ) , scorer: nil )
336
+ let graph = NetworkGraph ( network: . Bitcoin, logger: self . logger)
337
+
338
+ let constructionParameters = ChannelManagerConstructionParameters (
339
+ config: UserConfig . initWithDefault ( ) ,
340
+ entropySource: self . explicitKeysManager. asEntropySource ( ) ,
341
+ nodeSigner: self . explicitKeysManager. asNodeSigner ( ) ,
342
+ signerProvider: self . explicitKeysManager. asSignerProvider ( ) ,
343
+ feeEstimator: self . feeEstimator,
344
+ chainMonitor: self . chainMonitor!,
345
+ txBroadcaster: self . txBroadcaster,
346
+ logger: self . logger
347
+ )
348
+ self . constructor = ChannelManagerConstructor ( network: . Bitcoin, currentBlockchainTipHash: [ UInt8] ( repeating: 0 , count: 32 ) , currentBlockchainTipHeight: 0 , netGraph: graph, params: constructionParameters)
349
+ self . constructor? . chainSyncCompleted ( persister: TestChannelManagerPersister ( master: self ) )
330
350
self . channelManager = self . constructor!. channelManager
331
351
Task {
332
352
let events = await original. pendingEventTracker. getEvents ( )
@@ -400,7 +420,7 @@ public class HumanObjectPeerTestInstance {
400
420
let blockHeader = block. calculateHeader ( )
401
421
self . channelManager. asConfirm ( ) . transactionsConfirmed ( header: blockHeader, txdata: transactionTuples, height: height)
402
422
self . channelManager. asConfirm ( ) . bestBlockUpdated ( header: blockHeader, height: height)
403
-
423
+
404
424
for (_, monitor) in self . monitors {
405
425
let connectionResult = monitor. blockConnected ( header: blockHeader, txdata: transactionTuples, height: height, broadcaster: self . txBroadcaster, feeEstimator: self . feeEstimator, logger: self . logger)
406
426
XCTAssertEqual ( connectionResult. count, expectedMonitorUpdateLength)
@@ -422,10 +442,10 @@ public class HumanObjectPeerTestInstance {
422
442
423
443
424
444
fileprivate func connectPeers( peerA: Peer , peerB: Peer ) {
425
-
445
+
426
446
let connectionResult = peerA. tcpSocketHandler? . connect ( address: " 127.0.0.1 " , port: peerB. tcpPort!, theirNodeId: peerB. nodeId!)
427
447
print ( " connection result: \( connectionResult) " )
428
-
448
+
429
449
}
430
450
431
451
func test_multiple_peer_connections( ) async {
@@ -619,22 +639,25 @@ public class HumanObjectPeerTestInstance {
619
639
let originalChannelBalanceBToA = channelBToA. getBalanceMsat ( )
620
640
print ( " original balance A->B mSats: \( originalChannelBalanceAToB) " )
621
641
print ( " original balance B->A mSats: \( originalChannelBalanceBToA) " )
622
-
642
+
623
643
let logger = TestLogger ( )
624
644
625
645
do {
626
646
// create invoice for 10k satoshis to pay to peer2
627
647
628
- let invoiceResult = Bindings . swiftCreateInvoiceFromChannelmanager ( channelmanager: peer2. channelManager, keysManager: peer2. keysInterface, logger: logger, network: . Bitcoin, amtMsat: SEND_MSAT_AMOUNT_A_TO_B, description: " Invoice description " , invoiceExpiryDeltaSecs: 60 )
648
+ let invoiceResult = Bindings . createInvoiceFromChannelmanager ( channelmanager: peer2. channelManager, nodeSigner: peer2. explicitKeysManager. asNodeSigner ( ) , logger: logger, network: . Bitcoin, amtMsat: SEND_MSAT_AMOUNT_A_TO_B, description: " Invoice description " , invoiceExpiryDeltaSecs: 60 , minFinalCltvExpiryDelta: 24 )
649
+ if let invoiceError = invoiceResult. getError ( ) {
650
+ let creationError = invoiceError. getValueAsCreationError ( )
651
+ print ( " creation error: \( creationError) " )
652
+ }
629
653
let invoice = invoiceResult. getValue ( ) !
630
654
print ( " Invoice: \( invoice. toStr ( ) ) " )
631
655
632
656
let recreatedInvoice = Invoice . fromStr ( s: invoice. toStr ( ) )
633
657
XCTAssertTrue ( recreatedInvoice. isOk ( ) )
634
658
635
659
let channelManagerConstructor = peer1. constructor!
636
- let invoicePayer = channelManagerConstructor. payer!
637
- let invoicePaymentResult = invoicePayer. payInvoice ( invoice: invoice)
660
+ let invoicePaymentResult = Bindings . payInvoice ( invoice: invoice, retryStrategy: Bindings . Retry. initWithAttempts ( a: 3 ) , channelmanager: channelManagerConstructor. channelManager)
638
661
XCTAssertTrue ( invoicePaymentResult. isOk ( ) )
639
662
640
663
do {
@@ -693,13 +716,14 @@ public class HumanObjectPeerTestInstance {
693
716
" payment_failed_permanently " : paymentPathFailed. getPaymentFailedPermanently ( ) ,
694
717
" short_channel_id " : paymentPathFailed. getShortChannelId ( ) ,
695
718
" path " : paymentPathFailed. getPath ( ) . map { $0. getShortChannelId ( ) } ,
696
- " network_update " : paymentPathFailed. getNetworkUpdate ( ) . debugDescription
719
+ " retry " : paymentPathFailed. getRetry ( ) ,
720
+ " failure " : paymentPathFailed. getFailure ( )
697
721
]
698
-
722
+
699
723
print ( " payent path failure: \( failureDescriptor) " )
700
724
print ( " here " )
701
725
return
702
-
726
+
703
727
} else {
704
728
// process payment
705
729
let peer1Events = try ! await peer1. getManagerEvents ( expectedCount: 2 )
@@ -743,19 +767,19 @@ public class HumanObjectPeerTestInstance {
743
767
print ( " pre-payment balance A->B mSats: \( prePaymentBalanceAToB) " )
744
768
print ( " pre-payment balance B->A mSats: \( prePaymentBalanceBToA) " )
745
769
746
- let invoiceResult = Bindings . swiftCreateInvoiceFromChannelmanager ( channelmanager: peer1. channelManager, keysManager : peer1. keysInterface , logger: logger, network: . Bitcoin, amtMsat: nil , description: " Second invoice description " , invoiceExpiryDeltaSecs: 60 )
770
+ let invoiceResult = Bindings . createInvoiceFromChannelmanager ( channelmanager: peer1. channelManager, nodeSigner : peer1. explicitKeysManager . asNodeSigner ( ) , logger: logger, network: . Bitcoin, amtMsat: nil , description: " Second invoice description " , invoiceExpiryDeltaSecs: 60 , minFinalCltvExpiryDelta : 24 )
747
771
let invoice = invoiceResult. getValue ( ) !
748
772
print ( " Implicit amount invoice: \( invoice. toStr ( ) ) " )
749
773
750
774
let invoiceString = invoice. toStr ( )
751
775
let recreatedInvoice = Invoice . fromStr ( s: invoiceString)
752
776
XCTAssertTrue ( recreatedInvoice. isOk ( ) )
753
777
754
- let invoicePaymentResult = peer2 . constructor! . payer! . payZeroValueInvoice ( invoice: invoice, amountMsats: SEND_MSAT_AMOUNT_B_TO_A)
778
+ let invoicePaymentResult = Bindings . payZeroValueInvoice ( invoice: invoice, amountMsats: SEND_MSAT_AMOUNT_B_TO_A, retryStrategy : Retry . initWithAttempts ( a : 3 ) , channelmanager : peer2 . channelManager )
755
779
if let error = invoicePaymentResult. getError ( ) {
756
780
print ( " value type: \( error. getValueType ( ) ) " )
757
- if let routingError = error. getValueAsRouting ( ) {
758
- print ( " routing error: \( routingError. getErr ( ) ) " )
781
+ if let routingError = error. getValueAsSending ( ) {
782
+ print ( " sending error: \( routingError) " )
759
783
}
760
784
}
761
785
XCTAssertTrue ( invoicePaymentResult. isOk ( ) )
0 commit comments