Files
MichilisandClaude Fable 5.1 5a3b4dad7c Make go test ./... run and fix the stale tooltip test
internal/config.go panicked in init without a config.yaml and the i18n
loader only found translations/ from the repository root, so no test in
a package importing them could run. Config checks are skipped in a test
binary, the translation directory is located by walking up, GetAmount
no longer dereferences a nil price watcher, and the tooltip test expects
the text the code actually produces. Adds tests for amount validation.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-13 20:58:30 +00:00

56 lines
1.4 KiB
Go

package telegram
import (
"math"
"testing"
)
func TestCheckAmount(t *testing.T) {
good := []int64{1, 21, 1000, maxAmountSat}
for _, a := range good {
if got, err := checkAmount(float64(a), a); err != nil || got != a {
t.Errorf("checkAmount(%d) = %d, %v", a, got, err)
}
}
bad := []struct {
name string
f float64
a int64
}{
{"zero", 0, 0},
{"negative", -5, -5},
{"above max", float64(maxAmountSat + 1), maxAmountSat + 1},
{"nan", math.NaN(), 0},
{"+inf", math.Inf(1), math.MaxInt64},
{"-inf", math.Inf(-1), math.MinInt64},
}
for _, c := range bad {
if got, err := checkAmount(c.f, c.a); err == nil || got != 0 {
t.Errorf("%s: accepted: got %d, err %v", c.name, got, err)
}
}
}
// TestGetAmount covers the integer and "k" branches; the fiat branch needs a
// live price feed.
func TestGetAmount(t *testing.T) {
cases := map[string]int64{
"21": 21,
"1k": 1000,
"1.5k": 1500,
"1,5k": 1500,
"10000k": maxAmountSat,
}
for in, want := range cases {
if got, err := GetAmount(in); err != nil || got != want {
t.Errorf("GetAmount(%q) = %d, %v; want %d", in, got, err, want)
}
}
rejected := []string{"0", "-1", "-1k", "0k", "NaNk", "Infk", "10001k", "99999999999", "abc", ""}
for _, in := range rejected {
if got, err := GetAmount(in); err == nil {
t.Errorf("GetAmount(%q) accepted with %d", in, got)
}
}
}