Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

fix(storage): panic when test batch receipts get #373

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 38 additions & 21 deletions core/storage/src/tests/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,43 @@ use crate::adapter::rocks::RocksAdapter;
use crate::tests::{get_random_bytes, mock_signed_tx};
use crate::{CommonHashKey, TransactionSchema};

#[test]
fn test_adapter_insert() {
adapter_insert_test(MemoryAdapter::new());
#[tokio::test]
async fn test_adapter_insert() {
adapter_insert_test(MemoryAdapter::new()).await;
adapter_insert_test(RocksAdapter::new("rocksdb/test_adapter_insert".to_string(), 64).unwrap())
.await
}

#[test]
fn test_adapter_batch_modify() {
adapter_batch_modify_test(MemoryAdapter::new());
#[tokio::test]
async fn test_adapter_batch_modify() {
adapter_batch_modify_test(MemoryAdapter::new()).await;
adapter_batch_modify_test(
RocksAdapter::new("rocksdb/test_adapter_batch_modify".to_string(), 64).unwrap(),
)
.await
}

#[test]
fn test_adapter_remove() {
adapter_remove_test(MemoryAdapter::new());
#[tokio::test]
async fn test_adapter_remove() {
adapter_remove_test(MemoryAdapter::new()).await;
adapter_remove_test(RocksAdapter::new("rocksdb/test_adapter_remove".to_string(), 64).unwrap())
.await
}

fn adapter_insert_test(db: impl StorageAdapter) {
async fn adapter_insert_test(db: impl StorageAdapter) {
let tx_hash = Hash::digest(get_random_bytes(10));
let tx_key = CommonHashKey::new(1, tx_hash.clone());
let stx = mock_signed_tx(tx_hash.clone());

exec!(db.insert::<TransactionSchema>(tx_key.clone(), stx.clone()));
let stx = exec!(db.get::<TransactionSchema>(tx_key)).unwrap();
db.insert::<TransactionSchema>(tx_key.clone(), stx.clone())
.await
.unwrap();
let stx = db.get::<TransactionSchema>(tx_key).await.unwrap().unwrap();

assert_eq!(tx_hash, stx.tx_hash);
}

fn adapter_batch_modify_test(db: impl StorageAdapter) {
async fn adapter_batch_modify_test(db: impl StorageAdapter) {
let mut stxs = Vec::new();
let mut keys = Vec::new();
let mut inserts = Vec::new();
Expand All @@ -50,8 +55,10 @@ fn adapter_batch_modify_test(db: impl StorageAdapter) {
inserts.push(StorageBatchModify::Insert::<TransactionSchema>(stx));
}

exec!(db.batch_modify::<TransactionSchema>(keys.clone(), inserts));
let opt_stxs = exec!(db.get_batch::<TransactionSchema>(keys));
db.batch_modify::<TransactionSchema>(keys.clone(), inserts)
.await
.unwrap();
let opt_stxs = db.get_batch::<TransactionSchema>(keys).await.unwrap();

for i in 0..10 {
assert_eq!(
Expand All @@ -61,18 +68,28 @@ fn adapter_batch_modify_test(db: impl StorageAdapter) {
}
}

fn adapter_remove_test(db: impl StorageAdapter) {
async fn adapter_remove_test(db: impl StorageAdapter) {
let tx_hash = Hash::digest(get_random_bytes(10));
let tx_key = CommonHashKey::new(1, tx_hash.clone());
let is_exist = exec!(db.contains::<TransactionSchema>(tx_key.clone()));
let is_exist = db
.contains::<TransactionSchema>(tx_key.clone())
.await
.unwrap();
assert!(!is_exist);

let stx = &mock_signed_tx(tx_hash);
exec!(db.insert::<TransactionSchema>(tx_key.clone(), stx.clone()));
let is_exist = exec!(db.contains::<TransactionSchema>(tx_key.clone()));
db.insert::<TransactionSchema>(tx_key.clone(), stx.clone())
.await
.unwrap();
let is_exist = db
.contains::<TransactionSchema>(tx_key.clone())
.await
.unwrap();
assert!(is_exist);

exec!(db.remove::<TransactionSchema>(tx_key.clone()));
let is_exist = exec!(db.contains::<TransactionSchema>(tx_key));
db.remove::<TransactionSchema>(tx_key.clone())
.await
.unwrap();
let is_exist = db.contains::<TransactionSchema>(tx_key).await.unwrap();
assert!(!is_exist);
}
6 changes: 0 additions & 6 deletions core/storage/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
extern crate test;

macro_rules! exec {
($func: expr) => {
futures::executor::block_on(async { $func.await.unwrap() })
};
}

mod adapter;
mod storage;

Expand Down
Loading