lntest: add SendCoinsUnconfimed method
In this commit, we add a new method to the network harness that allows us to send funds to another party without confirming the transaction. This will be useful for testing funding channels with outputs that have not been confirmed yet.
This commit is contained in:
parent
0a335bbea2
commit
130124bb79
@ -1104,12 +1104,26 @@ func (n *NetworkHarness) DumpLogs(node *HarnessNode) (string, error) {
|
||||
}
|
||||
|
||||
// SendCoins attempts to send amt satoshis from the internal mining node to the
|
||||
// targeted lightning node using a P2WKH address.
|
||||
// targeted lightning node using a P2WKH address. 6 blocks are mined after in
|
||||
// order to confirm the transaction.
|
||||
func (n *NetworkHarness) SendCoins(ctx context.Context, amt btcutil.Amount,
|
||||
target *HarnessNode) error {
|
||||
|
||||
return n.sendCoins(
|
||||
ctx, amt, target, lnrpc.NewAddressRequest_WITNESS_PUBKEY_HASH,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
// SendCoinsUnconfirmed sends coins from the internal mining node to the target
|
||||
// lightning node using a P2WPKH address. No blocks are mined after, so the
|
||||
// transaction remains unconfirmed.
|
||||
func (n *NetworkHarness) SendCoinsUnconfirmed(ctx context.Context,
|
||||
amt btcutil.Amount, target *HarnessNode) error {
|
||||
|
||||
return n.sendCoins(
|
||||
ctx, amt, target, lnrpc.NewAddressRequest_WITNESS_PUBKEY_HASH,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
@ -1120,14 +1134,16 @@ func (n *NetworkHarness) SendCoinsNP2WKH(ctx context.Context,
|
||||
|
||||
return n.sendCoins(
|
||||
ctx, amt, target, lnrpc.NewAddressRequest_NESTED_PUBKEY_HASH,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
// sendCoins attempts to send amt satoshis from the internal mining node to the
|
||||
// targeted lightning node.
|
||||
// targeted lightning node. The confirmed boolean indicates whether the
|
||||
// transaction that pays to the target should confirm.
|
||||
func (n *NetworkHarness) sendCoins(ctx context.Context, amt btcutil.Amount,
|
||||
target *HarnessNode,
|
||||
addrType lnrpc.NewAddressRequest_AddressType) error {
|
||||
target *HarnessNode, addrType lnrpc.NewAddressRequest_AddressType,
|
||||
confirmed bool) error {
|
||||
|
||||
balReq := &lnrpc.WalletBalanceRequest{}
|
||||
initialBalance, err := target.WalletBalance(ctx, balReq)
|
||||
@ -1165,8 +1181,17 @@ func (n *NetworkHarness) sendCoins(ctx context.Context, amt btcutil.Amount,
|
||||
return err
|
||||
}
|
||||
|
||||
// Finally, generate 6 new blocks to ensure the output gains a
|
||||
// sufficient number of confirmations.
|
||||
// If the transaction should remain unconfirmed, then we'll wait until
|
||||
// the target node's unconfirmed balance reflects the expected balance
|
||||
// and exit.
|
||||
if !confirmed {
|
||||
expectedBalance := initialBalance.UnconfirmedBalance + int64(amt)
|
||||
return target.WaitForBalance(expectedBalance, false)
|
||||
}
|
||||
|
||||
// Otherwise, we'll generate 6 new blocks to ensure the output gains a
|
||||
// sufficient number of confirmations and wait for the balance to
|
||||
// reflect what's expected.
|
||||
if _, err := n.Miner.Node.Generate(6); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user