MCPcopy Create free account
hub / github.com/cowprotocol/services / postgres_solvable_orders_valid_from

Function postgres_solvable_orders_valid_from

crates/database/src/orders.rs:2244–2292  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2242 #[tokio::test]
2243 #[ignore]
2244 async fn postgres_solvable_orders_valid_from() {
2245 let mut db = PgConnection::connect("postgresql://").await.unwrap();
2246 let mut db = db.begin().await.unwrap();
2247 crate::clear_DANGER_(&mut db).await.unwrap();
2248
2249 async fn solvable_uids(ex: &mut PgConnection, now: i64) -> HashSet<OrderUid> {
2250 // `min_valid_to = now` mirrors production so `valid_to` expiry is
2251 // enforced.
2252 solvable_orders(ex, now, now)
2253 .map_ok(|o| o.uid)
2254 .try_collect()
2255 .await
2256 .unwrap()
2257 }
2258
2259 let gated = Order {
2260 uid: ByteArray([1u8; 56]),
2261 kind: OrderKind::Sell,
2262 sell_amount: 10.into(),
2263 buy_amount: 100.into(),
2264 // `valid_to` is past every checked `now`.
2265 valid_to: 10_000,
2266 partially_fillable: true,
2267 creation_timestamp: Utc::now(),
2268 valid_from: Some(1_000),
2269 ..Default::default()
2270 };
2271 insert_order(&mut db, &gated).await.unwrap();
2272
2273 // Gated out before valid_from.
2274 assert!(solvable_uids(&mut db, 999).await.is_empty());
2275 // Eligible exactly at, and after, valid_from.
2276 assert_eq!(solvable_uids(&mut db, 1_000).await, hashset![gated.uid]);
2277 assert_eq!(solvable_uids(&mut db, 2_000).await, hashset![gated.uid]);
2278
2279 let ungated = Order {
2280 uid: ByteArray([2u8; 56]),
2281 kind: OrderKind::Sell,
2282 sell_amount: 10.into(),
2283 buy_amount: 100.into(),
2284 valid_to: 100,
2285 partially_fillable: true,
2286 creation_timestamp: Utc::now(),
2287 valid_from: None,
2288 ..Default::default()
2289 };
2290 insert_order(&mut db, &ungated).await.unwrap();
2291 assert_eq!(solvable_uids(&mut db, 0).await, hashset![ungated.uid]);
2292 }
2293
2294 #[tokio::test]
2295 #[ignore]

Callers

nothing calls this directly

Calls 7

clear_DANGER_Function · 0.85
ByteArrayClass · 0.85
nowFunction · 0.85
unwrapMethod · 0.80
insert_orderFunction · 0.70
connectFunction · 0.50
intoMethod · 0.45

Tested by

no test coverage detected