lntest+itest: add testBumpFeeExternalInput

This commit is contained in:
yyforyongyu 2025-05-23 17:04:40 +08:00
parent 4cef7b30fe
commit f97f60d3d4
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
3 changed files with 60 additions and 0 deletions

View File

@ -463,6 +463,10 @@ var allTestCases = []*lntest.TestCase{
Name: "bumpfee",
TestFunc: testBumpFee,
},
{
Name: "bumpfee external input",
TestFunc: testBumpFeeExternalInput,
},
{
Name: "bumpforceclosefee",
TestFunc: testBumpForceCloseFee,

View File

@ -587,3 +587,47 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
// Clean up the mempool.
ht.MineBlocksAndAssertNumTxes(1, 2)
}
// testBumpFeeExternalInput assert that when the bump fee RPC is called with an
// outpoint unknown to the node's wallet, an error is returned.
func testBumpFeeExternalInput(ht *lntest.HarnessTest) {
alice := ht.NewNode("Alice", nil)
bob := ht.NewNode("Bob", nil)
// We'll start the test by sending Alice some coins, which she'll use
// to send to Bob.
ht.FundCoins(btcutil.SatoshiPerBitcoin, alice)
// Alice sends 0.5 BTC to Bob. This tx should have two outputs - one
// that belongs to Bob, the other is Alice's change output.
tx := ht.SendCoins(alice, bob, btcutil.SatoshiPerBitcoin/2)
txid := tx.TxHash()
// Find the wrong index to perform the fee bump. We assume the first
// output belongs to Bob, and switch to the second if the second output
// has a larger output value. Given we've funded Alice 1 btc, she then
// sends 0.5 btc to Bob, her change output will be below 0.5 btc after
// paying the mining fees.
wrongIndex := 0
if tx.TxOut[0].Value < tx.TxOut[1].Value {
wrongIndex = 1
}
// Alice now tries to bump the wrong output on this tx.
op := &lnrpc.OutPoint{
TxidBytes: txid[:],
OutputIndex: uint32(wrongIndex),
}
// Create a request with the wrong outpoint.
bumpFeeReq := &walletrpc.BumpFeeRequest{
Outpoint: op,
// We use a force param to create the sweeping tx immediately.
Immediate: true,
}
err := alice.RPC.BumpFeeAssertErr(bumpFeeReq)
require.ErrorContains(ht, err, "does not belong to the wallet")
// Clean up the mempool.
ht.MineBlocksAndAssertNumTxes(1, 1)
}

View File

@ -254,6 +254,18 @@ func (h *HarnessRPC) BumpFee(
return resp
}
// BumpFeeAssertErr makes a RPC call to the node's WalletKitClient and asserts
// that an error is returned.
func (h *HarnessRPC) BumpFeeAssertErr(req *walletrpc.BumpFeeRequest) error {
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
defer cancel()
_, err := h.WalletKit.BumpFee(ctxt, req)
require.Errorf(h, err, "%s: expect BumpFee to return an error", h.Name)
return err
}
// BumpForceCloseFee makes a RPC call to the node's WalletKitClient and asserts.
//
//nolint:ll