mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-09 14:39:54 +02:00
lntest+itest: add testBumpFeeExternalInput
This commit is contained in:
parent
4cef7b30fe
commit
f97f60d3d4
@ -463,6 +463,10 @@ var allTestCases = []*lntest.TestCase{
|
|||||||
Name: "bumpfee",
|
Name: "bumpfee",
|
||||||
TestFunc: testBumpFee,
|
TestFunc: testBumpFee,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "bumpfee external input",
|
||||||
|
TestFunc: testBumpFeeExternalInput,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "bumpforceclosefee",
|
Name: "bumpforceclosefee",
|
||||||
TestFunc: testBumpForceCloseFee,
|
TestFunc: testBumpForceCloseFee,
|
||||||
|
@ -587,3 +587,47 @@ func runBumpFee(ht *lntest.HarnessTest, alice *node.HarnessNode) {
|
|||||||
// Clean up the mempool.
|
// Clean up the mempool.
|
||||||
ht.MineBlocksAndAssertNumTxes(1, 2)
|
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)
|
||||||
|
}
|
||||||
|
@ -254,6 +254,18 @@ func (h *HarnessRPC) BumpFee(
|
|||||||
return resp
|
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.
|
// BumpForceCloseFee makes a RPC call to the node's WalletKitClient and asserts.
|
||||||
//
|
//
|
||||||
//nolint:ll
|
//nolint:ll
|
||||||
|
Loading…
x
Reference in New Issue
Block a user