itest: run multi-hop claim tests for all commit types

This commit is contained in:
Johan T. Halseth 2020-03-04 13:21:28 +01:00
parent 6ed0c83d11
commit 1ade912361
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
6 changed files with 53 additions and 37 deletions

@ -9,6 +9,7 @@ import (
"time"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/lnrpc"
@ -23,7 +24,7 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
type testCase struct {
name string
test func(net *lntest.NetworkHarness, t *harnessTest, alice,
bob *lntest.HarnessNode)
bob *lntest.HarnessNode, c commitType)
}
subTests := []testCase{
@ -67,32 +68,47 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
},
}
args := []string{}
alice, err := net.NewNode("Alice", args)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
defer shutdownAndAssert(net, t, alice)
bob, err := net.NewNode("Bob", args)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
defer shutdownAndAssert(net, t, bob)
ctxb := context.Background()
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
if err := net.ConnectNodes(ctxt, alice, bob); err != nil {
t.Fatalf("unable to connect alice to bob: %v", err)
commitTypes := []commitType{
commitTypeLegacy,
}
for _, subTest := range subTests {
subTest := subTest
for _, commitType := range commitTypes {
testName := fmt.Sprintf("committype=%v", commitType.String())
success := t.t.Run(subTest.name, func(t *testing.T) {
success := t.t.Run(testName, func(t *testing.T) {
ht := newHarnessTest(t, net)
subTest.test(net, ht, alice, bob)
args := commitType.Args()
alice, err := net.NewNode("Alice", args)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
defer shutdownAndAssert(net, ht, alice)
bob, err := net.NewNode("Bob", args)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
defer shutdownAndAssert(net, ht, bob)
ctxb := context.Background()
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
if err := net.ConnectNodes(ctxt, alice, bob); err != nil {
t.Fatalf("unable to connect alice to bob: %v", err)
}
for _, subTest := range subTests {
subTest := subTest
success := ht.t.Run(subTest.name, func(t *testing.T) {
ht := newHarnessTest(t, net)
subTest.test(net, ht, alice, bob, commitType)
})
if !success {
return
}
}
})
if !success {
return
@ -105,7 +121,7 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
// preimage via the witness beacon, we properly settle the HTLC on-chain using
// the HTLC success transaction in order to ensure we don't lose any funds.
func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
alice, bob *lntest.HarnessNode) {
alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background()
@ -113,7 +129,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
// Carol refusing to actually settle or directly cancel any HTLC's
// self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, false,
t, net, alice, bob, false, c,
)
// Clean up carol's node when the test finishes.
@ -585,8 +601,8 @@ func checkPaymentStatus(ctxt context.Context, node *lntest.HarnessNode,
}
func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
alice, bob *lntest.HarnessNode, carolHodl bool) (*lnrpc.ChannelPoint,
*lnrpc.ChannelPoint, *lntest.HarnessNode) {
alice, bob *lntest.HarnessNode, carolHodl bool, c commitType) (
*lnrpc.ChannelPoint, *lnrpc.ChannelPoint, *lntest.HarnessNode) {
ctxb := context.Background()
@ -634,7 +650,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
// Next, we'll create a new node "carol" and have Bob connect to her. If
// the carolHodl flag is set, we'll make carol always hold onto the
// HTLC, this way it'll force Bob to go to chain to resolve the HTLC.
carolFlags := []string{}
carolFlags := c.Args()
if carolHodl {
carolFlags = append(carolFlags, "--hodl.exit-settle")
}

@ -22,7 +22,7 @@ import (
// canceled backwards. Once the timeout has been reached, then we should sweep
// it on-chain, and cancel the HTLC backwards.
func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
alice, bob *lntest.HarnessNode) {
alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background()
@ -30,7 +30,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
// Carol refusing to actually settle or directly cancel any HTLC's
// self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, true,
t, net, alice, bob, true, c,
)
// Clean up carol's node when the test finishes.

@ -25,7 +25,7 @@ import (
// extract the preimage from the sweep transaction, and finish settling the
// HTLC backwards into the route.
func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
alice, bob *lntest.HarnessNode) {
alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background()
@ -33,7 +33,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
// Carol refusing to actually settle or directly cancel any HTLC's
// self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, false,
t, net, alice, bob, false, c,
)
// Clean up carol's node when the test finishes.

@ -23,7 +23,7 @@ import (
// HTLC directly on-chain using the preimage in order to ensure that we don't
// lose any funds.
func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest,
alice, bob *lntest.HarnessNode) {
alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background()
@ -31,7 +31,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
// Carol refusing to actually settle or directly cancel any HTLC's
// self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, false,
t, net, alice, bob, false, c,
)
// Clean up carol's node when the test finishes.

@ -20,7 +20,7 @@ import (
// that's timed out. At this point, the node should timeout the HTLC using the
// HTLC timeout transaction, then cancel it backwards as normal.
func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
t *harnessTest, alice, bob *lntest.HarnessNode) {
t *harnessTest, alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background()
@ -28,7 +28,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// Carol refusing to actually settle or directly cancel any HTLC's
// self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, true,
t, net, alice, bob, true, c,
)
// Clean up carol's node when the test finishes.

@ -20,7 +20,7 @@ import (
// transaction once the timeout has expired. Once we sweep the transaction, we
// should also cancel back the initial HTLC.
func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
t *harnessTest, alice, bob *lntest.HarnessNode) {
t *harnessTest, alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background()
@ -28,7 +28,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// Carol refusing to actually settle or directly cancel any HTLC's
// self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, true,
t, net, alice, bob, true, c,
)
// Clean up carol's node when the test finishes.