From 8b6842c7604186e67eb3f2cd1afa40e704a9e95c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 23 Nov 2017 00:29:08 -0600 Subject: [PATCH] lnwallet: update interface level tests to adhere to recent API changes --- lnwallet/interface_test.go | 64 +++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index 4fac7bfc1..08ff115a5 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -13,6 +13,7 @@ import ( "time" "github.com/boltdb/bolt" + "github.com/davecgh/go-spew/spew" "github.com/roasbeef/btcwallet/chain" @@ -257,10 +258,13 @@ 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. - feePerWeight := btcutil.Amount(alice.Cfg.FeeEstimator.EstimateFeePerWeight(1)) + feePerWeight, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) + if err != nil { + t.Fatalf("unable to query fee estimator: %v", err) + } feePerKw := feePerWeight * 1000 aliceChanReservation, err := alice.InitChannelReservation( - fundingAmount*2, fundingAmount, 0, feePerKw, + fundingAmount*2, fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash) if err != nil { t.Fatalf("unable to initialize funding reservation: %v", err) @@ -284,7 +288,7 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness, // receives' Alice's contribution, and consumes that so we can continue // the funding process. bobChanReservation, err := bob.InitChannelReservation(fundingAmount*2, - fundingAmount, 0, feePerKw, alicePub, aliceAddr, + fundingAmount, 0, feePerKw, feePerKw, alicePub, aliceAddr, chainHash) if err != nil { t.Fatalf("bob unable to init channel reservation: %v", err) @@ -403,10 +407,14 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness, // Create a single channel asking for 16 BTC total. fundingAmount := btcutil.Amount(8 * 1e8) - feePerWeight := btcutil.Amount(alice.Cfg.FeeEstimator.EstimateFeePerWeight(1)) + feePerWeight, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) + if err != nil { + t.Fatalf("unable to query fee estimator: %v", err) + } feePerKw := feePerWeight * 1000 - _, err := alice.InitChannelReservation(fundingAmount, - fundingAmount, 0, feePerKw, bobPub, bobAddr, chainHash) + _, err = alice.InitChannelReservation(fundingAmount, + fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash, + ) if err != nil { t.Fatalf("unable to initialize funding reservation 1: %v", err) } @@ -416,7 +424,7 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness, // that aren't locked, so this should fail. amt := btcutil.Amount(900 * 1e8) failedReservation, err := alice.InitChannelReservation(amt, amt, 0, - feePerKw, bobPub, bobAddr, chainHash) + feePerKw, feePerKw, bobPub, bobAddr, chainHash) if err == nil { t.Fatalf("not error returned, should fail on coin selection") } @@ -431,20 +439,24 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness, func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness, alice, _ *lnwallet.LightningWallet, t *testing.T) { - feePerWeight := btcutil.Amount(alice.Cfg.FeeEstimator.EstimateFeePerWeight(1)) + feePerWeight, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) + if err != nil { + t.Fatalf("unable to query fee estimator: %v", err) + } feePerKw := feePerWeight * 1000 // Create a reservation for 44 BTC. fundingAmount := btcutil.Amount(44 * 1e8) chanReservation, err := alice.InitChannelReservation(fundingAmount, - fundingAmount, 0, feePerKw, bobPub, bobAddr, chainHash) + fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash) if err != nil { t.Fatalf("unable to initialize funding reservation: %v", err) } // Attempt to create another channel with 44 BTC, this should fail. _, err = alice.InitChannelReservation(fundingAmount, - fundingAmount, 0, feePerKw, bobPub, bobAddr, chainHash) + fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash, + ) if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok { t.Fatalf("coin selection succeded should have insufficient funds: %v", err) @@ -474,7 +486,7 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness, // Request to fund a new channel should now succeed. _, err = alice.InitChannelReservation(fundingAmount, fundingAmount, 0, - feePerKw, bobPub, bobAddr, chainHash) + feePerKw, feePerKw, bobPub, bobAddr, chainHash) if err != nil { t.Fatalf("unable to initialize funding reservation: %v", err) } @@ -483,11 +495,15 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness, func testCancelNonExistantReservation(miner *rpctest.Harness, alice, _ *lnwallet.LightningWallet, t *testing.T) { - feeRate := btcutil.Amount(alice.Cfg.FeeEstimator.EstimateFeePerWeight(1)) + feeRate, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) + if err != nil { + t.Fatalf("unable to query fee estimator: %v", err) + } // Create our own reservation, give it some ID. - res := lnwallet.NewChannelReservation(1000, 1000, feeRate, alice, - 22, 10, &testHdSeed) + res := lnwallet.NewChannelReservation( + 1000, 1000, feeRate, alice, 22, 10, &testHdSeed, + ) // Attempt to cancel this reservation. This should fail, we know // nothing of it. @@ -550,10 +566,13 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness, // towards Bob's side. fundingAmt := btcutil.Amount(4 * 1e8) pushAmt := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin) - feePerWeight := btcutil.Amount(alice.Cfg.FeeEstimator.EstimateFeePerWeight(1)) + feePerWeight, err := alice.Cfg.FeeEstimator.EstimateFeePerWeight(1) + if err != nil { + t.Fatalf("unable to query fee estimator: %v", err) + } feePerKw := feePerWeight * 1000 aliceChanReservation, err := alice.InitChannelReservation(fundingAmt, - fundingAmt, pushAmt, feePerKw, bobPub, bobAddr, chainHash) + fundingAmt, pushAmt, feePerKw, feePerKw, bobPub, bobAddr, chainHash) if err != nil { t.Fatalf("unable to init channel reservation: %v", err) } @@ -577,7 +596,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness, // Next, Bob receives the initial request, generates a corresponding // reservation initiation, then consume Alice's contribution. bobChanReservation, err := bob.InitChannelReservation(fundingAmt, 0, - pushAmt, feePerKw, alicePub, aliceAddr, chainHash) + pushAmt, feePerKw, feePerKw, alicePub, aliceAddr, chainHash) if err != nil { t.Fatalf("unable to create bob reservation: %v", err) } @@ -806,7 +825,7 @@ func testListTransactionDetails(miner *rpctest.Harness, t.Fatalf("unable to make output script: %v", err) } burnOutput := wire.NewTxOut(outputAmt, outputScript) - burnTXID, err := alice.SendOutputs([]*wire.TxOut{burnOutput}) + burnTXID, err := alice.SendOutputs([]*wire.TxOut{burnOutput}, 10) if err != nil { t.Fatalf("unable to create burn tx: %v", err) } @@ -833,9 +852,10 @@ func testListTransactionDetails(miner *rpctest.Harness, t.Fatalf("num confs incorrect, got %v expected %v", txDetail.NumConfirmations, 1) } - if txDetail.Value >= -outputAmt { + if txDetail.Value != -outputAmt { + fmt.Println(spew.Sdump(txDetail)) t.Fatalf("tx value incorrect, got %v expected %v", - txDetail.Value, -outputAmt) + int64(txDetail.Value), -int64(outputAmt)) } if !bytes.Equal(txDetail.BlockHash[:], burnBlock[0][:]) { t.Fatalf("block hash mismatch, got %v expected %v", @@ -1003,7 +1023,7 @@ func testSignOutputUsingTweaks(r *rpctest.Harness, Value: btcutil.SatoshiPerBitcoin, PkScript: keyScript, } - txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}) + txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 10) if err != nil { t.Fatalf("unable to create output: %v", err) } @@ -1122,7 +1142,7 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet, Value: 1e8, PkScript: script, } - if _, err = w.SendOutputs([]*wire.TxOut{output}); err != nil { + if _, err = w.SendOutputs([]*wire.TxOut{output}, 10); err != nil { t.Fatalf("unable to send outputs: %v", err) } _, err = r.Node.Generate(50)