This commit is contained in:
2026-08-25 22:35:44 +08:00
parent ec58641d09
commit f14423418a
23 changed files with 738 additions and 680 deletions

View File

@@ -0,0 +1,39 @@
package logic
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestCalcBuyVolume(t *testing.T) {
for _, tt := range []struct {
price, value float64
want int
}{{10, 5000, 500}, {33, 5000, 100}, {100, 5000, 100}, {0, 5000, 0}} {
if got := calcBuyVolume(tt.price, tt.value); got != tt.want {
t.Fatalf("calcBuyVolume(%v,%v)=%d, want %d", tt.price, tt.value, got, tt.want)
}
}
}
func TestNewOrderTagIsShortAndFileSafe(t *testing.T) {
tag := newOrderTag("base")
if len(tag) > 24 || !strings.HasPrefix(tag, "zt-") || strings.ContainsAny(tag, `<>:"/\\|?*`) {
t.Fatalf("订单号不符合约束: %q", tag)
}
}
func TestLoadReceipt(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "order_zt.json")
raw := []byte(`{"order_id":"zt-b-123","qmt_order_id":"9","stock_code":"000001.SZ","side":"buy","requested_volume":500,"traded_volume":500,"status":"filled","updated_at":"2026-08-25T10:00:00+08:00"}`)
if err := os.WriteFile(path, raw, 0o644); err != nil {
t.Fatal(err)
}
got, err := loadReceipt(path)
if err != nil || got.Status != "filled" || got.TradedVolume != 500 {
t.Fatalf("loadReceipt()=%+v, %v", got, err)
}
}