Skip to content

Commit

Permalink
Fixed merge errors
Browse files Browse the repository at this point in the history
Signed-off-by: artem.ivanov <[email protected]>
  • Loading branch information
Artemkaaas committed Feb 15, 2024
1 parent 8af10e2 commit 230af4a
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 135 deletions.
30 changes: 0 additions & 30 deletions vdr/Cargo.lock

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

53 changes: 12 additions & 41 deletions vdr/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ impl Debug for LedgerClient {
#[cfg(test)]
pub mod test {
use super::*;
use crate::{client::MockClient, signer::basic_signer::test::basic_signer};
use crate::{
client::MockClient, types::transaction::test::read_transaction, utils::init_env_logger,
};
use once_cell::sync::Lazy;
use std::{env, fs, sync::RwLock};
use std::{env, fs};

pub const CHAIN_ID: u64 = 1337;
pub const CONTRACTS_SPEC_BASE_PATH: &str = "../smart_contracts/artifacts/contracts/";
Expand Down Expand Up @@ -313,6 +315,7 @@ pub mod test {
}

pub fn mock_client() -> LedgerClient {
init_env_logger();
let mut ledger_client = LedgerClient::new(
CHAIN_ID,
RPC_NODE_ADDRESS,
Expand All @@ -328,38 +331,6 @@ pub mod test {
ledger_client
}

pub fn write_transaction() -> Transaction {
let transaction = Transaction {
type_: TransactionType::Write,
from: Some(TRUSTEE_ACC.clone()),
to: VALIDATOR_CONTROL_ADDRESS.clone(),
nonce: Some(DEFAULT_NONCE.clone()),
chain_id: CHAIN_ID,
data: vec![],
signature: RwLock::new(None),
hash: None,
};
let signer = basic_signer();
let sign_bytes = transaction.get_signing_bytes().unwrap();
let signature = signer.sign(&sign_bytes, TRUSTEE_ACC.as_ref()).unwrap();
transaction.set_signature(signature);

transaction
}

pub fn read_transaction() -> Transaction {
Transaction {
type_: TransactionType::Read,
from: None,
to: VALIDATOR_CONTROL_ADDRESS.clone(),
nonce: None,
chain_id: CHAIN_ID,
data: vec![],
signature: RwLock::new(None),
hash: None,
}
}

pub fn mock_custom_client(client: Box<dyn Client>) -> LedgerClient {
let mut ledger_client = LedgerClient::new(
CHAIN_ID,
Expand Down Expand Up @@ -413,17 +384,17 @@ pub mod test {
name: VALIDATOR_CONTROL_NAME.to_string(),
abi: Value::Array(vec ! []),
}),
}], VdrError::ContractInvalidSpec("".to_string()))]
}], VdrError::ContractInvalidSpec("Either `spec_path` or `spec` must be provided".to_string()))]
#[case::non_existent_spec_path(vec![ContractConfig {
address: VALIDATOR_CONTROL_ADDRESS.to_string(),
spec_path: Some(build_contract_path("")),
spec: None,
}], VdrError::ContractInvalidSpec("".to_string()))]
}], VdrError::ContractInvalidSpec("Unable to read contract spec file. Err: \"Is a directory (os error 21)\"".to_string()))]
#[case::empty_contract_spec(vec![ContractConfig {
address: VALIDATOR_CONTROL_ADDRESS.to_string(),
spec_path: None,
spec: None,
}], VdrError::ContractInvalidSpec("".to_string()))]
}], VdrError::ContractInvalidSpec("Either `spec_path` or `spec` must be provided".to_string()))]
fn test_create_client_errors(
#[case] contract_config: Vec<ContractConfig>,
#[case] expected_error: VdrError,
Expand All @@ -432,12 +403,12 @@ pub mod test {
.err()
.unwrap();

assert!(matches!(client_err, expected_error));
assert_eq!(client_err, expected_error);
}

#[rstest]
#[case::empty_recipient_address("", VdrError::ClientInvalidTransaction("".to_string()))]
#[case::invalid_recipient_address(INVALID_ADDRESS, VdrError::ClientInvalidTransaction("".to_string()))]
#[case::empty_recipient_address("", VdrError::ClientInvalidTransaction("Invalid transaction target address \"0x\"".to_string()))]
#[case::invalid_recipient_address(INVALID_ADDRESS, VdrError::ClientInvalidTransaction("Invalid transaction target address \"0x123\"".to_string()))]
async fn call_transaction_various_recipient_addresses(
#[case] recipient_address: &str,
#[case] expected_error: VdrError,
Expand All @@ -450,7 +421,7 @@ pub mod test {

let error = client.submit_transaction(&transaction).await.unwrap_err();

assert!(matches!(error, expected_error));
assert_eq!(error, expected_error);
}

#[async_std::test]
Expand Down
4 changes: 2 additions & 2 deletions vdr/src/contracts/cl/credential_definition_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ pub mod test {
}

mod parse_resolve_credential_definition_result {
use super::*;

// use super::*;
//
// #[test]
// fn parse_resolve_credential_definition_result_test() {
// init_env_logger();
Expand Down
5 changes: 5 additions & 0 deletions vdr/src/contracts/cl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
pub mod credential_definition_registry;
pub mod schema_registry;
pub mod types;

pub use types::{
credential_definition::CredentialDefinition, credential_definition_id::CredentialDefinitionId,
schema::Schema, schema_id::SchemaId,
};
10 changes: 7 additions & 3 deletions vdr/src/contracts/cl/types/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,18 @@ pub mod test {
contracts::{cl::types::schema_id::SchemaId, did::types::did_doc::test::ISSUER_ID},
utils::rand_string,
};
use once_cell::sync::Lazy;

pub const SCHEMA_ID: &str =
"did:ethr:testnet:0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5/anoncreds/v0/SCHEMA/F1DClaFEzi3t/1.0.0";
pub const SCHEMA_NAME: &str = "F1DClaFEzi3t";
pub const SCHEMA_VERSION: &str = "1.0.0";
pub const SCHEMA_ATTRIBUTE_FIRST_NAME: &str = "First Name";
pub static SCHEMA_ATTRIBUTES: Lazy<HashSet<String>> = Lazy::new(|| {
let mut attr_names: HashSet<String> = HashSet::new();
attr_names.insert(SCHEMA_ATTRIBUTE_FIRST_NAME.to_string());
attr_names
});

pub fn schema_id(issuer_id: &DID, name: &str) -> SchemaId {
SchemaId::build(issuer_id, name, SCHEMA_VERSION)
Expand All @@ -117,14 +123,12 @@ pub mod test {
pub fn schema(issuer_id: &DID, name: Option<&str>) -> (SchemaId, Schema) {
let name = name.map(String::from).unwrap_or_else(rand_string);
let id = schema_id(issuer_id, name.as_str());
let mut attr_names: HashSet<String> = HashSet::new();
attr_names.insert(SCHEMA_ATTRIBUTE_FIRST_NAME.to_string());

let schema = Schema {
issuer_id: issuer_id.clone(),
name,
version: SCHEMA_VERSION.to_string(),
attr_names,
attr_names: SCHEMA_ATTRIBUTES.clone(),
};
(id, schema)
}
Expand Down
3 changes: 3 additions & 0 deletions vdr/src/contracts/network/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
pub mod validator_control;
pub mod validator_info;

pub use validator_control::*;
pub use validator_info::*;
2 changes: 1 addition & 1 deletion vdr/src/types/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl ContractSpec {
let contract_spec = std::fs::read_to_string(spec_path).map_err(|err| {
let vdr_error = VdrError::ContractInvalidSpec(format!(
"Unable to read contract spec file. Err: {:?}",
err
err.to_string()
));

warn!(
Expand Down
2 changes: 1 addition & 1 deletion vdr/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod contract;
mod event_query;
mod signature;
mod status;
mod transaction;
pub(crate) mod transaction;

pub use address::Address;
pub use contract::{ContractConfig, ContractSpec};
Expand Down
Loading

0 comments on commit 230af4a

Please sign in to comment.