mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-04-01 00:19:54 +02:00
lntest+itest: extend CloseChannelAssertPending
In this commit, we extend `CloseChannelAssertPending` with new args that returns the raw close status update (as we have more things we'd like to assert), and also allows us to pass in a custom fee rate.
This commit is contained in:
parent
39aa949a75
commit
57229e3a62
@ -109,7 +109,11 @@ func breachRetributionTestCase(ht *lntest.HarnessTest,
|
||||
// broadcasting his current channel state. This is actually the
|
||||
// commitment transaction of a prior *revoked* state, so he'll soon
|
||||
// feel the wrath of Carol's retribution.
|
||||
_, breachTXID := ht.CloseChannelAssertPending(bob, chanPoint, true)
|
||||
_, breachCloseUpd := ht.CloseChannelAssertPending(bob, chanPoint, true)
|
||||
closeUpd := breachCloseUpd.GetClosePending()
|
||||
require.NotNil(ht, closeUpd)
|
||||
breachTXID, err := chainhash.NewHash(closeUpd.Txid)
|
||||
require.NoError(ht, err)
|
||||
|
||||
// Here, Carol sees Bob's breach transaction in the mempool, but is
|
||||
// waiting for it to confirm before continuing her retribution. We
|
||||
@ -543,9 +547,13 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
|
||||
// broadcasting her current channel state. This is actually the
|
||||
// commitment transaction of a prior *revoked* state, so she'll soon
|
||||
// feel the wrath of Dave's retribution.
|
||||
closeUpdates, closeTxID := ht.CloseChannelAssertPending(
|
||||
closeUpdates, closeUpd := ht.CloseChannelAssertPending(
|
||||
carol, chanPoint, true,
|
||||
)
|
||||
pendingCloseUpd := closeUpd.GetClosePending()
|
||||
require.NotNil(ht, pendingCloseUpd)
|
||||
closeTxID, err := chainhash.NewHash(pendingCloseUpd.Txid)
|
||||
require.NoError(ht, err)
|
||||
|
||||
// Generate a single block to mine the breach transaction.
|
||||
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
|
||||
@ -593,7 +601,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
|
||||
return nil, errNotFound
|
||||
}
|
||||
|
||||
err := wait.NoError(func() error {
|
||||
err = wait.NoError(func() error {
|
||||
txid, err := findJusticeTx()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1255,14 +1255,40 @@ func (h *HarnessTest) OpenChannelAssertErr(srcNode, destNode *node.HarnessNode,
|
||||
"error returned, want %v, got %v", expectedErr, err)
|
||||
}
|
||||
|
||||
// closeChannelOpts holds the options for closing a channel.
|
||||
type closeChannelOpts struct {
|
||||
feeRate fn.Option[chainfee.SatPerVByte]
|
||||
}
|
||||
|
||||
// CloseChanOpt is a functional option to modify the way we close a channel.
|
||||
type CloseChanOpt func(*closeChannelOpts)
|
||||
|
||||
// WithCoopCloseFeeRate is a functional option to set the fee rate for a coop
|
||||
// close attempt.
|
||||
func WithCoopCloseFeeRate(rate chainfee.SatPerVByte) CloseChanOpt {
|
||||
return func(o *closeChannelOpts) {
|
||||
o.feeRate = fn.Some(rate)
|
||||
}
|
||||
}
|
||||
|
||||
// defaultCloseOpts returns the set of default close options.
|
||||
func defaultCloseOpts() *closeChannelOpts {
|
||||
return &closeChannelOpts{}
|
||||
}
|
||||
|
||||
// CloseChannelAssertPending attempts to close the channel indicated by the
|
||||
// passed channel point, initiated by the passed node. Once the CloseChannel
|
||||
// rpc is called, it will consume one event and assert it's a close pending
|
||||
// event. In addition, it will check that the closing tx can be found in the
|
||||
// mempool.
|
||||
func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode,
|
||||
cp *lnrpc.ChannelPoint,
|
||||
force bool) (rpc.CloseChanClient, *chainhash.Hash) {
|
||||
cp *lnrpc.ChannelPoint, force bool,
|
||||
opts ...CloseChanOpt) (rpc.CloseChanClient, *lnrpc.CloseStatusUpdate) {
|
||||
|
||||
closeOpts := defaultCloseOpts()
|
||||
for _, optFunc := range opts {
|
||||
optFunc(closeOpts)
|
||||
}
|
||||
|
||||
// Calls the rpc to close the channel.
|
||||
closeReq := &lnrpc.CloseChannelRequest{
|
||||
@ -1271,10 +1297,9 @@ func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode,
|
||||
NoWait: true,
|
||||
}
|
||||
|
||||
// For coop close, we use a default confg target of 6.
|
||||
if !force {
|
||||
closeReq.TargetConf = 6
|
||||
}
|
||||
closeOpts.feeRate.WhenSome(func(feeRate chainfee.SatPerVByte) {
|
||||
closeReq.SatPerVbyte = uint64(feeRate)
|
||||
})
|
||||
|
||||
var (
|
||||
stream rpc.CloseChanClient
|
||||
@ -1307,7 +1332,7 @@ func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode,
|
||||
// Assert the closing tx is in the mempool.
|
||||
h.miner.AssertTxInMempool(closeTxid)
|
||||
|
||||
return stream, closeTxid
|
||||
return stream, event
|
||||
}
|
||||
|
||||
// CloseChannel attempts to coop close a non-anchored channel identified by the
|
||||
|
Loading…
x
Reference in New Issue
Block a user