/note, /notes (list and batch), /redeem and /lnurlmints with confirm dialogs, group posting with private receipts, claim notifications, batch export as PDF/JSON/CSV, and LNURLcash notes detected inside the existing /lnurl, paste and QR-photo flows. Plain withdraw links behave as before. Two /lnurl log lines no longer print k1. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package telegram
|
||
|
||
import "testing"
|
||
|
||
func TestParseBatchCommand(t *testing.T) {
|
||
amount, count, memo, ok := parseBatchCommand("/notes 100 x 10 party time")
|
||
if !ok || amount != 100 || count != 10 || memo != "party time" {
|
||
t.Fatalf("got %d %d %q %v", amount, count, memo, ok)
|
||
}
|
||
if _, _, _, ok := parseBatchCommand("/notes"); ok {
|
||
t.Fatal("bare /notes is a list")
|
||
}
|
||
if _, _, _, ok := parseBatchCommand("/notes 100 y 10"); ok {
|
||
t.Fatal("wrong separator")
|
||
}
|
||
if _, _, _, ok := parseBatchCommand("/notes 100 x 0"); ok {
|
||
t.Fatal("zero count")
|
||
}
|
||
if _, c, _, ok := parseBatchCommand("/notes 1k × 3"); !ok || c != 3 {
|
||
t.Fatal("unicode times and 1k amounts must parse")
|
||
}
|
||
}
|
||
|
||
func TestRedactNoteURLs(t *testing.T) {
|
||
in := "/redeem lnurlw://mint.example/w?k1=" + "ab" + "cd"
|
||
if got := redactForLog(in); got == in || !contains(got, "/redeem <") {
|
||
t.Fatalf("note not redacted: %q", got)
|
||
}
|
||
in = "/lnurl https://mint.example/w?k1=abcd&amount=1000"
|
||
if got := redactForLog(in); got == in {
|
||
t.Fatalf("withdraw link with k1 not redacted: %q", got)
|
||
}
|
||
if got := redactForLog("/note 100 hello"); got != "/note 100 hello" {
|
||
t.Fatalf("plain command changed: %q", got)
|
||
}
|
||
if got := formatSat(1000_900); got != "1000.9" {
|
||
t.Fatalf("formatSat: %q", got)
|
||
}
|
||
if got := formatSat(21_000); got != "21" {
|
||
t.Fatalf("formatSat: %q", got)
|
||
}
|
||
}
|
||
|
||
func contains(s, sub string) bool {
|
||
return len(s) >= len(sub) && (func() bool {
|
||
for i := 0; i+len(sub) <= len(s); i++ {
|
||
if s[i:i+len(sub)] == sub {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
})()
|
||
}
|
||
|
||
func TestPreserveNoteCase(t *testing.T) {
|
||
if got := preserveNoteCase("LNURLW://Mint.Example/W/Abc?k1=AB"); got != "lnurlw://Mint.Example/W/Abc?k1=AB" {
|
||
t.Fatalf("got %q", got)
|
||
}
|
||
if got := preserveNoteCase("LIGHTNING:LNURL1ABC"); got != "lightning:lnurl1abc" {
|
||
t.Fatalf("got %q", got)
|
||
}
|
||
}
|