mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 15:11:09 +02:00
lntest+itest: return the tx from FundCoins
This is used is a following test.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/chainreg"
|
"github.com/lightningnetwork/lnd/chainreg"
|
||||||
"github.com/lightningnetwork/lnd/funding"
|
"github.com/lightningnetwork/lnd/funding"
|
||||||
"github.com/lightningnetwork/lnd/labels"
|
"github.com/lightningnetwork/lnd/labels"
|
||||||
@@ -466,20 +467,29 @@ func runChannelFundingInputTypes(ht *lntest.HarnessTest, alice,
|
|||||||
burnAddr = "bcrt1qxsnqpdc842lu8c0xlllgvejt6rhy49u6fmpgyz"
|
burnAddr = "bcrt1qxsnqpdc842lu8c0xlllgvejt6rhy49u6fmpgyz"
|
||||||
)
|
)
|
||||||
|
|
||||||
fundMixed := func(amt btcutil.Amount, target *node.HarnessNode) {
|
fundMixed := func(amt btcutil.Amount,
|
||||||
|
target *node.HarnessNode) *wire.MsgTx {
|
||||||
|
|
||||||
ht.FundCoins(amt/5, target)
|
ht.FundCoins(amt/5, target)
|
||||||
ht.FundCoins(amt/5, target)
|
ht.FundCoins(amt/5, target)
|
||||||
ht.FundCoinsP2TR(amt/5, target)
|
ht.FundCoinsP2TR(amt/5, target)
|
||||||
ht.FundCoinsP2TR(amt/5, target)
|
ht.FundCoinsP2TR(amt/5, target)
|
||||||
ht.FundCoinsP2TR(amt/5, target)
|
ht.FundCoinsP2TR(amt/5, target)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
fundMultipleP2TR := func(amt btcutil.Amount, target *node.HarnessNode) {
|
fundMultipleP2TR := func(amt btcutil.Amount,
|
||||||
|
target *node.HarnessNode) *wire.MsgTx {
|
||||||
|
|
||||||
ht.FundCoinsP2TR(amt/4, target)
|
ht.FundCoinsP2TR(amt/4, target)
|
||||||
ht.FundCoinsP2TR(amt/4, target)
|
ht.FundCoinsP2TR(amt/4, target)
|
||||||
ht.FundCoinsP2TR(amt/4, target)
|
ht.FundCoinsP2TR(amt/4, target)
|
||||||
ht.FundCoinsP2TR(amt/4, target)
|
ht.FundCoinsP2TR(amt/4, target)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
fundWithTypes := []func(amt btcutil.Amount, target *node.HarnessNode){
|
fundWithTypes := []func(amt btcutil.Amount,
|
||||||
|
target *node.HarnessNode) *wire.MsgTx{
|
||||||
ht.FundCoins, ht.FundCoinsNP2WKH, ht.FundCoinsP2TR, fundMixed,
|
ht.FundCoins, ht.FundCoinsNP2WKH, ht.FundCoinsP2TR, fundMixed,
|
||||||
fundMultipleP2TR,
|
fundMultipleP2TR,
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@ package lntest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -1425,7 +1424,7 @@ func (h *HarnessTest) IsNeutrinoBackend() bool {
|
|||||||
// transaction that pays to the target should confirm. For neutrino backend,
|
// transaction that pays to the target should confirm. For neutrino backend,
|
||||||
// the `confirmed` param is ignored.
|
// the `confirmed` param is ignored.
|
||||||
func (h *HarnessTest) fundCoins(amt btcutil.Amount, target *node.HarnessNode,
|
func (h *HarnessTest) fundCoins(amt btcutil.Amount, target *node.HarnessNode,
|
||||||
addrType lnrpc.AddressType, confirmed bool) {
|
addrType lnrpc.AddressType, confirmed bool) *wire.MsgTx {
|
||||||
|
|
||||||
initialBalance := target.RPC.WalletBalance()
|
initialBalance := target.RPC.WalletBalance()
|
||||||
|
|
||||||
@@ -1443,25 +1442,14 @@ func (h *HarnessTest) fundCoins(amt btcutil.Amount, target *node.HarnessNode,
|
|||||||
PkScript: addrScript,
|
PkScript: addrScript,
|
||||||
Value: int64(amt),
|
Value: int64(amt),
|
||||||
}
|
}
|
||||||
h.miner.SendOutput(output, defaultMinerFeeRate)
|
txid := h.miner.SendOutput(output, defaultMinerFeeRate)
|
||||||
|
|
||||||
// Encode the pkScript in hex as this the format that it will be
|
// Get the funding tx.
|
||||||
// returned via rpc.
|
tx := h.GetRawTransaction(*txid)
|
||||||
expPkScriptStr := hex.EncodeToString(addrScript)
|
msgTx := tx.MsgTx()
|
||||||
|
|
||||||
// Now, wait for ListUnspent to show the unconfirmed transaction
|
|
||||||
// containing the correct pkscript.
|
|
||||||
//
|
|
||||||
// Since neutrino doesn't support unconfirmed outputs, skip this check.
|
// Since neutrino doesn't support unconfirmed outputs, skip this check.
|
||||||
if !h.IsNeutrinoBackend() {
|
if !h.IsNeutrinoBackend() {
|
||||||
utxos := h.AssertNumUTXOsUnconfirmed(target, 1)
|
|
||||||
|
|
||||||
// Assert that the lone unconfirmed utxo contains the same
|
|
||||||
// pkscript as the output generated above.
|
|
||||||
pkScriptStr := utxos[0].PkScript
|
|
||||||
require.Equal(h, pkScriptStr, expPkScriptStr,
|
|
||||||
"pkscript mismatch")
|
|
||||||
|
|
||||||
expectedBalance := btcutil.Amount(
|
expectedBalance := btcutil.Amount(
|
||||||
initialBalance.UnconfirmedBalance,
|
initialBalance.UnconfirmedBalance,
|
||||||
) + amt
|
) + amt
|
||||||
@@ -1472,48 +1460,56 @@ func (h *HarnessTest) fundCoins(amt btcutil.Amount, target *node.HarnessNode,
|
|||||||
// the target node's unconfirmed balance reflects the expected balance
|
// the target node's unconfirmed balance reflects the expected balance
|
||||||
// and exit.
|
// and exit.
|
||||||
if !confirmed {
|
if !confirmed {
|
||||||
return
|
return msgTx
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we'll generate 1 new blocks to ensure the output gains a
|
// Otherwise, we'll generate 1 new blocks to ensure the output gains a
|
||||||
// sufficient number of confirmations and wait for the balance to
|
// sufficient number of confirmations and wait for the balance to
|
||||||
// reflect what's expected.
|
// reflect what's expected.
|
||||||
h.MineBlocksAndAssertNumTxes(1, 1)
|
h.MineBlockWithTx(msgTx)
|
||||||
|
|
||||||
expectedBalance := btcutil.Amount(initialBalance.ConfirmedBalance) + amt
|
expectedBalance := btcutil.Amount(initialBalance.ConfirmedBalance) + amt
|
||||||
h.WaitForBalanceConfirmed(target, expectedBalance)
|
h.WaitForBalanceConfirmed(target, expectedBalance)
|
||||||
|
|
||||||
|
return msgTx
|
||||||
}
|
}
|
||||||
|
|
||||||
// FundCoins attempts to send amt satoshis from the internal mining node to the
|
// FundCoins attempts to send amt satoshis from the internal mining node to the
|
||||||
// targeted lightning node using a P2WKH address. 1 blocks are mined after in
|
// targeted lightning node using a P2WKH address. 1 blocks are mined after in
|
||||||
// order to confirm the transaction.
|
// order to confirm the transaction.
|
||||||
func (h *HarnessTest) FundCoins(amt btcutil.Amount, hn *node.HarnessNode) {
|
func (h *HarnessTest) FundCoins(amt btcutil.Amount,
|
||||||
h.fundCoins(amt, hn, lnrpc.AddressType_WITNESS_PUBKEY_HASH, true)
|
hn *node.HarnessNode) *wire.MsgTx {
|
||||||
|
|
||||||
|
return h.fundCoins(amt, hn, lnrpc.AddressType_WITNESS_PUBKEY_HASH, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FundCoinsUnconfirmed attempts to send amt satoshis from the internal mining
|
// FundCoinsUnconfirmed attempts to send amt satoshis from the internal mining
|
||||||
// node to the targeted lightning node using a P2WKH address. No blocks are
|
// node to the targeted lightning node using a P2WKH address. No blocks are
|
||||||
// mined after and the UTXOs are unconfirmed.
|
// mined after and the UTXOs are unconfirmed.
|
||||||
func (h *HarnessTest) FundCoinsUnconfirmed(amt btcutil.Amount,
|
func (h *HarnessTest) FundCoinsUnconfirmed(amt btcutil.Amount,
|
||||||
hn *node.HarnessNode) {
|
hn *node.HarnessNode) *wire.MsgTx {
|
||||||
|
|
||||||
h.fundCoins(amt, hn, lnrpc.AddressType_WITNESS_PUBKEY_HASH, false)
|
return h.fundCoins(
|
||||||
|
amt, hn, lnrpc.AddressType_WITNESS_PUBKEY_HASH, false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FundCoinsNP2WKH attempts to send amt satoshis from the internal mining node
|
// FundCoinsNP2WKH attempts to send amt satoshis from the internal mining node
|
||||||
// to the targeted lightning node using a NP2WKH address.
|
// to the targeted lightning node using a NP2WKH address.
|
||||||
func (h *HarnessTest) FundCoinsNP2WKH(amt btcutil.Amount,
|
func (h *HarnessTest) FundCoinsNP2WKH(amt btcutil.Amount,
|
||||||
target *node.HarnessNode) {
|
target *node.HarnessNode) *wire.MsgTx {
|
||||||
|
|
||||||
h.fundCoins(amt, target, lnrpc.AddressType_NESTED_PUBKEY_HASH, true)
|
return h.fundCoins(
|
||||||
|
amt, target, lnrpc.AddressType_NESTED_PUBKEY_HASH, true,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FundCoinsP2TR attempts to send amt satoshis from the internal mining node to
|
// FundCoinsP2TR attempts to send amt satoshis from the internal mining node to
|
||||||
// the targeted lightning node using a P2TR address.
|
// the targeted lightning node using a P2TR address.
|
||||||
func (h *HarnessTest) FundCoinsP2TR(amt btcutil.Amount,
|
func (h *HarnessTest) FundCoinsP2TR(amt btcutil.Amount,
|
||||||
target *node.HarnessNode) {
|
target *node.HarnessNode) *wire.MsgTx {
|
||||||
|
|
||||||
h.fundCoins(amt, target, lnrpc.AddressType_TAPROOT_PUBKEY, true)
|
return h.fundCoins(amt, target, lnrpc.AddressType_TAPROOT_PUBKEY, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FundNumCoins attempts to send the given number of UTXOs from the internal
|
// FundNumCoins attempts to send the given number of UTXOs from the internal
|
||||||
|
Reference in New Issue
Block a user