lntemp+itest: refactor testNonstdSweep
This commit is contained in:
4 files changed
+38
-39
No files matched your search
@@ -11,6 +11,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcjson"
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
@@ -253,6 +254,16 @@ func (h *HarnessMiner) GetRawTransaction(txid *chainhash.Hash) *btcutil.Tx {
|
|||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRawTransactionVerbose makes a RPC call to the miner's
|
||||||
|
// GetRawTransactionVerbose and asserts.
|
||||||
|
func (h *HarnessMiner) GetRawTransactionVerbose(
|
||||||
|
txid *chainhash.Hash) *btcjson.TxRawResult {
|
||||||
|
|
||||||
|
tx, err := h.Client.GetRawTransactionVerbose(txid)
|
||||||
|
require.NoErrorf(h, err, "failed to get raw tx verbose: %v", txid)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
// AssertTxInMempool asserts a given transaction can be found in the mempool.
|
// AssertTxInMempool asserts a given transaction can be found in the mempool.
|
||||||
func (h *HarnessMiner) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx {
|
func (h *HarnessMiner) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx {
|
||||||
var msgTx *wire.MsgTx
|
var msgTx *wire.MsgTx
|
||||||
|
|||||||
@@ -433,4 +433,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
|||||||
Name: "scid alias upgrade",
|
Name: "scid alias upgrade",
|
||||||
TestFunc: testOptionScidUpgrade,
|
TestFunc: testOptionScidUpgrade,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "nonstd sweep",
|
||||||
|
TestFunc: testNonstdSweep,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -1,40 +1,39 @@
|
|||||||
package itest
|
package itest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntemp"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testNonstdSweep(net *lntest.NetworkHarness, t *harnessTest) {
|
func testNonstdSweep(ht *lntemp.HarnessTest) {
|
||||||
p2shAddr, err := btcutil.NewAddressScriptHash(
|
p2shAddr, err := btcutil.NewAddressScriptHash(
|
||||||
make([]byte, 1), harnessNetParams,
|
make([]byte, 1), harnessNetParams,
|
||||||
)
|
)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
p2pkhAddr, err := btcutil.NewAddressPubKeyHash(
|
p2pkhAddr, err := btcutil.NewAddressPubKeyHash(
|
||||||
make([]byte, 20), harnessNetParams,
|
make([]byte, 20), harnessNetParams,
|
||||||
)
|
)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
p2wshAddr, err := btcutil.NewAddressWitnessScriptHash(
|
p2wshAddr, err := btcutil.NewAddressWitnessScriptHash(
|
||||||
make([]byte, 32), harnessNetParams,
|
make([]byte, 32), harnessNetParams,
|
||||||
)
|
)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
p2wkhAddr, err := btcutil.NewAddressWitnessPubKeyHash(
|
p2wkhAddr, err := btcutil.NewAddressWitnessPubKeyHash(
|
||||||
make([]byte, 20), harnessNetParams,
|
make([]byte, 20), harnessNetParams,
|
||||||
)
|
)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
p2trAddr, err := btcutil.NewAddressTaproot(
|
p2trAddr, err := btcutil.NewAddressTaproot(
|
||||||
make([]byte, 32), harnessNetParams,
|
make([]byte, 32), harnessNetParams,
|
||||||
)
|
)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -64,10 +63,10 @@ func testNonstdSweep(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
test := test
|
test := test
|
||||||
success := t.t.Run(test.name, func(t *testing.T) {
|
success := ht.Run(test.name, func(t *testing.T) {
|
||||||
h := newHarnessTest(t, net)
|
st := ht.Subtest(t)
|
||||||
|
|
||||||
testNonStdSweepInner(net, h, test.address)
|
testNonStdSweepInner(st, test.address)
|
||||||
})
|
})
|
||||||
if !success {
|
if !success {
|
||||||
break
|
break
|
||||||
@@ -75,18 +74,14 @@ func testNonstdSweep(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNonStdSweepInner(net *lntest.NetworkHarness, t *harnessTest,
|
func testNonStdSweepInner(ht *lntemp.HarnessTest, address string) {
|
||||||
address string) {
|
carol := ht.NewNode("carol", nil)
|
||||||
|
|
||||||
ctxb := context.Background()
|
|
||||||
|
|
||||||
carol := net.NewNode(t.t, "carol", nil)
|
|
||||||
|
|
||||||
// Give Carol a UTXO so SendCoins will behave as expected.
|
// Give Carol a UTXO so SendCoins will behave as expected.
|
||||||
net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, carol)
|
ht.FundCoins(btcutil.SatoshiPerBitcoin, carol)
|
||||||
|
|
||||||
// Set the fee estimate to 1sat/vbyte.
|
// Set the fee estimate to 1sat/vbyte.
|
||||||
net.SetFeeEstimate(250)
|
ht.SetFeeEstimate(250)
|
||||||
|
|
||||||
// Make Carol call SendCoins with the SendAll flag and the created
|
// Make Carol call SendCoins with the SendAll flag and the created
|
||||||
// address.
|
// address.
|
||||||
@@ -96,20 +91,13 @@ func testNonStdSweepInner(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
SendAll: true,
|
SendAll: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
// If a non-standard transaction was created, then this SendCoins call
|
// If a non-standard transaction was created, then this SendCoins call
|
||||||
// will fail.
|
// will fail.
|
||||||
_, err := carol.SendCoins(ctxt, sendReq)
|
carol.RPC.SendCoins(sendReq)
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// Fetch the txid so we can grab the raw transaction.
|
// Fetch the txid so we can grab the raw transaction.
|
||||||
txid, err := waitForTxInMempool(net.Miner.Client, minerMempoolTimeout)
|
txid := ht.Miner.AssertNumTxsInMempool(1)[0]
|
||||||
require.NoError(t.t, err)
|
tx := ht.Miner.GetRawTransaction(txid)
|
||||||
|
|
||||||
tx, err := net.Miner.Client.GetRawTransaction(txid)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
msgTx := tx.MsgTx()
|
msgTx := tx.MsgTx()
|
||||||
|
|
||||||
@@ -123,9 +111,7 @@ func testNonStdSweepInner(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
for _, inp := range msgTx.TxIn {
|
for _, inp := range msgTx.TxIn {
|
||||||
// Fetch the previous outpoint's value.
|
// Fetch the previous outpoint's value.
|
||||||
prevOut := inp.PreviousOutPoint
|
prevOut := inp.PreviousOutPoint
|
||||||
|
ptx := ht.Miner.GetRawTransaction(&prevOut.Hash)
|
||||||
ptx, err := net.Miner.Client.GetRawTransaction(&prevOut.Hash)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
pout := ptx.MsgTx().TxOut[prevOut.Index]
|
pout := ptx.MsgTx().TxOut[prevOut.Index]
|
||||||
inputVal += int(pout.Value)
|
inputVal += int(pout.Value)
|
||||||
@@ -139,9 +125,11 @@ func testNonStdSweepInner(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
|
|
||||||
// Fetch the vsize of the transaction so we can determine if the
|
// Fetch the vsize of the transaction so we can determine if the
|
||||||
// transaction pays >= 1 sat/vbyte.
|
// transaction pays >= 1 sat/vbyte.
|
||||||
rawTx, err := net.Miner.Client.GetRawTransactionVerbose(txid)
|
rawTx := ht.Miner.GetRawTransactionVerbose(txid)
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// Require fee >= vbytes.
|
// Require fee >= vbytes.
|
||||||
require.True(t.t, fee >= int(rawTx.Vsize))
|
require.True(ht, fee >= int(rawTx.Vsize))
|
||||||
|
|
||||||
|
// Mine a block to keep the mempool clean.
|
||||||
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
}
|
}
|
||||||
@@ -56,10 +56,6 @@ var allTestCases = []*testCase{
|
|||||||
name: "taproot",
|
name: "taproot",
|
||||||
test: testTaproot,
|
test: testTaproot,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "nonstd sweep",
|
|
||||||
test: testNonstdSweep,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "taproot coop close",
|
name: "taproot coop close",
|
||||||
test: testTaprootCoopClose,
|
test: testTaprootCoopClose,
|
||||||
|
|||||||
Reference in new issue
Block a user