Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libvcx core lints #991

Merged
merged 19 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 69 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
echo "SKIP_CI ${{ needs.workflow-setup.outputs.SKIP_CI }}"
echo "DOCKER_IMG_CACHED_VDRPROXY ${{ needs.workflow-setup.outputs.DOCKER_IMG_CACHED_VDRPROXY }}"

clippy:
workspace_clippy:
runs-on: ubuntu-20.04
steps:
- name: "Git checkout"
Expand All @@ -108,49 +108,103 @@ jobs:
run: |
sudo apt-get update -y
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify clippy warnings"
- name: "Verify clippy across the entire workspace with default features"
run: |
cargo clippy
cargo clippy --tests --all-features
env:
RUSTFLAGS: -D warnings

check-did-resolver-feature-variants:
aries_vcx_clippy:
runs-on: ubuntu-20.04
strategy:
matrix:
backend: ["vdrtools", "modular_libs", "vdr_proxy_ledger"]
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN_VERSON }}
components: clippy
- name: "Install dependencies"
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify aries_vcx compiles with different dependency feature variants"
- name: "Verify clippy across the entire workspace with default features"
run: |
cd did_resolver_sov
cargo check
cargo clippy -p aries-vcx --features legacy_proof,migration --features ${{ matrix.backend }} --no-default-features
env:
RUSTFLAGS: -D warnings

check-aries-vcx-feature-variants:
aries_vcx_core_clippy:
runs-on: ubuntu-20.04
strategy:
matrix:
backend: ["vdrtools_anoncreds", "modular_libs", "vdr_proxy_ledger"]
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN_VERSON }}
components: rustfmt, clippy
components: clippy
- name: "Install dependencies"
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify aries_vcx compiles with different dependency feature variants"
- name: "Verify clippy across the entire workspace with default features"
run: |
cargo clippy -p aries_vcx_core --features legacy_proof,vdrtools_wallet --features ${{ matrix.backend }}
env:
RUSTFLAGS: -D warnings

libvcx_core_clippy:
runs-on: ubuntu-20.04
strategy:
matrix:
backend: ["anoncreds_credx", "anoncreds_vdrtools"]
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN_VERSON }}
components: clippy
- name: "Install dependencies"
shell: bash
run: |
cargo check --tests --all-features
cd aries_vcx
cargo check --no-default-features
cargo check --features vdrtools --no-default-features
cargo check --features modular_libs --no-default-features
sudo apt-get update -y
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify clippy across the entire workspace with default features"
run: |
cargo clippy -p libvcx_core --features ${{ matrix.backend }}
env:
RUSTFLAGS: -D warnings

node_wrapper_clippy:
runs-on: ubuntu-20.04
strategy:
matrix:
backend: ["anoncreds_credx", "anoncreds_vdrtools"]
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN_VERSON }}
components: clippy
- name: "Install dependencies"
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify clippy across the entire workspace with default features"
run: |
cargo clippy -p vcx-napi-rs --features ${{ matrix.backend }}
env:
RUSTFLAGS: -D warnings

##########################################################################################
############################## DOCKER BUILD ##########################################
Expand Down
22 changes: 14 additions & 8 deletions agency_client/src/agency_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,20 @@ impl AgencyClient {
}

pub fn new() -> Self {
AgencyClient {
Self::default()
}

// todo: use this in favor of `fn new()`
// pub fn new(config: &str, wallet_handle: WalletHandle, validate: bool) ->
// AgencyClientResult<Self> { let mut agency_client = Self::default();
// agency_client.process_config_string(config, wallet_handle, validate)?;
// Ok(agency_client)
// }
}

impl Default for AgencyClient {
fn default() -> Self {
Self {
wallet: Arc::new(StubAgencyClientWallet {}),
agency_url: "http://127.0.0.1:8080"
.parse()
Expand All @@ -140,11 +153,4 @@ impl AgencyClient {
my_vk: "".to_string(),
}
}

// todo: use this in favor of `fn new()`
// pub fn new(config: &str, wallet_handle: WalletHandle, validate: bool) ->
// AgencyClientResult<Self> { let mut agency_client = Self::default();
// agency_client.process_config_string(config, wallet_handle, validate)?;
// Ok(agency_client)
// }
}
9 changes: 0 additions & 9 deletions agency_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
#![allow(clippy::or_fun_call)]
#![allow(clippy::module_inception)]
#![allow(clippy::derive_partial_eq_without_eq)]
#![allow(clippy::new_without_default)]
#![allow(clippy::inherent_to_string)]
#![allow(clippy::large_enum_variant)]
#![deny(clippy::unwrap_used)]
#![crate_name = "agency_client"]

#[macro_use]
extern crate lazy_static;

Expand Down
5 changes: 1 addition & 4 deletions agency_client/src/messages/create_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ impl CreateKeyBuilder {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
agency_client::AgencyClient, errors::error::AgencyClientErrorKind,
testing::test_utils::SetupMocks,
};
use crate::errors::error::AgencyClientErrorKind;

#[test]
#[cfg(feature = "general_test")]
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/core/profile/vdr_proxy_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use aries_vcx_core::{
response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig},
},
wallet::{base_wallet::BaseWallet, indy::IndySdkWallet},
ResponseParser, VdrProxyClient, WalletHandle,
ResponseParser, VdrProxyClient,
};
use async_trait::async_trait;

Expand Down
1 change: 1 addition & 0 deletions aries_vcx_core/src/global/mockdata/mock_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lazy_static! {
RwLock::new(HashMap::new());
}

#[allow(dead_code)]
pub fn get_mock_creds_retrieved_for_proof_request() -> Option<String> {
let config = MOCK_SETTINGS
.read()
Expand Down
2 changes: 2 additions & 0 deletions aries_vcx_core/src/utils/constants.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

pub static ATTRS: &str = "attrs";
pub static LIBINDY_CRED_OFFER: &str = r#"{"issuer_did":"2hoqvcwupRTUNkXn6ArYzs","schema_key":{"name":"Home Address","version":"1.4","did":"2hoqvcwupRTUNkXn6ArYzs"},"key_correctness_proof":{"c":"8555253541554245344305351079388313043821365069629297255640200538622329722556","xz_cap":"64818256731588984794575029881576438712171978148821994354569423109505883511370051539530363090404289097908646608544866367046312481771587336183036163818849360474523320055058050733772575227932313793985470881830147160471852946598089626822740951538444260248405680001410943962258653118246973446307071417314391910474888369634752642195173997916292806072016186810315308257756689251031806948447462801785007243395079942815166817065271733596477143189406957903952991335446968764832960906258373699575234207180135806072152726528786138816315911998387303385565913657745597433033756984505440643451253917452841385494947936404135348354895376751800590086535707370194450915965147666804363452357419799188104044508109","xr_cap":{"address1":"8236425893392219787423825014385198460820517586004442204287421088285469674020926840448786131806503567730307555837801319715555107413533966776756997088003362401505821396887204933829958258785093075846810980429322007441122948459832086015057507926262051365966017173045228232337530339680355717180291794733363148324101203340879842496879728996183974739507710337122557429529832639384077022317326079678153237524335334790193774589523155338216849532635731123476861074950940938322358853287805286272076498390452028019829082291826739453475976800681550225322996208089503815975750152834370138410964418644082923687817510140143620366818252076463572791466640135793621279863114074326681043782582123182032344081138","address2":"30414471804770994051376437296525278254597585112268783700020054398847238843189530750793146903722533375657200785297557019465948393596156534191847866989266176618709331559949972729939131388887244366321127743968836991526071402029914419405781596054783690896660703606768577825229647587998380728894419570361864769440309185637967429191914824558483741394914212983254247799137730101941670911547714088499696084822272226072237693975774997990116374449197382931059877141968595755981160846810650806105803130004361523114137045586548743326078945833123588843296375692506658736851641735658969617721427932961073974202337608798761064528676757519926255271724266286989825397405029723387126754299497661658557574216867","city":"159795636056543233530021344623621334175753173834199599499234503024224170089287815725788337040803537786795901100564559891075793321268703839671526386175533087941057761454903389990043254221508542663884105491028667931433093528378567035675241504608287341705758154859625863922110474313370021277749973041267871971965548396722681397958408458464210449202419266126608057284371794186889175339171087558861231355840830361110708993602208821778313069364112399404445977187422249127909803315019664537899385297653020295835898441614009217452024854561288538496889400595485884757791655246945196819845725103196695608534259378231125159518322706097470964698852674734436475238855630473478573401236177640541599034507313","state":"215512468490315112938301657833926278136808116594771729699898320102646611321724434471863048390556908138905125523936043735201882025532772433002153410083708215401917118972375534193847316461794285777665177963351136804949997738950645361626956052973425101611071191598827068821964513860723502996877635652196651818308886110840798493982976675792164313480547213301748933952971154819253513296456319475340952940914757162158069252461973054465657233683514169036627218211903327888618365019366708902832859985119776192696909319524217085945724819529037625577237504453097885607411726308520123962852327787736505753002450290943635652415448032216336431217538662448209579828135627648861641446385394343199453905348086","zip":"238413810148929820131063264189691178282858328114757399256193590161266006646670344870416481980522447923115217342582281807424862378687793299109363839238237538377362459559820681904274866049652851183765153471969318096511161665533190643665261284892951569998678113101193901664492159340828270692168345719923300987213287650281559452357368956472066676438018575401605560388568884399190765464134955117933339552804676602790359330495723485338924295339609987825045590507344961620812843451249916254642836938597183261177212672766675968705705261108413829152581548433386403050115216912797280460237259161451733151284615735871654022007177671460429253488906111387740833557450384941388970535365310270275589048348152"}},"nonce":"45815185447169282124747"}"#;
pub static PROOF_REQUESTED_PREDICATES: &str = "requested_predicates";
Expand Down
Empty file removed libvcx/src/utils/validation.rs
Empty file.
3 changes: 2 additions & 1 deletion libvcx_core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ fn main() {
indy_dir.as_os_str().to_str().unwrap()
);

let files = vec![
let files = [
"libeay32md.dll",
"libsodium.dll",
"libzmq.dll",
"ssleay32md.dll",
];

for f in files.iter() {
if fs::copy(&indy_dir.join(f), &dst.join(f)).is_ok() {
println!(
Expand Down
6 changes: 3 additions & 3 deletions libvcx_core/src/api_vcx/api_global/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ pub async fn ledger_get_service(target_did: &str) -> LibvcxResult<AriesService>
}

pub async fn ledger_get_attr(target_did: &str, attr: &str) -> LibvcxResult<String> {
map_ariesvcx_result(get_attr(&get_main_indy_ledger_read()?, &target_did, attr).await)
map_ariesvcx_result(get_attr(&get_main_indy_ledger_read()?, target_did, attr).await)
}

pub async fn ledger_clear_attr(target_did: &str, attr: &str) -> LibvcxResult<String> {
map_ariesvcx_result(clear_attr(&get_main_indy_ledger_write()?, &target_did, attr).await)
map_ariesvcx_result(clear_attr(&get_main_indy_ledger_write()?, target_did, attr).await)
}

pub async fn ledger_write_endorser_did(
Expand Down Expand Up @@ -229,7 +229,7 @@ pub mod tests {
"mechanism": acc_mech_type
});

let auth_agreement = serde_json::to_value(&auth_agreement).unwrap();
let auth_agreement = serde_json::to_value(auth_agreement).unwrap();
assert_eq!(expected, auth_agreement);
}

Expand Down
51 changes: 20 additions & 31 deletions libvcx_core/src/api_vcx/api_global/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ use aries_vcx::{
wallet::base_wallet::BaseWallet,
PoolConfig,
},
core::profile::{
ledger::{indyvdr_build_ledger_read, indyvdr_build_ledger_write},
profile::Profile,
},
errors::error::VcxResult,
core::profile::ledger::{indyvdr_build_ledger_read, indyvdr_build_ledger_write},
};

use crate::{
Expand All @@ -32,15 +28,15 @@ use crate::{
};

lazy_static! {
pub static ref global_ledger_anoncreds_read: RwLock<Option<Arc<dyn AnoncredsLedgerRead>>> =
pub static ref GLOBAL_LEDGER_ANONCREDS_READ: RwLock<Option<Arc<dyn AnoncredsLedgerRead>>> =
RwLock::new(None);
pub static ref global_ledger_anoncreds_write: RwLock<Option<Arc<dyn AnoncredsLedgerWrite>>> =
pub static ref GLOBAL_LEDGER_ANONCREDS_WRITE: RwLock<Option<Arc<dyn AnoncredsLedgerWrite>>> =
RwLock::new(None);
pub static ref global_ledger_indy_read: RwLock<Option<Arc<dyn IndyLedgerRead>>> =
pub static ref GLOBAL_LEDGER_INDY_READ: RwLock<Option<Arc<dyn IndyLedgerRead>>> =
RwLock::new(None);
pub static ref global_ledger_indy_write: RwLock<Option<Arc<dyn IndyLedgerWrite>>> =
pub static ref GLOBAL_LEDGER_INDY_WRITE: RwLock<Option<Arc<dyn IndyLedgerWrite>>> =
RwLock::new(None);
pub static ref global_taa_configurator: RwLock<Option<Arc<dyn TaaConfigurator>>> =
pub static ref GLOBAL_TAA_CONFIGURATOR: RwLock<Option<Arc<dyn TaaConfigurator>>> =
RwLock::new(None);
}

Expand Down Expand Up @@ -122,25 +118,25 @@ async fn build_components_ledger(
let indy_write: Arc<dyn IndyLedgerWrite> = ledger_write.clone();
let anoncreds_read: Arc<dyn AnoncredsLedgerRead> = ledger_read.clone();
let indy_read: Arc<dyn IndyLedgerRead> = ledger_read.clone();
return Ok((
Ok((
anoncreds_read,
anoncreds_write,
indy_read,
indy_write,
taa_configurator,
));
))
}

pub fn reset_ledger_components() -> LibvcxResult<()> {
let mut anoncreds_read = global_ledger_anoncreds_read.write()?;
let mut anoncreds_read = GLOBAL_LEDGER_ANONCREDS_READ.write()?;
*anoncreds_read = None;
let mut anoncreds_write = global_ledger_anoncreds_write.write()?;
let mut anoncreds_write = GLOBAL_LEDGER_ANONCREDS_WRITE.write()?;
*anoncreds_write = None;
let mut indy_read = global_ledger_indy_read.write()?;
let mut indy_read = GLOBAL_LEDGER_INDY_READ.write()?;
*indy_read = None;
let mut indy_write = global_ledger_indy_write.write()?;
let mut indy_write = GLOBAL_LEDGER_INDY_WRITE.write()?;
*indy_write = None;
let mut taa_configurator = global_taa_configurator.write()?;
let mut taa_configurator = GLOBAL_TAA_CONFIGURATOR.write()?;
*taa_configurator = None;
Ok(())
}
Expand All @@ -150,15 +146,15 @@ pub async fn setup_ledger_components(config: &LibvcxLedgerConfig) -> LibvcxResul

let (anoncreds_read, anoncreds_write, indy_read, indy_write, taa_configurator) =
build_components_ledger(base_wallet, config).await?;
let mut anoncreds_read_guard = global_ledger_anoncreds_read.write()?;
let mut anoncreds_read_guard = GLOBAL_LEDGER_ANONCREDS_READ.write()?;
*anoncreds_read_guard = Some(anoncreds_read.clone());
let mut anoncreds_write_guard = global_ledger_anoncreds_write.write()?;
let mut anoncreds_write_guard = GLOBAL_LEDGER_ANONCREDS_WRITE.write()?;
*anoncreds_write_guard = Some(anoncreds_write.clone());
let mut indy_read_guard = global_ledger_indy_read.write()?;
let mut indy_read_guard = GLOBAL_LEDGER_INDY_READ.write()?;
*indy_read_guard = Some(indy_read.clone());
let mut indy_write_guard = global_ledger_indy_write.write()?;
let mut indy_write_guard = GLOBAL_LEDGER_INDY_WRITE.write()?;
*indy_write_guard = Some(indy_write.clone());
let mut indy_taa_configurator = global_taa_configurator.write()?;
let mut indy_taa_configurator = GLOBAL_TAA_CONFIGURATOR.write()?;
*indy_taa_configurator = Some(taa_configurator.clone());
Ok(())
}
Expand Down Expand Up @@ -195,7 +191,7 @@ pub async fn close_main_pool() -> LibvcxResult<()> {
#[cfg(test)]
pub mod tests {

use std::{num::NonZeroUsize, time::Duration};
use std::num::NonZeroUsize;

use aries_vcx::{
aries_vcx_core::ledger::indy::pool::test_utils::{
Expand Down Expand Up @@ -287,17 +283,11 @@ pub mod tests {
async fn test_open_pool_fails_if_genesis_file_is_invalid() {
let _setup = SetupEmpty::init();
_create_and_open_wallet().await.unwrap();
let pool_name = format!("invalidpool_{}", uuid::Uuid::new_v4().to_string());

let genesis_transactions =
TempFile::create_with_data(POOL1_TXN, "{ \"invalid\": \"genesis\" }");
set_config_value(CONFIG_GENESIS_PATH, &genesis_transactions.path).unwrap();
let config = LibvcxLedgerConfig {
genesis_path: genesis_transactions.path.clone(),
pool_config: None,
cache_config: None,
exclude_nodes: None,
};

// todo: indy-vdr panics if the file is invalid, see:
// indy-vdr-0.3.4/src/pool/runner.rs:44:22
assert_eq!(
Expand All @@ -314,7 +304,6 @@ pub mod tests {
async fn test_open_pool_fails_if_genesis_path_is_invalid() {
let _setup = SetupDefaults::init();
_create_and_open_wallet().await.unwrap();
let pool_name = format!("invalidpool_{}", uuid::Uuid::new_v4().to_string());

let config = LibvcxLedgerConfig {
genesis_path: "invalid/txn/path".to_string(),
Expand Down
Loading
Loading