Docker Build (Gitea) / Build and Push Docker Image (push) Successful in 13s
之前刻意保留的三处,在没有订单数据的前提下一起改掉: - 表前缀 bep_ → vupay_(6 张表 + gormigrate 的 vupay_migration) - api_type 取值 "epusdt"/"epusdt_order" → "vupay"/"vupay_order" - handler 包 app/handler/epusdt → app/handler/vupay、类型 Epusdt → Vupay、EpusdtSign → VupaySign 顺带清理: - 删 docs/faq/vupay.md(整篇是「本项目和 EPusdt 的关系」的上游叙事) - README 去掉「缘起于/原项目已转手」说明与上游致谢条目,联系邮箱不再指向 vupay.online - 修 app/task/testenv_test.go 的 model.Init 调用(上一版加 MySQL 支持时漏了第三个参数,go build 不编译测试所以没暴露) 验证:go build ./... / go vet ./... / go test ./app/... 全通过;全仓 grep -i epusdt 归零
104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
package task
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.viaeon.com/admin/vupay/app/model"
|
|
)
|
|
|
|
func newSolanaSlotTestServer(t *testing.T, head *atomic.Int64) *httptest.Server {
|
|
t.Helper()
|
|
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = fmt.Fprintf(w, `{"jsonrpc":"2.0","result":%d,"id":1}`, head.Load())
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
|
|
return srv
|
|
}
|
|
|
|
func createSolanaWaitingOrder(t *testing.T) {
|
|
t.Helper()
|
|
|
|
createTestOrder(t, model.Order{
|
|
OrderId: "merchant-order-1",
|
|
TradeId: "trade-order-1",
|
|
TradeType: model.UsdcSolana,
|
|
Rate: "7.00",
|
|
Amount: "1.23",
|
|
Money: "8.61",
|
|
Address: "GpsvqTPP7triXkqH8mVtXEM6at9DJ41UHy5dYPTFe16H",
|
|
Status: model.OrderStatusWaiting,
|
|
ApiType: model.OrderApiTypeVupay,
|
|
ExpiredAt: time.Now().Add(10 * time.Minute),
|
|
}, time.Now().Add(-time.Minute))
|
|
}
|
|
|
|
// 落后阈值设为 10,用 20 个 slot 的落后量验证,队列不会超过 chanx 的初始容量
|
|
const solanaTestMaxDiff = 10
|
|
|
|
func TestSolanaForwardCatchesUpWhileOrdersActive(t *testing.T) {
|
|
var head atomic.Int64
|
|
srv := newSolanaSlotTestServer(t, &head)
|
|
initTaskTestEnv(t, map[model.ConfKey]string{model.RpcEndpointSolana: srv.URL, model.BlockHeightMaxDiff: fmt.Sprint(solanaTestMaxDiff)})
|
|
createSolanaWaitingOrder(t)
|
|
|
|
const last = 458000000
|
|
s := newSolana()
|
|
s.lastSlotNum = last
|
|
head.Store(last + 2*solanaTestMaxDiff)
|
|
s.syncSlotForward(t.Context())
|
|
|
|
if s.lastSlotNum != last+2*solanaTestMaxDiff {
|
|
t.Fatalf("lastSlotNum = %d, want %d", s.lastSlotNum, last+2*solanaTestMaxDiff)
|
|
}
|
|
select {
|
|
case got := <-s.slotQueue.Out:
|
|
if got != last+1 {
|
|
t.Fatalf("first queued slot = %d, want %d: slots were skipped", got, last+1)
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatalf("no slot queued: slots %d-%d were skipped", last+1, last+2*solanaTestMaxDiff)
|
|
}
|
|
}
|
|
|
|
func TestSolanaForwardSkipsAfterIdle(t *testing.T) {
|
|
var head atomic.Int64
|
|
srv := newSolanaSlotTestServer(t, &head)
|
|
initTaskTestEnv(t, map[model.ConfKey]string{model.RpcEndpointSolana: srv.URL, model.BlockHeightMaxDiff: fmt.Sprint(solanaTestMaxDiff)})
|
|
|
|
const last = 458000000
|
|
s := newSolana()
|
|
s.lastSlotNum = last
|
|
head.Store(last + 2*solanaTestMaxDiff)
|
|
s.syncSlotForward(t.Context()) // 没有订单,暂停扫描
|
|
if s.lastSlotNum != last {
|
|
t.Fatalf("lastSlotNum = %d while idle, want %d", s.lastSlotNum, last)
|
|
}
|
|
|
|
createSolanaWaitingOrder(t)
|
|
s.syncSlotForward(t.Context())
|
|
if s.lastSlotNum != last+2*solanaTestMaxDiff || s.slotQueue.Len() != 0 {
|
|
t.Fatalf("lastSlotNum = %d, queued = %d; want a jump to %d after idle", s.lastSlotNum, s.slotQueue.Len(), last+2*solanaTestMaxDiff)
|
|
}
|
|
}
|
|
|
|
func TestSolanaForwardSkipsOnStartup(t *testing.T) {
|
|
var head atomic.Int64
|
|
srv := newSolanaSlotTestServer(t, &head)
|
|
initTaskTestEnv(t, map[model.ConfKey]string{model.RpcEndpointSolana: srv.URL, model.BlockHeightMaxDiff: fmt.Sprint(solanaTestMaxDiff)})
|
|
createSolanaWaitingOrder(t)
|
|
|
|
s := newSolana()
|
|
head.Store(458000000)
|
|
s.syncSlotForward(t.Context())
|
|
if s.lastSlotNum != 458000000 || s.slotQueue.Len() != 0 {
|
|
t.Fatalf("lastSlotNum = %d, queued = %d; want a jump to the latest slot on startup", s.lastSlotNum, s.slotQueue.Len())
|
|
}
|
|
}
|