Skip to content

Commit

Permalink
implement e2e test from snapshot to rewards for active voters and int…
Browse files Browse the repository at this point in the history
…egration test just for snapshot service and catalyst toolbox
  • Loading branch information
dkijania committed Jun 27, 2022
1 parent 1a55dd7 commit 4f0c891
Show file tree
Hide file tree
Showing 40 changed files with 600 additions and 110 deletions.
31 changes: 29 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ members = [
"vitup",
"valgrind",
"integration-tests",
"mainnet-tools",
"registration-service",
"registration-verify-service",
"snapshot-trigger-service",
"signals-handler",
"signals-handler"
]
2 changes: 2 additions & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", bran
vitup = { path = "../vitup"}
iapyx = { path = "../iapyx"}
valgrind = { path = "../valgrind"}
mainnet-tools = { path = "../mainnet-tools"}
snapshot-trigger-service = { path = "../snapshot-trigger-service" }
registration-service = { path = "../registration-service" }
rand_chacha = "0.2"
tokio = { version = "1.1", features = ["macros","rt","rt-multi-thread"] }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "catalyst-fund9", features = [ "property-test-api" ] }
catalyst-toolbox = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "catalyst-fund9", features=["test-api"]}
voting-hir = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "catalyst-fund9"}
thiserror = "1.0"
rand = "0.8"
libmath = "0.2.1"
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/src/backend/rewards/mod.rs

This file was deleted.

16 changes: 16 additions & 0 deletions integration-tests/src/common/mainnet_wallet_ext.rs
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(),
}
}
}
4 changes: 2 additions & 2 deletions integration-tests/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod assert;
pub mod load;
mod mainnet;
pub mod mainnet_wallet_ext;
pub mod registration;
mod rewards;
pub mod snapshot;
Expand All @@ -9,7 +9,7 @@ mod vote_plan_status;
mod wallet;

pub use assert::*;
pub use mainnet::MainnetWallet;
pub use mainnet_tools::wallet::MainnetWallet;
pub use rewards::{funded_proposals, VotesRegistry};
pub use static_data::SnapshotExtensions;
use thiserror::Error;
Expand Down
76 changes: 76 additions & 0 deletions integration-tests/src/common/snapshot/controller.rs
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();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
mod controller;
mod starter;

pub use controller::SnapshotServiceController;
pub use starter::SnapshotServiceStarter;

use snapshot_trigger_service::client::do_snapshot as do_snapshot_internal;
use snapshot_trigger_service::client::{Error, SnapshotResult};
use snapshot_trigger_service::client::{Error as SnapshotClientError, SnapshotResult};
use snapshot_trigger_service::config::JobParameters;
use thiserror::Error;

pub fn do_snapshot(job_params: JobParameters) -> Result<SnapshotResult, Error> {
pub fn do_snapshot(job_params: JobParameters) -> Result<SnapshotResult, SnapshotClientError> {
let snapshot_token = std::env::var("SNAPSHOT_TOKEN").expect("SNAPSHOT_TOKEN not defined");
let snapshot_address = std::env::var("SNAPSHOT_ADDRESS").expect("SNAPSHOT_ADDRESS not defined");

Expand All @@ -14,3 +21,13 @@ pub fn wait_for_db_sync() {
std::thread::sleep(std::time::Duration::from_secs(5 * 60));
println!("Wait finished.");
}

#[derive(Error, Debug)]
pub enum Error {
#[error("spawn error")]
Io(#[from] std::io::Error),
#[error(transparent)]
SnapshotClient(#[from] SnapshotClientError),
#[error(transparent)]
Config(#[from] snapshot_trigger_service::config::Error),
}
48 changes: 48 additions & 0 deletions integration-tests/src/common/snapshot/starter.rs
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.
1 change: 1 addition & 0 deletions integration-tests/src/component/backend/rewards/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod proposers_fund;
File renamed without changes.
3 changes: 3 additions & 0 deletions integration-tests/src/component/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod backend;
mod registration;
mod snapshot;
File renamed without changes.
40 changes: 40 additions & 0 deletions integration-tests/src/component/snapshot/local.rs
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);
}
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.
Loading

0 comments on commit 4f0c891

Please sign in to comment.