Merge pull request #8923 from yyforyongyu/fix-test-interface

chainntnfs+lntest: fix `TestInterfaces`
This commit is contained in:
Oliver Gugger 2024-07-24 05:57:07 -06:00 committed by GitHub
commit b10ebb2692
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 9 deletions

View File

@ -93,6 +93,9 @@ func syncNotifierWithMiner(t *testing.T, notifier *BitcoindNotifier,
"height: %v", err)
}
t.Logf("miner height=%v, bitcoind height=%v", minerHeight,
bitcoindHeight)
if bitcoindHeight == minerHeight {
return uint32(bitcoindHeight)
}

View File

@ -16,6 +16,7 @@ import (
"github.com/btcsuite/btcd/integration/rpctest"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lntest/unittest"
"github.com/stretchr/testify/require"
)
@ -36,7 +37,7 @@ func randPubKeyHashScript() ([]byte, *btcec.PrivateKey, error) {
}
pubKeyHash := btcutil.Hash160(privKey.PubKey().SerializeCompressed())
addrScript, err := btcutil.NewAddressPubKeyHash(
addrScript, err := btcutil.NewAddressWitnessPubKeyHash(
pubKeyHash, unittest.NetParams,
)
if err != nil {
@ -139,16 +140,26 @@ func CreateSpendTx(t *testing.T, prevOutPoint *wire.OutPoint,
t.Helper()
spendingTx := wire.NewMsgTx(1)
spendingTx.AddTxIn(&wire.TxIn{PreviousOutPoint: *prevOutPoint})
spendingTx.AddTxOut(&wire.TxOut{Value: 1e8, PkScript: prevOutput.PkScript})
// Create a new output.
outputAmt := int64(1e8)
witnessProgram, _, err := randPubKeyHashScript()
require.NoError(t, err, "unable to generate pkScript")
output := wire.NewTxOut(outputAmt, witnessProgram)
sigScript, err := txscript.SignatureScript(
spendingTx, 0, prevOutput.PkScript, txscript.SigHashAll,
privKey, true,
// Create a new tx.
tx := wire.NewMsgTx(2)
tx.AddTxIn(wire.NewTxIn(prevOutPoint, nil, nil))
tx.AddTxOut(output)
// Generate the witness.
sigHashes := input.NewTxSigHashesV0Only(tx)
witnessScript, err := txscript.WitnessSignature(
tx, sigHashes, 0, prevOutput.Value, prevOutput.PkScript,
txscript.SigHashAll, privKey, true,
)
require.NoError(t, err, "unable to sign tx")
spendingTx.TxIn[0].SignatureScript = sigScript
return spendingTx
tx.TxIn[0].Witness = witnessScript
return tx
}

View File

@ -59,6 +59,12 @@ func NewMiner(t *testing.T, netParams *chaincfg.Params, extraArgs []string,
t.Fatalf("unable to set up backend node: %v", err)
}
// Next mine enough blocks in order for segwit and the CSV package
// soft-fork to activate.
numBlocks := netParams.MinerConfirmationWindow*2 + 17
_, err = node.Client.Generate(numBlocks)
require.NoError(t, err, "failed to generate blocks")
return node
}