Skip to content

Commit

Permalink
extended test ledger with vote related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijania committed Sep 21, 2020
1 parent 84d98f7 commit 60d34ed
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions chain-impl-mockchain/src/testing/ledger.rs
Expand Up @@ -24,6 +24,7 @@ use crate::{
transaction::{Output, TxBuilder},
utxo::{Entry, Iter},
value::Value,
vote::CommitteeId,
};
use chain_addr::{Address, Discrimination};
use chain_crypto::*;
Expand All @@ -44,6 +45,7 @@ pub struct ConfigBuilder {
per_vote_certificate_fee: Option<PerVoteCertificateFee>,
leaders: Vec<BftLeaderId>,
seed: u64,
committees_ids: Vec<CommitteeId>,
rewards: Value,
treasury: Value,
treasury_params: TaxType,
Expand All @@ -65,6 +67,7 @@ impl ConfigBuilder {
linear_fee: None,
per_certificate_fee: None,
per_vote_certificate_fee: None,
committees_ids: Vec::new(),
seed,
rewards: Value(1_000_000),
reward_params: RewardParams::Linear {
Expand All @@ -85,6 +88,11 @@ impl ConfigBuilder {
}
}

pub fn with_committee_id(mut self, committee_id: CommitteeId) -> Self {
self.committees_ids.push(committee_id);
self
}

pub fn with_rewards(mut self, value: Value) -> Self {
self.rewards = value;
self
Expand Down Expand Up @@ -215,6 +223,10 @@ impl ConfigBuilder {
));
}

for committee_id in self.committees_ids {
ie.push(ConfigParam::AddCommitteeId(committee_id.clone()));
}

ie.push(ConfigParam::Block0Date(self.block0_date));
ie.push(ConfigParam::SlotDuration(self.slot_duration));
ie.push(ConfigParam::ConsensusGenesisPraosActiveSlotsCoeff(
Expand Down Expand Up @@ -458,6 +470,10 @@ impl TestLedger {
Ok(())
}

pub fn apply_protocol_changes(&mut self) -> Result<(), Error> {
Ok(self.ledger = self.ledger.apply_protocol_changes()?)
}

pub fn total_funds(&self) -> Value {
self.ledger
.get_total_value()
Expand Down Expand Up @@ -579,6 +595,10 @@ impl TestLedger {
self.ledger.date = self.ledger.date.next(self.ledger.era());
}

pub fn can_distribute_reward(&self) -> bool {
self.ledger.can_distribute_reward()
}

pub fn fast_forward_to(&mut self, date: BlockDate) {
self.set_date(date);
}
Expand Down

0 comments on commit 60d34ed

Please sign in to comment.