itest: fix wrong node queried for balance

This commit is contained in:
yyforyongyu 2021-06-01 16:50:44 +08:00
parent 23baa75c09
commit a60db53a5a
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868

View File

@ -3546,6 +3546,15 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
err) err)
} }
// Calculate the total fee Carol paid.
var totalFeeCarol btcutil.Amount
for _, tx := range sweepTxns {
fee, err := getTxFee(net.Miner.Client, tx)
require.NoError(t.t, err)
totalFeeCarol += fee
}
// We look up the sweep txns we have found in mempool and create // We look up the sweep txns we have found in mempool and create
// expected resolutions for carol. // expected resolutions for carol.
carolCommit, carolAnchor := findCommitAndAnchor( carolCommit, carolAnchor := findCommitAndAnchor(
@ -3651,7 +3660,9 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
// At this point, the CSV will expire in the next block, meaning that // At this point, the CSV will expire in the next block, meaning that
// the sweeping transaction should now be broadcast. So we fetch the // the sweeping transaction should now be broadcast. So we fetch the
// node's mempool to ensure it has been properly broadcast. // node's mempool to ensure it has been properly broadcast.
sweepingTXID, err := waitForTxInMempool(net.Miner.Client, minerMempoolTimeout) sweepingTXID, err := waitForTxInMempool(
net.Miner.Client, minerMempoolTimeout,
)
if err != nil { if err != nil {
t.Fatalf("failed to get sweep tx from mempool: %v", err) t.Fatalf("failed to get sweep tx from mempool: %v", err)
} }
@ -4227,21 +4238,30 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
t.Fatalf(predErr.Error()) t.Fatalf(predErr.Error())
} }
// At this point, Bob should now be aware of his new immediately // At this point, Carol should now be aware of her new immediately
// spendable on-chain balance, as it was Alice who broadcast the // spendable on-chain balance, as it was Alice who broadcast the
// commitment transaction. // commitment transaction.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
carolBalResp, err = net.Bob.WalletBalance(ctxt, carolBalReq) carolBalResp, err = carol.WalletBalance(ctxt, carolBalReq)
if err != nil { require.NoError(t.t, err, "unable to get carol's balance")
t.Fatalf("unable to get carol's balance: %v", err)
} // Carol's expected balance should be its starting balance plus the
carolExpectedBalance := btcutil.Amount(carolStartingBalance) + pushAmt // push amount sent by Alice and minus the miner fee paid.
if btcutil.Amount(carolBalResp.ConfirmedBalance) < carolExpectedBalance { carolExpectedBalance := btcutil.Amount(carolStartingBalance) +
t.Fatalf("carol's balance is incorrect: expected %v got %v", pushAmt - totalFeeCarol
carolExpectedBalance,
carolBalResp.ConfirmedBalance) // In addition, if this is an anchor-enabled channel, further add the
// anchor size.
if channelType == commitTypeAnchors {
carolExpectedBalance += btcutil.Amount(anchorSize)
} }
require.Equal(
t.t, carolExpectedBalance,
btcutil.Amount(carolBalResp.ConfirmedBalance),
"carol's balance is incorrect",
)
// Finally, we check that alice and carol have the set of resolutions // Finally, we check that alice and carol have the set of resolutions
// we expect. // we expect.
assertReports(ctxb, t, alice, op, aliceReports) assertReports(ctxb, t, alice, op, aliceReports)