Files
vupay/app/task/amount_match_test.go
admin a950fd2ead
Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 47s
rebrand: BEpusdt → VUPAY
展示层与标识符全量改名:
- module github.com/v03413/bepusdt → git.viaeon.com/admin/vupay(含全部 import)
- 二进制/镜像/容器/DB 名 bepusdt → vupay(Dockerfile、workflow IMAGE、compose、docs)
- 显示名 BEpusdt → VUPAY(前端 title、后端 banner、version 命令、通知文案)
- 默认路径 /var/lib/bepusdt → /var/lib/vupay,/var/log/bepusdt → /var/log/vupay
- Telegram 通知的频道按钮原来指向上游 t.me 群,改成站点链接(否则改名后是死链)

刻意保留(运行语义,改了会坏):
- api_type 取值 "epusdt" / "epusdt_order"(库里存量数据按此匹配)
- 表前缀 bep_(bep_order / bep_conf / …,改需 RENAME TABLE 迁移)
- 签名函数 EpusdtSign 与 handler 包名 epusdt(对外协议语义,非品牌)
- 所有加密/会话派生的字面量原样不动

验证:gofmt 通过、go build ./... 通过、全仓 grep -i bepusdt 归零
2026-11-25 09:06:06 +08:00

61 lines
1.8 KiB
Go

package task
import (
"testing"
"git.viaeon.com/admin/vupay/app/model"
"github.com/shopspring/decimal"
)
func TestAmountMatchHasPrefix(t *testing.T) {
initTaskTestEnv(t, map[model.ConfKey]string{model.PaymentMatchMode: string(model.HasPrefix)})
cases := []struct {
paid, order string
want bool
}{
{"1.5", "1.5", true},
{"1.50123", "1.5", true},
{"1.509", "1.5", true},
{"1.51", "1.5", false},
{"1.4999", "1.5", false},
{"2", "2", true},
{"2.009", "2", true},
{"2.01", "2", false},
{"2.5", "2", false},
{"10.379", "10.37", true},
{"10.38", "10.37", false},
{"20", "2", false},
{"100.5", "100", false},
{"123.456789", "123.45", true},
// 订单金额小数位多于原子精度时按订单金额的小数位截断
{"1.5059", "1.505", true},
{"1.506", "1.505", false},
}
for _, c := range cases {
got := amountMatch(decimal.RequireFromString(c.paid), c.order, string(model.UsdtTrc20))
if got != c.want {
t.Errorf("paid %s order %s: got %v, want %v", c.paid, c.order, got, c.want)
}
}
}
// 同一地址并发订单按原子精度递增金额,截断后每笔付款最多对应其中一笔
func TestAmountMatchHasPrefixConcurrentOrders(t *testing.T) {
initTaskTestEnv(t, map[model.ConfKey]string{model.PaymentMatchMode: string(model.HasPrefix)})
orders := []string{"1.5", "1.51", "1.52"}
payments := map[string]string{"1.5": "1.5", "1.50123": "1.5", "1.51": "1.51", "1.519": "1.51", "1.52": "1.52"}
for paid, want := range payments {
var matched []string
for _, o := range orders {
if amountMatch(decimal.RequireFromString(paid), o, string(model.UsdtTrc20)) {
matched = append(matched, o)
}
}
if len(matched) != 1 || matched[0] != want {
t.Errorf("paid %s matched %v, want only %s", paid, matched, want)
}
}
}