Skip to content

Commit f97f60d

Browse files
committed
lntest+itest: add testBumpFeeExternalInput
1 parent 4cef7b3 commit f97f60d

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ var allTestCases = []*lntest.TestCase{
463463
Name: "bumpfee",
464464
TestFunc: testBumpFee,
465465
},
466+
{
467+
Name: "bumpfee external input",
468+
TestFunc: testBumpFeeExternalInput,
469+
},
466470
{
467471
Name: "bumpforceclosefee",
468472
TestFunc: testBumpForceCloseFee,

itest/lnd_bump_fee.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,47 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
587587
// Clean up the mempool.
588588
ht.MineBlocksAndAssertNumTxes(1, 2)
589589
}
590+
591+
// testBumpFeeExternalInput assert that when the bump fee RPC is called with an
592+
// outpoint unknown to the node's wallet, an error is returned.
593+
func testBumpFeeExternalInput(ht *lntest.HarnessTest) {
594+
alice := ht.NewNode("Alice", nil)
595+
bob := ht.NewNode("Bob", nil)
596+
597+
// We'll start the test by sending Alice some coins, which she'll use
598+
// to send to Bob.
599+
ht.FundCoins(btcutil.SatoshiPerBitcoin, alice)
600+
601+
// Alice sends 0.5 BTC to Bob. This tx should have two outputs - one
602+
// that belongs to Bob, the other is Alice's change output.
603+
tx := ht.SendCoins(alice, bob, btcutil.SatoshiPerBitcoin/2)
604+
txid := tx.TxHash()
605+
606+
// Find the wrong index to perform the fee bump. We assume the first
607+
// output belongs to Bob, and switch to the second if the second output
608+
// has a larger output value. Given we've funded Alice 1 btc, she then
609+
// sends 0.5 btc to Bob, her change output will be below 0.5 btc after
610+
// paying the mining fees.
611+
wrongIndex := 0
612+
if tx.TxOut[0].Value < tx.TxOut[1].Value {
613+
wrongIndex = 1
614+
}
615+
616+
// Alice now tries to bump the wrong output on this tx.
617+
op := &lnrpc.OutPoint{
618+
TxidBytes: txid[:],
619+
OutputIndex: uint32(wrongIndex),
620+
}
621+
622+
// Create a request with the wrong outpoint.
623+
bumpFeeReq := &walletrpc.BumpFeeRequest{
624+
Outpoint: op,
625+
// We use a force param to create the sweeping tx immediately.
626+
Immediate: true,
627+
}
628+
err := alice.RPC.BumpFeeAssertErr(bumpFeeReq)
629+
require.ErrorContains(ht, err, "does not belong to the wallet")
630+
631+
// Clean up the mempool.
632+
ht.MineBlocksAndAssertNumTxes(1, 1)
633+
}

lntest/rpc/wallet_kit.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ func (h *HarnessRPC) BumpFee(
254254
return resp
255255
}
256256

257+
// BumpFeeAssertErr makes a RPC call to the node's WalletKitClient and asserts
258+
// that an error is returned.
259+
func (h *HarnessRPC) BumpFeeAssertErr(req *walletrpc.BumpFeeRequest) error {
260+
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
261+
defer cancel()
262+
263+
_, err := h.WalletKit.BumpFee(ctxt, req)
264+
require.Errorf(h, err, "%s: expect BumpFee to return an error", h.Name)
265+
266+
return err
267+
}
268+
257269
// BumpForceCloseFee makes a RPC call to the node's WalletKitClient and asserts.
258270
//
259271
//nolint:ll

0 commit comments

Comments
 (0)