-
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 e2e test from snapshot to rewards for active voters and int…
…egration test just for snapshot service and catalyst toolbox
- Loading branch information
Showing
40 changed files
with
600 additions
and
110 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::common::MainnetWallet; | ||
use vitup::config::Block0Initial; | ||
|
||
pub trait MainnetWalletExtension { | ||
fn as_initial_entry(&self) -> Block0Initial; | ||
} | ||
|
||
impl MainnetWalletExtension for MainnetWallet { | ||
fn as_initial_entry(&self) -> Block0Initial { | ||
Block0Initial::External { | ||
address: self.catalyst_address().to_string(), | ||
funds: self.stake(), | ||
role: Default::default(), | ||
} | ||
} | ||
} |
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,76 @@ | ||
use catalyst_toolbox::snapshot::RawSnapshot; | ||
use catalyst_toolbox::snapshot::Snapshot; | ||
use catalyst_toolbox::snapshot::VotingRegistration; | ||
use fraction::Fraction; | ||
use jortestkit::prelude::Wait; | ||
use snapshot_trigger_service::client::rest::SnapshotRestClient; | ||
use catalyst_toolbox::snapshot::voting_group::VotingGroupAssigner; | ||
use snapshot_trigger_service::config::Configuration; | ||
use snapshot_trigger_service::config::JobParameters; | ||
use std::process::Child; | ||
|
||
pub struct SnapshotServiceController { | ||
child: Child, | ||
configuration: Configuration, | ||
client: SnapshotRestClient, | ||
} | ||
|
||
impl SnapshotServiceController { | ||
pub fn new(child: Child, configuration: Configuration) -> Self { | ||
Self { | ||
child, | ||
client: SnapshotRestClient::new(format!("http://localhost:{}", configuration.port)), | ||
configuration, | ||
} | ||
} | ||
|
||
pub fn client(&self) -> &SnapshotRestClient { | ||
&self.client | ||
} | ||
|
||
pub fn shutdown(mut self) -> Result<(), std::io::Error> { | ||
self.child.kill() | ||
} | ||
|
||
pub fn configuration(&self) -> &Configuration { | ||
&self.configuration | ||
} | ||
|
||
pub fn snapshot( | ||
&self, | ||
job_params: JobParameters, | ||
threshold: u64, | ||
fraction: Fraction, | ||
voting_group_assigner: &impl VotingGroupAssigner, | ||
) -> Snapshot { | ||
let id = self.client().job_new(job_params.clone()).unwrap(); | ||
|
||
self.client() | ||
.wait_for_job_finish(&id, Wait::new(std::time::Duration::from_secs(10), 5)) | ||
.unwrap(); | ||
|
||
let snapshot_content = self | ||
.client() | ||
.get_snapshot(id, job_params.tag.as_ref().unwrap().to_string()) | ||
.unwrap(); | ||
let raw_snapshot: Vec<VotingRegistration> = | ||
serde_json::from_str(&snapshot_content).unwrap(); | ||
|
||
Snapshot::from_raw_snapshot( | ||
RawSnapshot::from(raw_snapshot), | ||
threshold.into(), | ||
fraction, | ||
voting_group_assigner, | ||
) | ||
.unwrap() | ||
} | ||
} | ||
|
||
impl Drop for SnapshotServiceController { | ||
fn drop(&mut self) { | ||
// There's no kill like overkill | ||
let _ = self.child.kill(); | ||
// FIXME: These should be better done in a test harness | ||
self.child.wait().unwrap(); | ||
} | ||
} |
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,48 @@ | ||
use crate::common::snapshot::SnapshotServiceController; | ||
use assert_fs::fixture::PathChild; | ||
use assert_fs::TempDir; | ||
use snapshot_trigger_service::config::write_config; | ||
use snapshot_trigger_service::config::Configuration; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
use super::Error; | ||
use std::process::Command; | ||
|
||
pub struct SnapshotServiceStarter { | ||
configuration: Configuration, | ||
path_to_bin: PathBuf, | ||
} | ||
|
||
impl Default for SnapshotServiceStarter { | ||
fn default() -> Self { | ||
Self { | ||
configuration: Default::default(), | ||
path_to_bin: Path::new("snapshot-trigger-service").to_path_buf(), | ||
} | ||
} | ||
} | ||
|
||
impl SnapshotServiceStarter { | ||
pub fn with_configuration(mut self, configuration: Configuration) -> Self { | ||
self.configuration = configuration; | ||
self | ||
} | ||
|
||
pub fn with_path_to_bin<P: AsRef<Path>>(mut self, path: P) -> Self { | ||
self.path_to_bin = path.as_ref().to_path_buf(); | ||
self | ||
} | ||
|
||
pub fn start(self, temp_dir: &TempDir) -> Result<SnapshotServiceController, Error> { | ||
let config_file = temp_dir.child("snapshot_trigger_service_config.yaml"); | ||
write_config(self.configuration.clone(), config_file.path())?; | ||
Ok(SnapshotServiceController::new( | ||
Command::new(self.path_to_bin) | ||
.arg("--config") | ||
.arg(config_file.path()) | ||
.spawn()?, | ||
self.configuration, | ||
)) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
mod proposers_fund; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
mod backend; | ||
mod registration; | ||
mod snapshot; |
File renamed without changes.
File renamed without changes.
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,40 @@ | ||
use crate::common::registration::do_registration; | ||
use crate::common::snapshot::do_snapshot; | ||
use crate::common::snapshot::wait_for_db_sync; | ||
use assert_fs::TempDir; | ||
use jormungandr_automation::testing::asserts::InitialsAssert; | ||
use snapshot_trigger_service::config::JobParameters; | ||
const GRACE_PERIOD_FOR_SNAPSHOT: u64 = 300; | ||
|
||
#[test] | ||
pub fn mixed_registration_transactions() { | ||
let temp_dir = TempDir::new().unwrap().into_persistent(); | ||
|
||
let first_registartion = do_registration(&temp_dir); | ||
first_registartion.assert_status_is_finished(); | ||
first_registartion.assert_qr_equals_to_sk(); | ||
|
||
let overriden_entry = first_registartion.snapshot_entry().unwrap(); | ||
|
||
println!("Waiting 10 mins before running next registration"); | ||
std::thread::sleep(std::time::Duration::from_secs(5 * 60)); | ||
println!("Wait finished."); | ||
|
||
let second_registartion = do_registration(&temp_dir); | ||
second_registartion.assert_status_is_finished(); | ||
second_registartion.assert_qr_equals_to_sk(); | ||
|
||
let correct_entry = second_registartion.snapshot_entry().unwrap(); | ||
|
||
let job_param = JobParameters { | ||
slot_no: Some(second_registartion.slot_no().unwrap() + GRACE_PERIOD_FOR_SNAPSHOT), | ||
tag: None, | ||
}; | ||
|
||
wait_for_db_sync(); | ||
let snapshot_result = do_snapshot(job_param).unwrap(); | ||
let initials = snapshot_result.initials(); | ||
|
||
initials.assert_contains(correct_entry); | ||
initials.assert_not_contain(overriden_entry); | ||
} |
2 changes: 2 additions & 0 deletions
2
integration-tests/src/snapshot/mod.rs → ...ation-tests/src/component/snapshot/mod.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
#[cfg(feature = "testnet-tests")] | ||
mod testnet; | ||
|
||
mod local; |
File renamed without changes.
Oops, something went wrong.