Skip to content

Commit 95728d8

Browse files
authored
Implement dbsync mock with cardano node mock (#151)
Implement necessary mocks which can simulate communication flow between db sync and cardano node. Removed JsonBasedDbSync as it was redundant to in memory db sync and just move persist and restore methods to in memory db sync. Introduced also basic multi-threaded mechanism of cardano node leadership process as well as db sync update thread. Thanks for that we can use background tokio tasks for producing new blocks and in the same time updates db sync
2 parents 3ec80d6 + 9c99488 commit 95728d8

File tree

37 files changed

+1306
-483
lines changed

37 files changed

+1306
-483
lines changed

Cargo.lock

Lines changed: 43 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vit-testing/integration-tests/src/common/mainnet_wallet_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::common::MainnetWallet;
1+
use crate::common::CardanoWallet;
22
use snapshot_lib::VoterHIR;
33
use vitup::config::Block0Initial;
44

@@ -7,7 +7,7 @@ pub trait MainnetWalletExtension {
77
fn as_voter_hir(&self, group: &str) -> VoterHIR;
88
}
99

10-
impl MainnetWalletExtension for MainnetWallet {
10+
impl MainnetWalletExtension for CardanoWallet {
1111
fn as_initial_entry(&self) -> Block0Initial {
1212
Block0Initial::External {
1313
address: self.catalyst_address().to_string(),

src/vit-testing/integration-tests/src/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod wallet;
1212
pub use reps::{empty_assigner, RepsVoterAssignerSource};
1313

1414
pub use assert::*;
15-
pub use mainnet_lib::MainnetWallet;
15+
pub use mainnet_lib::CardanoWallet;
1616
pub use rewards::{funded_proposals, VotesRegistry};
1717
pub use snapshot_filter::SnapshotFilter;
1818
pub use static_data::SnapshotExtensions;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::common::get_available_port;
22
use crate::common::snapshot::SnapshotServiceStarter;
3+
use assert_fs::fixture::PathChild;
34
use assert_fs::TempDir;
4-
use mainnet_lib::InMemoryDbSync;
5+
use mainnet_lib::{DbSyncError, InMemoryDbSync};
56
use snapshot_trigger_service::client::SnapshotResult;
67
use snapshot_trigger_service::config::{
78
ConfigurationBuilder, JobParameters, NetworkType, VotingToolsParams,
@@ -12,7 +13,8 @@ pub fn do_snapshot(
1213
job_parameters: JobParameters,
1314
testing_directory: &TempDir,
1415
) -> Result<SnapshotResult, Error> {
15-
db_sync_instance.persist()?;
16+
let mock_json_file = testing_directory.child("database.json");
17+
db_sync_instance.persist(mock_json_file.path())?;
1618

1719
let params = VotingToolsParams {
1820
bin: Some("snapshot_tool".to_string()),
@@ -25,7 +27,7 @@ pub fn do_snapshot(
2527
additional_params: Some(vec![
2628
"dry-run".to_string(),
2729
"--mock-json-file".to_string(),
28-
db_sync_instance.db_path().to_str().unwrap().to_string(),
30+
mock_json_file.path().to_str().unwrap().to_string(),
2931
]),
3032
};
3133

@@ -44,7 +46,7 @@ pub fn do_snapshot(
4446
#[derive(thiserror::Error, Debug)]
4547
pub enum Error {
4648
#[error(transparent)]
47-
DbSync(#[from] mainnet_lib::InMemoryDbSyncError),
49+
DbSync(#[from] DbSyncError),
4850
#[error(transparent)]
4951
SnapshotIntegration(#[from] crate::common::snapshot::Error),
5052
#[error(transparent)]

src/vit-testing/integration-tests/src/common/wallet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::common::MainnetWallet;
1+
use crate::common::CardanoWallet;
22
use std::path::Path;
33
use vitup::mode::standard::WalletProxyController;
44

55
pub fn iapyx_from_mainnet(
6-
wallet: &MainnetWallet,
6+
wallet: &CardanoWallet,
77
proxy: &WalletProxyController,
88
) -> Result<iapyx::Controller, iapyx::ControllerBuilderError> {
99
iapyx::ControllerBuilder::default()

src/vit-testing/integration-tests/src/component/backend/cip_36_support.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::common::RepsVoterAssignerSource;
44
use assert_fs::TempDir;
55
use chain_addr::Discrimination;
66
use fraction::Fraction;
7-
use mainnet_lib::MainnetWallet;
7+
use mainnet_lib::CardanoWallet;
88
use mainnet_lib::{MainnetNetworkBuilder, MainnetWalletStateBuilder};
99
use snapshot_trigger_service::config::JobParameters;
1010
use vit_servicing_station_tests::common::data::ArbitraryValidVotingTemplateGenerator;
@@ -25,17 +25,17 @@ pub fn cip_36_support() {
2525
tag: tag.clone(),
2626
};
2727

28-
let alice = MainnetWallet::new(1_000);
29-
let bob = MainnetWallet::new(1_000);
30-
let clarice = MainnetWallet::new(1_000);
31-
let dave = MainnetWallet::new(1_000);
28+
let alice = CardanoWallet::new(1_000);
29+
let bob = CardanoWallet::new(1_000);
30+
let clarice = CardanoWallet::new(1_000);
31+
let dave = CardanoWallet::new(1_000);
3232

33-
let (db_sync, reps) = MainnetNetworkBuilder::default()
33+
let (db_sync, _node, reps) = MainnetNetworkBuilder::default()
3434
.with(alice.as_direct_voter())
3535
.with(bob.as_representative())
3636
.with(clarice.as_representative())
3737
.with(dave.as_delegator(vec![(&bob, 1u8), (&clarice, 1u8)]))
38-
.build(&testing_directory);
38+
.build();
3939

4040
let snapshot_result = mock::do_snapshot(&db_sync, job_param, &testing_directory).unwrap();
4141

src/vit-testing/integration-tests/src/component/snapshot/local.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::common::mainnet_wallet_ext::MainnetWalletExtension;
22
use crate::common::snapshot::mock;
33
use crate::common::snapshot_filter::SnapshotFilterSource;
4-
use crate::common::MainnetWallet;
4+
use crate::common::CardanoWallet;
55
use assert_fs::TempDir;
66
use mainnet_lib::{MainnetNetworkBuilder, MainnetWalletStateBuilder};
77
use snapshot_lib::VoterHIR;
@@ -13,22 +13,22 @@ pub fn mixed_registration_transactions() {
1313
let testing_directory = TempDir::new().unwrap().into_persistent();
1414
let stake = 10_000;
1515

16-
let alice = MainnetWallet::new(stake);
17-
let bob = MainnetWallet::new(stake);
18-
let clarice = MainnetWallet::new(stake);
16+
let alice = CardanoWallet::new(stake);
17+
let bob = CardanoWallet::new(stake);
18+
let clarice = CardanoWallet::new(stake);
1919

20-
let david = MainnetWallet::new(500);
21-
let edgar = MainnetWallet::new(1_000);
22-
let fred = MainnetWallet::new(8_000);
20+
let david = CardanoWallet::new(500);
21+
let edgar = CardanoWallet::new(1_000);
22+
let fred = CardanoWallet::new(8_000);
2323

24-
let (db_sync, reps) = MainnetNetworkBuilder::default()
24+
let (db_sync, _node, reps) = MainnetNetworkBuilder::default()
2525
.with(alice.as_direct_voter())
2626
.with(bob.as_delegator(vec![(&david, 1)]))
2727
.with(clarice.as_delegator(vec![(&david, 1), (&edgar, 1)]))
2828
.with(david.as_representative())
2929
.with(edgar.as_representative())
3030
.with(fred.as_representative())
31-
.build(&testing_directory);
31+
.build();
3232

3333
let voters_hir = mock::do_snapshot(&db_sync, JobParameters::fund("fund9"), &testing_directory)
3434
.unwrap()

src/vit-testing/integration-tests/src/e2e/local/active_voters_rewards.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::common::iapyx_from_mainnet;
55
use crate::common::mainnet_wallet_ext::MainnetWalletExtension;
66
use crate::common::snapshot::mock;
77
use crate::common::snapshot_filter::SnapshotFilterSource;
8-
use crate::common::MainnetWallet;
8+
use crate::common::CardanoWallet;
99
use assert_fs::TempDir;
1010
use catalyst_toolbox::rewards::voters::calc_voter_rewards;
1111
use catalyst_toolbox::rewards::Threshold;
@@ -27,15 +27,15 @@ pub fn voters_with_at_least_one_vote() {
2727

2828
let stake = 10_000;
2929

30-
let alice_wallet = MainnetWallet::new(stake);
31-
let bob_wallet = MainnetWallet::new(stake);
32-
let clarice_wallet = MainnetWallet::new(stake);
30+
let alice_wallet = CardanoWallet::new(stake);
31+
let bob_wallet = CardanoWallet::new(stake);
32+
let clarice_wallet = CardanoWallet::new(stake);
3333

34-
let (db_sync, _) = MainnetNetworkBuilder::default()
34+
let (db_sync, _node, _reps) = MainnetNetworkBuilder::default()
3535
.with(alice_wallet.as_direct_voter())
3636
.with(bob_wallet.as_direct_voter())
3737
.with(clarice_wallet.as_direct_voter())
38-
.build(&testing_directory);
38+
.build();
3939

4040
let snapshot = mock::do_snapshot(&db_sync, JobParameters::fund("fund9"), &testing_directory)
4141
.unwrap()

0 commit comments

Comments
 (0)