itest: add open channel locked balance test

This commit is contained in:
Alex Akselrod 2024-02-21 09:46:33 -08:00
parent f61761277f
commit 07ba9d6015
No known key found for this signature in database
GPG Key ID: 57D7612D178AA487
2 changed files with 61 additions and 0 deletions

View File

@ -570,4 +570,8 @@ var allTestCases = []*lntest.TestCase{
Name: "coop close with htlcs",
TestFunc: testCoopCloseWithHtlcs,
},
{
Name: "open channel locked balance",
TestFunc: testOpenChannelLockedBalance,
},
}

View File

@ -14,6 +14,7 @@ import (
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/node"
"github.com/lightningnetwork/lnd/lntest/rpc"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/stretchr/testify/require"
)
@ -822,3 +823,59 @@ func testSimpleTaprootChannelActivation(ht *lntest.HarnessTest) {
// Our test is done and Alice closes her channel to Bob.
ht.CloseChannel(alice, chanPoint)
}
// testOpenChannelLockedBalance tests that when a funding reservation is
// made for opening a channel, the balance of the required outputs shows
// up as locked balance in the WalletBalance response.
func testOpenChannelLockedBalance(ht *lntest.HarnessTest) {
var (
alice = ht.Alice
bob = ht.Bob
req *lnrpc.ChannelAcceptRequest
err error
)
// We first make sure Alice has no locked wallet balance.
balance := alice.RPC.WalletBalance()
require.EqualValues(ht, 0, balance.LockedBalance)
// Next, we register a ChannelAcceptor on Bob. This way, we can get
// Alice's wallet balance after coin selection is done and outpoints
// are locked.
stream, cancel := bob.RPC.ChannelAcceptor()
defer cancel()
// Then, we request creation of a channel from Alice to Bob. We don't
// use OpenChannelSync since we want to receive Bob's message in the
// same goroutine.
openChannelReq := &lnrpc.OpenChannelRequest{
NodePubkey: bob.PubKey[:],
LocalFundingAmount: int64(funding.MaxBtcFundingAmount),
}
_ = alice.RPC.OpenChannel(openChannelReq)
// After that, we receive the request on Bob's side, get the wallet
// balance from Alice, and ensure the locked balance is non-zero.
err = wait.NoError(func() error {
req, err = stream.Recv()
return err
}, defaultTimeout)
require.NoError(ht, err)
balance = alice.RPC.WalletBalance()
require.NotEqualValues(ht, 0, balance.LockedBalance)
// Next, we let Bob deny the request.
resp := &lnrpc.ChannelAcceptResponse{
Accept: false,
PendingChanId: req.PendingChanId,
}
err = wait.NoError(func() error {
return stream.Send(resp)
}, defaultTimeout)
require.NoError(ht, err)
// Finally, we check to make sure the balance is unlocked again.
balance = alice.RPC.WalletBalance()
require.EqualValues(ht, 0, balance.LockedBalance)
}