Skip to content

Commit 4c996e2

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 cc938b1 commit 4c996e2

File tree

23 files changed

+294
-211
lines changed

23 files changed

+294
-211
lines changed

Cargo.lock

Lines changed: 42 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/snapshot/mock.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
use assert_fs::fixture::PathChild;
12
use crate::common::get_available_port;
23
use crate::common::snapshot::SnapshotServiceStarter;
34
use assert_fs::TempDir;
4-
use mainnet_lib::{JsonBasedBdSyncError, JsonBasedDbSync};
5+
use mainnet_lib::{DbSyncError, InMemoryDbSync};
56
use snapshot_trigger_service::client::SnapshotResult;
67
use snapshot_trigger_service::config::{
78
ConfigurationBuilder, JobParameters, NetworkType, VotingToolsParams,
89
};
910

1011
pub fn do_snapshot(
11-
db_sync_instance: &JsonBasedDbSync,
12+
db_sync_instance: &InMemoryDbSync,
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] JsonBasedBdSyncError),
49+
DbSync(#[from] DbSyncError),
4850
#[error(transparent)]
4951
SnapshotIntegration(#[from] crate::common::snapshot::Error),
5052
#[error(transparent)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn cip_36_support() {
3535
.with(bob.as_representative())
3636
.with(clarice.as_representative())
3737
.with(dave.as_delegator(vec![(&bob, 1u8), (&clarice, 1u8)]))
38-
.as_json(&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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn mixed_registration_transactions() {
2828
.with(david.as_representative())
2929
.with(edgar.as_representative())
3030
.with(fred.as_representative())
31-
.as_json(&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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn voters_with_at_least_one_vote() {
3535
.with(alice_wallet.as_direct_voter())
3636
.with(bob_wallet.as_direct_voter())
3737
.with(clarice_wallet.as_direct_voter())
38-
.as_json(&testing_directory);
38+
.build();
3939

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn cip36_mixed_delegation() {
2626
.with(alice.as_direct_voter())
2727
.with(bob.as_delegator(vec![(&david, 1)]))
2828
.with(clarice.as_delegator(vec![(&david, 1), (&edgar, 1)]))
29-
.as_json(&testing_directory);
29+
.build();
3030

3131
let voter_hir = mock::do_snapshot(&db_sync, JobParameters::fund("fund9"), &testing_directory)
3232
.unwrap()
@@ -74,7 +74,7 @@ pub fn voting_power_cap_for_reps() {
7474
.with(alice.as_delegator(vec![(&david, 1)]))
7575
.with(bob.as_delegator(vec![(&edgar, 1)]))
7676
.with(clarice.as_delegator(vec![(&fred, 1)]))
77-
.as_json(&testing_directory);
77+
.build();
7878

7979
let reps_circle_size = reps.len();
8080

@@ -106,7 +106,7 @@ pub fn voting_power_cap_for_direct() {
106106
.with(alice.as_direct_voter())
107107
.with(bob.as_direct_voter())
108108
.with(clarice.as_direct_voter())
109-
.as_json(&testing_directory);
109+
.build();
110110

111111
let voter_hir = mock::do_snapshot(&db_sync, JobParameters::fund("fund9"), &testing_directory)
112112
.unwrap()
@@ -138,7 +138,7 @@ pub fn voting_power_cap_for_mix() {
138138
.with(alice.as_direct_voter())
139139
.with(bob.as_direct_voter())
140140
.with(clarice.as_delegator(vec![(&david, 1)]))
141-
.as_json(&testing_directory);
141+
.build();
142142

143143
let voter_hir = mock::do_snapshot(&db_sync, JobParameters::fund("fund9"), &testing_directory)
144144
.unwrap()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn cip36_and_voting_group_merge() {
3838
.with(alice.as_direct_voter())
3939
.with(bob.as_delegator(vec![(&david, 1)]))
4040
.with(clarice.as_delegator(vec![(&david, 1), (&edgar, 1)]))
41-
.as_json(&testing_directory);
41+
.build();
4242

4343
let voter_hir = mock::do_snapshot(&db_sync, JobParameters::fund("fund9"), &testing_directory)
4444
.unwrap()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn put_raw_snapshot() {
2525
.with(alice_wallet.as_direct_voter())
2626
.with(bob_wallet.as_direct_voter())
2727
.with(clarice_wallet.as_direct_voter())
28-
.as_json(&testing_directory);
28+
.build();
2929

3030
let job_params = JobParameters::fund("fund9");
3131
let snapshot_result =

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

Lines changed: 2 additions & 2 deletions
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;
@@ -34,7 +34,7 @@ pub fn cip36_mixed_delegation_should_appear_in_block0() {
3434
.with(alice.as_direct_voter())
3535
.with(bob.as_delegator(vec![(&david_representative, 1)]))
3636
.with(clarice.as_delegator(vec![(&edgar_representative, 1), (&edgar_representative, 1)]))
37-
.as_json(&testing_directory);
37+
.build();
3838

3939
let snapshot_result =
4040
mock::do_snapshot(&db_sync, JobParameters::fund("fund9"), &testing_directory).unwrap();

src/vit-testing/mainnet-lib/src/cardano_node/block.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,29 @@ use cardano_serialization_lib::crypto::{BlockHash, Ed25519Signature, KESSignatur
44
use cardano_serialization_lib::utils::BigNum;
55
use crate::Settings;
66

7+
78
pub struct Block0{
89
pub block: Block,
910
pub settings: Settings
1011
}
1112

1213

14+
impl Default for Block0 {
15+
fn default() -> Self {
16+
Self {
17+
block: BlockBuilder::next_block(None,vec![]),
18+
settings: Default::default()
19+
}
20+
}
21+
}
22+
1323
pub struct BlockBuilder;
1424

1525
impl BlockBuilder {
1626

1727
pub fn next_block(prev: Option<&Block>, transactions: Vec<Transaction>) -> Block {
1828
let header_body = Self::block_header(
19-
prev.map(|b| b.header().header_body().block_number()).unwrap_or(0),
29+
prev.map(|b| b.header().header_body().block_number()).unwrap_or(1),
2030
prev.map(|b| b.header().header_body().block_body_hash())
2131
);
2232

@@ -51,14 +61,14 @@ impl BlockBuilder {
5161
let issuer_vkey = PrivateKey::generate_ed25519extended().unwrap().to_public();
5262

5363
HeaderBody::new_headerbody(block_number,
54-
&BigNum::zero(),
64+
&BigNum::from(block_number),
5565
prev_hash,
5666
&Vkey::new(&issuer_vkey),
57-
&VRFVKey::from_hex(&issuer_vkey.to_hex()).unwrap(),
58-
&VRFCert::from_hex(&issuer_vkey.to_hex()).unwrap(),
67+
&VRFVKey::from_bytes(Self::generate_random_bytes_of_len(32)).unwrap(),
68+
&VRFCert::new(Self::generate_random_bytes_of_len(32),Self::generate_random_bytes_of_len(VRFCert::PROOF_LEN)).unwrap(),
5969
0,
60-
&BlockHash::from_hex(&issuer_vkey.to_hex()).unwrap(),
61-
&OperationalCert::new(&KESVKey::from_hex(&issuer_vkey.to_hex()).unwrap(),0,0,&Ed25519Signature::from_hex(&issuer_vkey.to_hex()).unwrap()), &ProtocolVersion::new(0,1))
70+
&BlockHash::from_bytes(Self::generate_random_bytes_of_len(32)).unwrap(),
71+
&OperationalCert::new(&KESVKey::from_bytes(Self::generate_random_bytes_of_len(32)).unwrap(),0,0,&Ed25519Signature::from_bytes(Self::generate_random_bytes_of_len(64)).unwrap()), &ProtocolVersion::new(0,1))
6272

6373
}
6474
}

0 commit comments

Comments
 (0)