Skip to content

Commit c363e3f

Browse files
committed
test(v3): cover 14-block numeric + 12-block timestamptz ORE ordering
Direct comparator tests over generated fixtures: numeric terms are 702 bytes (N=14) and order across a full 14-value ascending chain spanning sign, magnitude, and fractional scale (so the left blocks decide ordering — the regression the missed 9 -> 1+n offset would fail); timestamptz terms are 604 bytes (N=12) and order 1900 < 2099. Verified end-to-end: numeric + timestamptz ordered matrix suites (211 each, incl. < <= > >= / ORDER BY / MIN / MAX) green; full SQLx suite 2026 passed; test:matrix:inventory reconciles both new ordered types; self-contained v3 install green.
1 parent 373e64d commit c363e3f

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

tests/sqlx/tests/ore_block_comparator_tests.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,81 @@ async fn comparator_rejects_sixteen_byte_term(pool: PgPool) -> Result<()> {
5050
);
5151
Ok(())
5252
}
53+
54+
/// Width: a numeric ORE term must be 14 blocks => 49*14 + 16 = 702 bytes.
55+
#[sqlx::test(fixtures(path = "../fixtures", scripts("eql_v2_numeric")))]
56+
async fn numeric_term_is_14_blocks(pool: PgPool) -> Result<()> {
57+
let width: i32 = sqlx::query_scalar(
58+
"SELECT octet_length((((eql_v3.ord_term( \
59+
(SELECT payload FROM fixtures.eql_v2_numeric WHERE plaintext = (-1000000)::numeric) \
60+
::eql_v3.numeric_ord)).terms)[1]).bytes)",
61+
)
62+
.fetch_one(&pool)
63+
.await?;
64+
assert_eq!(width, 702, "numeric ORE term must be 14 blocks (702 bytes)");
65+
Ok(())
66+
}
67+
68+
/// Full ascending chain of 14-block numeric terms: every adjacent pair must
69+
/// order `-1`. Spans sign, magnitude, and fractional (low-block) scale, so the
70+
/// left blocks — not just the right blocks — decide ordering. This is the
71+
/// regression the missed `9 -> 1+n` left-offset would fail; a single pair could
72+
/// pass against that bug.
73+
#[sqlx::test(fixtures(path = "../fixtures", scripts("eql_v2_numeric")))]
74+
async fn numeric_terms_order_in_ascending_chain(pool: PgPool) -> Result<()> {
75+
let ascending = [
76+
"-1000000000000",
77+
"-1000000",
78+
"-1.001",
79+
"-1",
80+
"-0.5",
81+
"-0.001",
82+
"0",
83+
"0.001",
84+
"0.5",
85+
"0.999999999",
86+
"1",
87+
"1.001",
88+
"1000000",
89+
"1000000000000",
90+
];
91+
for pair in ascending.windows(2) {
92+
let (lo, hi) = (pair[0], pair[1]);
93+
let cmp: i32 = sqlx::query_scalar(&format!(
94+
"SELECT eql_v3.compare_ore_block_256_terms( \
95+
eql_v3.ord_term((SELECT payload FROM fixtures.eql_v2_numeric WHERE plaintext = ({lo})::numeric)::eql_v3.numeric_ord), \
96+
eql_v3.ord_term((SELECT payload FROM fixtures.eql_v2_numeric WHERE plaintext = ({hi})::numeric)::eql_v3.numeric_ord))"
97+
))
98+
.fetch_one(&pool)
99+
.await?;
100+
assert_eq!(cmp, -1, "{lo} must order before {hi}");
101+
}
102+
Ok(())
103+
}
104+
105+
/// Symmetric 12-block (timestamptz, N=12 => 604 bytes) width + ordering check.
106+
/// 12 is the only N strictly between the working 8 and the headline 14.
107+
#[sqlx::test(fixtures(path = "../fixtures", scripts("eql_v2_timestamptz")))]
108+
async fn timestamptz_term_is_12_blocks_and_orders(pool: PgPool) -> Result<()> {
109+
let width: i32 = sqlx::query_scalar(
110+
"SELECT octet_length((((eql_v3.ord_term( \
111+
(SELECT payload FROM fixtures.eql_v2_timestamptz WHERE plaintext = '1970-01-01T00:00:00Z'::timestamptz) \
112+
::eql_v3.timestamptz_ord)).terms)[1]).bytes)",
113+
)
114+
.fetch_one(&pool)
115+
.await?;
116+
assert_eq!(
117+
width, 604,
118+
"timestamptz ORE term must be 12 blocks (604 bytes)"
119+
);
120+
121+
let cmp: i32 = sqlx::query_scalar(
122+
"SELECT eql_v3.compare_ore_block_256_terms( \
123+
eql_v3.ord_term((SELECT payload FROM fixtures.eql_v2_timestamptz WHERE plaintext = '1900-01-01T00:00:00Z'::timestamptz)::eql_v3.timestamptz_ord), \
124+
eql_v3.ord_term((SELECT payload FROM fixtures.eql_v2_timestamptz WHERE plaintext = '2099-12-31T23:59:59Z'::timestamptz)::eql_v3.timestamptz_ord))",
125+
)
126+
.fetch_one(&pool)
127+
.await?;
128+
assert_eq!(cmp, -1, "1900 must order before 2099");
129+
Ok(())
130+
}

0 commit comments

Comments
 (0)