Skip to content

Commit

Permalink
Integro-test
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Nov 27, 2023
1 parent c98939a commit 2596a3e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/e2e/tests/e2e/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! during a test.
use {
chrono::{DateTime, Utc},
database::{byte_array::ByteArray, order_events, Address, TransactionHash},
e2e::setup::Db,
futures::TryStreamExt,
Expand Down Expand Up @@ -43,6 +44,23 @@ pub struct Cip20Data {
pub competition: serde_json::Value,
}

pub async fn order_events_before_timestamp_count(db: &Db, timestamp: DateTime<Utc>) -> u64 {
let mut db = db.acquire().await.unwrap();

const QUERY: &str = r#"
SELECT COUNT(1)
FROM order_events
WHERE timestamp < $1
"#;
let count: i64 = sqlx::query_scalar(QUERY)
.bind(timestamp)
.fetch_one(db.deref_mut())
.await
.unwrap();

count as u64
}

/// Returns `Some(data)` if the all the expected CIP-20 data has been indexed
/// for the most recent `auction_transaction`.
pub async fn most_recent_cip_20_data(db: &Db) -> Option<Cip20Data> {
Expand Down
1 change: 1 addition & 0 deletions crates/e2e/tests/e2e/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod order_cancellation;
mod partially_fillable_balance;
mod partially_fillable_observed_score;
mod partially_fillable_pool;
mod periodic_db_cleanup;
mod quoting;
mod refunder;
mod settlement_without_onchain_liquidity;
Expand Down
52 changes: 52 additions & 0 deletions crates/e2e/tests/e2e/periodic_db_cleanup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use {
chrono::Utc,
database::{
byte_array::ByteArray,
order_events::{OrderEvent, OrderEventLabel},
},
e2e::setup::*,
shared::ethrpc::Web3,
std::{thread::sleep, time::Duration},
};

#[tokio::test]
#[ignore]
async fn local_node_test() {
run_test(test).await;
}

async fn test(web3: Web3) {
let onchain = OnchainComponents::deploy(web3.clone()).await;
let services = Services::new(onchain.contracts()).await;
let mut ex = services.db().begin().await.unwrap();
let event_a = OrderEvent {
order_uid: ByteArray([1; 56]),
timestamp: Utc::now() - chrono::Duration::days(31),
label: OrderEventLabel::Created,
};
let earliest_timestamp = Utc::now() - chrono::Duration::days(29);
let event_b = OrderEvent {
order_uid: ByteArray([2; 56]),
timestamp: earliest_timestamp,
label: OrderEventLabel::Created,
};
database::order_events::insert_order_event(&mut ex, &event_a)
.await
.unwrap();
database::order_events::insert_order_event(&mut ex, &event_b)
.await
.unwrap();
let count_before =
crate::database::order_events_before_timestamp_count(services.db(), earliest_timestamp)
.await;
assert_eq!(count_before, 2u64);

services.start_autopilot(vec![]);

sleep(Duration::from_secs(2));

let count_after =
crate::database::order_events_before_timestamp_count(services.db(), earliest_timestamp)
.await;
assert_eq!(count_after, 1u64);
}

0 comments on commit 2596a3e

Please sign in to comment.