diff --git a/lntest/harness.go b/lntest/harness.go index d0a36f6dd..4b12c8cf6 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -2282,6 +2282,28 @@ func (h *HarnessTest) SendCoins(a, b *node.HarnessNode, return tx } +// SendCoins sends all coins from node A to node B, returns the sending tx. +func (h *HarnessTest) SendAllCoins(a, b *node.HarnessNode) *wire.MsgTx { + // Create an address for Bob receive the coins. + req := &lnrpc.NewAddressRequest{ + Type: lnrpc.AddressType_TAPROOT_PUBKEY, + } + resp := b.RPC.NewAddress(req) + + // Send the coins from Alice to Bob. We should expect a tx to be + // broadcast and seen in the mempool. + sendReq := &lnrpc.SendCoinsRequest{ + Addr: resp.Address, + TargetConf: 6, + SendAll: true, + SpendUnconfirmed: true, + } + a.RPC.SendCoins(sendReq) + tx := h.GetNumTxsFromMempool(1)[0] + + return tx +} + // CreateSimpleNetwork creates the number of nodes specified by the number of // configs and makes a topology of `node1 -> node2 -> node3...`. Each node is // created using the specified config, the neighbors are connected, and the diff --git a/lntest/harness_assertion.go b/lntest/harness_assertion.go index 1b195a0a9..8cdbb4ad8 100644 --- a/lntest/harness_assertion.go +++ b/lntest/harness_assertion.go @@ -748,20 +748,12 @@ func (h *HarnessTest) WaitForGraphSync(hn *node.HarnessNode) { // AssertNumUTXOsWithConf waits for the given number of UTXOs with the // specified confirmations range to be available or fails if that isn't the // case before the default timeout. -// -// NOTE: for standby nodes(Alice and Bob), this method takes account of the -// previous state of the node's UTXOs. The previous state is snapshotted when -// finishing a previous test case via the cleanup function in `Subtest`. In -// other words, this assertion only checks the new changes made in the current -// test. func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode, expectedUtxos int, max, min int32) []*lnrpc.Utxo { var unconfirmed bool - old := hn.State.UTXO.Confirmed if max == 0 { - old = hn.State.UTXO.Unconfirmed unconfirmed = true } @@ -776,8 +768,8 @@ func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode, resp := hn.RPC.ListUnspent(req) total := len(resp.Utxos) - if total-old == expectedUtxos { - utxos = resp.Utxos[old:] + if total == expectedUtxos { + utxos = resp.Utxos return nil } @@ -787,8 +779,8 @@ func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode, desc += fmt.Sprintf("%v\n", utxo) } - return errNumNotMatched(hn.Name(), "num of UTXOs", - expectedUtxos, total-old, total, old, desc) + return fmt.Errorf("%s: assert num of UTXOs failed: want %d, "+ + "got: %d, %s", hn.Name(), expectedUtxos, total, desc) }, DefaultTimeout) require.NoError(h, err, "timeout waiting for UTXOs") @@ -797,10 +789,6 @@ func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode, // AssertNumUTXOsUnconfirmed asserts the expected num of unconfirmed utxos are // seen. -// -// NOTE: for standby nodes(Alice and Bob), this method takes account of the -// previous state of the node's UTXOs. Check `AssertNumUTXOsWithConf` for -// details. func (h *HarnessTest) AssertNumUTXOsUnconfirmed(hn *node.HarnessNode, num int) []*lnrpc.Utxo { @@ -809,10 +797,6 @@ func (h *HarnessTest) AssertNumUTXOsUnconfirmed(hn *node.HarnessNode, // AssertNumUTXOsConfirmed asserts the expected num of confirmed utxos are // seen, which means the returned utxos have at least one confirmation. -// -// NOTE: for standby nodes(Alice and Bob), this method takes account of the -// previous state of the node's UTXOs. Check `AssertNumUTXOsWithConf` for -// details. func (h *HarnessTest) AssertNumUTXOsConfirmed(hn *node.HarnessNode, num int) []*lnrpc.Utxo { @@ -821,10 +805,6 @@ func (h *HarnessTest) AssertNumUTXOsConfirmed(hn *node.HarnessNode, // AssertNumUTXOs asserts the expected num of utxos are seen, including // confirmed and unconfirmed outputs. -// -// NOTE: for standby nodes(Alice and Bob), this method takes account of the -// previous state of the node's UTXOs. Check `AssertNumUTXOsWithConf` for -// details. func (h *HarnessTest) AssertNumUTXOs(hn *node.HarnessNode, num int) []*lnrpc.Utxo {