Skip to content

Commit ae18826

Browse files
committed
fix tests
1 parent d190e3b commit ae18826

File tree

4 files changed

+52
-51
lines changed

4 files changed

+52
-51
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,18 @@ impl InMemoryNode {
7272
/// On accessing ledger state
7373
#[must_use]
7474
pub fn start(block0: Block0) -> Self {
75-
let slot_duration = block0.settings.slot_duration;
76-
let shared_ledger: Arc<RwLock<Ledger>> = Arc::new(RwLock::new(Ledger::new(block0)));
75+
Self::start_from_ledger(Ledger::new(block0))
76+
}
77+
78+
/// Starts node process from ledger
79+
///
80+
/// # Panics
81+
///
82+
/// On accessing ledger state
83+
#[must_use]
84+
pub fn start_from_ledger(ledger: Ledger) -> Self {
85+
let slot_duration = ledger.settings().slot_duration;
86+
let shared_ledger: Arc<RwLock<Ledger>> = Arc::new(RwLock::new(ledger));
7787
let shared_block_notifier = SharedPharos::default();
7888

7989
let ledger = shared_ledger.clone();

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::InMemoryNode;
1+
use crate::{Block0, InMemoryNode};
22
use cardano_serialization_lib::metadata::GeneralTransactionMetadata;
33
use cardano_serialization_lib::utils::BigNum;
44
use cardano_serialization_lib::{Block, Transaction, TransactionWitnessSet};
@@ -45,14 +45,22 @@ pub struct InMemoryDbSync {
4545
stakes: HashMap<Address, BigNum>,
4646
settings: Settings,
4747
}
48-
4948
impl Debug for InMemoryDbSync {
5049
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
5150
write!(f, "{:?}", self.settings)
5251
}
5352
}
5453

5554
impl InMemoryDbSync {
55+
56+
/// Creates new instance out of block0
57+
#[must_use]
58+
pub fn from_block0(block0: &Block0) -> Self {
59+
let mut db_sync = InMemoryDbSync::default();
60+
db_sync.on_block_propagation(&block0.block);
61+
db_sync
62+
}
63+
5664
/// Connects to Cardano mock node using simple observer/observable mechanism
5765
///
5866
/// # Panics

src/vit-testing/mainnet-lib/src/network/mod.rs

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub use crate::cardano_node::settings::Settings;
22
use crate::cardano_node::{Block0, BlockBuilder};
33
use crate::db_sync::{InMemoryDbSync, SharedInMemoryDbSync};
44
use crate::wallet::CardanoWallet;
5-
use crate::InMemoryNode;
5+
use crate::{InMemoryNode, Ledger};
66
use cardano_serialization_lib::address::Address;
77
use cardano_serialization_lib::Transaction;
88
use jormungandr_lib::crypto::account::Identifier;
@@ -24,43 +24,19 @@ impl MainnetNetworkBuilder {
2424
self
2525
}
2626

27-
/// Builds dbsync instance and set or representatives identifiers
28-
///
29-
/// # Panics
30-
///
31-
/// On internal logic issue
27+
/// Builds block0
3228
#[must_use]
33-
pub fn in_memory_internal(self) -> (SharedInMemoryDbSync, InMemoryNode, HashSet<Identifier>) {
29+
pub fn build_block0(&self) -> Block0 {
3430
let txs: Vec<_> = self
3531
.states
3632
.iter()
3733
.filter_map(|x| x.registration_tx.clone())
3834
.collect();
3935

40-
let block0 = Block0 {
36+
Block0 {
4137
block: BlockBuilder::next_block(None, &txs),
42-
settings: self.settings,
43-
};
44-
45-
let mut node = InMemoryNode::start(block0);
46-
47-
(
48-
InMemoryDbSync::default().connect_to_node(&mut node),
49-
node,
50-
self.states
51-
.iter()
52-
.map(|x| x.rep.as_ref())
53-
.filter(Option::is_some)
54-
.map(|x| x.unwrap().clone())
55-
.collect(),
56-
)
57-
}
58-
59-
/// Builds dbsync instance and set or representatives identifiers
60-
#[must_use]
61-
pub fn shared(self) -> (SharedInMemoryDbSync, InMemoryNode, HashSet<Identifier>) {
62-
let (db_sync, mut node, reps) = self.build();
63-
(db_sync.connect_to_node(&mut node), node, reps)
38+
settings: self.settings.clone(),
39+
}
6440
}
6541

6642
/// Builds dbsync instance and set or representatives identifiers
@@ -69,23 +45,14 @@ impl MainnetNetworkBuilder {
6945
///
7046
/// On internal logic issue
7147
#[must_use]
72-
pub fn build(self) -> (InMemoryDbSync, InMemoryNode, HashSet<Identifier>) {
73-
let txs: Vec<_> = self
74-
.states
75-
.iter()
76-
.filter_map(|x| x.registration_tx.clone())
77-
.collect();
78-
79-
let block0 = Block0 {
80-
block: BlockBuilder::next_block(None, &txs),
81-
settings: self.settings,
82-
};
83-
84-
let node = InMemoryNode::start(block0);
48+
pub fn build(self) -> (InMemoryDbSync, Ledger, HashSet<Identifier>) {
49+
let block0 = self.build_block0();
50+
let db_sync = InMemoryDbSync::from_block0(&block0);
51+
let ledger = Ledger::new(block0);
8552

8653
(
87-
InMemoryDbSync::default(),
88-
node,
54+
db_sync,
55+
ledger,
8956
self.states
9057
.iter()
9158
.map(|x| x.rep.as_ref())
@@ -94,6 +61,18 @@ impl MainnetNetworkBuilder {
9461
.collect(),
9562
)
9663
}
64+
65+
/// Builds dbsync instance and set or representatives identifiers tailored for async usage
66+
///
67+
/// # Panics
68+
///
69+
/// On internal logic issue
70+
#[must_use]
71+
pub fn build_shared(self) -> (SharedInMemoryDbSync, InMemoryNode, HashSet<Identifier>) {
72+
let (db_sync, ledger, reps) = self.build();
73+
let mut node = InMemoryNode::start_from_ledger(ledger);
74+
(db_sync.connect_to_node(&mut node),node, reps)
75+
}
9776
}
9877

9978
/// Wallet state builder for Network state builder is a trait which creates nice interface for

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ lazy_static::lazy_static! {
3030
pub static ref METADATUM_3: TransactionMetadatum = TransactionMetadatum::new_int(&Int::new_i32(3));
3131
/// metadatum label 4 constant
3232
pub static ref METADATUM_4: TransactionMetadatum = TransactionMetadatum::new_int(&Int::new_i32(4));
33-
/// metadatum label 4 constant
33+
/// metadatum label 5 constant
3434
pub static ref METADATUM_5: TransactionMetadatum = TransactionMetadatum::new_int(&Int::new_i32(5));
3535
}
3636

@@ -115,6 +115,10 @@ impl<'a> RegistrationTransactionBuilder<'a> {
115115
&METADATUM_4,
116116
&TransactionMetadatum::new_int(&Int::new(&BigNum::from(self.slot_no))),
117117
);
118+
meta_map.insert(
119+
&METADATUM_5,
120+
&TransactionMetadatum::new_int(&Int::new(&BigNum::zero())),
121+
);
118122

119123
let mut metadata = GeneralTransactionMetadata::new();
120124
metadata.insert(
@@ -145,7 +149,7 @@ impl<'a> RegistrationTransactionBuilder<'a> {
145149
pub fn build(self) -> Transaction {
146150
let metadata = self.build_metadata();
147151
TransactionBuilder::build_transaction_with_metadata(
148-
&self.wallet.address().to_address(),
152+
&self.wallet.reward_address().to_address(),
149153
self.wallet.stake,
150154
&metadata,
151155
)

0 commit comments

Comments
 (0)