Skip to content

Commit 7576c8f

Browse files
committed
Split geewallet payments test into two tests
One test which also tests revoke_and_ack (but which fails), and one that doesn't test revoke_and_ack (but which passes).
1 parent 46e4e59 commit 7576c8f

File tree

1 file changed

+57
-22
lines changed

1 file changed

+57
-22
lines changed

tests/DotNetLightning.Infrastructure.Tests/ChannelOperationTests.fs

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,31 @@ type internal ActorCreator =
212212
return actors
213213
}
214214

215+
static member sendGeewalletPayment alice bob = async {
216+
let bobNodeId = bob.CM.KeysRepository.GetNodeSecret().PubKey |> NodeId
217+
let aliceNodeId = alice.CM.KeysRepository.GetNodeSecret().PubKey |> NodeId
218+
219+
do! Async.Sleep 1000
220+
Console.WriteLine("testing geewallet payment")
221+
222+
223+
let aliceToBobAmount = 1000L |> LNMoney.MilliSatoshis
224+
let geewalletPaymentCmd = {
225+
Amount = aliceToBobAmount
226+
}
227+
228+
// Send geewallet payment from alice to bob
229+
let bobAcceptedGeewalletPaymentTask =
230+
bob.EventAggregator.AwaitChannelEvent(function WeAcceptedGeewalletPayment _ -> Some () | _ -> None)
231+
do!
232+
alice.CM.AcceptCommandAsync({
233+
NodeId = bobNodeId
234+
ChannelCommand = ChannelCommand.GeewalletPayment geewalletPaymentCmd
235+
}).AsTask() |> Async.AwaitTask
236+
237+
let! r = bobAcceptedGeewalletPaymentTask
238+
Expect.isSome r "timeout waiting for bob to accept geewallet payment"
239+
}
215240

216241
[<Tests>]
217242
let tests =
@@ -348,7 +373,7 @@ let tests =
348373
349374
do! alice.CM.AcceptCommandAsync({ NodeId = bobNodeId; ChannelCommand = ChannelCommand.AddHTLC addHtlcCmd }).AsTask() |> Async.AwaitTask
350375
let! r = bobAcceptedAddHTLCTask
351-
Expect.isSome r "timeout"
376+
Expect.isSome r "timeout waiting for bob to accept htlc"
352377
353378
354379
do! Async.Sleep 1000
@@ -362,10 +387,12 @@ let tests =
362387
bob.EventAggregator.AwaitChannelEvent(function WeAcceptedCommitmentSigned (revokeAndAck, commitments) -> Some (revokeAndAck, commitments) | _ -> None)
363388
do! alice.CM.AcceptCommandAsync({ NodeId = bobNodeId; ChannelCommand = SignCommitment }).AsTask() |> Async.AwaitTask
364389
let! r = aliceAcceptedSign
365-
Expect.isSome r "timeout"
390+
Expect.isSome r "timeout waiting for alice to accept sign command"
366391
let! r = bobAcceptedSign
392+
Expect.isSome r "timeout waiting for bob to accept commitment signature"
367393
let revokeAndAck, bobCommitments = r.Value
368394
let! r = aliceAcceptedRevokeAndAck
395+
Expect.isSome r "timeout waiting for alice to accept revoke_and_ack"
369396
let aliceCommitments = r.Value
370397
371398
@@ -412,29 +439,36 @@ let tests =
412439
""
413440
*)
414441

415-
442+
do! ActorCreator.sendGeewalletPayment alice bob
416443

417444
do! Async.Sleep 1000
418-
Console.WriteLine("testing geewallet payment")
445+
Console.WriteLine("alice signs her commit")
419446

447+
let aliceAcceptedSign =
448+
alice.EventAggregator.AwaitChannelEvent(function WeAcceptedCMDSign (_, commitments) -> Some commitments | _ -> None)
449+
let bobAcceptedSign =
450+
bob.EventAggregator.AwaitChannelEvent(function WeAcceptedCommitmentSigned (revokeAndAck, commitments) -> Some (revokeAndAck, commitments) | _ -> None)
451+
do! alice.CM.AcceptCommandAsync({ NodeId = bobNodeId; ChannelCommand = SignCommitment }).AsTask() |> Async.AwaitTask
452+
let! r = aliceAcceptedSign
453+
Expect.isSome r "timeout waiting for alice to accept sign command"
454+
let! r = bobAcceptedSign
455+
Expect.isSome r "timeout waiting for bob to accept commitment signature"
420456

421-
let aliceToBobAmount = 1000L |> LNMoney.MilliSatoshis
422-
let geewalletPaymentCmd = {
423-
Amount = aliceToBobAmount
424-
}
457+
do! Async.Sleep 1000
458+
Console.WriteLine("finishing geewallet payment test")
459+
}
425460

426-
// Send geewallet payment from alice to bob
427-
let bobAcceptedGeewalletPaymentTask =
428-
bob.EventAggregator.AwaitChannelEvent(function WeAcceptedGeewalletPayment _ -> Some () | _ -> None)
429-
do!
430-
alice.CM.AcceptCommandAsync({
431-
NodeId = bobNodeId
432-
ChannelCommand = ChannelCommand.GeewalletPayment geewalletPaymentCmd
433-
}).AsTask() |> Async.AwaitTask
461+
ptestAsync "Send geewallet payment with revoke_and_ack" {
462+
do! Async.Sleep 1000
434463

435-
let! r = bobAcceptedGeewalletPaymentTask
436-
Expect.isSome r "timeout waiting for bob to accept geewallet payment"
464+
Console.WriteLine("starting geewallet payment test")
465+
let alice = ActorCreator.getAlice()
466+
let bob = ActorCreator.getBob()
467+
let! actors = ActorCreator.initiateOpenedChannel(alice, bob)
468+
let bobNodeId = bob.CM.KeysRepository.GetNodeSecret().PubKey |> NodeId
469+
let aliceNodeId = alice.CM.KeysRepository.GetNodeSecret().PubKey |> NodeId
437470

471+
do! ActorCreator.sendGeewalletPayment alice bob
438472

439473
do! Async.Sleep 1000
440474
Console.WriteLine("alice signs her commit")
@@ -447,18 +481,19 @@ let tests =
447481
bob.EventAggregator.AwaitChannelEvent(function WeAcceptedCommitmentSigned (revokeAndAck, commitments) -> Some (revokeAndAck, commitments) | _ -> None)
448482
do! alice.CM.AcceptCommandAsync({ NodeId = bobNodeId; ChannelCommand = SignCommitment }).AsTask() |> Async.AwaitTask
449483
let! r = aliceAcceptedSign
450-
Expect.isSome r "timeout"
484+
Expect.isSome r "timeout waiting for alice to accept sign command"
451485
let! r = bobAcceptedSign
486+
Expect.isSome r "timeout waiting for bob to accept commitment signature"
452487
let revokeAndAck, bobCommitments = r.Value
488+
Expect.isSome r "timeout waiting for alice to accept revoke_and_ack"
453489
let! r = aliceAcceptedRevokeAndAck
454490
let aliceCommitments = r.Value
455491

456-
457492
do! Async.Sleep 1000
458493
Console.WriteLine(sprintf "alice now has: %s sat" (aliceCommitments.LocalCommit.Spec.ToLocal.ToString()))
459-
Console.WriteLine("finishing geewallet payment test")
494+
Console.WriteLine("finishing geewallet payment with revoke_and_ack test")
460495
}
461-
496+
462497
ptestAsync "Normal channel operation" {
463498
let alice = ActorCreator.getAlice()
464499
let bob = ActorCreator.getBob()

0 commit comments

Comments
 (0)