mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-11 01:11:02 +02:00
lntest: add SendAllCoins
and remove standby nodes context
Standby nodes are no longer used so we update `AssertNumUTXOs` to remove the confusing check.
This commit is contained in:
parent
06f1ef47fa
commit
0daadb05bf
@ -2282,6 +2282,28 @@ func (h *HarnessTest) SendCoins(a, b *node.HarnessNode,
|
|||||||
return tx
|
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
|
// CreateSimpleNetwork creates the number of nodes specified by the number of
|
||||||
// configs and makes a topology of `node1 -> node2 -> node3...`. Each node is
|
// configs and makes a topology of `node1 -> node2 -> node3...`. Each node is
|
||||||
// created using the specified config, the neighbors are connected, and the
|
// created using the specified config, the neighbors are connected, and the
|
||||||
|
@ -748,20 +748,12 @@ func (h *HarnessTest) WaitForGraphSync(hn *node.HarnessNode) {
|
|||||||
// AssertNumUTXOsWithConf waits for the given number of UTXOs with the
|
// AssertNumUTXOsWithConf waits for the given number of UTXOs with the
|
||||||
// specified confirmations range to be available or fails if that isn't the
|
// specified confirmations range to be available or fails if that isn't the
|
||||||
// case before the default timeout.
|
// 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,
|
func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode,
|
||||||
expectedUtxos int, max, min int32) []*lnrpc.Utxo {
|
expectedUtxos int, max, min int32) []*lnrpc.Utxo {
|
||||||
|
|
||||||
var unconfirmed bool
|
var unconfirmed bool
|
||||||
|
|
||||||
old := hn.State.UTXO.Confirmed
|
|
||||||
if max == 0 {
|
if max == 0 {
|
||||||
old = hn.State.UTXO.Unconfirmed
|
|
||||||
unconfirmed = true
|
unconfirmed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -776,8 +768,8 @@ func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode,
|
|||||||
resp := hn.RPC.ListUnspent(req)
|
resp := hn.RPC.ListUnspent(req)
|
||||||
total := len(resp.Utxos)
|
total := len(resp.Utxos)
|
||||||
|
|
||||||
if total-old == expectedUtxos {
|
if total == expectedUtxos {
|
||||||
utxos = resp.Utxos[old:]
|
utxos = resp.Utxos
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -787,8 +779,8 @@ func (h *HarnessTest) AssertNumUTXOsWithConf(hn *node.HarnessNode,
|
|||||||
desc += fmt.Sprintf("%v\n", utxo)
|
desc += fmt.Sprintf("%v\n", utxo)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errNumNotMatched(hn.Name(), "num of UTXOs",
|
return fmt.Errorf("%s: assert num of UTXOs failed: want %d, "+
|
||||||
expectedUtxos, total-old, total, old, desc)
|
"got: %d, %s", hn.Name(), expectedUtxos, total, desc)
|
||||||
}, DefaultTimeout)
|
}, DefaultTimeout)
|
||||||
require.NoError(h, err, "timeout waiting for UTXOs")
|
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
|
// AssertNumUTXOsUnconfirmed asserts the expected num of unconfirmed utxos are
|
||||||
// seen.
|
// 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,
|
func (h *HarnessTest) AssertNumUTXOsUnconfirmed(hn *node.HarnessNode,
|
||||||
num int) []*lnrpc.Utxo {
|
num int) []*lnrpc.Utxo {
|
||||||
|
|
||||||
@ -809,10 +797,6 @@ func (h *HarnessTest) AssertNumUTXOsUnconfirmed(hn *node.HarnessNode,
|
|||||||
|
|
||||||
// AssertNumUTXOsConfirmed asserts the expected num of confirmed utxos are
|
// AssertNumUTXOsConfirmed asserts the expected num of confirmed utxos are
|
||||||
// seen, which means the returned utxos have at least one confirmation.
|
// 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,
|
func (h *HarnessTest) AssertNumUTXOsConfirmed(hn *node.HarnessNode,
|
||||||
num int) []*lnrpc.Utxo {
|
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
|
// AssertNumUTXOs asserts the expected num of utxos are seen, including
|
||||||
// confirmed and unconfirmed outputs.
|
// 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,
|
func (h *HarnessTest) AssertNumUTXOs(hn *node.HarnessNode,
|
||||||
num int) []*lnrpc.Utxo {
|
num int) []*lnrpc.Utxo {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user