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" "time"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
@ -23,7 +24,7 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
type testCase struct { type testCase struct {
name string name string
test func(net *lntest.NetworkHarness, t *harnessTest, alice, test func(net *lntest.NetworkHarness, t *harnessTest, alice,
bob *lntest.HarnessNode) bob *lntest.HarnessNode, c commitType)
} }
subTests := []testCase{ subTests := []testCase{
@ -67,32 +68,47 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
}, },
} }
args := []string{} commitTypes := []commitType{
alice, err := net.NewNode("Alice", args) commitTypeLegacy,
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)
} }
for _, subTest := range subTests { for _, commitType := range commitTypes {
subTest := subTest 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) 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 { if !success {
return 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 // 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. // the HTLC success transaction in order to ensure we don't lose any funds.
func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest, func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
alice, bob *lntest.HarnessNode) { alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background() 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 // Carol refusing to actually settle or directly cancel any HTLC's
// self. // self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork( aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, false, t, net, alice, bob, false, c,
) )
// Clean up carol's node when the test finishes. // 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, func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
alice, bob *lntest.HarnessNode, carolHodl bool) (*lnrpc.ChannelPoint, alice, bob *lntest.HarnessNode, carolHodl bool, c commitType) (
*lnrpc.ChannelPoint, *lntest.HarnessNode) { *lnrpc.ChannelPoint, *lnrpc.ChannelPoint, *lntest.HarnessNode) {
ctxb := context.Background() 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 // 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 // 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. // HTLC, this way it'll force Bob to go to chain to resolve the HTLC.
carolFlags := []string{} carolFlags := c.Args()
if carolHodl { if carolHodl {
carolFlags = append(carolFlags, "--hodl.exit-settle") carolFlags = append(carolFlags, "--hodl.exit-settle")
} }

@ -22,7 +22,7 @@ import (
// canceled backwards. Once the timeout has been reached, then we should sweep // canceled backwards. Once the timeout has been reached, then we should sweep
// it on-chain, and cancel the HTLC backwards. // it on-chain, and cancel the HTLC backwards.
func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest, func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
alice, bob *lntest.HarnessNode) { alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background() 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 // Carol refusing to actually settle or directly cancel any HTLC's
// self. // self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork( aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, true, t, net, alice, bob, true, c,
) )
// Clean up carol's node when the test finishes. // 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 // extract the preimage from the sweep transaction, and finish settling the
// HTLC backwards into the route. // HTLC backwards into the route.
func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest, func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
alice, bob *lntest.HarnessNode) { alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background() 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 // Carol refusing to actually settle or directly cancel any HTLC's
// self. // self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork( aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, false, t, net, alice, bob, false, c,
) )
// Clean up carol's node when the test finishes. // 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 // HTLC directly on-chain using the preimage in order to ensure that we don't
// lose any funds. // lose any funds.
func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest, func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest,
alice, bob *lntest.HarnessNode) { alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background() 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 // Carol refusing to actually settle or directly cancel any HTLC's
// self. // self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork( aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, false, t, net, alice, bob, false, c,
) )
// Clean up carol's node when the test finishes. // 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 // that's timed out. At this point, the node should timeout the HTLC using the
// HTLC timeout transaction, then cancel it backwards as normal. // HTLC timeout transaction, then cancel it backwards as normal.
func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness, func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
t *harnessTest, alice, bob *lntest.HarnessNode) { t *harnessTest, alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background() ctxb := context.Background()
@ -28,7 +28,7 @@ func testMultiHopLocalForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// Carol refusing to actually settle or directly cancel any HTLC's // Carol refusing to actually settle or directly cancel any HTLC's
// self. // self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork( aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, true, t, net, alice, bob, true, c,
) )
// Clean up carol's node when the test finishes. // 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 // transaction once the timeout has expired. Once we sweep the transaction, we
// should also cancel back the initial HTLC. // should also cancel back the initial HTLC.
func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness, func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
t *harnessTest, alice, bob *lntest.HarnessNode) { t *harnessTest, alice, bob *lntest.HarnessNode, c commitType) {
ctxb := context.Background() ctxb := context.Background()
@ -28,7 +28,7 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
// Carol refusing to actually settle or directly cancel any HTLC's // Carol refusing to actually settle or directly cancel any HTLC's
// self. // self.
aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork( aliceChanPoint, bobChanPoint, carol := createThreeHopNetwork(
t, net, alice, bob, true, t, net, alice, bob, true, c,
) )
// Clean up carol's node when the test finishes. // Clean up carol's node when the test finishes.