feat(v2): crypto 预留表冷启动兜底——注入 loader 从 pending attempts 重建 reservation(兜重启丢内存)

This commit is contained in:
wangjia
2026-07-10 17:29:08 +08:00
parent c73f7ffaa9
commit e04cd73983
4 changed files with 144 additions and 2 deletions
+29
View File
@@ -0,0 +1,29 @@
package reconcile_test
import (
"context"
"testing"
"github.com/wangjia/pay/internal/model"
"github.com/wangjia/pay/internal/reconcile"
"github.com/wangjia/pay/internal/store"
)
func TestCryptoReservationLoaderFiltersPendingCrypto(t *testing.T) {
db := model.OpenTestDB(t)
s := store.NewOrderStore(db)
// 两条 attempt:crypto pending(要)、alipay pending(不要)。
_ = s.CreateAttempt(&model.Attempt{OutTradeNo: "O1", Channel: "crypto", ProviderRef: "CRYPTO-O1-12",
AmountMinor: 100, Currency: "USDT", Status: model.AttemptPending})
_ = s.CreateAttempt(&model.Attempt{OutTradeNo: "O2", Channel: "alipay", ProviderRef: "AL-O2",
AmountMinor: 200, Currency: "CNY", Status: model.AttemptPending})
loader := reconcile.CryptoReservationLoader(s)
items, err := loader(context.Background())
if err != nil {
t.Fatalf("loader: %v", err)
}
if len(items) != 1 || items[0].ProviderRef != "CRYPTO-O1-12" || items[0].AmountMinor != 100 {
t.Fatalf("只应含 crypto pending, got %+v", items)
}
}