chainfee: update test TestWebAPIFeeEstimator
This commit is contained in:
1 file changed
+41
-12
@@ -164,8 +164,9 @@ func TestSparseConfFeeSource(t *testing.T) {
|
|||||||
// as expected.
|
// as expected.
|
||||||
func TestWebAPIFeeEstimator(t *testing.T) {
|
func TestWebAPIFeeEstimator(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
feeFloor := uint32(FeePerKwFloor.FeePerKVByte())
|
feeFloor := uint32(FeePerKwFloor.FeePerKVByte())
|
||||||
|
testFeeRate := feeFloor * 100
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
target uint32
|
target uint32
|
||||||
@@ -173,11 +174,41 @@ func TestWebAPIFeeEstimator(t *testing.T) {
|
|||||||
est uint32
|
est uint32
|
||||||
err string
|
err string
|
||||||
}{
|
}{
|
||||||
{"target_below_min", 0, 12345, 12345, "too low, minimum"},
|
{
|
||||||
{"target_w_too-low_fee", 10, 42, feeFloor, ""},
|
name: "target_below_min",
|
||||||
{"API-omitted_target", 2, 0, 0, "web API does not include"},
|
target: 0,
|
||||||
{"valid_target", 20, 54321, 54321, ""},
|
apiEst: 0,
|
||||||
{"valid_target_extrapolated_fee", 25, 0, 54321, ""},
|
est: 0,
|
||||||
|
err: "too low, minimum",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "target_w_too-low_fee",
|
||||||
|
target: 100,
|
||||||
|
apiEst: 42,
|
||||||
|
est: feeFloor,
|
||||||
|
err: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "API-omitted_target",
|
||||||
|
target: 2,
|
||||||
|
apiEst: 0,
|
||||||
|
est: testFeeRate,
|
||||||
|
err: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "valid_target",
|
||||||
|
target: 20,
|
||||||
|
apiEst: testFeeRate,
|
||||||
|
est: testFeeRate,
|
||||||
|
err: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "valid_target_extrapolated_fee",
|
||||||
|
target: 25,
|
||||||
|
apiEst: 0,
|
||||||
|
est: testFeeRate,
|
||||||
|
err: "",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct mock fee source for the Estimator to pull fees from.
|
// Construct mock fee source for the Estimator to pull fees from.
|
||||||
@@ -196,12 +227,10 @@ func TestWebAPIFeeEstimator(t *testing.T) {
|
|||||||
estimator := NewWebAPIEstimator(feeSource, false)
|
estimator := NewWebAPIEstimator(feeSource, false)
|
||||||
|
|
||||||
// Test that requesting a fee when no fees have been cached fails.
|
// Test that requesting a fee when no fees have been cached fails.
|
||||||
_, err := estimator.EstimateFeePerKW(5)
|
feeRate, err := estimator.EstimateFeePerKW(5)
|
||||||
if err == nil ||
|
require.NoErrorf(t, err, "expected no error")
|
||||||
!strings.Contains(err.Error(), "web API does not include") {
|
require.Equalf(t, FeePerKwFloor, feeRate, "expected fee rate floor "+
|
||||||
|
"returned when no cached fee rate found")
|
||||||
t.Fatalf("expected fee estimation to fail, instead got: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := estimator.Start(); err != nil {
|
if err := estimator.Start(); err != nil {
|
||||||
t.Fatalf("unable to start fee estimator, got: %v", err)
|
t.Fatalf("unable to start fee estimator, got: %v", err)
|
||||||
|
|||||||
Reference in new issue
Block a user