package coinledger import "testing" func TestNormalizeListQueryCapsPageSize(t *testing.T) { query := normalizeListQuery(listQuery{Page: -1, PageSize: 1000, UserKeyword: " 10001 "}) if query.Page != 1 || query.PageSize != 100 || query.UserKeyword != "10001" { t.Fatalf("normalized query mismatch: %+v", query) } } func TestCoinLedgerWhereUsesTimeWindowAndUserFilter(t *testing.T) { query := listQuery{StartAtMS: 100, EndAtMS: 200} where, args := coinLedgerWhere("lalu", query, []int64{11, 22}) if want := "WHERE e.app_code = ? AND e.asset_type = ? AND e.created_at_ms >= ? AND e.created_at_ms < ? AND e.user_id IN (?,?)"; where != want { t.Fatalf("where mismatch:\nwant %s\n got %s", want, where) } if len(args) != 6 || args[0] != "lalu" || args[1] != coinAssetType || args[2] != int64(100) || args[3] != int64(200) || args[4] != int64(11) || args[5] != int64(22) { t.Fatalf("args mismatch: %#v", args) } } func TestDirectionAndAmountForDelta(t *testing.T) { if directionForDelta(-9) != directionOut || absInt64(-9) != 9 { t.Fatalf("expense projection mismatch") } if directionForDelta(12) != directionIn || absInt64(12) != 12 { t.Fatalf("income projection mismatch") } }