Skip to content

Commit

Permalink
Revert "implement e2e test from snapshot to rewards for active voters…
Browse files Browse the repository at this point in the history
… and integration test just for snapshot service and catalyst toolbox"

This reverts commit 34a0b74.
  • Loading branch information
dkijania committed Jul 13, 2022
1 parent 0108f73 commit bf2da2a
Show file tree
Hide file tree
Showing 52 changed files with 123 additions and 944 deletions.
38 changes: 5 additions & 33 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ members = [
"vitup",
"valgrind",
"integration-tests",
"mainnet-tools",
"registration-service",
"registration-verify-service",
"snapshot-trigger-service",
"signals-handler"
"signals-handler",
]
3 changes: 0 additions & 3 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = []
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,64 +1,35 @@
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;
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,
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/src/backend/rewards/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod active_voters_rewards;
mod proposers_fund;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
Expand All @@ -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<chain_crypto::Ed25519Extended> {
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(),
}
}
}
16 changes: 0 additions & 16 deletions integration-tests/src/common/mainnet_wallet_ext.rs

This file was deleted.

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;
pub mod mainnet_wallet_ext;
mod mainnet;
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_tools::wallet::MainnetWallet;
pub use mainnet::MainnetWallet;
pub use rewards::{funded_proposals, VotesRegistry};
pub use static_data::SnapshotExtensions;
use thiserror::Error;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SnapshotResult, SnapshotClientError> {
pub fn do_snapshot(job_params: JobParameters) -> Result<SnapshotResult, Error> {
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 @@ -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),
}
Loading

0 comments on commit bf2da2a

Please sign in to comment.