itest: refactor testTaprootCoopClose

This commit is contained in:
yyforyongyu committed 2023-01-18 10:53:58 +08:00
1 parent 38eaa36d90
commit 368b3337bd
3 files changed
+32 -45

No files matched your search

+4
View File
@@ -485,4 +485,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
Name: "remote signer", Name: "remote signer",
TestFunc: testRemoteSigner, TestFunc: testRemoteSigner,
}, },
{
Name: "taproot coop close",
TestFunc: testTaprootCoopClose,
},
} }
+28 -41
View File
@@ -22,7 +22,6 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntemp" "github.com/lightningnetwork/lnd/lntemp"
"github.com/lightningnetwork/lnd/lntemp/node" "github.com/lightningnetwork/lnd/lntemp/node"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@@ -1763,47 +1762,25 @@ func createMuSigSessions(ht *lntemp.HarnessTest, node *node.HarnessNode,
return internalKey, combinedKey, sessResp1, sessResp2, sessResp3 return internalKey, combinedKey, sessResp1, sessResp2, sessResp3
} }
// assertTaprootDeliveryUsed returns true if a Taproot addr was used in the
// co-op close transaction.
func assertTaprootDeliveryUsed(net *lntest.NetworkHarness,
t *harnessTest, closingTxid *chainhash.Hash) bool {
tx, err := net.Miner.Client.GetRawTransaction(closingTxid)
require.NoError(t.t, err, "unable to get closing tx")
for _, txOut := range tx.MsgTx().TxOut {
if !txscript.IsPayToTaproot(txOut.PkScript) {
return false
}
}
return true
}
// testTaprootCoopClose asserts that if both peers signal ShutdownAnySegwit, // testTaprootCoopClose asserts that if both peers signal ShutdownAnySegwit,
// then a taproot closing addr is used. Otherwise, we shouldn't expect one to // then a taproot closing addr is used. Otherwise, we shouldn't expect one to
// be used. // be used.
func testTaprootCoopClose(net *lntest.NetworkHarness, t *harnessTest) { func testTaprootCoopClose(ht *lntemp.HarnessTest) {
// We'll start by making two new nodes, and funding a channel between // We'll start by making two new nodes, and funding a channel between
// them. // them.
carol := net.NewNode(t.t, "Carol", nil) carol := ht.NewNode("Carol", nil)
defer shutdownAndAssert(net, t, carol) ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol) dave := ht.NewNode("Dave", nil)
ht.EnsureConnected(carol, dave)
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
net.EnsureConnected(t.t, carol, dave)
chanAmt := funding.MaxBtcFundingAmount chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(100000) pushAmt := btcutil.Amount(100000)
satPerVbyte := btcutil.Amount(1) satPerVbyte := btcutil.Amount(1)
// We'll now open a channel between Carol and Dave. // We'll now open a channel between Carol and Dave.
chanPoint := openChannelAndAssert( chanPoint := ht.OpenChannel(
t, net, carol, dave, carol, dave, lntemp.OpenChannelParams{
lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
SatPerVByte: satPerVbyte, SatPerVByte: satPerVbyte,
@@ -1811,24 +1788,34 @@ func testTaprootCoopClose(net *lntest.NetworkHarness, t *harnessTest) {
) )
// We'll now close out the channel and obtain the closing TXID. // We'll now close out the channel and obtain the closing TXID.
closingTxid := closeChannelAndAssert(t, net, carol, chanPoint, false) closingTxid := ht.CloseChannel(carol, chanPoint)
// assertTaprootDeliveryUsed returns true if a Taproot addr was used in
// the co-op close transaction.
assertTaprootDeliveryUsed := func(closingTxid *chainhash.Hash) bool {
tx := ht.Miner.GetRawTransaction(closingTxid)
for _, txOut := range tx.MsgTx().TxOut {
if !txscript.IsPayToTaproot(txOut.PkScript) {
return false
}
}
return true
}
// We expect that the closing transaction only has P2TR addresses. // We expect that the closing transaction only has P2TR addresses.
require.True(t.t, assertTaprootDeliveryUsed(net, t, closingTxid), require.True(ht, assertTaprootDeliveryUsed(closingTxid),
"taproot addr not used!") "taproot addr not used!")
// Now we'll bring Eve into the mix, Eve is running older software that // Now we'll bring Eve into the mix, Eve is running older software that
// doesn't understand Taproot. // doesn't understand Taproot.
eveArgs := []string{"--protocol.no-any-segwit"} eveArgs := []string{"--protocol.no-any-segwit"}
eve := net.NewNode(t.t, "Eve", eveArgs) eve := ht.NewNode("Eve", eveArgs)
defer shutdownAndAssert(net, t, eve) ht.EnsureConnected(carol, eve)
net.EnsureConnected(t.t, carol, eve)
// We'll now open up a chanel again between Carol and Eve. // We'll now open up a chanel again between Carol and Eve.
chanPoint = openChannelAndAssert( chanPoint = ht.OpenChannel(
t, net, carol, eve, carol, eve, lntemp.OpenChannelParams{
lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
PushAmt: pushAmt, PushAmt: pushAmt,
SatPerVByte: satPerVbyte, SatPerVByte: satPerVbyte,
@@ -1837,7 +1824,7 @@ func testTaprootCoopClose(net *lntest.NetworkHarness, t *harnessTest) {
// We'll now close out this channel and expect that no Taproot // We'll now close out this channel and expect that no Taproot
// addresses are used in the co-op close transaction. // addresses are used in the co-op close transaction.
closingTxid = closeChannelAndAssert(t, net, carol, chanPoint, false) closingTxid = ht.CloseChannel(carol, chanPoint)
require.False(t.t, assertTaprootDeliveryUsed(net, t, closingTxid), require.False(ht, assertTaprootDeliveryUsed(closingTxid),
"taproot addr shouldn't be used!") "taproot addr shouldn't be used!")
} }
-4
View File
@@ -8,10 +8,6 @@ var allTestCases = []*testCase{
name: "async bidirectional payments", name: "async bidirectional payments",
test: testBidirectionalAsyncPayments, test: testBidirectionalAsyncPayments,
}, },
{
name: "taproot coop close",
test: testTaprootCoopClose,
},
{ {
name: "trackpayments", name: "trackpayments",
test: testTrackPayments, test: testTrackPayments,