lnwallet: update interface level tests to adhere to recent API changes

This commit is contained in:
Olaoluwa Osuntokun 2017-11-23 00:29:08 -06:00
parent 4a277276fd
commit 8b6842c760
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -13,6 +13,7 @@ import (
"time" "time"
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
"github.com/davecgh/go-spew/spew"
"github.com/roasbeef/btcwallet/chain" "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 // Alice initiates a channel funded with 5 BTC for each side, so 10 BTC
// total. She also generates 2 BTC in change. // 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 feePerKw := feePerWeight * 1000
aliceChanReservation, err := alice.InitChannelReservation( aliceChanReservation, err := alice.InitChannelReservation(
fundingAmount*2, fundingAmount, 0, feePerKw, fundingAmount*2, fundingAmount, 0, feePerKw, feePerKw,
bobPub, bobAddr, chainHash) bobPub, bobAddr, chainHash)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err) 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 // receives' Alice's contribution, and consumes that so we can continue
// the funding process. // the funding process.
bobChanReservation, err := bob.InitChannelReservation(fundingAmount*2, bobChanReservation, err := bob.InitChannelReservation(fundingAmount*2,
fundingAmount, 0, feePerKw, alicePub, aliceAddr, fundingAmount, 0, feePerKw, feePerKw, alicePub, aliceAddr,
chainHash) chainHash)
if err != nil { if err != nil {
t.Fatalf("bob unable to init channel reservation: %v", err) 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. // Create a single channel asking for 16 BTC total.
fundingAmount := btcutil.Amount(8 * 1e8) 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 feePerKw := feePerWeight * 1000
_, err := alice.InitChannelReservation(fundingAmount, _, err = alice.InitChannelReservation(fundingAmount,
fundingAmount, 0, feePerKw, bobPub, bobAddr, chainHash) fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash,
)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation 1: %v", err) 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. // that aren't locked, so this should fail.
amt := btcutil.Amount(900 * 1e8) amt := btcutil.Amount(900 * 1e8)
failedReservation, err := alice.InitChannelReservation(amt, amt, 0, failedReservation, err := alice.InitChannelReservation(amt, amt, 0,
feePerKw, bobPub, bobAddr, chainHash) feePerKw, feePerKw, bobPub, bobAddr, chainHash)
if err == nil { if err == nil {
t.Fatalf("not error returned, should fail on coin selection") t.Fatalf("not error returned, should fail on coin selection")
} }
@ -431,20 +439,24 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness, func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
alice, _ *lnwallet.LightningWallet, t *testing.T) { 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 feePerKw := feePerWeight * 1000
// Create a reservation for 44 BTC. // Create a reservation for 44 BTC.
fundingAmount := btcutil.Amount(44 * 1e8) fundingAmount := btcutil.Amount(44 * 1e8)
chanReservation, err := alice.InitChannelReservation(fundingAmount, chanReservation, err := alice.InitChannelReservation(fundingAmount,
fundingAmount, 0, feePerKw, bobPub, bobAddr, chainHash) fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err) t.Fatalf("unable to initialize funding reservation: %v", err)
} }
// Attempt to create another channel with 44 BTC, this should fail. // Attempt to create another channel with 44 BTC, this should fail.
_, err = alice.InitChannelReservation(fundingAmount, _, err = alice.InitChannelReservation(fundingAmount,
fundingAmount, 0, feePerKw, bobPub, bobAddr, chainHash) fundingAmount, 0, feePerKw, feePerKw, bobPub, bobAddr, chainHash,
)
if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok { if _, ok := err.(*lnwallet.ErrInsufficientFunds); !ok {
t.Fatalf("coin selection succeded should have insufficient funds: %v", t.Fatalf("coin selection succeded should have insufficient funds: %v",
err) err)
@ -474,7 +486,7 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
// Request to fund a new channel should now succeed. // Request to fund a new channel should now succeed.
_, err = alice.InitChannelReservation(fundingAmount, fundingAmount, 0, _, err = alice.InitChannelReservation(fundingAmount, fundingAmount, 0,
feePerKw, bobPub, bobAddr, chainHash) feePerKw, feePerKw, bobPub, bobAddr, chainHash)
if err != nil { if err != nil {
t.Fatalf("unable to initialize funding reservation: %v", err) t.Fatalf("unable to initialize funding reservation: %v", err)
} }
@ -483,11 +495,15 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
func testCancelNonExistantReservation(miner *rpctest.Harness, func testCancelNonExistantReservation(miner *rpctest.Harness,
alice, _ *lnwallet.LightningWallet, t *testing.T) { 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. // Create our own reservation, give it some ID.
res := lnwallet.NewChannelReservation(1000, 1000, feeRate, alice, res := lnwallet.NewChannelReservation(
22, 10, &testHdSeed) 1000, 1000, feeRate, alice, 22, 10, &testHdSeed,
)
// Attempt to cancel this reservation. This should fail, we know // Attempt to cancel this reservation. This should fail, we know
// nothing of it. // nothing of it.
@ -550,10 +566,13 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
// towards Bob's side. // towards Bob's side.
fundingAmt := btcutil.Amount(4 * 1e8) fundingAmt := btcutil.Amount(4 * 1e8)
pushAmt := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin) 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 feePerKw := feePerWeight * 1000
aliceChanReservation, err := alice.InitChannelReservation(fundingAmt, aliceChanReservation, err := alice.InitChannelReservation(fundingAmt,
fundingAmt, pushAmt, feePerKw, bobPub, bobAddr, chainHash) fundingAmt, pushAmt, feePerKw, feePerKw, bobPub, bobAddr, chainHash)
if err != nil { if err != nil {
t.Fatalf("unable to init channel reservation: %v", err) 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 // Next, Bob receives the initial request, generates a corresponding
// reservation initiation, then consume Alice's contribution. // reservation initiation, then consume Alice's contribution.
bobChanReservation, err := bob.InitChannelReservation(fundingAmt, 0, bobChanReservation, err := bob.InitChannelReservation(fundingAmt, 0,
pushAmt, feePerKw, alicePub, aliceAddr, chainHash) pushAmt, feePerKw, feePerKw, alicePub, aliceAddr, chainHash)
if err != nil { if err != nil {
t.Fatalf("unable to create bob reservation: %v", err) 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) t.Fatalf("unable to make output script: %v", err)
} }
burnOutput := wire.NewTxOut(outputAmt, outputScript) burnOutput := wire.NewTxOut(outputAmt, outputScript)
burnTXID, err := alice.SendOutputs([]*wire.TxOut{burnOutput}) burnTXID, err := alice.SendOutputs([]*wire.TxOut{burnOutput}, 10)
if err != nil { if err != nil {
t.Fatalf("unable to create burn tx: %v", err) 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", t.Fatalf("num confs incorrect, got %v expected %v",
txDetail.NumConfirmations, 1) 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", t.Fatalf("tx value incorrect, got %v expected %v",
txDetail.Value, -outputAmt) int64(txDetail.Value), -int64(outputAmt))
} }
if !bytes.Equal(txDetail.BlockHash[:], burnBlock[0][:]) { if !bytes.Equal(txDetail.BlockHash[:], burnBlock[0][:]) {
t.Fatalf("block hash mismatch, got %v expected %v", t.Fatalf("block hash mismatch, got %v expected %v",
@ -1003,7 +1023,7 @@ func testSignOutputUsingTweaks(r *rpctest.Harness,
Value: btcutil.SatoshiPerBitcoin, Value: btcutil.SatoshiPerBitcoin,
PkScript: keyScript, PkScript: keyScript,
} }
txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}) txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 10)
if err != nil { if err != nil {
t.Fatalf("unable to create output: %v", err) t.Fatalf("unable to create output: %v", err)
} }
@ -1122,7 +1142,7 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet,
Value: 1e8, Value: 1e8,
PkScript: script, 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) t.Fatalf("unable to send outputs: %v", err)
} }
_, err = r.Node.Generate(50) _, err = r.Node.Generate(50)