From 7e7fca78c4a2bda05dbec72ca7e69e9804c15014 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 7 Dec 2021 20:14:06 +0800 Subject: [PATCH] chainfee: update test TestWebAPIFeeEstimator --- lnwallet/chainfee/estimator_test.go | 53 ++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/lnwallet/chainfee/estimator_test.go b/lnwallet/chainfee/estimator_test.go index 575b763a8..0ac92a562 100644 --- a/lnwallet/chainfee/estimator_test.go +++ b/lnwallet/chainfee/estimator_test.go @@ -164,8 +164,9 @@ func TestSparseConfFeeSource(t *testing.T) { // as expected. func TestWebAPIFeeEstimator(t *testing.T) { t.Parallel() - feeFloor := uint32(FeePerKwFloor.FeePerKVByte()) + testFeeRate := feeFloor * 100 + testCases := []struct { name string target uint32 @@ -173,11 +174,41 @@ func TestWebAPIFeeEstimator(t *testing.T) { est uint32 err string }{ - {"target_below_min", 0, 12345, 12345, "too low, minimum"}, - {"target_w_too-low_fee", 10, 42, feeFloor, ""}, - {"API-omitted_target", 2, 0, 0, "web API does not include"}, - {"valid_target", 20, 54321, 54321, ""}, - {"valid_target_extrapolated_fee", 25, 0, 54321, ""}, + { + name: "target_below_min", + target: 0, + apiEst: 0, + 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. @@ -196,12 +227,10 @@ func TestWebAPIFeeEstimator(t *testing.T) { estimator := NewWebAPIEstimator(feeSource, false) // Test that requesting a fee when no fees have been cached fails. - _, err := estimator.EstimateFeePerKW(5) - if err == nil || - !strings.Contains(err.Error(), "web API does not include") { - - t.Fatalf("expected fee estimation to fail, instead got: %v", err) - } + feeRate, err := estimator.EstimateFeePerKW(5) + require.NoErrorf(t, err, "expected no error") + require.Equalf(t, FeePerKwFloor, feeRate, "expected fee rate floor "+ + "returned when no cached fee rate found") if err := estimator.Start(); err != nil { t.Fatalf("unable to start fee estimator, got: %v", err)