itest: flatten PSBT funding test cases

So it's easier to get the logs and debug.
This commit is contained in:
yyforyongyu committed 2024-12-20 19:38:07 +08:00
1 parent 762e59d78c
commit 9f764c25f9
3 files changed
+98 -116

No files matched your search

+1 -4
View File
@@ -283,10 +283,6 @@ var allTestCases = []*lntest.TestCase{
Name: "open channel reorg test", Name: "open channel reorg test",
TestFunc: testOpenChannelAfterReorg, TestFunc: testOpenChannelAfterReorg,
}, },
{
Name: "psbt channel funding",
TestFunc: testPsbtChanFunding,
},
{ {
Name: "sign psbt", Name: "sign psbt",
TestFunc: testSignPsbt, TestFunc: testSignPsbt,
@@ -694,4 +690,5 @@ func init() {
// Register subtests. // Register subtests.
allTestCases = append(allTestCases, multiHopForceCloseTestCases...) allTestCases = append(allTestCases, multiHopForceCloseTestCases...)
allTestCases = append(allTestCases, watchtowerTestCases...) allTestCases = append(allTestCases, watchtowerTestCases...)
allTestCases = append(allTestCases, psbtFundingTestCases...)
} }
+96 -111
View File
@@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"testing" "testing"
"time"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa" "github.com/btcsuite/btcd/btcec/v2/ecdsa"
@@ -27,119 +26,85 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
// testPsbtChanFunding makes sure a channel can be opened between carol and dave // psbtFundingTestCases contains the test cases for funding via PSBT.
// by using a Partially Signed Bitcoin Transaction that funds the channel var psbtFundingTestCases = []*lntest.TestCase{
// multisig funding output. {
func testPsbtChanFunding(ht *lntest.HarnessTest) { Name: "psbt funding anchor",
const ( TestFunc: func(ht *lntest.HarnessTest) {
burnAddr = "bcrt1qxsnqpdc842lu8c0xlllgvejt6rhy49u6fmpgyz" runPsbtChanFunding(
) ht, false, lnrpc.CommitmentType_ANCHORS,
)
testCases := []struct {
name string
commitmentType lnrpc.CommitmentType
private bool
}{
{
name: "anchors",
commitmentType: lnrpc.CommitmentType_ANCHORS,
private: false,
}, },
{ },
name: "simple taproot", {
commitmentType: lnrpc.CommitmentType_SIMPLE_TAPROOT, Name: "psbt external funding anchor",
TestFunc: func(ht *lntest.HarnessTest) {
// Set this to true once simple taproot channels can be runPsbtChanFundingExternal(
// announced to the network. ht, false, lnrpc.CommitmentType_ANCHORS,
private: true, )
}, },
} },
{
for _, tc := range testCases { Name: "psbt single step funding anchor",
tc := tc TestFunc: func(ht *lntest.HarnessTest) {
runPsbtChanFundingSingleStep(
success := ht.T.Run(tc.name, func(tt *testing.T) { ht, false, lnrpc.CommitmentType_ANCHORS,
st := ht.Subtest(tt) )
},
args := lntest.NodeArgsForCommitType(tc.commitmentType) },
{
// First, we'll create two new nodes that we'll use to Name: "psbt funding simple taproot",
// open channels between for this test. Dave gets some TestFunc: func(ht *lntest.HarnessTest) {
// coins that will be used to fund the PSBT, just to runPsbtChanFunding(
// make sure that Carol has an empty wallet. ht, true, lnrpc.CommitmentType_SIMPLE_TAPROOT,
carol := st.NewNode("carol", args) )
dave := st.NewNode("dave", args) },
},
// We just send enough funds to satisfy the anchor {
// channel reserve for 5 channels (50k sats). Name: "psbt external funding simple taproot",
st.FundCoins(50_000, carol) TestFunc: func(ht *lntest.HarnessTest) {
st.FundCoins(50_000, dave) runPsbtChanFundingExternal(
ht, true, lnrpc.CommitmentType_SIMPLE_TAPROOT,
st.RunTestCase(&lntest.TestCase{ )
Name: tc.name, },
TestFunc: func(sst *lntest.HarnessTest) { },
runPsbtChanFunding( {
sst, carol, dave, tc.private, Name: "psbt single step funding simple taproot",
tc.commitmentType, TestFunc: func(ht *lntest.HarnessTest) {
) runPsbtChanFundingSingleStep(
}, ht, true, lnrpc.CommitmentType_SIMPLE_TAPROOT,
}) )
},
// Empty out the wallets so there aren't any lingering },
// coins.
sendAllCoinsConfirm(st, carol, burnAddr)
sendAllCoinsConfirm(st, dave, burnAddr)
// Now we test the second scenario. Again, we just send
// enough funds to satisfy the anchor channel reserve
// for 5 channels (50k sats).
st.FundCoins(50_000, carol)
st.FundCoins(50_000, dave)
st.RunTestCase(&lntest.TestCase{
Name: tc.name,
TestFunc: func(sst *lntest.HarnessTest) {
runPsbtChanFundingExternal(
sst, carol, dave, tc.private,
tc.commitmentType,
)
},
})
// Empty out the wallets a last time, so there aren't
// any lingering coins.
sendAllCoinsConfirm(st, carol, burnAddr)
sendAllCoinsConfirm(st, dave, burnAddr)
// The last test case tests the anchor channel reserve
// itself, so we need empty wallets.
st.RunTestCase(&lntest.TestCase{
Name: tc.name,
TestFunc: func(sst *lntest.HarnessTest) {
runPsbtChanFundingSingleStep(
sst, carol, dave, tc.private,
tc.commitmentType,
)
},
})
})
if !success {
// Log failure time to help relate the lnd logs to the
// failure.
ht.Logf("Failure time: %v", time.Now().Format(
"2006-01-02 15:04:05.000",
))
break
}
}
} }
// runPsbtChanFunding makes sure a channel can be opened between carol and dave // runPsbtChanFunding makes sure a channel can be opened between carol and dave
// by using a Partially Signed Bitcoin Transaction that funds the channel // by using a Partially Signed Bitcoin Transaction that funds the channel
// multisig funding output. // multisig funding output.
func runPsbtChanFunding(ht *lntest.HarnessTest, carol, dave *node.HarnessNode, func runPsbtChanFunding(ht *lntest.HarnessTest, private bool,
private bool, commitType lnrpc.CommitmentType) { commitType lnrpc.CommitmentType) {
args := lntest.NodeArgsForCommitType(commitType)
// First, we'll create two new nodes that we'll use to open channels
// between for this test. Dave gets some coins that will be used to
// fund the PSBT, just to make sure that Carol has an empty wallet.
carol := ht.NewNode("carol", args)
dave := ht.NewNode("dave", args)
// We just send enough funds to satisfy the anchor channel reserve for
// 5 channels (50k sats).
ht.FundCoins(50_000, carol)
ht.FundCoins(50_000, dave)
runPsbtChanFundingWithNodes(ht, carol, dave, private, commitType)
}
// runPsbtChanFundingWithNodes run a test case to make sure a channel can be
// opened between carol and dave by using a PSBT that funds the channel
// multisig funding output.
func runPsbtChanFundingWithNodes(ht *lntest.HarnessTest, carol,
dave *node.HarnessNode, private bool, commitType lnrpc.CommitmentType) {
const chanSize = funding.MaxBtcFundingAmount const chanSize = funding.MaxBtcFundingAmount
ht.FundCoins(btcutil.SatoshiPerBitcoin, dave) ht.FundCoins(btcutil.SatoshiPerBitcoin, dave)
@@ -330,8 +295,21 @@ func runPsbtChanFunding(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
// and dave by using a Partially Signed Bitcoin Transaction that funds the // and dave by using a Partially Signed Bitcoin Transaction that funds the
// channel multisig funding output and is fully funded by an external third // channel multisig funding output and is fully funded by an external third
// party. // party.
func runPsbtChanFundingExternal(ht *lntest.HarnessTest, carol, func runPsbtChanFundingExternal(ht *lntest.HarnessTest, private bool,
dave *node.HarnessNode, private bool, commitType lnrpc.CommitmentType) { commitType lnrpc.CommitmentType) {
args := lntest.NodeArgsForCommitType(commitType)
// First, we'll create two new nodes that we'll use to open channels
// between for this test. Dave gets some coins that will be used to
// fund the PSBT, just to make sure that Carol has an empty wallet.
carol := ht.NewNode("carol", args)
dave := ht.NewNode("dave", args)
// We just send enough funds to satisfy the anchor channel reserve for
// 5 channels (50k sats).
ht.FundCoins(50_000, carol)
ht.FundCoins(50_000, dave)
const chanSize = funding.MaxBtcFundingAmount const chanSize = funding.MaxBtcFundingAmount
@@ -498,8 +476,15 @@ func runPsbtChanFundingExternal(ht *lntest.HarnessTest, carol,
// the wallet of both nodes are empty and one of them uses PSBT and an external // the wallet of both nodes are empty and one of them uses PSBT and an external
// wallet to fund the channel while creating reserve output in the same // wallet to fund the channel while creating reserve output in the same
// transaction. // transaction.
func runPsbtChanFundingSingleStep(ht *lntest.HarnessTest, carol, func runPsbtChanFundingSingleStep(ht *lntest.HarnessTest, private bool,
dave *node.HarnessNode, private bool, commitType lnrpc.CommitmentType) { commitType lnrpc.CommitmentType) {
args := lntest.NodeArgsForCommitType(commitType)
// First, we'll create two new nodes that we'll use to open channels
// between for this test.
carol := ht.NewNode("carol", args)
dave := ht.NewNode("dave", args)
const chanSize = funding.MaxBtcFundingAmount const chanSize = funding.MaxBtcFundingAmount
+1 -1
View File
@@ -123,7 +123,7 @@ func testRemoteSigner(ht *lntest.HarnessTest) {
name: "psbt", name: "psbt",
randomSeed: true, randomSeed: true,
fn: func(tt *lntest.HarnessTest, wo, carol *node.HarnessNode) { fn: func(tt *lntest.HarnessTest, wo, carol *node.HarnessNode) {
runPsbtChanFunding( runPsbtChanFundingWithNodes(
tt, carol, wo, false, tt, carol, wo, false,
lnrpc.CommitmentType_LEGACY, lnrpc.CommitmentType_LEGACY,
) )