lntest/lnd test: make OpenChannel take channel param struct
Also add option for setting min_htlc value on channel creation.
This commit is contained in:
2 files changed
+368
-91
No files matched your search
+31
-9
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
// NetworkHarness is an integration testing harness for the lightning network.
|
||||
@@ -687,15 +688,35 @@ func (n *NetworkHarness) WaitForTxBroadcast(ctx context.Context, txid chainhash.
|
||||
}
|
||||
}
|
||||
|
||||
// OpenChannelParams houses the params to specify when opening a new channel.
|
||||
type OpenChannelParams struct {
|
||||
// Amt is the local amount being put into the channel.
|
||||
Amt btcutil.Amount
|
||||
|
||||
// PushAmt is the amount that should be pushed to the remote when the
|
||||
// channel is opened.
|
||||
PushAmt btcutil.Amount
|
||||
|
||||
// Private is a boolan indicating whether the opened channel should be
|
||||
// private.
|
||||
Private bool
|
||||
|
||||
// SpendUnconfirmed is a boolean indicating whether we can utilize
|
||||
// unconfirmed outputs to fund the channel.
|
||||
SpendUnconfirmed bool
|
||||
|
||||
// MinHtlc is the htlc_minumum_msat value set when opening the channel.
|
||||
MinHtlc lnwire.MilliSatoshi
|
||||
}
|
||||
|
||||
// OpenChannel attempts to open a channel between srcNode and destNode with the
|
||||
// passed channel funding parameters. If the passed context has a timeout, then
|
||||
// if the timeout is reached before the channel pending notification is
|
||||
// received, an error is returned. The confirmed boolean determines whether we
|
||||
// should fund the channel with confirmed outputs or not.
|
||||
func (n *NetworkHarness) OpenChannel(ctx context.Context,
|
||||
srcNode, destNode *HarnessNode, amt btcutil.Amount,
|
||||
pushAmt btcutil.Amount,
|
||||
private, confirmed bool) (lnrpc.Lightning_OpenChannelClient, error) {
|
||||
srcNode, destNode *HarnessNode, p OpenChannelParams) (
|
||||
lnrpc.Lightning_OpenChannelClient, error) {
|
||||
|
||||
// Wait until srcNode and destNode have the latest chain synced.
|
||||
// Otherwise, we may run into a check within the funding manager that
|
||||
@@ -708,17 +729,18 @@ func (n *NetworkHarness) OpenChannel(ctx context.Context,
|
||||
return nil, fmt.Errorf("Unable to sync destNode chain: %v", err)
|
||||
}
|
||||
|
||||
minConfs := int32(0)
|
||||
if confirmed {
|
||||
minConfs = 1
|
||||
minConfs := int32(1)
|
||||
if p.SpendUnconfirmed {
|
||||
minConfs = 0
|
||||
}
|
||||
|
||||
openReq := &lnrpc.OpenChannelRequest{
|
||||
NodePubkey: destNode.PubKey[:],
|
||||
LocalFundingAmount: int64(amt),
|
||||
PushSat: int64(pushAmt),
|
||||
Private: private,
|
||||
LocalFundingAmount: int64(p.Amt),
|
||||
PushSat: int64(p.PushAmt),
|
||||
Private: p.Private,
|
||||
MinConfs: minConfs,
|
||||
MinHtlcMsat: int64(p.MinHtlc),
|
||||
}
|
||||
|
||||
respStream, err := srcNode.OpenChannel(ctx, openReq)
|
||||
|
||||
Reference in new issue
Block a user