Skip to content

Commit b10ebb2

Browse files
authored
Merge pull request #8923 from yyforyongyu/fix-test-interface
chainntnfs+lntest: fix `TestInterfaces`
2 parents 6f37db3 + 48a0efe commit b10ebb2

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

chainntnfs/bitcoindnotify/bitcoind_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ func syncNotifierWithMiner(t *testing.T, notifier *BitcoindNotifier,
9393
"height: %v", err)
9494
}
9595

96+
t.Logf("miner height=%v, bitcoind height=%v", minerHeight,
97+
bitcoindHeight)
98+
9699
if bitcoindHeight == minerHeight {
97100
return uint32(bitcoindHeight)
98101
}

chainntnfs/test_utils.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/btcsuite/btcd/integration/rpctest"
1717
"github.com/btcsuite/btcd/txscript"
1818
"github.com/btcsuite/btcd/wire"
19+
"github.com/lightningnetwork/lnd/input"
1920
"github.com/lightningnetwork/lnd/lntest/unittest"
2021
"github.com/stretchr/testify/require"
2122
)
@@ -36,7 +37,7 @@ func randPubKeyHashScript() ([]byte, *btcec.PrivateKey, error) {
3637
}
3738

3839
pubKeyHash := btcutil.Hash160(privKey.PubKey().SerializeCompressed())
39-
addrScript, err := btcutil.NewAddressPubKeyHash(
40+
addrScript, err := btcutil.NewAddressWitnessPubKeyHash(
4041
pubKeyHash, unittest.NetParams,
4142
)
4243
if err != nil {
@@ -139,16 +140,26 @@ func CreateSpendTx(t *testing.T, prevOutPoint *wire.OutPoint,
139140

140141
t.Helper()
141142

142-
spendingTx := wire.NewMsgTx(1)
143-
spendingTx.AddTxIn(&wire.TxIn{PreviousOutPoint: *prevOutPoint})
144-
spendingTx.AddTxOut(&wire.TxOut{Value: 1e8, PkScript: prevOutput.PkScript})
145-
146-
sigScript, err := txscript.SignatureScript(
147-
spendingTx, 0, prevOutput.PkScript, txscript.SigHashAll,
148-
privKey, true,
143+
// Create a new output.
144+
outputAmt := int64(1e8)
145+
witnessProgram, _, err := randPubKeyHashScript()
146+
require.NoError(t, err, "unable to generate pkScript")
147+
output := wire.NewTxOut(outputAmt, witnessProgram)
148+
149+
// Create a new tx.
150+
tx := wire.NewMsgTx(2)
151+
tx.AddTxIn(wire.NewTxIn(prevOutPoint, nil, nil))
152+
tx.AddTxOut(output)
153+
154+
// Generate the witness.
155+
sigHashes := input.NewTxSigHashesV0Only(tx)
156+
witnessScript, err := txscript.WitnessSignature(
157+
tx, sigHashes, 0, prevOutput.Value, prevOutput.PkScript,
158+
txscript.SigHashAll, privKey, true,
149159
)
150160
require.NoError(t, err, "unable to sign tx")
151-
spendingTx.TxIn[0].SignatureScript = sigScript
152161

153-
return spendingTx
162+
tx.TxIn[0].Witness = witnessScript
163+
164+
return tx
154165
}

lntest/unittest/backend.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ func NewMiner(t *testing.T, netParams *chaincfg.Params, extraArgs []string,
5959
t.Fatalf("unable to set up backend node: %v", err)
6060
}
6161

62+
// Next mine enough blocks in order for segwit and the CSV package
63+
// soft-fork to activate.
64+
numBlocks := netParams.MinerConfirmationWindow*2 + 17
65+
_, err = node.Client.Generate(numBlocks)
66+
require.NoError(t, err, "failed to generate blocks")
67+
6268
return node
6369
}
6470

0 commit comments

Comments
 (0)