mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-03 10:12:28 +02:00
multi: move many t.Fatalf calls to require.NoError
This commit is contained in:
@@ -132,9 +132,7 @@ func assertProperBalance(t *testing.T, lw *lnwallet.LightningWallet,
|
||||
numConfirms int32, amount float64) {
|
||||
|
||||
balance, err := lw.ConfirmedBalance(numConfirms, lnwallet.DefaultAccountName)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for balance: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for balance")
|
||||
if balance.ToBTC() != amount {
|
||||
t.Fatalf("wallet credits not properly loaded, should have 40BTC, "+
|
||||
"instead have %v", balance)
|
||||
@@ -161,9 +159,7 @@ func mineAndAssertTxInBlock(t *testing.T, miner *rpctest.Harness,
|
||||
|
||||
// We'll mined a block to confirm it.
|
||||
blockHashes, err := miner.Client.Generate(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate new block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate new block")
|
||||
|
||||
// Finally, we'll check it was actually mined in this block.
|
||||
block, err := miner.Client.GetBlock(blockHashes[0])
|
||||
@@ -188,13 +184,9 @@ func newPkScript(t *testing.T, w *lnwallet.LightningWallet,
|
||||
t.Helper()
|
||||
|
||||
addr, err := w.NewAddress(addrType, false, lnwallet.DefaultAccountName)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new address: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create new address")
|
||||
pkScript, err := txscript.PayToAddrScript(addr)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create output script: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create output script")
|
||||
|
||||
return pkScript
|
||||
}
|
||||
@@ -210,9 +202,7 @@ func sendCoins(t *testing.T, miner *rpctest.Harness,
|
||||
tx, err := sender.SendOutputs(
|
||||
[]*wire.TxOut{output}, feeRate, minConf, labels.External,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send transaction: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to send transaction")
|
||||
|
||||
if mineBlock {
|
||||
mineAndAssertTxInBlock(t, miner, tx.TxHash())
|
||||
@@ -239,9 +229,7 @@ func assertTxInWallet(t *testing.T, w *lnwallet.LightningWallet,
|
||||
// finding the expected transaction with its expected confirmation
|
||||
// status.
|
||||
txs, err := w.ListTransactionDetails(0, btcwallet.UnconfirmedHeight, "")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve transactions: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve transactions")
|
||||
for _, tx := range txs {
|
||||
if tx.Hash != txHash {
|
||||
continue
|
||||
@@ -445,9 +433,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
alice, bob *lnwallet.LightningWallet, t *testing.T) {
|
||||
|
||||
fundingAmount, err := btcutil.NewAmount(5)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create amt: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create amt")
|
||||
|
||||
// In this scenario, we'll test a dual funder reservation, with each
|
||||
// side putting in 10 BTC.
|
||||
@@ -455,9 +441,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
// Alice initiates a channel funded with 5 BTC for each side, so 10 BTC
|
||||
// total. She also generates 2 BTC in change.
|
||||
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query fee estimator")
|
||||
aliceReq := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
@@ -470,9 +454,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
aliceChanReservation, err := alice.InitChannelReservation(aliceReq)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to initialize funding reservation: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to initialize funding reservation")
|
||||
aliceChanReservation.SetNumConfsRequired(numReqConfs)
|
||||
channelConstraints := &channeldb.ChannelConstraints{
|
||||
DustLimit: alice.Cfg.DefaultConstraints.DustLimit,
|
||||
@@ -485,9 +467,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
err = aliceChanReservation.CommitConstraints(
|
||||
channelConstraints, defaultMaxLocalCsvDelay, false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to verify constraints: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to verify constraints")
|
||||
|
||||
// The channel reservation should now be populated with a multi-sig key
|
||||
// from our HD chain, a change output with 3 BTC, and 2 outputs
|
||||
@@ -515,23 +495,17 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
bobChanReservation, err := bob.InitChannelReservation(bobReq)
|
||||
if err != nil {
|
||||
t.Fatalf("bob unable to init channel reservation: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "bob unable to init channel reservation")
|
||||
err = bobChanReservation.CommitConstraints(
|
||||
channelConstraints, defaultMaxLocalCsvDelay, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to verify constraints: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to verify constraints")
|
||||
bobChanReservation.SetNumConfsRequired(numReqConfs)
|
||||
|
||||
assertContributionInitPopulated(t, bobChanReservation.OurContribution())
|
||||
|
||||
err = bobChanReservation.ProcessContribution(aliceContribution)
|
||||
if err != nil {
|
||||
t.Fatalf("bob unable to process alice's contribution: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "bob unable to process alice's contribution")
|
||||
assertContributionInitPopulated(t, bobChanReservation.TheirContribution())
|
||||
|
||||
bobContribution := bobChanReservation.OurContribution()
|
||||
@@ -541,9 +515,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
// material required to craft the funding transaction and commitment
|
||||
// transactions.
|
||||
err = aliceChanReservation.ProcessContribution(bobContribution)
|
||||
if err != nil {
|
||||
t.Fatalf("alice unable to process bob's contribution: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "alice unable to process bob's contribution")
|
||||
assertContributionInitPopulated(t, aliceChanReservation.TheirContribution())
|
||||
|
||||
// At this point, all Alice's signatures should be fully populated.
|
||||
@@ -578,9 +550,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
_, err = bobChanReservation.CompleteReservation(
|
||||
aliceFundingSigs, aliceCommitSig,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to consume bob's sigs: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to consume bob's sigs")
|
||||
|
||||
// At this point, the funding tx should have been populated.
|
||||
fundingTx := aliceChanReservation.FinalFundingTx()
|
||||
@@ -592,9 +562,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
// DB.
|
||||
fundingSha := fundingTx.TxHash()
|
||||
aliceChannels, err := alice.Cfg.Database.FetchOpenChannels(bobPub)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve channel from DB: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve channel from DB")
|
||||
if !bytes.Equal(aliceChannels[0].FundingOutpoint.Hash[:], fundingSha[:]) {
|
||||
t.Fatalf("channel state not properly saved")
|
||||
}
|
||||
@@ -602,9 +570,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
t.Fatalf("channel not detected as dual funder")
|
||||
}
|
||||
bobChannels, err := bob.Cfg.Database.FetchOpenChannels(alicePub)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve channel from DB: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve channel from DB")
|
||||
if !bytes.Equal(bobChannels[0].FundingOutpoint.Hash[:], fundingSha[:]) {
|
||||
t.Fatalf("channel state not properly saved")
|
||||
}
|
||||
@@ -614,24 +580,16 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
|
||||
// Let Alice publish the funding transaction.
|
||||
err = alice.PublishTransaction(fundingTx, "")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish funding tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to publish funding tx")
|
||||
|
||||
// Mine a single block, the funding transaction should be included
|
||||
// within this block.
|
||||
err = waitForMempoolTx(miner, &fundingSha)
|
||||
if err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "tx not relayed to miner")
|
||||
blockHashes, err := miner.Client.Generate(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate block")
|
||||
block, err := miner.Client.GetBlock(blockHashes[0])
|
||||
if err != nil {
|
||||
t.Fatalf("unable to find block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to find block")
|
||||
if len(block.Transactions) != 2 {
|
||||
t.Fatalf("funding transaction wasn't mined: %v", err)
|
||||
}
|
||||
@@ -645,13 +603,9 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
|
||||
// Wait for wallets to catch up to prevent issues in subsequent tests.
|
||||
err = waitForWalletSync(miner, alice)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to sync alice: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to sync alice")
|
||||
err = waitForWalletSync(miner, bob)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to sync bob: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to sync bob")
|
||||
}
|
||||
|
||||
func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
|
||||
@@ -659,13 +613,9 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
|
||||
|
||||
// Create a single channel asking for 16 BTC total.
|
||||
fundingAmount, err := btcutil.NewAmount(8)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create amt: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create amt")
|
||||
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query fee estimator")
|
||||
req := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
@@ -686,9 +636,7 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
|
||||
// requesting 900 BTC. We only have around 64BTC worth of outpoints
|
||||
// that aren't locked, so this should fail.
|
||||
amt, err := btcutil.NewAmount(900)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create amt: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create amt")
|
||||
failedReq := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
@@ -717,15 +665,11 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
|
||||
alice, _ *lnwallet.LightningWallet, t *testing.T) {
|
||||
|
||||
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query fee estimator")
|
||||
|
||||
// Create a reservation for 44 BTC.
|
||||
fundingAmount, err := btcutil.NewAmount(44)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create amt: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create amt")
|
||||
req := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
@@ -739,9 +683,7 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
|
||||
PendingChanID: [32]byte{2, 3, 4, 5},
|
||||
}
|
||||
chanReservation, err := alice.InitChannelReservation(req)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to initialize funding reservation: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to initialize funding reservation")
|
||||
|
||||
// Attempt to create another channel with 44 BTC, this should fail.
|
||||
req.PendingChanID = [32]byte{3, 4, 5, 6}
|
||||
@@ -784,9 +726,7 @@ func testCancelNonExistentReservation(miner *rpctest.Harness,
|
||||
alice, _ *lnwallet.LightningWallet, t *testing.T) {
|
||||
|
||||
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query fee estimator")
|
||||
|
||||
// Create our own reservation, give it some ID.
|
||||
res, err := lnwallet.NewChannelReservation(
|
||||
@@ -794,9 +734,7 @@ func testCancelNonExistentReservation(miner *rpctest.Harness,
|
||||
lnwire.FFAnnounceChannel, lnwallet.CommitmentTypeTweakless,
|
||||
nil, [32]byte{}, 0,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create res: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create res")
|
||||
|
||||
// Attempt to cancel this reservation. This should fail, we know
|
||||
// nothing of it.
|
||||
@@ -813,9 +751,7 @@ func testReservationInitiatorBalanceBelowDustCancel(miner *rpctest.Harness,
|
||||
// and result in a failure to create the reservation.
|
||||
const numBTC = 4
|
||||
fundingAmount, err := btcutil.NewAmount(numBTC)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create amt: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create amt")
|
||||
|
||||
feePerKw := chainfee.SatPerKWeight(
|
||||
numBTC * numBTC * btcutil.SatoshiPerBitcoin,
|
||||
@@ -897,14 +833,10 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
// funded solely by us. We'll also initially push 1 BTC of the channel
|
||||
// towards Bob's side.
|
||||
fundingAmt, err := btcutil.NewAmount(4)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create amt: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create amt")
|
||||
pushAmt := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
|
||||
feePerKw, err := alice.Cfg.FeeEstimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query fee estimator")
|
||||
aliceReq := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
PendingChanID: pendingChanID,
|
||||
@@ -920,9 +852,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
ChanFunder: aliceChanFunder,
|
||||
}
|
||||
aliceChanReservation, err := alice.InitChannelReservation(aliceReq)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init channel reservation: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to init channel reservation")
|
||||
aliceChanReservation.SetNumConfsRequired(numReqConfs)
|
||||
channelConstraints := &channeldb.ChannelConstraints{
|
||||
DustLimit: alice.Cfg.DefaultConstraints.DustLimit,
|
||||
@@ -935,9 +865,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
err = aliceChanReservation.CommitConstraints(
|
||||
channelConstraints, defaultMaxLocalCsvDelay, false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to verify constraints: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to verify constraints")
|
||||
|
||||
// Verify all contribution fields have been set properly, but only if
|
||||
// Alice is the funder herself.
|
||||
@@ -972,15 +900,11 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
CommitType: commitType,
|
||||
}
|
||||
bobChanReservation, err := bob.InitChannelReservation(bobReq)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob reservation: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create bob reservation")
|
||||
err = bobChanReservation.CommitConstraints(
|
||||
channelConstraints, defaultMaxLocalCsvDelay, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to verify constraints: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to verify constraints")
|
||||
bobChanReservation.SetNumConfsRequired(numReqConfs)
|
||||
|
||||
// We'll ensure that Bob's contribution also gets generated properly.
|
||||
@@ -990,9 +914,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
// With his contribution generated, he can now process Alice's
|
||||
// contribution.
|
||||
err = bobChanReservation.ProcessSingleContribution(aliceContribution)
|
||||
if err != nil {
|
||||
t.Fatalf("bob unable to process alice's contribution: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "bob unable to process alice's contribution")
|
||||
assertContributionInitPopulated(t, bobChanReservation.TheirContribution())
|
||||
|
||||
// Bob will next send over his contribution to Alice, we simulate this
|
||||
@@ -1042,9 +964,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
_, err = bobChanReservation.CompleteReservationSingle(
|
||||
fundingPoint, aliceCommitSig,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("bob unable to consume single reservation: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "bob unable to consume single reservation")
|
||||
|
||||
// Finally, we'll conclude the reservation process by sending over
|
||||
// Bob's commitment signature, which is the final thing Alice needs to
|
||||
@@ -1056,9 +976,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
_, err = aliceChanReservation.CompleteReservation(
|
||||
nil, bobCommitSig,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("alice unable to complete reservation: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "alice unable to complete reservation")
|
||||
|
||||
// If the caller provided an alternative way to obtain the funding tx,
|
||||
// then we'll use that. Otherwise, we'll obtain it directly from Alice.
|
||||
@@ -1073,9 +991,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
// DB for both Alice and Bob.
|
||||
fundingSha := fundingTx.TxHash()
|
||||
aliceChannels, err := alice.Cfg.Database.FetchOpenChannels(bobPub)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve channel from DB: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve channel from DB")
|
||||
if len(aliceChannels) != 1 {
|
||||
t.Fatalf("alice didn't save channel state: %v", err)
|
||||
}
|
||||
@@ -1093,9 +1009,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
}
|
||||
|
||||
bobChannels, err := bob.Cfg.Database.FetchOpenChannels(alicePub)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve channel from DB: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve channel from DB")
|
||||
if len(bobChannels) != 1 {
|
||||
t.Fatalf("bob didn't save channel state: %v", err)
|
||||
}
|
||||
@@ -1114,24 +1028,16 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
|
||||
// Let Alice publish the funding transaction.
|
||||
err = alice.PublishTransaction(fundingTx, "")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish funding tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to publish funding tx")
|
||||
|
||||
// Mine a single block, the funding transaction should be included
|
||||
// within this block.
|
||||
err = waitForMempoolTx(miner, &fundingSha)
|
||||
if err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "tx not relayed to miner")
|
||||
blockHashes, err := miner.Client.Generate(1)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate block")
|
||||
block, err := miner.Client.GetBlock(blockHashes[0])
|
||||
if err != nil {
|
||||
t.Fatalf("unable to find block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to find block")
|
||||
if len(block.Transactions) != 2 {
|
||||
t.Fatalf("funding transaction wasn't mined: %d",
|
||||
len(block.Transactions))
|
||||
@@ -1198,16 +1104,12 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
|
||||
// Get the miner's current best block height before we mine blocks.
|
||||
_, startHeight, err := miner.Client.GetBestBlock()
|
||||
if err != nil {
|
||||
t.Fatalf("cannot get best block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "cannot get best block")
|
||||
|
||||
// Generate 10 blocks to mine all the transactions created above.
|
||||
const numBlocksMined = 10
|
||||
blocks, err := miner.Client.Generate(numBlocksMined)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to mine blocks: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to mine blocks")
|
||||
|
||||
// Our new best block height should be our start height + the number of
|
||||
// blocks we just mined.
|
||||
@@ -1219,15 +1121,11 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
// not include unconfirmed transactions, since all of our transactions
|
||||
// should be confirmed.
|
||||
err = waitForWalletSync(miner, alice)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't sync Alice's wallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Couldn't sync Alice's wallet")
|
||||
txDetails, err := alice.ListTransactionDetails(
|
||||
startHeight, chainTip, "",
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fetch tx details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to fetch tx details")
|
||||
|
||||
// This is a mapping from:
|
||||
// blockHash -> transactionHash -> transactionOutputs
|
||||
@@ -1311,33 +1209,23 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
// Next create a transaction paying to an output which isn't under the
|
||||
// wallet's control.
|
||||
minerAddr, err := miner.NewAddress()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate address: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate address")
|
||||
outputScript, err := txscript.PayToAddrScript(minerAddr)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make output script: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to make output script")
|
||||
burnOutput := wire.NewTxOut(outputAmt, outputScript)
|
||||
burnTX, err := alice.SendOutputs(
|
||||
[]*wire.TxOut{burnOutput}, 2500, 1, labels.External,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create burn tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create burn tx")
|
||||
burnTXID := burnTX.TxHash()
|
||||
err = waitForMempoolTx(miner, &burnTXID)
|
||||
if err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "tx not relayed to miner")
|
||||
|
||||
// Before we mine the next block, we'll ensure that the above
|
||||
// transaction shows up in the set of unconfirmed transactions returned
|
||||
// by ListTransactionDetails.
|
||||
err = waitForWalletSync(miner, alice)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't sync Alice's wallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Couldn't sync Alice's wallet")
|
||||
|
||||
// Query our wallet for transactions from the chain tip, including
|
||||
// unconfirmed transactions. The transaction above should be included
|
||||
@@ -1346,9 +1234,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
txDetails, err = alice.ListTransactionDetails(
|
||||
chainTip, btcwallet.UnconfirmedHeight, "",
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fetch tx details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to fetch tx details")
|
||||
var mempoolTxFound bool
|
||||
for _, txDetail := range txDetails {
|
||||
if !bytes.Equal(txDetail.Hash[:], burnTXID[:]) {
|
||||
@@ -1387,9 +1273,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
// Generate one block for our transaction to confirm in.
|
||||
var numBlocks int32 = 1
|
||||
burnBlock, err := miner.Client.Generate(uint32(numBlocks))
|
||||
if err != nil {
|
||||
t.Fatalf("unable to mine block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to mine block")
|
||||
|
||||
// Progress our chain tip by the number of blocks we have just mined.
|
||||
chainTip += numBlocks
|
||||
@@ -1399,13 +1283,9 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
// are inclusive, so we use chainTip for both parameters to get only
|
||||
// transactions from the last block.
|
||||
err = waitForWalletSync(miner, alice)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't sync Alice's wallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Couldn't sync Alice's wallet")
|
||||
txDetails, err = alice.ListTransactionDetails(chainTip, chainTip, "")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fetch tx details: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to fetch tx details")
|
||||
var burnTxFound bool
|
||||
for _, txDetail := range txDetails {
|
||||
if !bytes.Equal(txDetail.Hash[:], burnTXID[:]) {
|
||||
@@ -1438,21 +1318,15 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
// Generate a block which has no wallet transactions in it.
|
||||
chainTip += numBlocks
|
||||
_, err = miner.Client.Generate(uint32(numBlocks))
|
||||
if err != nil {
|
||||
t.Fatalf("unable to mine block: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to mine block")
|
||||
|
||||
err = waitForWalletSync(miner, alice)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't sync Alice's wallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Couldn't sync Alice's wallet")
|
||||
|
||||
// Query for transactions only in the latest block. We do not expect
|
||||
// any transactions to be returned.
|
||||
txDetails, err = alice.ListTransactionDetails(chainTip, chainTip, "")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unexpected error")
|
||||
if len(txDetails) != 0 {
|
||||
t.Fatalf("expected 0 transactions, got: %v", len(txDetails))
|
||||
}
|
||||
@@ -1591,29 +1465,21 @@ func testTransactionSubscriptions(miner *rpctest.Harness,
|
||||
b := txscript.NewScriptBuilder()
|
||||
b.AddOp(txscript.OP_RETURN)
|
||||
outputScript, err := b.Script()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make output script: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to make output script")
|
||||
burnOutput := wire.NewTxOut(outputAmt, outputScript)
|
||||
tx, err := alice.SendOutputs(
|
||||
[]*wire.TxOut{burnOutput}, 2500, 1, labels.External,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create burn tx: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create burn tx")
|
||||
txid := tx.TxHash()
|
||||
err = waitForMempoolTx(miner, &txid)
|
||||
if err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "tx not relayed to miner")
|
||||
|
||||
// Before we mine the next block, we'll ensure that the above
|
||||
// transaction shows up in the set of unconfirmed transactions returned
|
||||
// by ListTransactionDetails.
|
||||
err = waitForWalletSync(miner, alice)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't sync Alice's wallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "Couldn't sync Alice's wallet")
|
||||
|
||||
// As we just sent the transaction and it was landed in the mempool, we
|
||||
// should get a notification for a new unconfirmed transactions
|
||||
@@ -1781,9 +1647,7 @@ func newTx(t *testing.T, r *rpctest.Harness, pubKey *btcec.PublicKey,
|
||||
t.Helper()
|
||||
|
||||
keyScript, err := scriptFromKey(pubKey)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate script: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate script")
|
||||
|
||||
// Instruct the wallet to fund the output with a newly created
|
||||
// transaction.
|
||||
@@ -1794,9 +1658,7 @@ func newTx(t *testing.T, r *rpctest.Harness, pubKey *btcec.PublicKey,
|
||||
tx, err := alice.SendOutputs(
|
||||
[]*wire.TxOut{newOutput}, 2500, 1, labels.External,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create output: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create output")
|
||||
|
||||
// Query for the transaction generated above so we can located the
|
||||
// index of our output.
|
||||
@@ -1824,9 +1686,7 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
|
||||
// Generate a pubkey, and pay-to-addr script.
|
||||
keyDesc, err := alice.DeriveNextKey(keychain.KeyFamilyMultiSig)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to obtain public key: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to obtain public key")
|
||||
|
||||
// We will first check that publishing a transaction already in the
|
||||
// mempool does NOT return an error. Create the tx.
|
||||
@@ -1834,22 +1694,16 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
|
||||
// Publish the transaction.
|
||||
err = alice.PublishTransaction(tx1, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to publish")
|
||||
|
||||
txid1 := tx1.TxHash()
|
||||
err = waitForMempoolTx(r, &txid1)
|
||||
if err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "tx not relayed to miner")
|
||||
|
||||
// Publish the exact same transaction again. This should not return an
|
||||
// error, even though the transaction is already in the mempool.
|
||||
err = alice.PublishTransaction(tx1, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to publish")
|
||||
|
||||
// Mine the transaction.
|
||||
if _, err := r.Client.Generate(1); err != nil {
|
||||
@@ -1867,9 +1721,7 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
|
||||
// Publish this tx.
|
||||
err = alice.PublishTransaction(tx2, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to publish")
|
||||
|
||||
// Mine the transaction.
|
||||
if err := mineAndAssert(r, tx2); err != nil {
|
||||
@@ -1879,9 +1731,7 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
// Publish the transaction again. It is already mined, and we don't
|
||||
// expect this to return an error.
|
||||
err = alice.PublishTransaction(tx2, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to publish")
|
||||
|
||||
// We'll do the next mempool check on both RBF and non-RBF enabled
|
||||
// transactions.
|
||||
@@ -2035,9 +1885,7 @@ func testSignOutputUsingTweaks(r *rpctest.Harness,
|
||||
pubKey, err := alice.DeriveNextKey(
|
||||
keychain.KeyFamilyMultiSig,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to obtain public key: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to obtain public key")
|
||||
|
||||
// As we'd like to test both single tweak, and double tweak spends,
|
||||
// we'll generate a commitment pre-image, then derive a revocation key
|
||||
@@ -2179,32 +2027,22 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet,
|
||||
// create any new non-coinbase transactions. We'll then check if it's
|
||||
// the same after the empty reorg.
|
||||
_, err := r.Client.Generate(5)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate blocks on passed node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate blocks on passed node")
|
||||
|
||||
// Give wallet time to catch up.
|
||||
err = waitForWalletSync(r, w)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to sync wallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to sync wallet")
|
||||
|
||||
// Send some money from the miner to the wallet
|
||||
err = loadTestCredits(r, w, 20, 4)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send money to lnwallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to send money to lnwallet")
|
||||
|
||||
// Send some money from the wallet back to the miner.
|
||||
// Grab a fresh address from the miner to house this output.
|
||||
minerAddr, err := r.NewAddress()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate address for miner: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate address for miner")
|
||||
script, err := txscript.PayToAddrScript(minerAddr)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create pay to addr script: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create pay to addr script")
|
||||
output := &wire.TxOut{
|
||||
Value: 1e8,
|
||||
PkScript: script,
|
||||
@@ -2212,46 +2050,30 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet,
|
||||
tx, err := w.SendOutputs(
|
||||
[]*wire.TxOut{output}, 2500, 1, labels.External,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send outputs: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to send outputs")
|
||||
txid := tx.TxHash()
|
||||
err = waitForMempoolTx(r, &txid)
|
||||
if err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "tx not relayed to miner")
|
||||
_, err = r.Client.Generate(50)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate blocks on passed node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to generate blocks on passed node")
|
||||
|
||||
// Give wallet time to catch up.
|
||||
err = waitForWalletSync(r, w)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to sync wallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to sync wallet")
|
||||
|
||||
// Get the original balance.
|
||||
origBalance, err := w.ConfirmedBalance(1, lnwallet.DefaultAccountName)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for balance: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for balance")
|
||||
|
||||
// Now we cause a reorganization as follows.
|
||||
// Step 1: create a new miner and start it.
|
||||
r2, err := rpctest.New(r.ActiveNet, nil, []string{"--txindex"}, "")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create mining node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create mining node")
|
||||
err = r2.SetUp(false, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to set up mining node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to set up mining node")
|
||||
defer r2.TearDown()
|
||||
newBalance, err := w.ConfirmedBalance(1, lnwallet.DefaultAccountName)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for balance: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for balance")
|
||||
if origBalance != newBalance {
|
||||
t.Fatalf("wallet balance incorrect, should have %v, "+
|
||||
"instead have %v", origBalance, newBalance)
|
||||
@@ -2260,13 +2082,9 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet,
|
||||
// Step 2: connect the miner to the passed miner and wait for
|
||||
// synchronization.
|
||||
err = r2.Client.AddNode(r.P2PAddress(), rpcclient.ANAdd)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect mining nodes together: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to connect mining nodes together")
|
||||
err = rpctest.JoinNodes([]*rpctest.Harness{r2, r}, rpctest.Blocks)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to synchronize mining nodes: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to synchronize mining nodes")
|
||||
|
||||
// Step 3: Do a set of reorgs by disconnecting the two miners, mining
|
||||
// one block on the passed miner and two on the created miner,
|
||||
@@ -2341,9 +2159,7 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet,
|
||||
|
||||
// Now we check that the wallet balance stays the same.
|
||||
newBalance, err = w.ConfirmedBalance(1, lnwallet.DefaultAccountName)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to query for balance: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to query for balance")
|
||||
if origBalance != newBalance {
|
||||
t.Fatalf("wallet balance incorrect, should have %v, "+
|
||||
"instead have %v", origBalance, newBalance)
|
||||
@@ -2364,9 +2180,7 @@ func testChangeOutputSpendConfirmation(r *rpctest.Harness,
|
||||
// we'll craft the following transaction so that Alice doesn't have any
|
||||
// UTXOs left.
|
||||
aliceBalance, err := alice.ConfirmedBalance(0, lnwallet.DefaultAccountName)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve alice's balance: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve alice's balance")
|
||||
bobPkScript := newPkScript(t, bob, lnwallet.WitnessPubKey)
|
||||
|
||||
// We'll use a transaction fee of 14380 satoshis, which will allow us to
|
||||
@@ -2389,9 +2203,7 @@ func testChangeOutputSpendConfirmation(r *rpctest.Harness,
|
||||
// With the transaction sent and confirmed, Alice's balance should now
|
||||
// be 0.
|
||||
aliceBalance, err = alice.ConfirmedBalance(0, lnwallet.DefaultAccountName)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve alice's balance: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve alice's balance")
|
||||
if aliceBalance != 0 {
|
||||
t.Fatalf("expected alice's balance to be 0 BTC, found %v",
|
||||
aliceBalance)
|
||||
@@ -2445,9 +2257,7 @@ func testSpendUnconfirmed(miner *rpctest.Harness,
|
||||
// First we will empty out bob's wallet, sending the entire balance
|
||||
// to alice.
|
||||
bobBalance, err := bob.ConfirmedBalance(0, lnwallet.DefaultAccountName)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to retrieve bob's balance: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to retrieve bob's balance")
|
||||
txFee := btcutil.Amount(28760)
|
||||
output := &wire.TxOut{
|
||||
Value: int64(bobBalance - txFee),
|
||||
@@ -2504,9 +2314,7 @@ func testSpendUnconfirmed(miner *rpctest.Harness,
|
||||
|
||||
// Mine the unconfirmed transactions.
|
||||
err = waitForMempoolTx(miner, &txHash)
|
||||
if err != nil {
|
||||
t.Fatalf("tx not relayed to miner: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "tx not relayed to miner")
|
||||
if _, err := miner.Client.Generate(1); err != nil {
|
||||
t.Fatalf("unable to generate block: %v", err)
|
||||
}
|
||||
@@ -2601,9 +2409,7 @@ func testCreateSimpleTx(r *rpctest.Harness, w *lnwallet.LightningWallet,
|
||||
|
||||
// Send some money from the miner to the wallet
|
||||
err := loadTestCredits(r, w, 20, 4)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send money to lnwallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to send money to lnwallet")
|
||||
|
||||
// The test cases we will run through for all backends.
|
||||
testCases := []struct {
|
||||
@@ -3083,13 +2889,9 @@ func testSingleFunderExternalFundingTx(miner *rpctest.Harness,
|
||||
// First, we'll obtain multi-sig keys from both Alice and Bob which
|
||||
// simulates them exchanging keys on a higher level.
|
||||
aliceFundingKey, err := alice.DeriveNextKey(keychain.KeyFamilyMultiSig)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to obtain alice funding key: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to obtain alice funding key")
|
||||
bobFundingKey, err := bob.DeriveNextKey(keychain.KeyFamilyMultiSig)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to obtain bob funding key: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to obtain bob funding key")
|
||||
|
||||
// We'll now set up for them to open a 4 BTC channel, with 1 BTC pushed
|
||||
// to Bob's side.
|
||||
@@ -3120,9 +2922,7 @@ func testSingleFunderExternalFundingTx(miner *rpctest.Harness,
|
||||
)
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to perform coin selection: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to perform coin selection")
|
||||
|
||||
// With our intent created, we'll instruct it to finalize the funding
|
||||
// transaction, and also hand us the outpoint so we can simulate
|
||||
@@ -3168,9 +2968,7 @@ func testSingleFunderExternalFundingTx(miner *rpctest.Harness,
|
||||
)
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create shim intent for bob: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create shim intent for bob")
|
||||
|
||||
// At this point, we have everything we need to carry out our test, so
|
||||
// we'll being the funding flow between Alice and Bob.
|
||||
@@ -3180,9 +2978,7 @@ func testSingleFunderExternalFundingTx(miner *rpctest.Harness,
|
||||
// from Alice.
|
||||
pendingChanID := testHdSeed
|
||||
err = bob.RegisterFundingIntent(pendingChanID, bobShimIntent)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to register intent: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to register intent")
|
||||
|
||||
// Now we can carry out the single funding flow as normal, we'll
|
||||
// specify our external funder and funding transaction, as well as the
|
||||
@@ -3219,9 +3015,7 @@ func TestLightningWallet(t *testing.T, targetBackEnd string) {
|
||||
miningNode, err := rpctest.New(
|
||||
netParams, nil, []string{"--txindex"}, "",
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create mining node: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create mining node")
|
||||
defer miningNode.TearDown()
|
||||
if err := miningNode.SetUp(true, 25); err != nil {
|
||||
t.Fatalf("unable to set up mining node: %v", err)
|
||||
@@ -3237,27 +3031,19 @@ func TestLightningWallet(t *testing.T, targetBackEnd string) {
|
||||
rpcConfig := miningNode.RPCConfig()
|
||||
|
||||
tempDir, err := ioutil.TempDir("", "channeldb")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temp dir: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create temp dir")
|
||||
db, err := channeldb.Open(tempDir)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create db: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create db")
|
||||
testCfg := chainntnfs.CacheConfig{
|
||||
QueryDisable: false,
|
||||
}
|
||||
hintCache, err := chainntnfs.NewHeightHintCache(testCfg, db.Backend)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create height hint cache: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create height hint cache")
|
||||
blockCache := blockcache.NewBlockCache(10000)
|
||||
chainNotifier, err := btcdnotify.New(
|
||||
&rpcConfig, netParams, hintCache, hintCache, blockCache,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create notifier: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create notifier")
|
||||
if err := chainNotifier.Start(); err != nil {
|
||||
t.Fatalf("unable to start notifier: %v", err)
|
||||
}
|
||||
@@ -3300,15 +3086,11 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver,
|
||||
)
|
||||
|
||||
tempTestDirAlice, err := ioutil.TempDir("", "lnwallet")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temp directory: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create temp directory")
|
||||
defer os.RemoveAll(tempTestDirAlice)
|
||||
|
||||
tempTestDirBob, err := ioutil.TempDir("", "lnwallet")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temp directory: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create temp directory")
|
||||
defer os.RemoveAll(tempTestDirBob)
|
||||
|
||||
blockCache := blockcache.NewBlockCache(10000)
|
||||
@@ -3622,18 +3404,14 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver,
|
||||
chainNotifier, aliceWalletController, aliceKeyRing,
|
||||
aliceSigner, bio,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test ln wallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test ln wallet")
|
||||
defer alice.Shutdown()
|
||||
|
||||
bob, err := createTestWallet(
|
||||
tempTestDirBob, miningNode, netParams,
|
||||
chainNotifier, bobWalletController, bobKeyRing, bobSigner, bio,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test ln wallet: %v", err)
|
||||
}
|
||||
require.NoError(t, err, "unable to create test ln wallet")
|
||||
defer bob.Shutdown()
|
||||
|
||||
// Both wallets should now have 80BTC available for
|
||||
|
Reference in New Issue
Block a user