Skip to content

Commit

Permalink
node-data: move faker methods to relevant modules
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jul 3, 2024
1 parent 114a6f1 commit bef750e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
15 changes: 0 additions & 15 deletions node-data/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,6 @@ pub mod faker {
use super::*;
use crate::bls::PublicKeyBytes;
use rand::Rng;
use transaction::faker::gen_dummy_tx;

impl<T> Dummy<T> for Block {
/// Creates a block with 3 transactions and random header.
fn dummy_with_rng<R: Rng + ?Sized>(_config: &T, rng: &mut R) -> Self {
let txs = vec![
gen_dummy_tx(rng.gen()),
gen_dummy_tx(rng.gen()),
gen_dummy_tx(rng.gen()),
];
let header: Header = Faker.fake();

Block::new(header, txs).expect("valid hash")
}
}

impl<T> Dummy<T> for PublicKeyBytes {
fn dummy_with_rng<R: Rng + ?Sized>(_config: &T, rng: &mut R) -> Self {
Expand Down
21 changes: 21 additions & 0 deletions node-data/src/ledger/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,24 @@ impl BlockWithLabel {
matches!(self.label(), Label::Final(_)) || self.blk.header().height == 0
}
}

#[cfg(any(feature = "faker", test))]
pub mod faker {
use super::*;
use rand::Rng;
use transaction::faker::gen_dummy_tx;

impl<T> Dummy<T> for Block {
/// Creates a block with 3 transactions and random header.
fn dummy_with_rng<R: Rng + ?Sized>(_config: &T, rng: &mut R) -> Self {
let txs = vec![
gen_dummy_tx(rng.gen()),
gen_dummy_tx(rng.gen()),
gen_dummy_tx(rng.gen()),
];
let header: Header = Faker.fake();

Block::new(header, txs).expect("valid hash")
}
}
}

0 comments on commit bef750e

Please sign in to comment.