Skip to content

Commit

Permalink
Corrected comments, printlns, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed Dec 1, 2023
1 parent e1fc91e commit c7e3a99
Show file tree
Hide file tree
Showing 43 changed files with 109 additions and 118 deletions.
8 changes: 5 additions & 3 deletions integration-tests/tests/blockchain/contract_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::{RuskHttpClient, WalletPath};
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::wallet_accessor::Password::PwdHash;
use zk_citadel_moat::{Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter};
use phoenix_core::transaction::ModuleId;
use std::path::PathBuf;
use toml_base_config::BaseConfig;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::wallet_accessor::Password::PwdHash;
use zk_citadel_moat::{
Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter,
};

const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet");
const PWD_HASH: &str =
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/blockchain/get_crs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::RuskHttpClient;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::{CrsGetter, Error};
use toml_base_config::BaseConfig;
use tracing::trace;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::{CrsGetter, Error};

const MIN_CRS_SIZE: usize = 10 * 1024 * 1024;

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/blockchain/retrieve_txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::RuskHttpClient;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::{Error, TxInquirer};
use toml_base_config::BaseConfig;
use tracing::trace;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::{Error, TxInquirer};

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/citadel/int_test_lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use toml_base_config::BaseConfig;
use zk_citadel_moat::license_provider::ReferenceLP;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::Error;
use toml_base_config::BaseConfig;

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "exp_tests"), ignore)]
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/tests/citadel/int_test_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ use dusk_bytes::DeserializableSlice;
use dusk_pki::SecretSpendKey;
use dusk_plonk::prelude::*;
use dusk_wallet::{RuskHttpClient, WalletPath};
use rand::rngs::{OsRng, StdRng};
use rand::SeedableRng;
use std::path::PathBuf;
use toml_base_config::BaseConfig;
use tracing::{info, Level};
use zk_citadel::license::Request;
use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP};
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::wallet_accessor::Password::PwdHash;
Expand All @@ -32,12 +38,6 @@ use zk_citadel_moat::{
LicenseSessionId, LicenseUser, PayloadRetriever, RequestCreator,
RequestJson, RequestSender, TxAwaiter,
};
use rand::rngs::{OsRng, StdRng};
use rand::SeedableRng;
use std::path::PathBuf;
use toml_base_config::BaseConfig;
use tracing::{info, Level};
use zk_citadel::license::Request;

const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet");
const PWD_HASH: &str =
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/tests/citadel/issue_license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use dusk_jubjub::JubJubScalar;
use dusk_wallet::WalletPath;
use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP};
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::wallet_accessor::Password::PwdHash;
use zk_citadel_moat::{Error, JsonLoader, RequestCreator, RequestJson};
use rand::rngs::StdRng;
use rand::SeedableRng;
use std::path::PathBuf;
use toml_base_config::BaseConfig;
use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP};
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::wallet_accessor::Password::PwdHash;
use zk_citadel_moat::{Error, JsonLoader, RequestCreator, RequestJson};

const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet");
const PWD_HASH: &str =
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/citadel/license_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use dusk_bls12_381::BlsScalar;
use dusk_wallet::RuskHttpClient;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::{CitadelInquirer, Error, LicenseSessionId, StreamAux};
use toml_base_config::BaseConfig;
use tracing::trace;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::{CitadelInquirer, Error, LicenseSessionId, StreamAux};

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/citadel/retrieve_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::RuskHttpClient;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::{Error, PayloadRetriever, RequestScanner};
use toml_base_config::BaseConfig;
use tracing::trace;
use zk_citadel::license::Request;
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::{Error, PayloadRetriever, RequestScanner};

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "vol_tests"), ignore)]
Expand Down
14 changes: 8 additions & 6 deletions integration-tests/tests/citadel/send_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::{RuskHttpClient, WalletPath};
use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password::PwdHash};
use zk_citadel_moat::{
Error, PayloadExtractor, PayloadRetriever, RequestCreator, RequestJson,
RequestSender, TxInquirer, MAX_REQUEST_SIZE,
};
use zk_citadel_moat::{JsonLoader, TxAwaiter};
use rand::rngs::StdRng;
use rand::SeedableRng;
use std::path::PathBuf;
Expand All @@ -19,6 +13,14 @@ use tokio::time::sleep;
use toml_base_config::BaseConfig;
use tracing::Level;
use zk_citadel::license::Request;
use zk_citadel_moat::wallet_accessor::{
BlockchainAccessConfig, Password::PwdHash,
};
use zk_citadel_moat::{
Error, PayloadExtractor, PayloadRetriever, RequestCreator, RequestJson,
RequestSender, TxInquirer, MAX_REQUEST_SIZE,
};
use zk_citadel_moat::{JsonLoader, TxAwaiter};

const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet");
const PWD_HASH: &str =
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/tests/websocket/ws_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use crate::websocket::ws_license_contract_mock_multi_server;
use dusk_bls12_381::BlsScalar;
use zk_citadel_moat::{CitadelInquirerWs, Error, LicenseSession, LicenseSessionId};
use zk_citadel_moat::{
CitadelInquirerWs, Error, LicenseSession, LicenseSessionId,
};

const TEST_DURATION_SECONDS: u64 = 4;
const PORT: u32 = 9126;
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/websocket/ws_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use crate::websocket::ws_common::*;
use dusk_bls12_381::BlsScalar;
use futures_util::{SinkExt, StreamExt};
use zk_citadel_moat::{Error, LicenseSession, MAX_RESPONSE_SIZE};
use tokio::net::{TcpListener, TcpStream};
use tokio_tungstenite::tungstenite::Message;
use tracing::trace;
use zk_citadel_moat::{Error, LicenseSession, MAX_RESPONSE_SIZE};

pub async fn ws_license_contract_mock_server(
seconds: u64,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/websocket/ws_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use crate::websocket::{
send_request_to_ws_server, ws_license_contract_mock_server,
};
use zk_citadel_moat::Error;
use tracing::trace;
use zk_citadel_moat::Error;

const TEST_DURATION_SECONDS: u64 = 4;
const PORT: u32 = 9125;
Expand Down
3 changes: 0 additions & 3 deletions moat-cli/moat-cli-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use std::num::ParseIntError;
use std::sync::Arc;
use thiserror::Error;

// todo: rename CliError to Error
// todo: make sure it is used in other CLIs as well

#[derive(Error, Debug, Clone)]
pub enum Error {
/// Moat core error
Expand Down
4 changes: 2 additions & 2 deletions moat-cli/moat-cli-lp/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use crate::SeedableRng;
use dusk_jubjub::JubJubScalar;
use dusk_pki::SecretSpendKey;
use dusk_wallet::{RuskHttpClient, WalletPath};
use moat_cli_common::Error;
use rand::rngs::StdRng;
use zk_citadel_moat::license_provider::{LicenseIssuer, ReferenceLP};
use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password};
use zk_citadel_moat::{BcInquirer, CitadelInquirer};
use moat_cli_common::Error;
use rand::rngs::StdRng;

/// Commands that can be run against the Moat
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-lp/src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::prompt;
use crate::{Command, Menu};
use dusk_pki::SecretSpendKey;
use dusk_wallet::WalletPath;
use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password};
use moat_cli_common::Error;
use requestty::{ErrorKind, Question};
use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password};

#[derive(PartialEq, Eq, Hash, Debug, Clone)]
enum OpSelection {
Expand Down
6 changes: 4 additions & 2 deletions moat-cli/moat-cli-lp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ use clap::Parser;
use crate::config::LPCliConfig;
use crate::interactor::Interactor;
use dusk_wallet::{Wallet, WalletPath};
use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash};
use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor};
use moat_cli_common::Error;
use rand::SeedableRng;
use toml_base_config::BaseConfig;
use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash};
use zk_citadel_moat::wallet_accessor::{
BlockchainAccessConfig, WalletAccessor,
};

#[tokio::main]
async fn main() -> Result<(), Error> {
Expand Down
8 changes: 2 additions & 6 deletions moat-cli/moat-cli-lp/src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use requestty::{ErrorKind, Question};
pub(crate) fn request_request_hash() -> Result<String, ErrorKind> {
let q = Question::input("request_hash")
.message("Please enter request hash:".to_string())
.validate_on_key(|_, _| {
true // todo: add some validation of the request hash
})
.validate_on_key(|_, _| true)
.validate(|request_hash, _| {
if request_hash.is_empty() {
Err("Please enter a valid request hash".to_string())
Expand All @@ -29,9 +27,7 @@ pub(crate) fn request_request_hash() -> Result<String, ErrorKind> {
pub(crate) fn request_attr_data() -> Result<String, ErrorKind> {
let q = Question::input("attr_data")
.message("Please enter the attribute data:".to_string())
.validate_on_key(|_, _| {
true // todo: add some validation of the attr_data
})
.validate_on_key(|_, _| true)
.validate(|attr_data, _| {
if attr_data.is_empty() {
Err("Please enter valid attribute data".to_string())
Expand Down
7 changes: 3 additions & 4 deletions moat-cli/moat-cli-sp/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::run_result::{
LicenseContractSummary, RunResult, ServiceRequestSummery, SessionSummary,
LicenseContractSummary, RunResult, ServiceRequestSummary, SessionSummary,
};
use crate::Error;
use dusk_bls12_381::BlsScalar;
use dusk_bytes::DeserializableSlice;
use dusk_jubjub::JubJubAffine;
use dusk_pki::PublicSpendKey;
use dusk_wallet::RuskHttpClient;
use zk_citadel::license::{Session, SessionCookie};
use zk_citadel_moat::wallet_accessor::BlockchainAccessConfig;
use zk_citadel_moat::{CitadelInquirer, LicenseSessionId};
use zk_citadel::license::{Session, SessionCookie};

/// Commands that can be run against the Moat
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
Expand Down Expand Up @@ -90,8 +90,7 @@ impl Command {

let session = Session::from(&session.public_inputs);
let granted = session.verifies_ok(sc, pk_lp, pk_sp);
println!("session id={}", hex::encode(session_id.id.to_bytes()));
let service_request_summary = ServiceRequestSummery {
let service_request_summary = ServiceRequestSummary {
service_granted: granted,
};
Ok(RunResult::RequestService(service_request_summary))
Expand Down
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-sp/src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::prompt;
use crate::{Command, Menu};
use dusk_pki::PublicSpendKey;
use dusk_wallet::WalletPath;
use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password};
use moat_cli_common::Error;
use requestty::{ErrorKind, Question};
use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password};

#[derive(PartialEq, Eq, Hash, Debug, Clone)]
enum OpSelection {
Expand Down
6 changes: 4 additions & 2 deletions moat-cli/moat-cli-sp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ use clap::Parser;
use crate::config::SPCliConfig;
use crate::interactor::Interactor;
use dusk_wallet::{Wallet, WalletPath};
use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash};
use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor};
use moat_cli_common::Error;
use toml_base_config::BaseConfig;
use zk_citadel_moat::wallet_accessor::Password::{Pwd, PwdHash};
use zk_citadel_moat::wallet_accessor::{
BlockchainAccessConfig, WalletAccessor,
};

#[tokio::main]
async fn main() -> Result<(), Error> {
Expand Down
12 changes: 3 additions & 9 deletions moat-cli/moat-cli-sp/src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use requestty::{ErrorKind, Question};
pub(crate) fn request_session_id() -> Result<String, ErrorKind> {
let q = Question::input("session_id")
.message("Please enter session id:".to_string())
.validate_on_key(|_, _| {
true // todo: add some validation of the session id
})
.validate_on_key(|_, _| true)
.validate(|id, _| {
if id.is_empty() {
Err("Please enter a valid session id".to_string())
Expand All @@ -29,9 +27,7 @@ pub(crate) fn request_session_id() -> Result<String, ErrorKind> {
pub(crate) fn request_session_cookie() -> Result<String, ErrorKind> {
let q = Question::input("session_cookie")
.message("Please enter session cookie:".to_string())
.validate_on_key(|_, _| {
true // todo: add some validation of the session id
})
.validate_on_key(|_, _| true)
.validate(|id, _| {
if id.is_empty() {
Err("Please enter a valid session cookie".to_string())
Expand All @@ -49,9 +45,7 @@ pub(crate) fn request_session_cookie() -> Result<String, ErrorKind> {
pub(crate) fn request_psk_lp() -> Result<String, ErrorKind> {
let q = Question::input("psk_lp_bytes")
.message("Please enter the LP address:".to_string())
.validate_on_key(|_, _| {
true // todo: add some validation of psk_lp
})
.validate_on_key(|_, _| true)
.validate(|id, _| {
if id.is_empty() {
Err("Please enter a valid address for the LP".to_string())
Expand Down
4 changes: 2 additions & 2 deletions moat-cli/moat-cli-sp/src/run_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::fmt;

pub struct ServiceRequestSummery {
pub struct ServiceRequestSummary {
pub service_granted: bool,
}

Expand All @@ -23,7 +23,7 @@ pub struct LicenseContractSummary {
#[allow(clippy::large_enum_variant)]
/// Possible results of running a command in interactive mode
pub enum RunResult {
RequestService(ServiceRequestSummery),
RequestService(ServiceRequestSummary),
GetSession(Option<SessionSummary>),
ShowState(LicenseContractSummary),
}
Expand Down
8 changes: 4 additions & 4 deletions moat-cli/moat-cli-user/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use dusk_bytes::DeserializableSlice;
use dusk_pki::{PublicSpendKey, SecretSpendKey};
use dusk_plonk::prelude::*;
use dusk_wallet::{RuskHttpClient, WalletPath};
use moat_cli_common::Error;
use rand::rngs::{OsRng, StdRng};
use zk_citadel::license::{License, SessionCookie};
use zk_citadel_moat::wallet_accessor::{BlockchainAccessConfig, Password};
use zk_citadel_moat::{
BcInquirer, CitadelInquirer, CrsGetter, LicenseCircuit, LicenseUser,
RequestCreator, RequestSender, TxAwaiter,
};
use moat_cli_common::Error;
use rand::rngs::{OsRng, StdRng};
use zk_citadel::license::{License, SessionCookie};

use std::fs::File;
use std::io::prelude::*;
Expand Down Expand Up @@ -124,7 +124,7 @@ impl Command {
let psk_lp =
PublicSpendKey::from_slice(psk_lp_bytes_formatted.as_slice())?;

let rng = &mut StdRng::from_entropy(); // seed_from_u64(0xcafe);
let rng = &mut StdRng::from_entropy();
let request = RequestCreator::create(&ssk, &psk_lp, rng)?;
let request_hash = RunResult::to_hash_hex(&request);
let tx_id = RequestSender::send_request(
Expand Down
Loading

0 comments on commit c7e3a99

Please sign in to comment.