Skip to content

Commit

Permalink
Split geewallet payments test into two tests
Browse files Browse the repository at this point in the history
One test which also tests revoke_and_ack (but which fails), and one that
doesn't test revoke_and_ack (but which passes).
  • Loading branch information
canndrew committed Mar 12, 2020
1 parent 46e4e59 commit 7576c8f
Showing 1 changed file with 57 additions and 22 deletions.
79 changes: 57 additions & 22 deletions tests/DotNetLightning.Infrastructure.Tests/ChannelOperationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,31 @@ type internal ActorCreator =
return actors
}

static member sendGeewalletPayment alice bob = async {
let bobNodeId = bob.CM.KeysRepository.GetNodeSecret().PubKey |> NodeId
let aliceNodeId = alice.CM.KeysRepository.GetNodeSecret().PubKey |> NodeId

do! Async.Sleep 1000
Console.WriteLine("testing geewallet payment")


let aliceToBobAmount = 1000L |> LNMoney.MilliSatoshis
let geewalletPaymentCmd = {
Amount = aliceToBobAmount
}

// Send geewallet payment from alice to bob
let bobAcceptedGeewalletPaymentTask =
bob.EventAggregator.AwaitChannelEvent(function WeAcceptedGeewalletPayment _ -> Some () | _ -> None)
do!
alice.CM.AcceptCommandAsync({
NodeId = bobNodeId
ChannelCommand = ChannelCommand.GeewalletPayment geewalletPaymentCmd
}).AsTask() |> Async.AwaitTask

let! r = bobAcceptedGeewalletPaymentTask
Expect.isSome r "timeout waiting for bob to accept geewallet payment"
}

[<Tests>]
let tests =
Expand Down Expand Up @@ -348,7 +373,7 @@ let tests =
do! alice.CM.AcceptCommandAsync({ NodeId = bobNodeId; ChannelCommand = ChannelCommand.AddHTLC addHtlcCmd }).AsTask() |> Async.AwaitTask
let! r = bobAcceptedAddHTLCTask
Expect.isSome r "timeout"
Expect.isSome r "timeout waiting for bob to accept htlc"
do! Async.Sleep 1000
Expand All @@ -362,10 +387,12 @@ let tests =
bob.EventAggregator.AwaitChannelEvent(function WeAcceptedCommitmentSigned (revokeAndAck, commitments) -> Some (revokeAndAck, commitments) | _ -> None)
do! alice.CM.AcceptCommandAsync({ NodeId = bobNodeId; ChannelCommand = SignCommitment }).AsTask() |> Async.AwaitTask
let! r = aliceAcceptedSign
Expect.isSome r "timeout"
Expect.isSome r "timeout waiting for alice to accept sign command"
let! r = bobAcceptedSign
Expect.isSome r "timeout waiting for bob to accept commitment signature"
let revokeAndAck, bobCommitments = r.Value
let! r = aliceAcceptedRevokeAndAck
Expect.isSome r "timeout waiting for alice to accept revoke_and_ack"
let aliceCommitments = r.Value
Expand Down Expand Up @@ -412,29 +439,36 @@ let tests =
""
*)


do! ActorCreator.sendGeewalletPayment alice bob

do! Async.Sleep 1000
Console.WriteLine("testing geewallet payment")
Console.WriteLine("alice signs her commit")

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

let aliceToBobAmount = 1000L |> LNMoney.MilliSatoshis
let geewalletPaymentCmd = {
Amount = aliceToBobAmount
}
do! Async.Sleep 1000
Console.WriteLine("finishing geewallet payment test")
}

// Send geewallet payment from alice to bob
let bobAcceptedGeewalletPaymentTask =
bob.EventAggregator.AwaitChannelEvent(function WeAcceptedGeewalletPayment _ -> Some () | _ -> None)
do!
alice.CM.AcceptCommandAsync({
NodeId = bobNodeId
ChannelCommand = ChannelCommand.GeewalletPayment geewalletPaymentCmd
}).AsTask() |> Async.AwaitTask
ptestAsync "Send geewallet payment with revoke_and_ack" {
do! Async.Sleep 1000

let! r = bobAcceptedGeewalletPaymentTask
Expect.isSome r "timeout waiting for bob to accept geewallet payment"
Console.WriteLine("starting geewallet payment test")
let alice = ActorCreator.getAlice()
let bob = ActorCreator.getBob()
let! actors = ActorCreator.initiateOpenedChannel(alice, bob)
let bobNodeId = bob.CM.KeysRepository.GetNodeSecret().PubKey |> NodeId
let aliceNodeId = alice.CM.KeysRepository.GetNodeSecret().PubKey |> NodeId

do! ActorCreator.sendGeewalletPayment alice bob

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


do! Async.Sleep 1000
Console.WriteLine(sprintf "alice now has: %s sat" (aliceCommitments.LocalCommit.Spec.ToLocal.ToString()))
Console.WriteLine("finishing geewallet payment test")
Console.WriteLine("finishing geewallet payment with revoke_and_ack test")
}

ptestAsync "Normal channel operation" {
let alice = ActorCreator.getAlice()
let bob = ActorCreator.getBob()
Expand Down

0 comments on commit 7576c8f

Please sign in to comment.