Forráskód Böngészése

Add more tests for the storage layer

Cesar Rodas 5 hónapja
szülő
commit
10ab61ddc0
1 módosított fájl, 47 hozzáadás és 0 törlés
  1. 47 0
      crates/cdk-common/src/database/mint/test.rs

+ 47 - 0
crates/cdk-common/src/database/mint/test.rs

@@ -78,11 +78,58 @@ where
     tx.commit().await.unwrap();
 }
 
+/// Test the basic storing and retrieving proofs from the database. Probably the database would use
+/// binary/Vec<u8> to store data, that's why this test would quickly identify issues before running
+/// other tests
+pub async fn add_and_find_proofs<DB>(db: DB)
+where
+    DB: Database<database::Error> + KeysDatabase<Err = database::Error>,
+{
+    let keyset_id = setup_keyset(&db).await;
+
+    let quote_id = Uuid::max();
+
+    let proofs = vec![
+        Proof {
+            amount: Amount::from(100),
+            keyset_id,
+            secret: Secret::generate(),
+            c: SecretKey::generate().public_key(),
+            witness: None,
+            dleq: None,
+        },
+        Proof {
+            amount: Amount::from(200),
+            keyset_id,
+            secret: Secret::generate(),
+            c: SecretKey::generate().public_key(),
+            witness: None,
+            dleq: None,
+        },
+    ];
+
+    // Add proofs to database
+    let mut tx = Database::begin_transaction(&db).await.unwrap();
+    tx.add_proofs(proofs.clone(), Some(quote_id.clone()))
+        .await
+        .unwrap();
+    assert!(tx.commit().await.is_ok());
+
+    let proofs_from_db = db.get_proofs_by_ys(&[proofs[0].c, proofs[1].c]).await;
+    assert!(proofs_from_db.is_ok());
+    assert_eq!(proofs_from_db.unwrap().len(), 2);
+
+    let proofs_from_db = db.get_proof_ys_by_quote_id(&quote_id).await;
+    assert!(proofs_from_db.is_ok());
+    assert_eq!(proofs_from_db.unwrap().len(), 2);
+}
+
 /// Unit test that is expected to be passed for a correct database implementation
 #[macro_export]
 macro_rules! mint_db_test {
     ($make_db_fn:ident) => {
         mint_db_test!(state_transition, $make_db_fn);
+        mint_db_test!(add_and_find_proofs, $make_db_fn);
     };
     ($name:ident, $make_db_fn:ident) => {
         #[tokio::test]