Files
MichilisandClaude Fable 5.1 8514341118 Update the Go toolchain and golang.org/x/net
go run with the host's Go 1.21.6 reached 13 known net/http, crypto/tls
and crypto/x509 vulnerabilities, and golang.org/x/net was from 2021. The
module now asks for go1.26.11 through the toolchain directive (Go 1.21+
downloads it on first run) and uses x/net v0.62.0 and gorilla/websocket
v1.5.3. govulncheck is down to two findings in dependencies with no fix
(imroc/req v0.3.0, lnd v0.15 zpay32) that the bot's code paths do not
exercise.

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

53 lines
1.8 KiB
Go

package verify
import (
"strings"
"testing"
)
func TestValidPaymentHash(t *testing.T) {
ok := strings.Repeat("ab", 32)
cases := map[string]bool{
ok: true,
strings.ToUpper(ok): false, // LNbits uses lowercase
ok + "?x=1": false, // would reach the same payment under a new replay key
ok[:62]: false,
ok + "a": false,
"": false,
strings.Repeat("g", 64): false,
"../" + ok[3:]: false,
strings.Repeat("ab", 31) + "a\n": false,
}
for in, want := range cases {
if got := ValidPaymentHash(in); got != want {
t.Errorf("ValidPaymentHash(%q) = %v, want %v", in, got, want)
}
}
}
func TestSettledIncoming(t *testing.T) {
hash := strings.Repeat("01", 32)
good := Payment{Paid: true, PaymentHash: hash, WalletID: "w1", AmountMsat: 21000}
if got, err := SettledIncoming(good, hash, "w1"); err != nil || got != 21000 {
t.Fatalf("settled payment rejected: amount=%d err=%v", got, err)
}
bad := []struct {
name string
p Payment
}{
{"unpaid", Payment{Paid: false, PaymentHash: hash, WalletID: "w1", AmountMsat: 21000}},
{"other hash", Payment{Paid: true, PaymentHash: strings.Repeat("02", 32), WalletID: "w1", AmountMsat: 21000}},
{"other wallet", Payment{Paid: true, PaymentHash: hash, WalletID: "w2", AmountMsat: 21000}},
{"outgoing", Payment{Paid: true, PaymentHash: hash, WalletID: "w1", AmountMsat: -21000}},
{"zero", Payment{Paid: true, PaymentHash: hash, WalletID: "w1", AmountMsat: 0}},
{"empty", Payment{}},
}
for _, c := range bad {
if got, err := SettledIncoming(c.p, hash, "w1"); err == nil || got != 0 {
t.Errorf("%s: accepted with amount=%d err=%v", c.name, got, err)
}
}
}