diff --git a/Cargo.lock b/Cargo.lock index ef7194a2..129ee329 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -516,7 +516,7 @@ dependencies = [ [[package]] name = "catalyst-toolbox" version = "0.5.0" -source = "git+https://github.com/input-output-hk/catalyst-toolbox.git?branch=catalyst-fund9#9abbf7e3a259ca79433976859ad9b2e0d503b4e9" +source = "git+https://github.com/input-output-hk/catalyst-toolbox.git?branch=catalyst-fund9#3ff3e5fed70f5a8adb400a6764945b250d1599e3" dependencies = [ "assert_fs", "bech32 0.8.1", @@ -2793,7 +2793,6 @@ dependencies = [ "chain-ser", "chrono", "csv", - "fraction", "hersir", "iapyx", "jcli", @@ -2801,7 +2800,6 @@ dependencies = [ "jormungandr-lib", "jortestkit", "libmath", - "mainnet-tools", "rand 0.8.5", "rand_chacha 0.2.2", "registration-service", @@ -2815,7 +2813,6 @@ dependencies = [ "vit-servicing-station-lib", "vit-servicing-station-tests", "vitup", - "voting-hir", ] [[package]] @@ -3317,29 +3314,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "mainnet-tools" -version = "0.1.0" -dependencies = [ - "assert_fs", - "bech32 0.8.1", - "catalyst-toolbox", - "chain-addr", - "chain-crypto", - "futures", - "hex", - "jormungandr-lib", - "rand 0.8.5", - "serde", - "serde_json", - "signals-handler", - "structopt", - "tempdir", - "thiserror", - "thor", - "tokio 1.19.2", -] - [[package]] name = "matchers" version = "0.0.1" @@ -5558,7 +5532,7 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "snapshot-service" version = "0.1.0" -source = "git+https://github.com/input-output-hk/vit-servicing-station.git?branch=catalyst-fund9#90e434f2445c47010b141a8a49b7df6e4eaeceec" +source = "git+https://github.com/input-output-hk/vit-servicing-station.git?branch=catalyst-fund9#d9ff489af48946781535e8c1a9c8f8cad7589c1b" dependencies = [ "jormungandr-lib", "notify", @@ -5577,13 +5551,11 @@ name = "snapshot-trigger-service" version = "0.1.0" dependencies = [ "assert_fs", - "catalyst-toolbox", "chain-addr", "chrono", "futures", "jormungandr-lib", "jortestkit", - "mainnet-tools", "reqwest 0.10.10", "serde", "serde_json", @@ -6701,7 +6673,7 @@ dependencies = [ [[package]] name = "vit-servicing-station-lib" version = "0.5.0" -source = "git+https://github.com/input-output-hk/vit-servicing-station.git?branch=catalyst-fund9#90e434f2445c47010b141a8a49b7df6e4eaeceec" +source = "git+https://github.com/input-output-hk/vit-servicing-station.git?branch=catalyst-fund9#d9ff489af48946781535e8c1a9c8f8cad7589c1b" dependencies = [ "async-trait", "base64 0.12.3", @@ -6733,7 +6705,7 @@ dependencies = [ [[package]] name = "vit-servicing-station-tests" version = "0.5.0" -source = "git+https://github.com/input-output-hk/vit-servicing-station.git?branch=catalyst-fund9#6076317d85f20870e28317efc32661b94ff1fe06" +source = "git+https://github.com/input-output-hk/vit-servicing-station.git?branch=catalyst-fund9#d9ff489af48946781535e8c1a9c8f8cad7589c1b" dependencies = [ "assert_cmd 2.0.4", "assert_fs", @@ -6853,7 +6825,7 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "voting-hir" version = "0.1.0" -source = "git+https://github.com/input-output-hk/catalyst-toolbox.git?branch=catalyst-fund9#9abbf7e3a259ca79433976859ad9b2e0d503b4e9" +source = "git+https://github.com/input-output-hk/catalyst-toolbox.git?branch=catalyst-fund9#839821ac7c6a774ff06a1ba34df9b5a126e5293c" dependencies = [ "jormungandr-lib", "serde", diff --git a/Cargo.toml b/Cargo.toml index 031cc5da..bb084dec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,9 +4,8 @@ members = [ "vitup", "valgrind", "integration-tests", - "mainnet-tools", "registration-service", "registration-verify-service", "snapshot-trigger-service", - "signals-handler" + "signals-handler", ] diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index eb7b1343..f7520a37 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -22,14 +22,12 @@ 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" @@ -40,7 +38,6 @@ chrono = "0.4.19" serde_json = "1.0.53" serde = "1.0.53" csv = "1.1" -fraction = "0.10" [features] load-tests = [] diff --git a/integration-tests/src/component/backend/features/batch.rs b/integration-tests/src/backend/features/batch.rs similarity index 100% rename from integration-tests/src/component/backend/features/batch.rs rename to integration-tests/src/backend/features/batch.rs diff --git a/integration-tests/src/component/backend/features/mod.rs b/integration-tests/src/backend/features/mod.rs similarity index 100% rename from integration-tests/src/component/backend/features/mod.rs rename to integration-tests/src/backend/features/mod.rs diff --git a/integration-tests/src/component/backend/features/persistent_log.rs b/integration-tests/src/backend/features/persistent_log.rs similarity index 100% rename from integration-tests/src/component/backend/features/persistent_log.rs rename to integration-tests/src/backend/features/persistent_log.rs diff --git a/integration-tests/src/component/backend/features/update_proposal.rs b/integration-tests/src/backend/features/update_proposal.rs similarity index 100% rename from integration-tests/src/component/backend/features/update_proposal.rs rename to integration-tests/src/backend/features/update_proposal.rs diff --git a/integration-tests/src/component/backend/features/votes_history.rs b/integration-tests/src/backend/features/votes_history.rs similarity index 100% rename from integration-tests/src/component/backend/features/votes_history.rs rename to integration-tests/src/backend/features/votes_history.rs diff --git a/integration-tests/src/component/backend/mod.rs b/integration-tests/src/backend/mod.rs similarity index 100% rename from integration-tests/src/component/backend/mod.rs rename to integration-tests/src/backend/mod.rs diff --git a/integration-tests/src/e2e/local/active_voters_rewards.rs b/integration-tests/src/backend/rewards/active_voters_rewards.rs similarity index 64% rename from integration-tests/src/e2e/local/active_voters_rewards.rs rename to integration-tests/src/backend/rewards/active_voters_rewards.rs index 4bebd29a..37e498bd 100644 --- a/integration-tests/src/e2e/local/active_voters_rewards.rs +++ b/integration-tests/src/backend/rewards/active_voters_rewards.rs @@ -1,21 +1,14 @@ use crate::Vote; use crate::common::iapyx_from_mainnet; -use crate::common::mainnet_wallet_ext::MainnetWalletExtension; -use crate::common::snapshot::SnapshotServiceStarter; use crate::common::MainnetWallet; use assert_fs::TempDir; use catalyst_toolbox::rewards::voters::calc_voter_rewards; +use catalyst_toolbox::snapshot::RawSnapshot; +use catalyst_toolbox::snapshot::Snapshot; use chain_impl_mockchain::block::BlockDate; -use fraction::Fraction; use jormungandr_automation::testing::time; -use mainnet_tools::db_sync::DbSyncInstance; -use mainnet_tools::network::MainnetNetwork; -use mainnet_tools::voting_tools::VotingToolsMock; -use snapshot_trigger_service::config::ConfigurationBuilder; -use snapshot_trigger_service::config::JobParameters; use vit_servicing_station_tests::common::data::ArbitraryValidVotingTemplateGenerator; -use catalyst_toolbox::snapshot::snapshot_test_api::DummyAssigner; use vitup::config::VoteBlockchainTime; use vitup::config::{Block0Initials, ConfigBuilder}; use vitup::testing::spawn_network; @@ -23,42 +16,20 @@ use vitup::testing::vitup_setup; #[test] pub fn voters_with_at_least_one_vote() { - let testing_directory = TempDir::new().unwrap().into_persistent(); - let stake = 10_000; let alice_wallet = MainnetWallet::new(stake); let bob_wallet = MainnetWallet::new(stake); let clarice_wallet = MainnetWallet::new(stake); - let mut mainnet_network = MainnetNetwork::default(); - let mut db_sync_instance = DbSyncInstance::default(); - - mainnet_network.sync_with(&mut db_sync_instance); - - alice_wallet - .send_direct_voting_registration() - .to(&mut mainnet_network); - bob_wallet - .send_direct_voting_registration() - .to(&mut mainnet_network); - clarice_wallet - .send_direct_voting_registration() - .to(&mut mainnet_network); + let raw_snapshot = vec![ + alice_wallet.as_voting_registration(), + bob_wallet.as_voting_registration(), + clarice_wallet.as_voting_registration(), + ]; - let voting_tools = - VotingToolsMock::default().connect_to_db_sync(&db_sync_instance, &testing_directory); - - let configuration = ConfigurationBuilder::default() - .with_voting_tools_params(voting_tools.into()) - .with_tmp_result_dir(&testing_directory) - .build(); - - let snapshot = SnapshotServiceStarter::default() - .with_configuration(configuration) - .start(&testing_directory) - .unwrap() - .snapshot(JobParameters::fund("fund9"), 450u64, Fraction::from(1u64),&DummyAssigner); + let snapshot = Snapshot::from_raw_snapshot(RawSnapshot::from(raw_snapshot), 450.into()); + let testing_directory = TempDir::new().unwrap().into_persistent(); let vote_timing = VoteBlockchainTime { vote_start: 0, @@ -125,7 +96,7 @@ pub fn voters_with_at_least_one_vote() { assert_eq!( records .iter() - .find(|(x, _y)| **x == alice_wallet.reward_address_as_bech32()) + .find(|(x, _y)| **x == alice_wallet.reward_address()) .unwrap() .1, &50u32.into() @@ -134,7 +105,7 @@ pub fn voters_with_at_least_one_vote() { assert_eq!( records .iter() - .find(|(x, _y)| **x == bob_wallet.reward_address_as_bech32()) + .find(|(x, _y)| **x == bob_wallet.reward_address()) .unwrap() .1, &50u32.into() diff --git a/integration-tests/src/backend/rewards/mod.rs b/integration-tests/src/backend/rewards/mod.rs new file mode 100644 index 00000000..0029e449 --- /dev/null +++ b/integration-tests/src/backend/rewards/mod.rs @@ -0,0 +1,2 @@ +mod active_voters_rewards; +mod proposers_fund; diff --git a/integration-tests/src/component/backend/rewards/proposers_fund.rs b/integration-tests/src/backend/rewards/proposers_fund.rs similarity index 100% rename from integration-tests/src/component/backend/rewards/proposers_fund.rs rename to integration-tests/src/backend/rewards/proposers_fund.rs diff --git a/integration-tests/src/component/backend/sanity/mod.rs b/integration-tests/src/backend/sanity/mod.rs similarity index 100% rename from integration-tests/src/component/backend/sanity/mod.rs rename to integration-tests/src/backend/sanity/mod.rs diff --git a/integration-tests/src/component/backend/sanity/private.rs b/integration-tests/src/backend/sanity/private.rs similarity index 100% rename from integration-tests/src/component/backend/sanity/private.rs rename to integration-tests/src/backend/sanity/private.rs diff --git a/integration-tests/src/component/backend/sanity/public.rs b/integration-tests/src/backend/sanity/public.rs similarity index 100% rename from integration-tests/src/component/backend/sanity/public.rs rename to integration-tests/src/backend/sanity/public.rs diff --git a/mainnet-tools/src/wallet/mod.rs b/integration-tests/src/common/mainnet.rs similarity index 51% rename from mainnet-tools/src/wallet/mod.rs rename to integration-tests/src/common/mainnet.rs index 42c0c35a..5d606815 100644 --- a/mainnet-tools/src/wallet/mod.rs +++ b/integration-tests/src/common/mainnet.rs @@ -1,15 +1,10 @@ -mod sender; - -use bech32::ToBase32; use catalyst_toolbox::snapshot::registration::{Delegations, VotingRegistration}; use chain_addr::Discrimination; -use jormungandr_lib::crypto::account::Identifier; use jormungandr_lib::crypto::account::SigningKey; -use jormungandr_lib::interfaces::Address; -use sender::RegistrationSender; +use vitup::config::Block0Initial; pub struct MainnetWallet { - catalyst: thor::Wallet, + inner: thor::Wallet, reward_address: String, stake_public_key: String, stake: u64, @@ -19,7 +14,7 @@ impl MainnetWallet { pub fn new(stake: u64) -> Self { let mut rng = rand::thread_rng(); Self { - catalyst: thor::Wallet::new_account(&mut rng, Discrimination::Production), + inner: thor::Wallet::new_account(&mut rng, Discrimination::Production), stake, reward_address: "0x".to_owned() + &SigningKey::generate_extended(&mut rng) @@ -36,42 +31,29 @@ impl MainnetWallet { self.reward_address.clone() } - pub fn reward_address_as_bech32(&self) -> String { - let bytes = hex::decode(self.reward_address.clone().trim_start_matches("0x")).unwrap(); - bech32::encode("stake", &bytes.to_base32(), bech32::Variant::Bech32).unwrap() - } - pub fn stake_public_key(&self) -> String { self.stake_public_key.clone() } pub fn catalyst_secret_key(&self) -> chain_crypto::SecretKey { - self.catalyst.secret_key() + self.inner.secret_key() } - pub fn catalyst_public_key(&self) -> Identifier { - self.catalyst.secret_key().to_public().into() - } - - pub fn catalyst_address(&self) -> Address { - self.catalyst.address() - } - - pub fn send_voting_registration(&self, delegations: Delegations) -> RegistrationSender { - RegistrationSender::new(VotingRegistration { + pub fn as_voting_registration(&self) -> VotingRegistration { + VotingRegistration { stake_public_key: self.stake_public_key(), voting_power: self.stake.into(), reward_address: self.reward_address(), - delegations, + delegations: Delegations::Legacy(self.inner.identifier().into()), voting_purpose: 0, - }) - } - - pub fn send_direct_voting_registration(&self) -> RegistrationSender { - self.send_voting_registration(Delegations::Legacy(self.catalyst.identifier().into())) + } } - pub fn stake(&self) -> u64 { - self.stake + pub fn as_initial_entry(&self) -> Block0Initial { + Block0Initial::External { + address: self.inner.address().to_string(), + funds: self.stake, + role: Default::default(), + } } } diff --git a/integration-tests/src/common/mainnet_wallet_ext.rs b/integration-tests/src/common/mainnet_wallet_ext.rs deleted file mode 100644 index 96ea6d51..00000000 --- a/integration-tests/src/common/mainnet_wallet_ext.rs +++ /dev/null @@ -1,16 +0,0 @@ -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(), - } - } -} diff --git a/integration-tests/src/common/mod.rs b/integration-tests/src/common/mod.rs index 61cfccc7..6c796c33 100644 --- a/integration-tests/src/common/mod.rs +++ b/integration-tests/src/common/mod.rs @@ -1,6 +1,6 @@ mod assert; pub mod load; -pub mod mainnet_wallet_ext; +mod mainnet; pub mod registration; mod rewards; pub mod snapshot; @@ -9,7 +9,7 @@ mod vote_plan_status; mod wallet; pub use assert::*; -pub use mainnet_tools::wallet::MainnetWallet; +pub use mainnet::MainnetWallet; pub use rewards::{funded_proposals, VotesRegistry}; pub use static_data::SnapshotExtensions; use thiserror::Error; diff --git a/integration-tests/src/common/snapshot/mod.rs b/integration-tests/src/common/snapshot.rs similarity index 55% rename from integration-tests/src/common/snapshot/mod.rs rename to integration-tests/src/common/snapshot.rs index 1dd268af..cd18aebf 100644 --- a/integration-tests/src/common/snapshot/mod.rs +++ b/integration-tests/src/common/snapshot.rs @@ -1,15 +1,8 @@ -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 as SnapshotClientError, SnapshotResult}; +use snapshot_trigger_service::client::{Error, SnapshotResult}; use snapshot_trigger_service::config::JobParameters; -use thiserror::Error; -pub fn do_snapshot(job_params: JobParameters) -> Result { +pub fn do_snapshot(job_params: JobParameters) -> Result { 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"); @@ -21,13 +14,3 @@ 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), -} diff --git a/integration-tests/src/common/snapshot/controller.rs b/integration-tests/src/common/snapshot/controller.rs deleted file mode 100644 index e12570bb..00000000 --- a/integration-tests/src/common/snapshot/controller.rs +++ /dev/null @@ -1,76 +0,0 @@ -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 = - 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(); - } -} diff --git a/integration-tests/src/common/snapshot/starter.rs b/integration-tests/src/common/snapshot/starter.rs deleted file mode 100644 index 4b5342e3..00000000 --- a/integration-tests/src/common/snapshot/starter.rs +++ /dev/null @@ -1,48 +0,0 @@ -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>(mut self, path: P) -> Self { - self.path_to_bin = path.as_ref().to_path_buf(); - self - } - - pub fn start(self, temp_dir: &TempDir) -> Result { - 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, - )) - } -} diff --git a/integration-tests/src/component/backend/rewards/mod.rs b/integration-tests/src/component/backend/rewards/mod.rs deleted file mode 100644 index 41300e2f..00000000 --- a/integration-tests/src/component/backend/rewards/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod proposers_fund; \ No newline at end of file diff --git a/integration-tests/src/component/mod.rs b/integration-tests/src/component/mod.rs deleted file mode 100644 index e7ac1efd..00000000 --- a/integration-tests/src/component/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod backend; -mod registration; -mod snapshot; \ No newline at end of file diff --git a/integration-tests/src/component/snapshot/local.rs b/integration-tests/src/component/snapshot/local.rs deleted file mode 100644 index 809612e5..00000000 --- a/integration-tests/src/component/snapshot/local.rs +++ /dev/null @@ -1,40 +0,0 @@ -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); -} \ No newline at end of file diff --git a/integration-tests/src/e2e/local/mod.rs b/integration-tests/src/e2e/local/mod.rs deleted file mode 100644 index 6ea8d2f0..00000000 --- a/integration-tests/src/e2e/local/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod active_voters_rewards; \ No newline at end of file diff --git a/integration-tests/src/e2e/mod.rs b/integration-tests/src/e2e/mod.rs index 20611614..b1bbe91c 100644 --- a/integration-tests/src/e2e/mod.rs +++ b/integration-tests/src/e2e/mod.rs @@ -1,4 +1,2 @@ #[cfg(feature = "testnet-tests")] mod testnet; - -mod local; diff --git a/integration-tests/src/integration/from_snapshot_to_catalyst_toolbox.rs b/integration-tests/src/integration/from_snapshot_to_catalyst_toolbox.rs deleted file mode 100644 index 8e264d20..00000000 --- a/integration-tests/src/integration/from_snapshot_to_catalyst_toolbox.rs +++ /dev/null @@ -1,102 +0,0 @@ -use catalyst_toolbox::snapshot::voting_group::RepsVotersAssigner; -use catalyst_toolbox::snapshot::Delegations; -use crate::common::snapshot::SnapshotServiceStarter; -use crate::common::MainnetWallet; -use assert_fs::TempDir; -use fraction::Fraction; -use mainnet_tools::db_sync::DbSyncInstance; -use mainnet_tools::network::MainnetNetwork; -use std::collections::HashSet; -use mainnet_tools::voting_tools::VotingToolsMock; -use snapshot_trigger_service::config::ConfigurationBuilder; -use snapshot_trigger_service::config::JobParameters; -use voting_hir::VoterHIR; - - -const DIRECT_VOTING_GROUP: &str = "direct"; -const REP_VOTING_GROUP: &str = "rep"; - -#[test] -pub fn cip36_mixed_delegation() { - let testing_directory = TempDir::new().unwrap().into_persistent(); - - - let stake = 10_000; - - let alice_voter = MainnetWallet::new(stake); - let bob_voter = MainnetWallet::new(stake); - let clarice_voter = MainnetWallet::new(stake); - - let david_representative = MainnetWallet::new(500); - let edgar_representative = MainnetWallet::new(1_000); - let fred_representative = MainnetWallet::new(8_000); - - let mut reps = HashSet::new(); - reps.insert(edgar_representative.catalyst_public_key()); - reps.insert(david_representative.catalyst_public_key()); - reps.insert(fred_representative.catalyst_public_key()); - - let mut mainnet_network = MainnetNetwork::default(); - let mut db_sync_instance = DbSyncInstance::default(); - - mainnet_network.sync_with(&mut db_sync_instance); - - alice_voter - .send_direct_voting_registration() - .to(&mut mainnet_network); - bob_voter - .send_voting_registration(Delegations::New( - vec![(david_representative.catalyst_public_key(),1)] - )) - .to(&mut mainnet_network); - clarice_voter - .send_voting_registration(Delegations::New( - vec![ - (david_representative.catalyst_public_key(),1), - (edgar_representative.catalyst_public_key(),1) - ] - )) - .to(&mut mainnet_network); - - let voting_tools = - VotingToolsMock::default().connect_to_db_sync(&db_sync_instance, &testing_directory); - - let configuration = ConfigurationBuilder::default() - .with_voting_tools_params(voting_tools.into()) - .with_tmp_result_dir(&testing_directory) - .build(); - - - let assigner = RepsVotersAssigner::new_from_repsdb(DIRECT_VOTING_GROUP.to_string(), REP_VOTING_GROUP.to_string(), reps).unwrap(); - - let voter_hir = SnapshotServiceStarter::default() - .with_configuration(configuration) - .start(&testing_directory) - .unwrap() - .snapshot(JobParameters::fund("fund9"), 450u64, Fraction::from(1u64),&assigner) - .to_voter_hir(); - - assert_eq!(voter_hir.len(),3); - assert!(voter_hir.contains( - &VoterHIR { - voting_key: alice_voter.catalyst_public_key(), - voting_group: DIRECT_VOTING_GROUP.to_string(), - voting_power: stake.into(), - } - )); - assert!(voter_hir.contains( - &VoterHIR { - voting_key: david_representative.catalyst_public_key(), - voting_group: REP_VOTING_GROUP.to_string(), - voting_power: (stake + stake/2).into(), - } - )); - assert!(voter_hir.contains( - &VoterHIR { - voting_key: edgar_representative.catalyst_public_key(), - voting_group: REP_VOTING_GROUP.to_string(), - voting_power: (stake/2).into(), - } - )); - assert!(!voter_hir.iter().any(|x| x.voting_key == fred_representative.catalyst_public_key())); -} \ No newline at end of file diff --git a/integration-tests/src/integration/from_snapshot_to_vitup.rs b/integration-tests/src/integration/from_snapshot_to_vitup.rs deleted file mode 100644 index a13a60cf..00000000 --- a/integration-tests/src/integration/from_snapshot_to_vitup.rs +++ /dev/null @@ -1,91 +0,0 @@ -use catalyst_toolbox::snapshot::voting_group::RepsVotersAssigner; -use catalyst_toolbox::snapshot::Delegations; -use crate::common::snapshot::SnapshotServiceStarter; -use crate::common::MainnetWallet; -use assert_fs::TempDir; -use fraction::Fraction; -use mainnet_tools::db_sync::DbSyncInstance; -use mainnet_tools::network::MainnetNetwork; -use std::collections::HashSet; -use mainnet_tools::voting_tools::VotingToolsMock; -use snapshot_trigger_service::config::ConfigurationBuilder; -use jormungandr_automation::testing::block0::read_initials; -use snapshot_trigger_service::config::JobParameters; -use voting_hir::VoterHIR; -use vitup::config::ConfigBuilder; - -const DIRECT_VOTING_GROUP: &str = "direct"; -const REP_VOTING_GROUP: &str = "rep"; - -#[test] -pub fn cip36_mixed_delegation_should_appear_in_block0() { - let testing_directory = TempDir::new().unwrap().into_persistent(); - - - let stake = 10_000; - - let alice_voter = MainnetWallet::new(stake); - let bob_voter = MainnetWallet::new(stake); - let clarice_voter = MainnetWallet::new(stake); - - let david_representative = MainnetWallet::new(500); - let edgar_representative = MainnetWallet::new(1_000); - let fred_representative = MainnetWallet::new(8_000); - - let mut reps = HashSet::new(); - reps.insert(edgar_representative.catalyst_public_key()); - reps.insert(david_representative.catalyst_public_key()); - reps.insert(fred_representative.catalyst_public_key()); - - let mut mainnet_network = MainnetNetwork::default(); - let mut db_sync_instance = DbSyncInstance::default(); - - mainnet_network.sync_with(&mut db_sync_instance); - - alice_voter - .send_direct_voting_registration() - .to(&mut mainnet_network); - bob_voter - .send_voting_registration(Delegations::New( - vec![(david_representative.catalyst_public_key(),1)] - )) - .to(&mut mainnet_network); - clarice_voter - .send_voting_registration(Delegations::New( - vec![ - (david_representative.catalyst_public_key(),1), - (edgar_representative.catalyst_public_key(),1) - ] - )) - .to(&mut mainnet_network); - - let voting_tools = - VotingToolsMock::default().connect_to_db_sync(&db_sync_instance, &testing_directory); - - let configuration = ConfigurationBuilder::default() - .with_voting_tools_params(voting_tools.into()) - .with_tmp_result_dir(&testing_directory) - .build(); - - - let assigner = RepsVotersAssigner::new_from_repsdb(DIRECT_VOTING_GROUP.to_string(), REP_VOTING_GROUP.to_string(), reps).unwrap(); - - let voter_hir = SnapshotServiceStarter::default() - .with_configuration(configuration) - .start(&testing_directory) - .unwrap() - .snapshot(JobParameters::fund("fund9"), 450u64, Fraction::from(1u64),&assigner) - .to_voter_hir(); - - - let config = ConfigBuilder::default().build(); - config.initials.block0.extend_from_external(read_initials(voter_hir).unwrap()); - println!("{:?}",config); -} - -pub fn write_config>(config: Configuration, path: P) -> Result<(), Error> { - use std::io::Write; - let mut file = std::fs::File::create(&path)?; - file.write_all(serde_json::to_string(&config)?.as_bytes()) - .map_err(Into::into) -} \ No newline at end of file diff --git a/integration-tests/src/integration/mod.rs b/integration-tests/src/integration/mod.rs deleted file mode 100644 index 0107961a..00000000 --- a/integration-tests/src/integration/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod from_snapshot_to_catalyst_toolbox; -//mod from_snapshot_to_vitup; \ No newline at end of file diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 58306fd6..3f8f8ff4 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -1,10 +1,11 @@ cfg_if::cfg_if! { if #[cfg(test)] { pub mod common; - pub mod component; + pub mod backend; pub mod non_functional; - pub mod integration; + pub mod registration; pub mod e2e; + pub mod snapshot; } } diff --git a/integration-tests/src/component/registration/mod.rs b/integration-tests/src/registration/mod.rs similarity index 100% rename from integration-tests/src/component/registration/mod.rs rename to integration-tests/src/registration/mod.rs diff --git a/integration-tests/src/component/registration/testnet.rs b/integration-tests/src/registration/testnet.rs similarity index 100% rename from integration-tests/src/component/registration/testnet.rs rename to integration-tests/src/registration/testnet.rs diff --git a/integration-tests/src/component/snapshot/mod.rs b/integration-tests/src/snapshot/mod.rs similarity index 81% rename from integration-tests/src/component/snapshot/mod.rs rename to integration-tests/src/snapshot/mod.rs index 919d93e0..b1bbe91c 100644 --- a/integration-tests/src/component/snapshot/mod.rs +++ b/integration-tests/src/snapshot/mod.rs @@ -1,4 +1,2 @@ #[cfg(feature = "testnet-tests")] mod testnet; - -mod local; \ No newline at end of file diff --git a/integration-tests/src/component/snapshot/testnet.rs b/integration-tests/src/snapshot/testnet.rs similarity index 100% rename from integration-tests/src/component/snapshot/testnet.rs rename to integration-tests/src/snapshot/testnet.rs diff --git a/mainnet-tools/Cargo.toml b/mainnet-tools/Cargo.toml deleted file mode 100644 index d4722480..00000000 --- a/mainnet-tools/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "mainnet-tools" -version = "0.1.0" -authors = ["dkijania "] -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -hex = "0.4" -bech32 = "0.8.1" -structopt = "0.3" -thiserror = "1.0" -futures = "0.3.8" -serde_json = "1.0" -signals-handler = { path = "../signals-handler" } -serde = { version = "1", features = ["derive"] } -tokio = { version = "1.2", features = ["macros","rt","process"] } -jormungandr-lib = { git = "https://github.com/input-output-hk/jormungandr.git", branch = "catalyst-fund9" } -catalyst-toolbox = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "catalyst-fund9", features = [ "test-api" ]} -chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "catalyst-fund9", features = [ "property-test-api" ] } -chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "catalyst-fund9", features = [ "property-test-api" ] } -tempdir = "0.3.7" -thor = { git = "https://github.com/input-output-hk/jormungandr.git", branch = "catalyst-fund9" } -rand = "0.8" -assert_fs = "1.0" diff --git a/mainnet-tools/src/bin/voting-tools-mock.rs b/mainnet-tools/src/bin/voting-tools-mock.rs deleted file mode 100644 index 5a6b047c..00000000 --- a/mainnet-tools/src/bin/voting-tools-mock.rs +++ /dev/null @@ -1,7 +0,0 @@ -use mainnet_tools::voting_tools::VotingToolsCommand; -use structopt::StructOpt; - -pub fn main() { - std::env::set_var("RUST_BACKTRACE", "full"); - VotingToolsCommand::from_args().exec() -} diff --git a/mainnet-tools/src/db_sync/mod.rs b/mainnet-tools/src/db_sync/mod.rs deleted file mode 100644 index b02def5a..00000000 --- a/mainnet-tools/src/db_sync/mod.rs +++ /dev/null @@ -1,54 +0,0 @@ -use catalyst_toolbox::snapshot::VotingRegistration; -use jormungandr_lib::interfaces::BlockDate; -use std::collections::hash_map::Entry; -use std::collections::HashMap; - -#[derive(Default)] -pub struct DbSyncInstance { - state: HashMap>, - settings: Settings, -} - -impl DbSyncInstance { - pub fn notify(&mut self, block_date: BlockDate, registration: VotingRegistration) { - match self.state.entry(block_date) { - Entry::Vacant(e) => { - e.insert(vec![registration]); - } - Entry::Occupied(mut e) => { - e.get_mut().push(registration); - } - } - } - - pub fn query_all_registration_transactions(&self) -> Vec { - self.state - .values() - .cloned() - .fold(vec![], |mut vec, mut value| { - vec.append(&mut value); - vec - }) - } - - pub fn settings(&self) -> &Settings { - &self.settings - } -} - -#[derive(Debug, Clone)] -pub struct Settings { - pub db_name: String, - pub db_user: String, - pub db_host: String, -} - -impl Default for Settings { - fn default() -> Self { - Self { - db_name: "mock".to_string(), - db_user: "mock".to_string(), - db_host: "mock".to_string(), - } - } -} diff --git a/mainnet-tools/src/lib.rs b/mainnet-tools/src/lib.rs deleted file mode 100644 index 07447ea0..00000000 --- a/mainnet-tools/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod db_sync; -pub mod network; -pub mod voting_tools; -pub mod wallet; diff --git a/mainnet-tools/src/network/mod.rs b/mainnet-tools/src/network/mod.rs deleted file mode 100644 index f3719503..00000000 --- a/mainnet-tools/src/network/mod.rs +++ /dev/null @@ -1,33 +0,0 @@ -use crate::db_sync::DbSyncInstance; -use catalyst_toolbox::snapshot::VotingRegistration; -use jormungandr_lib::interfaces::BlockDate; - -pub struct MainnetNetwork<'a> { - block_date: BlockDate, - observers: Vec<&'a mut DbSyncInstance>, -} - -impl Default for MainnetNetwork<'_> { - fn default() -> Self { - Self { - block_date: BlockDate::new(0, 0), - observers: vec![], - } - } -} - -impl<'a> MainnetNetwork<'a> { - pub fn accept(&mut self, registration: VotingRegistration) { - self.notify_all(self.block_date, registration); - } - - pub fn sync_with(&mut self, observer: &'a mut DbSyncInstance) { - self.observers.push(observer); - } - - fn notify_all(&mut self, block_date: BlockDate, registration: VotingRegistration) { - for observer in &mut self.observers { - observer.notify(block_date, registration.clone()); - } - } -} diff --git a/mainnet-tools/src/voting_tools/command.rs b/mainnet-tools/src/voting_tools/command.rs deleted file mode 100644 index 391b9288..00000000 --- a/mainnet-tools/src/voting_tools/command.rs +++ /dev/null @@ -1,60 +0,0 @@ -use super::content; -use std::path::Path; -use std::path::PathBuf; -use structopt::StructOpt; - -pub const PATH_TO_DYNAMIC_CONTENT: &str = "PATH_TO_DYNAMIC_CONTENT"; - -#[derive(StructOpt, Debug)] -pub struct VotingToolsCommand { - #[structopt(long = "mainnet")] - pub mainnet: bool, - - #[structopt(long = "testnet-magic")] - pub testnet_magic: Option, - - #[structopt(long = "db")] - pub db: String, - - #[structopt(long = "db-user")] - pub db_user: String, - - #[structopt(long = "db-host")] - pub db_host: PathBuf, - - #[structopt(long = "out-file")] - pub out_file: PathBuf, - - #[structopt(long = "scale")] - pub scale: u64, - - #[structopt(long = "slot-no")] - pub slot_no: Option, -} - -impl VotingToolsCommand { - pub fn exec(&self) { - println!("Params: {:?}", self); - println!("sleeping 5 sec.."); - std::thread::sleep(std::time::Duration::from_secs(5)); - println!("saving {:?}", self.out_file); - - match std::env::var(PATH_TO_DYNAMIC_CONTENT) { - Ok(value) => { - std::fs::copy(value, &self.out_file).unwrap(); - } - Err(_) => { - write_snapshot( - serde_json::to_string(&content::default()).unwrap(), - &self.out_file, - ); - } - }; - } -} - -pub fn write_snapshot>(content: String, path: P) { - use std::io::Write; - let mut file = std::fs::File::create(&path).unwrap(); - file.write_all(content.as_bytes()).unwrap(); -} diff --git a/mainnet-tools/src/voting_tools/content.rs b/mainnet-tools/src/voting_tools/content.rs deleted file mode 100644 index 3beaaf51..00000000 --- a/mainnet-tools/src/voting_tools/content.rs +++ /dev/null @@ -1,50 +0,0 @@ -use catalyst_toolbox::snapshot::registration::Delegations; -use catalyst_toolbox::snapshot::VotingRegistration; -use jormungandr_lib::crypto::account::Identifier; - -pub fn default() -> Vec { - vec![ - VotingRegistration { - reward_address: "0xe1ffff2912572257b59dca84c965e4638a09f1524af7a15787eb0d8a46" - .to_string(), - stake_public_key: "0xe7d6616840734686855ec80ee9658f5ead9e29e494ec6889a5d1988b50eb8d0f" - .to_string(), - voting_power: 177689370111.into(), - delegations: Delegations::Legacy( - Identifier::from_hex( - "0xc21ddb4abb04bd5ce21091eef1676e44889d806e6e1a6a9a7dc25c0eba54cc33", - ) - .unwrap(), - ), - voting_purpose: 0, - }, - VotingRegistration { - reward_address: "0xe1fffc8bcb1578a15413bf11413639fa270a9ffa36d9a0c4d2c93536fe" - .to_string(), - stake_public_key: "0x2f9a90d87321a255efd038fea5df2a2349ea2c32fa584b73f2a46f655f235919" - .to_string(), - voting_power: 9420156337.into(), - delegations: Delegations::Legacy( - Identifier::from_hex( - "0x3f656a1ba4ea8b33c81961fee6f15f09600f024435b1a7ada1e5b77b03a41a6d", - ) - .unwrap(), - ), - voting_purpose: 0, - }, - VotingRegistration { - reward_address: "0xe1fff825e1bf009d35d9160f6340250b581f5d37c17538e960c0410b20" - .to_string(), - stake_public_key: "0x66ae1553036548b99b93c783811bb281be5a196a12d950bda4ac9b83630afbd1" - .to_string(), - voting_power: 82168168290u64.into(), - delegations: Delegations::Legacy( - Identifier::from_hex( - "0x125860fc4870bb480d1d2a97f101e1c5c845c0222400fdaba7bcca93e79bd66e", - ) - .unwrap(), - ), - voting_purpose: 0, - }, - ] -} diff --git a/mainnet-tools/src/voting_tools/mod.rs b/mainnet-tools/src/voting_tools/mod.rs deleted file mode 100644 index 11686211..00000000 --- a/mainnet-tools/src/voting_tools/mod.rs +++ /dev/null @@ -1,52 +0,0 @@ -mod command; -mod content; - -use crate::db_sync::DbSyncInstance; -use crate::voting_tools::command::PATH_TO_DYNAMIC_CONTENT; -use assert_fs::fixture::PathChild; -use assert_fs::TempDir; -pub use command::VotingToolsCommand; -use std::env; -use std::io::Write; -use std::path::Path; -use std::path::PathBuf; - -#[derive(Debug, Clone)] -pub struct VotingToolsMock { - path: PathBuf, -} - -impl Default for VotingToolsMock { - fn default() -> Self { - Self { - path: Path::new("voting-tools-mock").to_path_buf(), - } - } -} - -impl VotingToolsMock { - pub fn connect_to_db_sync(self, db_sync: &DbSyncInstance, temp_dir: &TempDir) -> Self { - let voting_registrations = db_sync.query_all_registration_transactions(); - let snapshot_tmp = temp_dir.child("snapshot.tmp"); - - env::set_var( - PATH_TO_DYNAMIC_CONTENT, - snapshot_tmp.path().to_str().unwrap(), - ); - - println!("{:?}", snapshot_tmp.path()); - - let mut file = std::fs::File::create(&snapshot_tmp.path()).unwrap(); - file.write_all( - serde_json::to_string(&voting_registrations) - .unwrap() - .as_bytes(), - ) - .unwrap(); - self - } - - pub fn path(&self) -> PathBuf { - self.path.to_path_buf() - } -} diff --git a/mainnet-tools/src/wallet/sender.rs b/mainnet-tools/src/wallet/sender.rs deleted file mode 100644 index 9a927dac..00000000 --- a/mainnet-tools/src/wallet/sender.rs +++ /dev/null @@ -1,18 +0,0 @@ -use crate::network::MainnetNetwork; -use catalyst_toolbox::snapshot::VotingRegistration; - -pub struct RegistrationSender { - voting_registration: VotingRegistration, -} - -impl RegistrationSender { - pub fn new(voting_registration: VotingRegistration) -> Self { - Self { - voting_registration, - } - } - - pub fn to(self, network: &mut MainnetNetwork) { - network.accept(self.voting_registration); - } -} diff --git a/mainnet-tools/src/bin/voter-registration-mock.rs b/registration-service/src/bin/voter-registration.rs similarity index 99% rename from mainnet-tools/src/bin/voter-registration-mock.rs rename to registration-service/src/bin/voter-registration.rs index a7a6c7ee..be2856e4 100644 --- a/mainnet-tools/src/bin/voter-registration-mock.rs +++ b/registration-service/src/bin/voter-registration.rs @@ -1,7 +1,8 @@ -use futures::future::FutureExt; use std::fs::File; use std::io::Write; use std::path::{Path, PathBuf}; + +use futures::future::FutureExt; use structopt::StructOpt; use thiserror::Error; diff --git a/registration-verify-service/src/job/mod.rs b/registration-verify-service/src/job/mod.rs index 193156d6..258f442b 100644 --- a/registration-verify-service/src/job/mod.rs +++ b/registration-verify-service/src/job/mod.rs @@ -204,7 +204,6 @@ impl RegistrationVerifyJob { get_snapshot_from_history_by_id( job_id, - &request.tag.clone().unwrap_or_else(|| "".to_string()), self.snapshot_token.to_string(), self.snapshot_address.to_string(), )? diff --git a/snapshot-trigger-service/Cargo.toml b/snapshot-trigger-service/Cargo.toml index 8a034eda..d8ecc13d 100644 --- a/snapshot-trigger-service/Cargo.toml +++ b/snapshot-trigger-service/Cargo.toml @@ -14,7 +14,6 @@ structopt = "0.3" jortestkit = { git = "https://github.com/input-output-hk/jortestkit.git", branch= "master" } jormungandr-lib = { git = "https://github.com/input-output-hk/jormungandr.git", branch = "catalyst-fund9" } chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "catalyst-fund9" } -catalyst-toolbox = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "catalyst-fund9", features=["test-api"]} futures = "0.3.8" assert_fs = "1.0" serde = { version = "1", features = ["derive"] } @@ -24,7 +23,6 @@ tokio = { version = "1.2", features = ["macros","rt","process"] } serde_json = "1.0" serde_yaml = "0.8" signals-handler = { path = "../signals-handler" } -mainnet-tools = { path = "../mainnet-tools"} [dependencies.reqwest] version = "0.10.10" diff --git a/snapshot-trigger-service/src/bin/voting-tools-mock.rs b/snapshot-trigger-service/src/bin/voting-tools-mock.rs new file mode 100644 index 00000000..1cdf8ba4 --- /dev/null +++ b/snapshot-trigger-service/src/bin/voting-tools-mock.rs @@ -0,0 +1,71 @@ +use std::path::Path; +use std::path::PathBuf; +use structopt::StructOpt; + +pub fn main() { + std::env::set_var("RUST_BACKTRACE", "full"); + VotingToolsCommand::from_args().exec() +} + +#[derive(StructOpt, Debug)] +pub struct VotingToolsCommand { + #[structopt(long = "mainnet")] + pub mainnet: bool, + + #[structopt(long = "testnet-magic")] + pub testnet_magic: Option, + + #[structopt(long = "db")] + pub db: String, + + #[structopt(long = "db-user")] + pub db_user: String, + + #[structopt(long = "db-host")] + pub db_host: PathBuf, + + #[structopt(long = "out-file")] + pub out_file: PathBuf, + + #[structopt(long = "scale")] + pub scale: u64, + + #[structopt(long = "slot-no")] + pub slot_no: Option, +} + +impl VotingToolsCommand { + pub fn exec(&self) { + println!("Params: {:?}", self); + println!("slepping 5 sec.."); + std::thread::sleep(std::time::Duration::from_secs(5)); + println!("saving {:?}", self.out_file); + let content = "[ \ + { \ + \"reward_address\": \"0xe1ffff2912572257b59dca84c965e4638a09f1524af7a15787eb0d8a46\", \ + \"stake_public_key\": \"0xe7d6616840734686855ec80ee9658f5ead9e29e494ec6889a5d1988b50eb8d0f\", \ + \"voting_power\": 177689370111, \ + \"voting_public_key\": \"0xc21ddb4abb04bd5ce21091eef1676e44889d806e6e1a6a9a7dc25c0eba54cc33\" \ + }, \ + { \ + \"reward_address\": \"0xe1fffc8bcb1578a15413bf11413639fa270a9ffa36d9a0c4d2c93536fe\", \ + \"stake_public_key\": \"0x2f9a90d87321a255efd038fea5df2a2349ea2c32fa584b73f2a46f655f235919\", \ + \"voting_power\": 9420156337, \ + \"voting_public_key\": \"0x3f656a1ba4ea8b33c81961fee6f15f09600f024435b1a7ada1e5b77b03a41a6d\" \ + }, \ + { \ + \"reward_address\": \"0xe1fff825e1bf009d35d9160f6340250b581f5d37c17538e960c0410b20\", \ + \"stake_public_key\": \"0x66ae1553036548b99b93c783811bb281be5a196a12d950bda4ac9b83630afbd1\", \ + \"voting_power\": 82168168290, \ + \"voting_public_key\": \"0x125860fc4870bb480d1d2a97f101e1c5c845c0222400fdaba7bcca93e79bd66e\" \ + } \ + ]"; + write_snapshot(content.to_string(), &self.out_file); + } +} + +pub fn write_snapshot>(content: String, path: P) { + use std::io::Write; + let mut file = std::fs::File::create(&path).unwrap(); + file.write_all(content.as_bytes()).unwrap(); +} diff --git a/snapshot-trigger-service/src/client/mod.rs b/snapshot-trigger-service/src/client/mod.rs index 3b3e9f9a..43c3deee 100644 --- a/snapshot-trigger-service/src/client/mod.rs +++ b/snapshot-trigger-service/src/client/mod.rs @@ -21,7 +21,7 @@ pub fn do_snapshot, P: Into>( SnapshotRestClient::new_with_token(snapshot_token.into(), snapshot_address.into()); println!("Snapshot params: {:?}", job_params); - let snapshot_job_id = snapshot_client.job_new(job_params.clone()).unwrap(); + let snapshot_job_id = snapshot_client.job_new(job_params).unwrap(); let wait = WaitBuilder::new().tries(10).sleep_between_tries(10).build(); println!("waiting for snapshot job"); @@ -29,10 +29,7 @@ pub fn do_snapshot, P: Into>( snapshot_client.wait_for_job_finish(snapshot_job_id.clone(), wait)?; println!("Snapshot done: {:?}", snapshot_jobs_status); - let snapshot = snapshot_client.get_snapshot( - snapshot_job_id, - job_params.tag.unwrap_or_else(|| "".to_string()), - )?; + let snapshot = snapshot_client.get_snapshot(snapshot_job_id)?; Ok(SnapshotResult { status: snapshot_jobs_status, @@ -42,7 +39,6 @@ pub fn do_snapshot, P: Into>( pub fn get_snapshot_by_id, S: Into, P: Into>( job_id: Q, - tag: Q, snapshot_token: S, snapshot_address: P, ) -> Result { @@ -50,7 +46,7 @@ pub fn get_snapshot_by_id, S: Into, P: Into>( SnapshotRestClient::new_with_token(snapshot_token.into(), snapshot_address.into()); let job_id = job_id.into(); - let snapshot = snapshot_client.get_snapshot(job_id.clone(), tag.into())?; + let snapshot = snapshot_client.get_snapshot(job_id.clone())?; let status = snapshot_client.job_status(job_id)?; Ok(SnapshotResult { @@ -61,7 +57,6 @@ pub fn get_snapshot_by_id, S: Into, P: Into>( pub fn get_snapshot_from_history_by_id, S: Into, P: Into>( job_id: Q, - tag: Q, snapshot_token: S, snapshot_address: P, ) -> Result { @@ -69,7 +64,7 @@ pub fn get_snapshot_from_history_by_id, S: Into, P: Into SnapshotRestClient::new_with_token(snapshot_token.into(), snapshot_address.into()); let job_id = job_id.into(); - let snapshot = snapshot_client.get_snapshot(job_id.clone(), tag.into())?; + let snapshot = snapshot_client.get_snapshot(job_id.clone())?; let status = snapshot_client.get_status(job_id)?; Ok(SnapshotResult { @@ -142,6 +137,4 @@ pub enum Error { ChainError(#[from] chain_addr::Error), #[error("serialization error")] SerdeError(#[from] serde_json::Error), - #[error(transparent)] - Config(#[from] crate::config::Error), } diff --git a/snapshot-trigger-service/src/client/rest.rs b/snapshot-trigger-service/src/client/rest.rs index 6847cc08..c1658fb7 100644 --- a/snapshot-trigger-service/src/client/rest.rs +++ b/snapshot-trigger-service/src/client/rest.rs @@ -35,7 +35,7 @@ impl SnapshotRestClient { } fn path>(&self, path: S) -> String { - format!("{}/{}", self.address, path.into().replace('\"', "")) + format!("{}/{}", self.address, path.into()) } fn get>(&self, local_path: S) -> Result { @@ -68,21 +68,13 @@ impl SnapshotRestClient { pub fn download_snapshot, P: AsRef>( &self, id: S, - tag: S, output: P, ) -> Result<(), Error> { - self.download( - format!("{}/{}_snapshot.json", id.into(), tag.into()), - output, - ) + self.download(format!("{}/snapshot.json", id.into()), output) } - pub fn get_snapshot>(&self, id: S, tag: S) -> Result { - self.get(format!( - "api/job/files/get/{}/{}_snapshot.json", - id.into().replace("'\"'", ""), - tag.into() - )) + pub fn get_snapshot>(&self, id: S) -> Result { + self.get(format!("api/job/files/get/{}/snapshot.json", id.into())) } pub fn download_job_status, P: AsRef>( @@ -103,10 +95,7 @@ impl SnapshotRestClient { sub_location: S, output: P, ) -> Result<(), Error> { - let content = self.get(format!( - "api/job/files/get/{}", - sub_location.into().replace("'\"'", "") - ))?; + let content = self.get(format!("api/job/files/get/{}", sub_location.into()))?; let mut file = std::fs::File::create(&output)?; file.write_all(content.as_bytes())?; Ok(()) diff --git a/snapshot-trigger-service/src/config/job.rs b/snapshot-trigger-service/src/config/job.rs index 0db0b61c..7d12d065 100644 --- a/snapshot-trigger-service/src/config/job.rs +++ b/snapshot-trigger-service/src/config/job.rs @@ -6,19 +6,3 @@ pub struct JobParameters { pub slot_no: Option, pub tag: Option, } - -impl JobParameters { - pub fn daily() -> Self { - Self { - slot_no: None, - tag: Some("daily".to_string()), - } - } - - pub fn fund>(fund: S) -> Self { - Self { - slot_no: None, - tag: Some(fund.into()), - } - } -} diff --git a/snapshot-trigger-service/src/config/mod.rs b/snapshot-trigger-service/src/config/mod.rs index 9f462ec1..963cc0fb 100644 --- a/snapshot-trigger-service/src/config/mod.rs +++ b/snapshot-trigger-service/src/config/mod.rs @@ -1,9 +1,6 @@ mod job; -use assert_fs::fixture::PathChild; -use assert_fs::TempDir; pub use job::JobParameters; -use mainnet_tools::voting_tools::VotingToolsMock; use serde::{Deserialize, Serialize}; use std::path::Path; use std::path::PathBuf; @@ -67,55 +64,6 @@ impl Configuration { } } -#[derive(Default, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)] -pub struct ConfigurationBuilder { - configuration: Configuration, -} - -impl ConfigurationBuilder { - pub fn with_port(mut self, port: u16) -> Self { - self.configuration.port = port; - self - } - - pub fn with_result_dir>(mut self, path: P) -> Self { - self.configuration.result_dir = path.as_ref().to_path_buf(); - self - } - - pub fn with_tmp_result_dir(self, tmp: &TempDir) -> Self { - self.with_result_dir(tmp.child("snapshot_result").path()) - } - - pub fn with_voting_tools_params(mut self, voting_tools: VotingToolsParams) -> Self { - self.configuration.voting_tools = voting_tools; - self - } - - pub fn build(self) -> Configuration { - self.configuration - } -} - -impl Default for Configuration { - fn default() -> Self { - Self { - port: 3030, - voting_tools: VotingToolsParams { - bin: None, - nix_branch: None, - network: NetworkType::Mainnet, - db: "".to_string(), - db_user: "".to_string(), - db_host: "".to_string(), - scale: 1_000_000, - }, - result_dir: Path::new(".").to_path_buf(), - token: None, - } - } -} - #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)] pub struct VotingToolsParams { /// binary name @@ -137,22 +85,6 @@ pub struct VotingToolsParams { pub scale: u32, } -impl From for VotingToolsParams { - fn from(voting_tools_mock: VotingToolsMock) -> Self { - let config = mainnet_tools::db_sync::Settings::default(); - - Self { - bin: Some(voting_tools_mock.path().to_str().unwrap().to_string()), - nix_branch: None, - network: NetworkType::Mainnet, - db: config.db_name, - db_user: config.db_user, - db_host: config.db_host, - scale: 1_000_000, - } - } -} - impl VotingToolsParams { pub fn command(&self) -> Result { if let Some(bin) = &self.bin { @@ -181,13 +113,6 @@ pub fn read_config>(config: P) -> Result { serde_json::from_str(&contents).map_err(Into::into) } -pub fn write_config>(config: Configuration, path: P) -> Result<(), Error> { - use std::io::Write; - let mut file = std::fs::File::create(&path)?; - file.write_all(serde_json::to_string(&config)?.as_bytes()) - .map_err(Into::into) -} - #[derive(Debug, Error)] pub enum Error { #[error("cannot parse configuration")] diff --git a/vitup/src/mode/interactive/mod.rs b/vitup/src/mode/interactive/mod.rs index 35164572..3c55a6dd 100644 --- a/vitup/src/mode/interactive/mod.rs +++ b/vitup/src/mode/interactive/mod.rs @@ -35,7 +35,7 @@ impl VitInteractiveCommandExec { } } -impl<'a> InteractiveCommandExec for VitInteractiveCommandExec { +impl InteractiveCommandExec for VitInteractiveCommandExec { fn parse_and_exec( &mut self, tokens: Vec,