Skip to content

Commit 5156890

Browse files
mock search API (#293)
* mock search API * Revert files that should be untracked Co-authored-by: dkijania <[email protected]>
1 parent 26c8dfb commit 5156890

File tree

22 files changed

+561
-70
lines changed

22 files changed

+561
-70
lines changed

Cargo.lock

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rand_chacha = "0.2"
2929
tokio = { version = "1.1", features = ["macros","rt","rt-multi-thread"] }
3030
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = [ "property-test-api" ] }
3131
catalyst-toolbox = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "main", features=["test-api"]}
32-
snapshot-lib = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "main", features=["proptest", "test-api"]}
32+
snapshot-lib = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "main", features=["test-api"]}
3333
thiserror = "1.0"
3434
netstat2 = "0.9"
3535
image = "0.23.9"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
use crate::Vote;
2+
3+
use crate::common::iapyx_from_mainnet;
4+
use crate::common::MainnetWallet;
5+
use assert_fs::TempDir;
6+
use catalyst_toolbox::rewards::voters::calc_voter_rewards;
7+
use catalyst_toolbox::snapshot::RawSnapshot;
8+
use catalyst_toolbox::snapshot::Snapshot;
9+
use chain_impl_mockchain::block::BlockDate;
10+
use jormungandr_automation::testing::time;
11+
use jormungandr_lib::crypto::account::Identifier;
12+
use vit_servicing_station_tests::common::data::ArbitraryValidVotingTemplateGenerator;
13+
use vitup::config::VoteBlockchainTime;
14+
use vitup::config::{Block0Initials, ConfigBuilder};
15+
use vitup::testing::spawn_network;
16+
use vitup::testing::vitup_setup;
17+
use snapshot_lib::VotingGroup;
18+
19+
#[test]
20+
pub fn voters_with_at_least_one_vote() {
21+
let stake = 10_000;
22+
23+
let alice_wallet = MainnetWallet::new(stake);
24+
let bob_wallet = MainnetWallet::new(stake);
25+
let clarice_wallet = MainnetWallet::new(stake);
26+
27+
let raw_snapshot = vec![
28+
alice_wallet.as_voting_registration(),
29+
bob_wallet.as_voting_registration(),
30+
clarice_wallet.as_voting_registration(),
31+
];
32+
33+
let assigner = |_: &Identifier| VotingGroup::new();
34+
35+
let snapshot = Snapshot::from_raw_snapshot(
36+
RawSnapshot::from(raw_snapshot),
37+
450.into(),
38+
1.into(),
39+
&assigner,
40+
)
41+
.unwrap();
42+
let testing_directory = TempDir::new().unwrap().into_persistent();
43+
44+
let vote_timing = VoteBlockchainTime {
45+
vote_start: 0,
46+
tally_start: 1,
47+
tally_end: 2,
48+
slots_per_epoch: 30,
49+
};
50+
let config = ConfigBuilder::default()
51+
.block0_initials(Block0Initials(vec![
52+
alice_wallet.as_initial_entry(),
53+
bob_wallet.as_initial_entry(),
54+
clarice_wallet.as_initial_entry(),
55+
]))
56+
.vote_timing(vote_timing.into())
57+
.slot_duration_in_seconds(2)
58+
.proposals_count(3)
59+
.voting_power(100)
60+
.private(false)
61+
.build();
62+
63+
let mut template_generator = ArbitraryValidVotingTemplateGenerator::new();
64+
let (mut controller, vit_parameters, network_params) =
65+
vitup_setup(&config, testing_directory.path().to_path_buf()).unwrap();
66+
67+
let (nodes, _vit_station, wallet_proxy) = spawn_network(
68+
&mut controller,
69+
vit_parameters,
70+
network_params,
71+
&mut template_generator,
72+
)
73+
.unwrap();
74+
75+
let mut alice = iapyx_from_mainnet(&alice_wallet, &wallet_proxy).unwrap();
76+
let mut bob = iapyx_from_mainnet(&bob_wallet, &wallet_proxy).unwrap();
77+
78+
let fund1_vote_plan = &controller.defined_vote_plans()[0];
79+
80+
alice
81+
.vote_for(fund1_vote_plan.id(), 0, Vote::Yes as u8)
82+
.unwrap();
83+
84+
bob.vote_for(fund1_vote_plan.id(), 1, Vote::Yes as u8)
85+
.unwrap();
86+
87+
bob.vote_for(fund1_vote_plan.id(), 0, Vote::Yes as u8)
88+
.unwrap();
89+
90+
let target_date = BlockDate {
91+
epoch: 1,
92+
slot_id: 0,
93+
};
94+
time::wait_for_date(target_date.into(), nodes[0].rest());
95+
96+
let _block0 = &controller.settings().block0;
97+
let records = calc_voter_rewards(
98+
nodes[0].rest().account_votes_count().unwrap(),
99+
1,
100+
snapshot.to_full_snapshot_info(),
101+
100u32.into(),
102+
)
103+
.unwrap();
104+
105+
assert_eq!(
106+
records
107+
.iter()
108+
.find(|(x, _y)| **x == alice_wallet.reward_address())
109+
.unwrap()
110+
.1,
111+
&50u32.into()
112+
);
113+
114+
assert_eq!(
115+
records
116+
.iter()
117+
.find(|(x, _y)| **x == bob_wallet.reward_address())
118+
.unwrap()
119+
.1,
120+
&50u32.into()
121+
);
122+
}

snapshot-trigger-service/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jortestkit = { git = "https://github.com/input-output-hk/jortestkit.git", branch
1515
jormungandr-lib = { git = "https://github.com/input-output-hk/jormungandr.git", branch = "master" }
1616
chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
1717
catalyst-toolbox = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "main", features=["test-api"]}
18-
snapshot-lib = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "main", features=["proptest"] }
18+
snapshot-lib = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "main" }
1919
futures = "0.3.8"
2020
assert_fs = "1.0"
2121
serde = { version = "1", features = ["derive"] }

valgrind/src/startup/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,14 @@ impl ValigrindStartupCommand {
8585
}
8686
}
8787

88-
#[derive(Clone, Debug, Serialize, Deserialize)]
88+
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
8989
#[serde(untagged)]
9090
pub enum Protocol {
91+
#[default]
9192
Http,
9293
Https(Certs),
9394
}
9495

95-
impl Default for Protocol {
96-
fn default() -> Self {
97-
Self::Http
98-
}
99-
}
100-
10196
impl Protocol {
10297
pub fn schema(&self) -> String {
10398
match self {

vitup/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jortestkit = { git = "https://github.com/input-output-hk/jortestkit.git", branch
3030
vit-servicing-station-tests = { git = "https://github.com/input-output-hk/vit-servicing-station.git", branch = "master" }
3131
vit-servicing-station-lib = { git = "https://github.com/input-output-hk/vit-servicing-station.git", branch = "master" }
3232
catalyst-toolbox = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "main"}
33-
snapshot-lib = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "main", features=["proptest"] }
33+
snapshot-lib = { git = "https://github.com/input-output-hk/catalyst-toolbox.git", branch = "main" }
3434
valgrind = { path = "../valgrind" }
3535
poldercast = { git = "https://github.com/primetype/poldercast.git", rev = "8305f1560392a9d26673ca996e7646c8834533ef" }
3636
rand = "0.8"

vitup/src/builders/helpers/qr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::config::Config;
22
use catalyst_toolbox::kedqr::{generate, KeyQrCode};
33
use chain_crypto::SecretKey;
44
use chain_impl_mockchain::key::EitherEd25519SecretKey;
5-
use hersir::builder::WalletTemplate;
5+
use hersir::config::WalletTemplate;
66
use image::ImageError;
77
use std::collections::HashMap;
88
use std::fs::File;
@@ -32,7 +32,7 @@ pub fn generate_qr_and_hashes<P: AsRef<Path>>(
3232
let pin = initials
3333
.iter()
3434
.find_map(|(template, pin)| {
35-
if template.alias() == *alias {
35+
if template.alias() == Some(alias.to_string()) {
3636
Some(pin)
3737
} else {
3838
None

vitup/src/builders/helpers/static_data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn build_servicing_station_parameters(
146146
vote_plan: _vote_plan,
147147
} = data
148148
{
149-
let key: ElectionPublicKey = keys.election_public_key();
149+
let key: ElectionPublicKey = keys.election_key();
150150
parameters
151151
.current_fund
152152
.set_vote_encryption_key(key.to_bech32_str(), &alias.alias);

0 commit comments

Comments
 (0)