itest: explicit checking ChannelBalance response
This commit is contained in:
parent
f8c1bee637
commit
1b200c9930
@ -42,25 +42,48 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
commitFee := cType.calcStaticFee(0)
|
commitFee := cType.calcStaticFee(0)
|
||||||
assertBaseBalance := func() {
|
assertBaseBalance := func() {
|
||||||
balReq := &lnrpc.ChannelBalanceRequest{}
|
// Alice has opened a channel with Bob with zero push amount, so
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
// it's remote balance is zero.
|
||||||
aliceBal, err := net.Alice.ChannelBalance(ctxt, balReq)
|
expBalanceAlice := &lnrpc.ChannelBalanceResponse{
|
||||||
if err != nil {
|
LocalBalance: &lnrpc.Amount{
|
||||||
t.Fatalf("unable to get channel balance: %v", err)
|
Sat: uint64(chanAmt - commitFee),
|
||||||
|
Msat: uint64(lnwire.NewMSatFromSatoshis(
|
||||||
|
chanAmt - commitFee,
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
RemoteBalance: &lnrpc.Amount{},
|
||||||
|
UnsettledLocalBalance: &lnrpc.Amount{},
|
||||||
|
UnsettledRemoteBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenLocalBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenRemoteBalance: &lnrpc.Amount{},
|
||||||
|
// Deprecated fields.
|
||||||
|
Balance: int64(chanAmt - commitFee),
|
||||||
}
|
}
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
assertChannelBalanceResp(t, net.Alice, expBalanceAlice)
|
||||||
bobBal, err := net.Bob.ChannelBalance(ctxt, balReq)
|
|
||||||
if err != nil {
|
// Bob has a channel with Alice and another with Carol, so it's
|
||||||
t.Fatalf("unable to get channel balance: %v", err)
|
// local and remote balances are both chanAmt - commitFee.
|
||||||
}
|
expBalanceBob := &lnrpc.ChannelBalanceResponse{
|
||||||
if aliceBal.Balance != int64(chanAmt-commitFee) {
|
LocalBalance: &lnrpc.Amount{
|
||||||
t.Fatalf("alice has an incorrect balance: expected %v got %v",
|
Sat: uint64(chanAmt - commitFee),
|
||||||
int64(chanAmt-commitFee), aliceBal)
|
Msat: uint64(lnwire.NewMSatFromSatoshis(
|
||||||
}
|
chanAmt - commitFee,
|
||||||
if bobBal.Balance != int64(chanAmt-commitFee) {
|
)),
|
||||||
t.Fatalf("bob has an incorrect balance: expected %v got %v",
|
},
|
||||||
int64(chanAmt-commitFee), bobBal)
|
RemoteBalance: &lnrpc.Amount{
|
||||||
|
Sat: uint64(chanAmt - commitFee),
|
||||||
|
Msat: uint64(lnwire.NewMSatFromSatoshis(
|
||||||
|
chanAmt - commitFee,
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
UnsettledLocalBalance: &lnrpc.Amount{},
|
||||||
|
UnsettledRemoteBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenLocalBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenRemoteBalance: &lnrpc.Amount{},
|
||||||
|
// Deprecated fields.
|
||||||
|
Balance: int64(chanAmt - commitFee),
|
||||||
}
|
}
|
||||||
|
assertChannelBalanceResp(t, net.Bob, expBalanceBob)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we'd like to test some multi-hop failure scenarios, we'll
|
// Since we'd like to test some multi-hop failure scenarios, we'll
|
||||||
|
@ -301,7 +301,7 @@ func testPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to get carol's balance: %v", err)
|
t.Fatalf("unable to get carol's balance: %v", err)
|
||||||
}
|
}
|
||||||
if balRes.Balance == 0 {
|
if balRes.LocalBalance.Sat == 0 {
|
||||||
t.Fatalf("carol has an empty channel balance")
|
t.Fatalf("carol has an empty channel balance")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1096,6 +1096,23 @@ func channelCommitType(node *lntest.HarnessNode,
|
|||||||
return 0, fmt.Errorf("channel point %v not found", chanPoint)
|
return 0, fmt.Errorf("channel point %v not found", chanPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assertChannelBalanceResp makes a ChannelBalance request and checks the
|
||||||
|
// returned reponse matches the expected.
|
||||||
|
func assertChannelBalanceResp(t *harnessTest,
|
||||||
|
node *lntest.HarnessNode, expected *lnrpc.ChannelBalanceResponse) {
|
||||||
|
|
||||||
|
t.t.Helper()
|
||||||
|
|
||||||
|
ctxt, _ := context.WithTimeout(context.Background(), defaultTimeout)
|
||||||
|
req := &lnrpc.ChannelBalanceRequest{}
|
||||||
|
resp, err := node.ChannelBalance(ctxt, req)
|
||||||
|
|
||||||
|
require.NoError(t.t, err, "unable to get node's balance")
|
||||||
|
require.Equal(
|
||||||
|
t.t, expected, resp, "balance is incorrect",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// basicChannelFundingTest is a sub-test of the main testBasicChannelFunding
|
// basicChannelFundingTest is a sub-test of the main testBasicChannelFunding
|
||||||
// test. Given two nodes: Alice and Bob, it'll assert proper channel creation,
|
// test. Given two nodes: Alice and Bob, it'll assert proper channel creation,
|
||||||
// then return a function closure that should be called to assert proper
|
// then return a function closure that should be called to assert proper
|
||||||
@ -1144,33 +1161,46 @@ func basicChannelFundingTest(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
|
|
||||||
// With the channel open, ensure that the amount specified above has
|
// With the channel open, ensure that the amount specified above has
|
||||||
// properly been pushed to Bob.
|
// properly been pushed to Bob.
|
||||||
balReq := &lnrpc.ChannelBalanceRequest{}
|
aliceLocalBalance := chanAmt - pushAmt - cType.calcStaticFee(0)
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
expBalanceAlice := &lnrpc.ChannelBalanceResponse{
|
||||||
aliceBal, err := alice.ChannelBalance(ctxt, balReq)
|
LocalBalance: &lnrpc.Amount{
|
||||||
if err != nil {
|
Sat: uint64(aliceLocalBalance),
|
||||||
return nil, nil, nil, fmt.Errorf("unable to get alice's "+
|
Msat: uint64(lnwire.NewMSatFromSatoshis(
|
||||||
"balance: %v", err)
|
aliceLocalBalance,
|
||||||
}
|
)),
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
},
|
||||||
bobBal, err := bob.ChannelBalance(ctxt, balReq)
|
RemoteBalance: &lnrpc.Amount{
|
||||||
if err != nil {
|
Sat: uint64(pushAmt),
|
||||||
return nil, nil, nil, fmt.Errorf("unable to get bobs's "+
|
Msat: uint64(lnwire.NewMSatFromSatoshis(pushAmt)),
|
||||||
"balance: %v", err)
|
},
|
||||||
|
UnsettledLocalBalance: &lnrpc.Amount{},
|
||||||
|
UnsettledRemoteBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenLocalBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenRemoteBalance: &lnrpc.Amount{},
|
||||||
|
// Deprecated fields.
|
||||||
|
Balance: int64(aliceLocalBalance),
|
||||||
}
|
}
|
||||||
|
assertChannelBalanceResp(t, alice, expBalanceAlice)
|
||||||
|
|
||||||
expBalanceAlice := chanAmt - pushAmt - cType.calcStaticFee(0)
|
expBalanceBob := &lnrpc.ChannelBalanceResponse{
|
||||||
aliceBalance := btcutil.Amount(aliceBal.Balance)
|
LocalBalance: &lnrpc.Amount{
|
||||||
if aliceBalance != expBalanceAlice {
|
Sat: uint64(pushAmt),
|
||||||
return nil, nil, nil, fmt.Errorf("alice's balance is "+
|
Msat: uint64(lnwire.NewMSatFromSatoshis(pushAmt)),
|
||||||
"incorrect: expected %v got %v",
|
},
|
||||||
expBalanceAlice, aliceBalance)
|
RemoteBalance: &lnrpc.Amount{
|
||||||
}
|
Sat: uint64(aliceLocalBalance),
|
||||||
|
Msat: uint64(lnwire.NewMSatFromSatoshis(
|
||||||
bobBalance := btcutil.Amount(bobBal.Balance)
|
aliceLocalBalance,
|
||||||
if bobBalance != pushAmt {
|
)),
|
||||||
return nil, nil, nil, fmt.Errorf("bob's balance is incorrect: "+
|
},
|
||||||
"expected %v got %v", pushAmt, bobBalance)
|
UnsettledLocalBalance: &lnrpc.Amount{},
|
||||||
|
UnsettledRemoteBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenLocalBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenRemoteBalance: &lnrpc.Amount{},
|
||||||
|
// Deprecated fields.
|
||||||
|
Balance: int64(pushAmt),
|
||||||
}
|
}
|
||||||
|
assertChannelBalanceResp(t, bob, expBalanceBob)
|
||||||
|
|
||||||
req := &lnrpc.ListChannelsRequest{}
|
req := &lnrpc.ListChannelsRequest{}
|
||||||
aliceChannel, err := alice.ListChannels(context.Background(), req)
|
aliceChannel, err := alice.ListChannels(context.Background(), req)
|
||||||
@ -1422,25 +1452,48 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// With the channel open, we'll check the balances on each side of the
|
// With the channel open, we'll check the balances on each side of the
|
||||||
// channel as a sanity check to ensure things worked out as intended.
|
// channel as a sanity check to ensure things worked out as intended.
|
||||||
balReq := &lnrpc.ChannelBalanceRequest{}
|
carolLocalBalance := chanAmt - pushAmt - cType.calcStaticFee(0)
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
expBalanceCarol := &lnrpc.ChannelBalanceResponse{
|
||||||
carolBal, err := carol.ChannelBalance(ctxt, balReq)
|
LocalBalance: &lnrpc.Amount{
|
||||||
if err != nil {
|
Sat: uint64(carolLocalBalance),
|
||||||
t.Fatalf("unable to get carol's balance: %v", err)
|
Msat: uint64(lnwire.NewMSatFromSatoshis(
|
||||||
|
carolLocalBalance,
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
RemoteBalance: &lnrpc.Amount{
|
||||||
|
Sat: uint64(pushAmt),
|
||||||
|
Msat: uint64(lnwire.NewMSatFromSatoshis(
|
||||||
|
pushAmt,
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
UnsettledLocalBalance: &lnrpc.Amount{},
|
||||||
|
UnsettledRemoteBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenLocalBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenRemoteBalance: &lnrpc.Amount{},
|
||||||
|
// Deprecated fields.
|
||||||
|
Balance: int64(carolLocalBalance),
|
||||||
}
|
}
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
assertChannelBalanceResp(t, carol, expBalanceCarol)
|
||||||
aliceBal, err := net.Alice.ChannelBalance(ctxt, balReq)
|
|
||||||
if err != nil {
|
expBalanceAlice := &lnrpc.ChannelBalanceResponse{
|
||||||
t.Fatalf("unable to get alice's balance: %v", err)
|
LocalBalance: &lnrpc.Amount{
|
||||||
}
|
Sat: uint64(pushAmt),
|
||||||
if carolBal.Balance != int64(chanAmt-pushAmt-cType.calcStaticFee(0)) {
|
Msat: uint64(lnwire.NewMSatFromSatoshis(pushAmt)),
|
||||||
t.Fatalf("carol's balance is incorrect: expected %v got %v",
|
},
|
||||||
chanAmt-pushAmt-cType.calcStaticFee(0), carolBal)
|
RemoteBalance: &lnrpc.Amount{
|
||||||
}
|
Sat: uint64(carolLocalBalance),
|
||||||
if aliceBal.Balance != int64(pushAmt) {
|
Msat: uint64(lnwire.NewMSatFromSatoshis(
|
||||||
t.Fatalf("alice's balance is incorrect: expected %v got %v",
|
carolLocalBalance,
|
||||||
pushAmt, aliceBal.Balance)
|
)),
|
||||||
|
},
|
||||||
|
UnsettledLocalBalance: &lnrpc.Amount{},
|
||||||
|
UnsettledRemoteBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenLocalBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenRemoteBalance: &lnrpc.Amount{},
|
||||||
|
// Deprecated fields.
|
||||||
|
Balance: int64(pushAmt),
|
||||||
}
|
}
|
||||||
|
assertChannelBalanceResp(t, net.Alice, expBalanceAlice)
|
||||||
|
|
||||||
// Now that we're done with the test, the channel can be closed.
|
// Now that we're done with the test, the channel can be closed.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||||
@ -2858,8 +2911,8 @@ func findTxAtHeight(ctx context.Context, t *harnessTest, height int32,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// testChannelBalance creates a new channel between Alice and Bob, then
|
// testChannelBalance creates a new channel between Alice and Bob, then checks
|
||||||
// checks channel balance to be equal amount specified while creation of channel.
|
// channel balance to be equal amount specified while creation of channel.
|
||||||
func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
ctxb := context.Background()
|
ctxb := context.Background()
|
||||||
|
|
||||||
@ -2869,20 +2922,28 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Creates a helper closure to be used below which asserts the proper
|
// Creates a helper closure to be used below which asserts the proper
|
||||||
// response to a channel balance RPC.
|
// response to a channel balance RPC.
|
||||||
checkChannelBalance := func(node lnrpc.LightningClient,
|
checkChannelBalance := func(node *lntest.HarnessNode,
|
||||||
amount btcutil.Amount) {
|
local, remote btcutil.Amount) {
|
||||||
|
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
expectedResponse := &lnrpc.ChannelBalanceResponse{
|
||||||
response, err := node.ChannelBalance(ctxt, &lnrpc.ChannelBalanceRequest{})
|
LocalBalance: &lnrpc.Amount{
|
||||||
if err != nil {
|
Sat: uint64(local),
|
||||||
t.Fatalf("unable to get channel balance: %v", err)
|
Msat: uint64(lnwire.NewMSatFromSatoshis(local)),
|
||||||
}
|
},
|
||||||
|
RemoteBalance: &lnrpc.Amount{
|
||||||
balance := btcutil.Amount(response.Balance)
|
Sat: uint64(remote),
|
||||||
if balance != amount {
|
Msat: uint64(lnwire.NewMSatFromSatoshis(
|
||||||
t.Fatalf("channel balance wrong: %v != %v", balance,
|
remote,
|
||||||
amount)
|
)),
|
||||||
|
},
|
||||||
|
UnsettledLocalBalance: &lnrpc.Amount{},
|
||||||
|
UnsettledRemoteBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenLocalBalance: &lnrpc.Amount{},
|
||||||
|
PendingOpenRemoteBalance: &lnrpc.Amount{},
|
||||||
|
// Deprecated fields.
|
||||||
|
Balance: int64(local),
|
||||||
}
|
}
|
||||||
|
assertChannelBalanceResp(t, node, expectedResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before beginning, make sure alice and bob are connected.
|
// Before beginning, make sure alice and bob are connected.
|
||||||
@ -2920,10 +2981,10 @@ func testChannelBalance(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// As this is a single funder channel, Alice's balance should be
|
// As this is a single funder channel, Alice's balance should be
|
||||||
// exactly 0.5 BTC since now state transitions have taken place yet.
|
// exactly 0.5 BTC since now state transitions have taken place yet.
|
||||||
checkChannelBalance(net.Alice, amount-cType.calcStaticFee(0))
|
checkChannelBalance(net.Alice, amount-cType.calcStaticFee(0), 0)
|
||||||
|
|
||||||
// Ensure Bob currently has no available balance within the channel.
|
// Ensure Bob currently has no available balance within the channel.
|
||||||
checkChannelBalance(net.Bob, 0)
|
checkChannelBalance(net.Bob, 0, amount-cType.calcStaticFee(0))
|
||||||
|
|
||||||
// Finally close the channel between Alice and Bob, asserting that the
|
// Finally close the channel between Alice and Bob, asserting that the
|
||||||
// channel has been properly closed on-chain.
|
// channel has been properly closed on-chain.
|
||||||
@ -9154,10 +9215,10 @@ func testRevokedCloseRetributionAltruistWatchtower(net *lntest.NetworkHarness,
|
|||||||
t.Fatalf("unable to get dave's balance: %v", err)
|
t.Fatalf("unable to get dave's balance: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if daveBalResp.Balance != 0 {
|
if daveBalResp.LocalBalance.Sat != 0 {
|
||||||
predErr = fmt.Errorf("Dave should end up with zero "+
|
predErr = fmt.Errorf("Dave should end up with zero "+
|
||||||
"channel balance, instead has %d",
|
"channel balance, instead has %d",
|
||||||
daveBalResp.Balance)
|
daveBalResp.LocalBalance.Sat)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user