itest+lntest: fix flake in testListSweeps
We now make sure we assert the `ListSweeps` results in a wait closure.
This commit is contained in:
4 files changed
+76
-21
No files matched your search
+20
-14
@@ -868,27 +868,33 @@ func testListSweeps(ht *lntest.HarnessTest) {
|
|||||||
ht.AssertNumTxsInMempool(1)
|
ht.AssertNumTxsInMempool(1)
|
||||||
|
|
||||||
// List all unconfirmed sweeps that alice's node had broadcast.
|
// List all unconfirmed sweeps that alice's node had broadcast.
|
||||||
sweepResp := alice.RPC.ListSweeps(false, -1)
|
req1 := &walletrpc.ListSweepsRequest{
|
||||||
txIDs := sweepResp.GetTransactionIds().TransactionIds
|
Verbose: false,
|
||||||
require.Lenf(ht, txIDs, 1, "number of pending sweeps, starting from "+
|
StartHeight: -1,
|
||||||
"height -1")
|
}
|
||||||
|
ht.AssertNumSweeps(alice, req1, 1)
|
||||||
|
|
||||||
// Now list sweeps from the closing of the first channel. We should
|
// Now list sweeps from the closing of the first channel. We should
|
||||||
// only see the sweep from the second channel and the pending one.
|
// only see the sweep from the second channel and the pending one.
|
||||||
sweepResp = alice.RPC.ListSweeps(false, blockHeight)
|
req2 := &walletrpc.ListSweepsRequest{
|
||||||
txIDs = sweepResp.GetTransactionIds().TransactionIds
|
Verbose: false,
|
||||||
require.Lenf(ht, txIDs, 2, "number of sweeps, starting from height %d",
|
StartHeight: blockHeight,
|
||||||
blockHeight)
|
}
|
||||||
|
ht.AssertNumSweeps(alice, req2, 2)
|
||||||
|
|
||||||
// Finally list all sweeps from the closing of the second channel. We
|
// Finally list all sweeps from the closing of the second channel. We
|
||||||
// should see all sweeps, including the pending one.
|
// should see all sweeps, including the pending one.
|
||||||
sweepResp = alice.RPC.ListSweeps(false, 0)
|
req3 := &walletrpc.ListSweepsRequest{
|
||||||
txIDs = sweepResp.GetTransactionIds().TransactionIds
|
Verbose: false,
|
||||||
require.Lenf(ht, txIDs, 3, "number of sweeps, starting from height 0")
|
StartHeight: 0,
|
||||||
|
}
|
||||||
|
ht.AssertNumSweeps(alice, req3, 3)
|
||||||
|
|
||||||
// Mine the pending sweep and make sure it is no longer returned.
|
// Mine the pending sweep and make sure it is no longer returned.
|
||||||
ht.MineBlocksAndAssertNumTxes(1, 1)
|
ht.MineBlocksAndAssertNumTxes(1, 1)
|
||||||
sweepResp = alice.RPC.ListSweeps(false, -1)
|
req4 := &walletrpc.ListSweepsRequest{
|
||||||
txIDs = sweepResp.GetTransactionIds().TransactionIds
|
Verbose: false,
|
||||||
require.Empty(ht, txIDs, "pending sweep should not be returned")
|
StartHeight: -1,
|
||||||
|
}
|
||||||
|
ht.AssertNumSweeps(alice, req4, 0)
|
||||||
}
|
}
|
||||||
+6
-1
@@ -2059,9 +2059,14 @@ func (h *HarnessTest) CalculateTxesFeeRate(txns []*wire.MsgTx) int64 {
|
|||||||
func (h *HarnessTest) AssertSweepFound(hn *node.HarnessNode,
|
func (h *HarnessTest) AssertSweepFound(hn *node.HarnessNode,
|
||||||
sweep string, verbose bool, startHeight int32) {
|
sweep string, verbose bool, startHeight int32) {
|
||||||
|
|
||||||
|
req := &walletrpc.ListSweepsRequest{
|
||||||
|
Verbose: verbose,
|
||||||
|
StartHeight: startHeight,
|
||||||
|
}
|
||||||
|
|
||||||
err := wait.NoError(func() error {
|
err := wait.NoError(func() error {
|
||||||
// List all sweeps that alice's node had broadcast.
|
// List all sweeps that alice's node had broadcast.
|
||||||
sweepResp := hn.RPC.ListSweeps(verbose, startHeight)
|
sweepResp := hn.RPC.ListSweeps(req)
|
||||||
|
|
||||||
var found bool
|
var found bool
|
||||||
if verbose {
|
if verbose {
|
||||||
|
|||||||
@@ -2817,6 +2817,54 @@ func (h *HarnessTest) AssertAtLeastNumPendingSweeps(hn *node.HarnessNode,
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssertNumSweeps asserts the number of sweeps for the given node.
|
||||||
|
func (h *HarnessTest) AssertNumSweeps(hn *node.HarnessNode,
|
||||||
|
req *walletrpc.ListSweepsRequest,
|
||||||
|
n int) *walletrpc.ListSweepsResponse {
|
||||||
|
|
||||||
|
var result *walletrpc.ListSweepsResponse
|
||||||
|
|
||||||
|
// The ListSweeps call is wrapped in wait.NoError to handle potential
|
||||||
|
// timing issues. Sweep transactions might not be immediately reflected
|
||||||
|
// or processed by the node after an event (e.g., channel closure or
|
||||||
|
// block mining) due to propagation or processing delays. This ensures
|
||||||
|
// the system retries the call until the expected sweep is found,
|
||||||
|
// preventing test flakes caused by race conditions.
|
||||||
|
err := wait.NoError(func() error {
|
||||||
|
resp := hn.RPC.ListSweeps(req)
|
||||||
|
|
||||||
|
var txIDs []string
|
||||||
|
if req.Verbose {
|
||||||
|
details := resp.GetTransactionDetails()
|
||||||
|
if details != nil {
|
||||||
|
for _, tx := range details.Transactions {
|
||||||
|
txIDs = append(txIDs, tx.TxHash)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ids := resp.GetTransactionIds()
|
||||||
|
if ids != nil {
|
||||||
|
txIDs = ids.TransactionIds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
num := len(txIDs)
|
||||||
|
|
||||||
|
// Exit early if the num matches.
|
||||||
|
if num == n {
|
||||||
|
result = resp
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("want %d, got %d, sweeps: %v, req: %v", n,
|
||||||
|
num, txIDs, req)
|
||||||
|
}, DefaultTimeout)
|
||||||
|
|
||||||
|
require.NoErrorf(h, err, "%s: check num of sweeps timeout", hn.Name())
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// FindSweepingTxns asserts the expected number of sweeping txns are found in
|
// FindSweepingTxns asserts the expected number of sweeping txns are found in
|
||||||
// the txns specified and return them.
|
// the txns specified and return them.
|
||||||
func (h *HarnessTest) FindSweepingTxns(txns []*wire.MsgTx,
|
func (h *HarnessTest) FindSweepingTxns(txns []*wire.MsgTx,
|
||||||
|
|||||||
@@ -169,16 +169,12 @@ func (h *HarnessRPC) VerifyMessageWithAddr(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListSweeps makes a ListSweeps RPC call to the node's WalletKit client.
|
// ListSweeps makes a ListSweeps RPC call to the node's WalletKit client.
|
||||||
func (h *HarnessRPC) ListSweeps(verbose bool,
|
func (h *HarnessRPC) ListSweeps(
|
||||||
startHeight int32) *walletrpc.ListSweepsResponse {
|
req *walletrpc.ListSweepsRequest) *walletrpc.ListSweepsResponse {
|
||||||
|
|
||||||
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
|
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
req := &walletrpc.ListSweepsRequest{
|
|
||||||
Verbose: verbose,
|
|
||||||
StartHeight: startHeight,
|
|
||||||
}
|
|
||||||
resp, err := h.WalletKit.ListSweeps(ctxt, req)
|
resp, err := h.WalletKit.ListSweeps(ctxt, req)
|
||||||
h.NoError(err, "ListSweeps")
|
h.NoError(err, "ListSweeps")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user