sweep: add unit tests for TestDetermineFeePerKw and CraftSweepAllTx

Along the way we also extend the mockFeeEstimator to be able to return a
fee rate for a specified confirmation target.
This commit is contained in:
Olaoluwa Osuntokun
2018-12-24 15:29:55 -06:00
parent b2c712fb67
commit eda6ed224f
3 changed files with 436 additions and 4 deletions

View File

@ -1,8 +1,9 @@
package sweep
import (
"github.com/lightningnetwork/lnd/lnwallet"
"sync"
"github.com/lightningnetwork/lnd/lnwallet"
)
// mockFeeEstimator implements a mock fee estimator. It closely resembles
@ -13,6 +14,8 @@ type mockFeeEstimator struct {
relayFee lnwallet.SatPerKWeight
blocksToFee map[uint32]lnwallet.SatPerKWeight
lock sync.Mutex
}
@ -20,8 +23,9 @@ func newMockFeeEstimator(feePerKW,
relayFee lnwallet.SatPerKWeight) *mockFeeEstimator {
return &mockFeeEstimator{
feePerKW: feePerKW,
relayFee: relayFee,
feePerKW: feePerKW,
relayFee: relayFee,
blocksToFee: make(map[uint32]lnwallet.SatPerKWeight),
}
}
@ -41,6 +45,10 @@ func (e *mockFeeEstimator) EstimateFeePerKW(numBlocks uint32) (
e.lock.Lock()
defer e.lock.Unlock()
if fee, ok := e.blocksToFee[numBlocks]; ok {
return fee, nil
}
return e.feePerKW, nil
}