-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement snapshot integration test (#275)
* update catalyst-toolbox
- Loading branch information
Showing
42 changed files
with
601 additions
and
302 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use jormungandr_lib::crypto::account::Identifier; | ||
use snapshot_lib::voting_group::RepsVotersAssigner; | ||
use std::collections::HashSet; | ||
|
||
pub const DIRECT_VOTING_GROUP: &str = "direct"; | ||
pub const REP_VOTING_GROUP: &str = "rep"; | ||
|
||
pub trait RepsVoterAssignerSource { | ||
fn into_reps_voter_assigner(self) -> RepsVotersAssigner; | ||
} | ||
|
||
impl RepsVoterAssignerSource for HashSet<Identifier> { | ||
fn into_reps_voter_assigner(self) -> RepsVotersAssigner { | ||
RepsVotersAssigner::new_from_repsdb( | ||
DIRECT_VOTING_GROUP.to_string(), | ||
REP_VOTING_GROUP.to_string(), | ||
self, | ||
) | ||
.unwrap() | ||
} | ||
} | ||
|
||
pub fn empty_assigner() -> RepsVotersAssigner { | ||
HashSet::new().into_reps_voter_assigner() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 27 additions & 3 deletions
30
integration-tests/src/common/snapshot/voter_hirs_asserts.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
use crate::common::RepsVoterAssignerSource; | ||
use chain_addr::Discrimination; | ||
use fraction::Fraction; | ||
use jormungandr_lib::crypto::account::Identifier; | ||
use jormungandr_lib::interfaces::InitialUTxO; | ||
use jormungandr_lib::interfaces::Value; | ||
use snapshot_lib::registration::VotingRegistration; | ||
use snapshot_lib::voting_group::VotingGroupAssigner; | ||
use snapshot_lib::{RawSnapshot, Snapshot, VoterHIR}; | ||
use snapshot_trigger_service::client::SnapshotResult; | ||
use std::collections::HashSet; | ||
|
||
pub trait SnapshotFilterSource { | ||
fn filter( | ||
&self, | ||
voting_threshold: Value, | ||
cap: Fraction, | ||
voting_group_assigner: &impl VotingGroupAssigner, | ||
) -> SnapshotFilter; | ||
fn filter_default(&self, reps: &HashSet<Identifier>) -> SnapshotFilter; | ||
} | ||
|
||
impl SnapshotFilterSource for SnapshotResult { | ||
fn filter( | ||
&self, | ||
voting_threshold: Value, | ||
cap: Fraction, | ||
voting_group_assigner: &impl VotingGroupAssigner, | ||
) -> SnapshotFilter { | ||
SnapshotFilter::from_snapshot_result(self, voting_threshold, cap, voting_group_assigner) | ||
} | ||
|
||
fn filter_default(&self, reps: &HashSet<Identifier>) -> SnapshotFilter { | ||
SnapshotFilter::from_snapshot_result_default(self, reps) | ||
} | ||
} | ||
|
||
pub struct SnapshotFilter { | ||
snapshot: Snapshot, | ||
} | ||
|
||
impl SnapshotFilter { | ||
pub(crate) fn from_snapshot_result_default( | ||
result: &SnapshotResult, | ||
reps: &HashSet<Identifier>, | ||
) -> Self { | ||
Self::from_snapshot_result( | ||
result, | ||
450u64.into(), | ||
Fraction::new(1u64, 3u64), | ||
&reps.clone().into_reps_voter_assigner(), | ||
) | ||
} | ||
} | ||
|
||
impl SnapshotFilter { | ||
pub fn from_snapshot_result( | ||
snapshot_result: &SnapshotResult, | ||
voting_threshold: Value, | ||
cap: Fraction, | ||
voting_group_assigner: &impl VotingGroupAssigner, | ||
) -> SnapshotFilter { | ||
Self::from_voting_registrations( | ||
snapshot_result.registrations().to_vec(), | ||
voting_threshold, | ||
cap, | ||
voting_group_assigner, | ||
) | ||
} | ||
|
||
pub fn from_voting_registrations( | ||
voting_registrations: Vec<VotingRegistration>, | ||
voting_threshold: Value, | ||
cap: Fraction, | ||
voting_group_assigner: &impl VotingGroupAssigner, | ||
) -> SnapshotFilter { | ||
Self { | ||
snapshot: Snapshot::from_raw_snapshot( | ||
RawSnapshot::from(voting_registrations), | ||
voting_threshold, | ||
cap, | ||
voting_group_assigner, | ||
) | ||
.unwrap(), | ||
} | ||
} | ||
|
||
pub fn to_voters_hirs(&self) -> Vec<VoterHIR> { | ||
self.snapshot | ||
.voting_keys() | ||
.map(|vk| VoterHIR { | ||
voting_key: vk.clone(), | ||
voting_power: self | ||
.snapshot | ||
.contributions_for_voting_key(vk) | ||
.iter() | ||
.map(|c| c.value) | ||
.sum::<u64>() | ||
.into(), | ||
voting_group: "direct".to_string(), | ||
}) | ||
.collect() | ||
} | ||
|
||
pub fn to_block0_initials(&self) -> Vec<InitialUTxO> { | ||
self.snapshot.to_block0_initials(Discrimination::Production) | ||
} | ||
|
||
pub fn snapshot(&self) -> Snapshot { | ||
self.snapshot.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::common::snapshot::do_snapshot; | ||
use crate::common::snapshot_filter::SnapshotFilterSource; | ||
use crate::common::RepsVoterAssignerSource; | ||
use assert_fs::TempDir; | ||
use chain_addr::Discrimination; | ||
use fraction::Fraction; | ||
use snapshot_trigger_service::config::JobParameters; | ||
use std::collections::HashSet; | ||
use vit_servicing_station_tests::common::data::ArbitraryValidVotingTemplateGenerator; | ||
use vitup::config::Block0Initials; | ||
use vitup::config::ConfigBuilder; | ||
use vitup::config::SnapshotInitials; | ||
use vitup::testing::spawn_network; | ||
use vitup::testing::vitup_setup; | ||
|
||
#[test] | ||
pub fn cip_36_support() { | ||
let testing_directory = TempDir::new().unwrap().into_persistent(); | ||
let voting_threshold = 1; | ||
let tag = None; | ||
|
||
let job_param = JobParameters { | ||
slot_no: None, | ||
tag: tag.clone(), | ||
}; | ||
|
||
let snapshot_result = do_snapshot(job_param).unwrap(); | ||
let reps = HashSet::new(); | ||
|
||
let snapshot_filter = snapshot_result.filter( | ||
voting_threshold.into(), | ||
Fraction::new(1u64, 3u64), | ||
&reps.into_reps_voter_assigner(), | ||
); | ||
|
||
let config = ConfigBuilder::default() | ||
.voting_power(voting_threshold) | ||
.block0_initials(Block0Initials::new_from_external( | ||
snapshot_filter.to_voters_hirs(), | ||
Discrimination::Production, | ||
)) | ||
.snapshot_initials(SnapshotInitials::from_voters_hir( | ||
snapshot_filter.to_voters_hirs(), | ||
tag.unwrap_or_else(|| "".to_string()), | ||
)) | ||
.build(); | ||
|
||
let mut template_generator = ArbitraryValidVotingTemplateGenerator::new(); | ||
|
||
let (mut controller, vit_parameters, network_params) = | ||
vitup_setup(&config, testing_directory.path().to_path_buf()).unwrap(); | ||
let (_nodes, _vit_station, _wallet_proxy) = spawn_network( | ||
&mut controller, | ||
vit_parameters, | ||
network_params, | ||
&mut template_generator, | ||
) | ||
.unwrap(); | ||
|
||
std::thread::sleep(std::time::Duration::from_secs(3600)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod cip_36_support; | ||
mod features; | ||
mod rewards; | ||
mod sanity; |
Oops, something went wrong.