Skip to content

Commit 959e704

Browse files
committed
chore(coprocessor): update unit-tests in zkproof to use PostgresPoolManager
1 parent 61323fe commit 959e704

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

coprocessor/fhevm-engine/zkproof-worker/src/tests/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ mod utils;
88
#[tokio::test]
99
#[serial(db)]
1010
async fn test_verify_proof() {
11-
let (pool, _instance) = utils::setup().await.expect("valid setup");
11+
let (pool_mngr, _instance) = utils::setup().await.expect("valid setup");
12+
let pool = pool_mngr.pool();
1213

1314
// Generate Valid ZkPok
1415
let aux: (crate::auxiliary::ZkData, [u8; 92]) =
@@ -42,7 +43,8 @@ async fn test_verify_proof() {
4243
#[tokio::test]
4344
#[serial(db)]
4445
async fn test_verify_empty_input_list() {
45-
let (pool, _instance) = utils::setup().await.expect("valid setup");
46+
let (pool_mngr, _instance) = utils::setup().await.expect("valid setup");
47+
let pool = pool_mngr.pool();
4648

4749
let aux: (crate::auxiliary::ZkData, [u8; 92]) =
4850
utils::aux_fixture(ACL_CONTRACT_ADDR.to_owned());
@@ -61,7 +63,8 @@ async fn test_verify_empty_input_list() {
6163
#[tokio::test]
6264
#[serial(db)]
6365
async fn test_max_input_index() {
64-
let (db, _instance) = utils::setup().await.expect("valid setup");
66+
let (pool_mngr, _instance) = utils::setup().await.expect("valid setup");
67+
let pool = pool_mngr.pool();
6568

6669
let aux: (crate::auxiliary::ZkData, [u8; 92]) =
6770
utils::aux_fixture(ACL_CONTRACT_ADDR.to_owned());
@@ -70,11 +73,11 @@ async fn test_max_input_index() {
7073
let inputs = vec![utils::ZkInput::U8(1); MAX_INPUT_INDEX as usize + 2];
7174

7275
assert!(!utils::is_valid(
73-
&db,
76+
&pool,
7477
utils::insert_proof(
75-
&db,
78+
&pool,
7679
101,
77-
&utils::generate_zk_pok_with_inputs(&db, &aux.1, &inputs).await,
80+
&utils::generate_zk_pok_with_inputs(&pool, &aux.1, &inputs).await,
7881
&aux.0
7982
)
8083
.await
@@ -87,11 +90,11 @@ async fn test_max_input_index() {
8790
// Test with highest number of inputs - 255
8891
let inputs = vec![utils::ZkInput::U64(2); MAX_INPUT_INDEX as usize + 1];
8992
assert!(utils::is_valid(
90-
&db,
93+
&pool,
9194
utils::insert_proof(
92-
&db,
95+
&pool,
9396
102,
94-
&utils::generate_zk_pok_with_inputs(&db, &aux.1, &inputs).await,
97+
&utils::generate_zk_pok_with_inputs(&pool, &aux.1, &inputs).await,
9598
&aux.0
9699
)
97100
.await

coprocessor/fhevm-engine/zkproof-worker/src/tests/utils.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use fhevm_engine_common::pg_pool::PostgresPoolManager;
12
use fhevm_engine_common::{tenant_keys, utils::safe_serialize};
23
use std::sync::Arc;
34
use std::time::{Duration, SystemTime};
@@ -7,7 +8,7 @@ use tokio::time::sleep;
78

89
use crate::auxiliary::ZkData;
910

10-
pub async fn setup() -> anyhow::Result<(sqlx::PgPool, DBInstance)> {
11+
pub async fn setup() -> anyhow::Result<(PostgresPoolManager, DBInstance)> {
1112
let _ = tracing_subscriber::fmt().json().with_level(true).try_init();
1213
let test_instance = test_harness::instance::setup_test_db(ImportMode::WithKeysNoSns)
1314
.await
@@ -22,27 +23,35 @@ pub async fn setup() -> anyhow::Result<(sqlx::PgPool, DBInstance)> {
2223
worker_thread_count: 1,
2324
};
2425

25-
let pool = sqlx::postgres::PgPoolOptions::new()
26-
.max_connections(10)
27-
.connect(&conf.database_url)
28-
.await?;
26+
let pool_mngr = PostgresPoolManager::connect_pool(
27+
test_instance.parent_token.child_token(),
28+
conf.database_url.as_str(),
29+
Duration::from_secs(15),
30+
10,
31+
Duration::from_secs(2),
32+
None, // TODO: conf.pg_auto_explain_with_min_duration
33+
)
34+
.await
35+
.unwrap();
36+
37+
let pmngr = pool_mngr.clone();
2938

3039
sqlx::query("TRUNCATE TABLE verify_proofs")
31-
.execute(&pool)
40+
.execute(&pmngr.pool())
3241
.await
3342
.unwrap();
3443

3544
let last_active_at = Arc::new(RwLock::new(SystemTime::now()));
36-
let db_pool = pool.clone();
45+
3746
tokio::spawn(async move {
38-
crate::verifier::execute_verify_proofs_loop(db_pool, conf.clone(), last_active_at.clone())
47+
crate::verifier::execute_verify_proofs_loop(pmngr, conf.clone(), last_active_at.clone())
3948
.await
4049
.unwrap();
4150
});
4251

4352
sleep(Duration::from_secs(2)).await;
4453

45-
Ok((pool, test_instance))
54+
Ok((pool_mngr, test_instance))
4655
}
4756

4857
/// Checks if the proof is valid by querying the database continuously.

coprocessor/fhevm-engine/zkproof-worker/src/verifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use fhevm_engine_common::healthz_server::{HealthCheckService, HealthStatus, Vers
3030
use tokio::time::interval;
3131
use tokio::{select, time::Duration};
3232
use tokio_util::sync::CancellationToken;
33-
use tracing::{error, info};
33+
use tracing::{debug, error, info};
3434

3535
const MAX_CACHED_TENANT_KEYS: usize = 100;
3636
const EVENT_CIPHERTEXT_COMPUTED: &str = "event_ciphertext_computed";
@@ -205,7 +205,7 @@ async fn execute_worker(
205205
};
206206
},
207207
_ = idle_event.tick() => {
208-
info!("Polling timeout, rechecking for requests");
208+
debug!("Polling timeout, rechecking for requests");
209209
},
210210
_ = token.cancelled() => {
211211
info!("Cancellation requested, stopping worker");

0 commit comments

Comments
 (0)