Skip to content

Commit 8baa785

Browse files
committed
added InMemory Cardano node and Db Sync. Added fake leadership and update processes to simulate node updated to db sync
1 parent b7779e0 commit 8baa785

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/vit-testing/integration-tests/src/common/snapshot/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use assert_fs::fixture::PathChild;
12
use crate::common::get_available_port;
23
use crate::common::snapshot::SnapshotServiceStarter;
34
use assert_fs::fixture::PathChild;

src/vit-testing/integration-tests/src/integration/from_snapshot_to_vitup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::common::snapshot::mock;
2-
use crate::common::{CardanoWallet, RepsVoterAssignerSource, SnapshotFilter};
2+
use crate::common::{CardanoWallet, SnapshotFilter, RepsVoterAssignerSource};
33
use assert_fs::TempDir;
44
use chain_impl_mockchain::certificate::VotePlan;
55
use fraction::Fraction;

src/vit-testing/mainnet-lib/src/db_sync/in_memory.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ use std::fs::File;
1313
use std::io::Write;
1414
use std::path::Path;
1515
use std::sync::{Arc, RwLock};
16+
use cardano_serialization_lib::{Block, Transaction, TransactionWitnessSet};
17+
use cardano_serialization_lib::utils::BigNum;
18+
use futures::executor::block_on;
19+
use futures_util::StreamExt;
20+
use serde::{Deserialize,Serialize};
21+
use pharos::{Channel,Observable};
1622
use tokio::task::JoinHandle;
23+
use crate::InMemoryNode;
1724

1825
pub type BlockNo = u32;
1926
pub type Address = String;
@@ -24,7 +31,14 @@ pub struct SharedInMemoryDbSync {
2431
pub(crate) update_thread: JoinHandle<()>,
2532
// Allowing for now since there is no usage yet in explorer service
2633
#[allow(dead_code)]
27-
pub(crate) db_sync: Arc<RwLock<InMemoryDbSync>>,
34+
35+
/// thread safe `InMemoryDbSync`. It has inner struct db_sync with rw lock guard and handle to update
36+
/// thread which listen to `InMemoryNode` mock block updates
37+
pub struct SharedInMemoryDbSync{
38+
pub(crate) update_thread: JoinHandle<()>,
39+
// Allowing for now since there is no usage yet in explorer service
40+
#[allow(dead_code)]
41+
pub(crate) db_sync: Arc<RwLock<InMemoryDbSync>>
2842
}
2943

3044
impl Drop for SharedInMemoryDbSync {
@@ -33,6 +47,7 @@ impl Drop for SharedInMemoryDbSync {
3347
}
3448
}
3549

50+
3651
/// Mock of real cardano db sync. At this moment we only stores transactions metadata
3752
/// as the only purpose of existance for this struct is to provide catalyst voting registrations
3853
/// Struct can be persisted and restored from json file using `serde_json`.
@@ -41,8 +56,9 @@ pub struct InMemoryDbSync {
4156
pub(crate) transactions: HashMap<BlockNo, Vec<Transaction>>,
4257
pub(crate) blocks: Vec<Block>,
4358
stakes: HashMap<Address, BigNum>,
44-
settings: Settings,
59+
settings: Settings
4560
}
61+
4662
impl Debug for InMemoryDbSync {
4763
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
4864
write!(f, "{:?}", self.settings)
@@ -73,18 +89,18 @@ impl InMemoryDbSync {
7389
let shared_db_sync = Arc::new(RwLock::new(self));
7490
let db_sync = shared_db_sync.clone();
7591

76-
let handle = tokio::spawn(async move {
77-
loop {
92+
let handle = tokio::spawn( async move {
93+
loop {
7894
let block = observer.next().await;
7995
if let Some(block) = block {
8096
db_sync.write().unwrap().on_block_propagation(&block);
8197
}
8298
}
8399
});
84100

85-
SharedInMemoryDbSync {
101+
SharedInMemoryDbSync{
86102
update_thread: handle,
87-
db_sync: shared_db_sync,
103+
db_sync: shared_db_sync
88104
}
89105
}
90106

src/vit-testing/mainnet-lib/src/wallet/registration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl<'a> RegistrationTransactionBuilder<'a> {
156156
}
157157
}
158158

159+
/// Metadata conversion error
159160
/// Metadata conversion error
160161
#[derive(thiserror::Error, Debug)]
161162
pub enum JsonConversionError {

0 commit comments

Comments
 (0)