Skip to content

Commit

Permalink
update jortestkit (#3904)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijania authored Mar 25, 2022
1 parent 25e2fbb commit e8c4bca
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 33 deletions.
22 changes: 16 additions & 6 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions testing/jormungandr-automation/src/jcli/api/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use assert_cmd::assert::OutputAssertExt;
use assert_fs::{prelude::*, NamedTempFile};
use chain_impl_mockchain::vote::Choice;
use jormungandr_lib::interfaces::TaxType;
use jortestkit::file;
use jortestkit::process::output_extensions::ProcessOutput;
use jortestkit::{file, process::output_extensions::ProcessOutput};
use std::path::Path;

#[derive(Debug)]
Expand Down Expand Up @@ -156,7 +155,7 @@ impl Certificate {
.as_single_line()
}

pub fn stake_pool_id<P: AsRef<Path>>(self, input_file: P) -> String {
pub fn stake_pool_id<P: AsRef<Path>>(self, input_file: P) -> Result<String, std::io::Error> {
println!("Running get stake pool id...");
let temp_file = NamedTempFile::new("stake_pool.id").unwrap();
self.command
Expand All @@ -168,7 +167,7 @@ impl Certificate {
file::read_file(temp_file.path())
}

pub fn vote_plan_id<S: Into<String>>(self, cert: S) -> String {
pub fn vote_plan_id<S: Into<String>>(self, cert: S) -> Result<String, std::io::Error> {
println!("Running get stake pool id...");
let input_file = NamedTempFile::new("cert_file").unwrap();
input_file.write_str(&cert.into()).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl CommunicationKey {
}

#[allow(clippy::wrong_self_convention)]
pub fn to_public(self, input: String) -> String {
pub fn to_public(self, input: String) -> Result<String, std::io::Error> {
let input_file = NamedTempFile::new("input.tmp").unwrap();
input_file.write_str(&input).unwrap();
let output_file = NamedTempFile::new("output.tmp").unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ impl MemberKey {
}

#[allow(clippy::wrong_self_convention)]
pub fn to_public<S: Into<String>>(self, member_secret_key: S) -> String {
pub fn to_public<S: Into<String>>(
self,
member_secret_key: S,
) -> Result<String, std::io::Error> {
let input_file = NamedTempFile::new("member_key.tmp").unwrap();
input_file.write_str(&member_secret_key.into()).unwrap();

Expand Down
5 changes: 4 additions & 1 deletion testing/jormungandr-automation/src/jcli/api/votes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ impl Votes {
Crs::new(self.votes_command.crs())
}

pub fn election_public_key<S: Into<String>>(self, member_key: S) -> String {
pub fn election_public_key<S: Into<String>>(
self,
member_key: S,
) -> Result<String, std::io::Error> {
let output_file = NamedTempFile::new("election_public_key.tmp").unwrap();
self.votes_command
.election_public_key(member_key, output_file.path())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl CertificateBuilder {
stake_pool_id: &str,
stake_key_pub: &str,
stake_key_file: &Path,
) -> String {
) -> Result<String, std::io::Error> {
let temp_dir = TempDir::new().unwrap();

let stake_delegation_cert = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ pub fn compare_schema<P: AsRef<Path>>(actual_schema_path: P) {
PathBuf::from_str("./jormungandr-automation/resources/explorer/graphql/schema.graphql")
.unwrap();

if !file::have_the_same_content(actual_schema_path.as_ref(), &expected_schema_path) {
file::copy_file(actual_schema_path.as_ref(), &expected_schema_path, true);
if !file::have_the_same_content(actual_schema_path.as_ref(), &expected_schema_path).unwrap() {
file::copy_file(actual_schema_path.as_ref(), &expected_schema_path, true).unwrap();
println!("discrepancies detected, already replaced file with new content. Please commit to update schema");
}
}
4 changes: 3 additions & 1 deletion testing/jormungandr-automation/src/jormungandr/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ pub fn get_jormungandr_bin(release: &Release, temp_dir: &impl PathChild) -> Path
let release_dir = temp_dir.child(format!("release-{}", release.version()));
release_dir.create_dir_all().unwrap();
decompress(output.path(), release_dir.path()).unwrap();
file::find_file(release_dir.path(), "jormungandr").unwrap()
file::find_file(release_dir.path(), "jormungandr")
.unwrap()
.unwrap()
}
2 changes: 1 addition & 1 deletion testing/jormungandr-automation/src/jormungandr/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl RemoteJormungandrBuilder {

pub fn with_node_config(mut self, node_config: PathBuf) -> Self {
self.node_config =
Some(serde_yaml::from_str(&jortestkit::file::read_file(node_config)).unwrap());
Some(serde_yaml::from_str(&jortestkit::file::read_file(node_config).unwrap()).unwrap());
self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn test_create_and_sign_new_stake_delegation() {

let input_file = temp_dir.child("certificate");
input_file.write_str(&certificate).unwrap();
let stake_pool_id = jcli.certificate().stake_pool_id(input_file.path());
let stake_pool_id = jcli.certificate().stake_pool_id(input_file.path()).unwrap();
let certificate = jcli
.certificate()
.new_stake_delegation(&stake_pool_id, &owner.identifier().to_bech32_str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ pub fn jcli_creates_correct_retirement_certificate() {

let input_file = temp_dir.child("certificate");
input_file.write_str(&certificate).unwrap();
let stake_pool_id = jcli.certificate().stake_pool_id(input_file.path());
let stake_pool_id = jcli.certificate().stake_pool_id(input_file.path()).unwrap();

let expected_certificate = jcli.certificate().new_stake_pool_retirement(&stake_pool_id);
let actual_certificate = assert_new_stake_pool_retirement(&stake_pool_id);
let retirement_cert_file = temp_dir.child("retirement_certificate");
retirement_cert_file.write_str(&actual_certificate).unwrap();
let stake_pool_id_from_retirement = jcli
.certificate()
.stake_pool_id(retirement_cert_file.path());
.stake_pool_id(retirement_cert_file.path())
.unwrap();
assert_eq!(expected_certificate, actual_certificate);
assert_eq!(stake_pool_id, stake_pool_id_from_retirement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ pub fn create_new_stake_pool(

let stake_pool_id = jcli
.certificate()
.stake_pool_id(stake_pool_certificate_file.path());
.stake_pool_id(stake_pool_certificate_file.path())
.unwrap();

assert!(
jcli.rest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub fn jcli_e2e_flow_private_vote() {
.votes()
.committee()
.communication_key()
.to_public(communication_sk);
.to_public(communication_sk)
.unwrap();
let crs = "Committee member crs";
let member_sk =
jcli.votes()
Expand All @@ -52,8 +53,9 @@ pub fn jcli_e2e_flow_private_vote() {
.votes()
.committee()
.member_key()
.to_public(member_sk.clone());
let election_public_key = jcli.votes().election_public_key(member_pk.clone());
.to_public(member_sk.clone())
.unwrap();
let election_public_key = jcli.votes().election_public_key(member_pk.clone()).unwrap();

let member_sk_file = NamedTempFile::new("member.sk").unwrap();
member_sk_file.write_str(&member_sk).unwrap();
Expand Down Expand Up @@ -134,7 +136,7 @@ pub fn jcli_e2e_flow_private_vote() {

time::wait_for_epoch(1, jormungandr.rest());

let vote_plan_id = jcli.certificate().vote_plan_id(&vote_plan_cert);
let vote_plan_id = jcli.certificate().vote_plan_id(&vote_plan_cert).unwrap();
let yes_vote_cast = jcli.certificate().new_private_vote_cast(
vote_plan_id.clone(),
0,
Expand Down Expand Up @@ -278,7 +280,8 @@ pub fn jcli_private_vote_invalid_proof() {
.votes()
.committee()
.communication_key()
.to_public(communication_sk);
.to_public(communication_sk)
.unwrap();
let crs = "Committee member crs";

let invald_crs = "Invalid Committee member crs";
Expand All @@ -292,7 +295,8 @@ pub fn jcli_private_vote_invalid_proof() {
.votes()
.committee()
.member_key()
.to_public(member_sk.clone());
.to_public(member_sk.clone())
.unwrap();

let member_sk_file = NamedTempFile::new("member.sk").unwrap();
member_sk_file.write_str(&member_sk).unwrap();
Expand Down Expand Up @@ -373,7 +377,7 @@ pub fn jcli_private_vote_invalid_proof() {
jormungandr.rest(),
);

let vote_plan_id = jcli.certificate().vote_plan_id(&vote_plan_cert);
let vote_plan_id = jcli.certificate().vote_plan_id(&vote_plan_cert).unwrap();

jcli.fragment_sender(&jormungandr)
.send(&tx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ pub fn jcli_e2e_flow() {

time::wait_for_epoch(1, jormungandr.rest());

let vote_plan_id = jcli.certificate().vote_plan_id(&vote_plan_cert);
let vote_plan_id = jcli.certificate().vote_plan_id(&vote_plan_cert).unwrap();
let vote_cast = jcli
.certificate()
.new_public_vote_cast(vote_plan_id.clone(), 0, yes_choice);
Expand Down
2 changes: 1 addition & 1 deletion testing/mjolnir/src/mjolnir_lib/bootstrap/scenario/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn copy_initial_storage_if_used(
fs::remove_dir_all(&client_storage).expect("cannot remove existing client storage");
}
fs::create_dir(&client_storage).expect("cannot create client storage");
file::copy_folder(storage, &client_storage, true);
file::copy_folder(storage, &client_storage, true).unwrap()
}
}

Expand Down
2 changes: 1 addition & 1 deletion testing/thor/src/fragment/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl FragmentExporter {
.ends_with(".fragment")
})
.map(|path| {
let content = jortestkit::prelude::read_file(path);
let content = jortestkit::prelude::read_file(path).unwrap();
let bytes = hex::decode(content.trim()).unwrap();
Ok(bytes)
})
Expand Down
2 changes: 1 addition & 1 deletion testing/thor/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Wallet {
spending_counter: Option<SpendingCounter>,
discrimination: Discrimination,
) -> Wallet {
let bech32_str = jortestkit::file::read_file(secret_key_file);
let bech32_str = jortestkit::file::read_file(secret_key_file).unwrap();
Wallet::Account(account::Wallet::from_existing_account(
&bech32_str,
spending_counter.map(Into::into),
Expand Down

0 comments on commit e8c4bca

Please sign in to comment.