@@ -12,34 +12,34 @@ import LDKHeaders
1212import XCTest
1313
1414public class HumanObjectPeerTestInstance {
15-
15+
1616 private let configuration : Configuration
17-
17+
1818 public class Configuration {
1919//
2020 public var useFilter : Bool = false ;
2121 public var useRouter : Bool = false ;
2222 public var shouldRecipientRejectPayment : Bool = false ;
23-
23+
2424 // public var nice_close: Bool = false;
2525 // public var use_km_wrapper: Bool = false;
2626 // public var use_manual_watch: Bool = false;
2727 // public var reload_peers: Bool = false;
2828 // public var break_cross_peer_refs: Bool = false;
2929 // public var use_nio_peer_handler: Bool = false;
30-
30+
3131 private class func listCustomizeableProperties( ) -> [ String ] {
3232 return [ " useFilter " , " useRouter " , " shouldRecipientRejectPayment " ]
3333 }
34-
34+
3535 public class func combinationCount( ) -> UInt {
3636 return 1 << self . listCustomizeableProperties ( ) . count
3737 }
38-
38+
3939 }
40-
41-
42-
40+
41+
42+
4343 public init ( configuration: Configuration ) {
4444 self . configuration = configuration
4545 }
@@ -54,8 +54,7 @@ public class HumanObjectPeerTestInstance {
5454 var filterAdditions : Set < String >
5555 let monitors : [ String : ChannelMonitor ]
5656 private( set) var filter : Filter ?
57- private( set) var keysInterface : KeysInterface !
58- private( set) var explicitKeysManager : KeysManager ?
57+ private( set) var explicitKeysManager : KeysManager !
5958 private( set) var router : GossipSync !
6059 private( set) var channelManager : ChannelManager !
6160 private( set) var peerManager : PeerManager !
@@ -196,18 +195,18 @@ public class HumanObjectPeerTestInstance {
196195 }
197196 }
198197
199- fileprivate class TestKeysInterface : KeysInterface {
198+ fileprivate class TestKeysInterface : SignerProvider {
200199
201200 weak var master : Peer !
202- let interface : KeysInterface
201+ let interface : SignerProvider
203202
204- fileprivate init ( master: Peer , underlyingInterface: KeysInterface ) {
203+ fileprivate init ( master: Peer , underlyingInterface: SignerProvider ) {
205204 self . master = master
206205 self . interface = underlyingInterface
207206 super. init ( )
208207 }
209-
210- override func deriveChannelSigner( channelValueSatoshis: UInt64 , channelKeysId: [ UInt8 ] ) -> Bindings . Sign {
208+
209+ override func deriveChannelSigner( channelValueSatoshis: UInt64 , channelKeysId: [ UInt8 ] ) -> Bindings . WriteableEcdsaChannelSigner {
211210 let ck = self . interface. deriveChannelSigner ( channelValueSatoshis: channelValueSatoshis, channelKeysId: channelKeysId)
212211 return ck
213212 }
@@ -230,17 +229,18 @@ public class HumanObjectPeerTestInstance {
230229 await master. pendingEventTracker. addEvent ( event: event)
231230 }
232231 }
233-
232+
234233 override func persistManager( channelManager: Bindings . ChannelManager ) -> Bindings . Result_NoneErrorZ {
235234 . initWithOk( )
236235 }
237-
236+
238237 override func persistScorer( scorer: Bindings . WriteableScore ) -> Bindings . Result_NoneErrorZ {
239238 . initWithOk( )
240239 }
241-
240+
242241 override func persistGraph( networkGraph: Bindings . NetworkGraph ) -> Bindings . Result_NoneErrorZ {
243- . initWithOk( )
242+ let writtenGraph = networkGraph. write ( ) ;
243+ return Result_NoneErrorZ . initWithOk ( )
244244 }
245245
246246 }
@@ -284,13 +284,11 @@ public class HumanObjectPeerTestInstance {
284284 let timestamp_seconds = UInt64 ( NSDate ( ) . timeIntervalSince1970)
285285 let timestamp_nanos = UInt32 ( truncating: NSNumber ( value: timestamp_seconds * 1000 * 1000 ) )
286286 let keysManager = KeysManager ( seed: keySeed, startingTimeSecs: timestamp_seconds, startingTimeNanos: timestamp_nanos)
287-
288- self . keysInterface = keysManager. asKeysInterface ( )
289287 self . explicitKeysManager = keysManager
290288
291289 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) )
294292 } else {
295293 self . router = GossipSync . none ( )
296294 }
@@ -302,16 +300,27 @@ public class HumanObjectPeerTestInstance {
302300 do {
303301 // channel manager constructor is mandatory
304302
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)
308304
309305 let scoringParams = ProbabilisticScoringParameters . initWithDefault ( )
310306 let probabalisticScorer = ProbabilisticScorer ( params: scoringParams, networkGraph: graph, logger: self . logger)
311307 let score = probabalisticScorer. asScore ( )
312308 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 ) )
315324 self . channelManager = self . constructor!. channelManager
316325 self . peerManager = self . constructor!. peerManager
317326 }
@@ -324,9 +333,20 @@ public class HumanObjectPeerTestInstance {
324333
325334 do {
326335 // 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 ) )
330350 self . channelManager = self . constructor!. channelManager
331351 Task {
332352 let events = await original. pendingEventTracker. getEvents ( )
@@ -400,7 +420,7 @@ public class HumanObjectPeerTestInstance {
400420 let blockHeader = block. calculateHeader ( )
401421 self . channelManager. asConfirm ( ) . transactionsConfirmed ( header: blockHeader, txdata: transactionTuples, height: height)
402422 self . channelManager. asConfirm ( ) . bestBlockUpdated ( header: blockHeader, height: height)
403-
423+
404424 for (_, monitor) in self . monitors {
405425 let connectionResult = monitor. blockConnected ( header: blockHeader, txdata: transactionTuples, height: height, broadcaster: self . txBroadcaster, feeEstimator: self . feeEstimator, logger: self . logger)
406426 XCTAssertEqual ( connectionResult. count, expectedMonitorUpdateLength)
@@ -422,10 +442,10 @@ public class HumanObjectPeerTestInstance {
422442
423443
424444 fileprivate func connectPeers( peerA: Peer , peerB: Peer ) {
425-
445+
426446 let connectionResult = peerA. tcpSocketHandler? . connect ( address: " 127.0.0.1 " , port: peerB. tcpPort!, theirNodeId: peerB. nodeId!)
427447 print ( " connection result: \( connectionResult) " )
428-
448+
429449 }
430450
431451 func test_multiple_peer_connections( ) async {
@@ -619,22 +639,25 @@ public class HumanObjectPeerTestInstance {
619639 let originalChannelBalanceBToA = channelBToA. getBalanceMsat ( )
620640 print ( " original balance A->B mSats: \( originalChannelBalanceAToB) " )
621641 print ( " original balance B->A mSats: \( originalChannelBalanceBToA) " )
622-
642+
623643 let logger = TestLogger ( )
624644
625645 do {
626646 // create invoice for 10k satoshis to pay to peer2
627647
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+ }
629653 let invoice = invoiceResult. getValue ( ) !
630654 print ( " Invoice: \( invoice. toStr ( ) ) " )
631655
632656 let recreatedInvoice = Invoice . fromStr ( s: invoice. toStr ( ) )
633657 XCTAssertTrue ( recreatedInvoice. isOk ( ) )
634658
635659 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)
638661 XCTAssertTrue ( invoicePaymentResult. isOk ( ) )
639662
640663 do {
@@ -693,13 +716,14 @@ public class HumanObjectPeerTestInstance {
693716 " payment_failed_permanently " : paymentPathFailed. getPaymentFailedPermanently ( ) ,
694717 " short_channel_id " : paymentPathFailed. getShortChannelId ( ) ,
695718 " path " : paymentPathFailed. getPath ( ) . map { $0. getShortChannelId ( ) } ,
696- " network_update " : paymentPathFailed. getNetworkUpdate ( ) . debugDescription
719+ " retry " : paymentPathFailed. getRetry ( ) ,
720+ " failure " : paymentPathFailed. getFailure ( )
697721 ]
698-
722+
699723 print ( " payent path failure: \( failureDescriptor) " )
700724 print ( " here " )
701725 return
702-
726+
703727 } else {
704728 // process payment
705729 let peer1Events = try ! await peer1. getManagerEvents ( expectedCount: 2 )
@@ -743,19 +767,19 @@ public class HumanObjectPeerTestInstance {
743767 print ( " pre-payment balance A->B mSats: \( prePaymentBalanceAToB) " )
744768 print ( " pre-payment balance B->A mSats: \( prePaymentBalanceBToA) " )
745769
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 )
747771 let invoice = invoiceResult. getValue ( ) !
748772 print ( " Implicit amount invoice: \( invoice. toStr ( ) ) " )
749773
750774 let invoiceString = invoice. toStr ( )
751775 let recreatedInvoice = Invoice . fromStr ( s: invoiceString)
752776 XCTAssertTrue ( recreatedInvoice. isOk ( ) )
753777
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 )
755779 if let error = invoicePaymentResult. getError ( ) {
756780 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) " )
759783 }
760784 }
761785 XCTAssertTrue ( invoicePaymentResult. isOk ( ) )
0 commit comments