mirror of
https://github.com/trezor/blockbook.git
synced 2026-03-01 13:24:25 +01:00
* feat: support new alternative_estimate_fee option - mempoolspacemedian * chore: introduce a fallback median fee rate in case it comes zero from mempool space response * chore: add and test util function for rounding to significant digits * chore: use rounding of medianFee to 3 significant digits * chore: make the new alternative_estimate_fee be configurable, change its name from Median to Block * chore: return 1000 sats/kB fee for MempoolSpaceBlock estimation method when block not identified * chore: make the fallback fee rate configurable, improve tests, improve function names
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
//go:build unittest
|
|
|
|
package common
|
|
|
|
import (
|
|
"math"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func Test_RoundToSignificantDigits(t *testing.T) {
|
|
type testCase struct {
|
|
input float64
|
|
digits int
|
|
want float64
|
|
}
|
|
|
|
tests := []testCase{
|
|
{input: 1234.5678, digits: 3, want: 1230},
|
|
{input: 1234.5678, digits: 4, want: 1235},
|
|
{input: 1234.5678, digits: 5, want: 1234.6},
|
|
{input: 0.0123456, digits: 3, want: 0.0123},
|
|
{input: 98765.4321, digits: 3, want: 98800},
|
|
{input: 1.99999, digits: 3, want: 2.00},
|
|
{input: 999.999, digits: 3, want: 1000},
|
|
{input: 0.0006789, digits: 3, want: 0.000679},
|
|
{input: 5.123456, digits: 3, want: 5.12},
|
|
{input: 4.456789, digits: 3, want: 4.46},
|
|
{input: 3.789012, digits: 3, want: 3.79},
|
|
{input: 2.012345, digits: 3, want: 2.01},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(strconv.FormatFloat(tt.input, 'f', -1, 64), func(t *testing.T) {
|
|
got := RoundToSignificantDigits(tt.input, tt.digits)
|
|
|
|
// Use relative epsilon for float comparison
|
|
epsilon := 1e-9
|
|
if math.Abs(got-tt.want) > epsilon {
|
|
t.Errorf("RoundToSignificantDigits(%v, %d) = %v, want %v", tt.input, tt.digits, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|