Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Added integration tests for Ledger Api
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemkaaas committed Jun 1, 2017
1 parent 6c1a4dd commit eea8420
Show file tree
Hide file tree
Showing 23 changed files with 582 additions and 486 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ local_nodes_pool = []
[dependencies]
int_traits = { version = "0.1.1", optional = true }
env_logger = "0.4.2"
hex = "0.2.0"
libc = "0.2.21"
log = "0.3.7"
openssl = { version = "0.9.11", optional = true }
Expand Down
20 changes: 13 additions & 7 deletions src/api/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ pub extern fn sovrin_build_schema_request(command_handle: i32,
/// #Params
/// command_handle: command handle to map callback to caller context.
/// submitter_did: Id of Identity stored in secured Wallet.
/// dest: Id of Identity stored in secured Wallet.
/// data: name, version
/// cb: Callback that takes command result as parameter.
///
Expand All @@ -368,16 +369,19 @@ pub extern fn sovrin_build_schema_request(command_handle: i32,
#[no_mangle]
pub extern fn sovrin_build_get_schema_request(command_handle: i32,
submitter_did: *const c_char,
dest: *const c_char,
data: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
request_json: *const c_char)>) -> ErrorCode {
check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam2);
check_useful_c_str!(data, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(dest, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(data, ErrorCode::CommonInvalidParam4);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5);

let result = CommandExecutor::instance()
.send(Command::Ledger(LedgerCommand::BuildGetSchemaRequest(
submitter_did,
dest,
data,
Box::new(move |result| {
let (err, request_json) = result_to_err_code_1!(result, String::new());
Expand Down Expand Up @@ -406,13 +410,12 @@ pub extern fn sovrin_build_get_schema_request(command_handle: i32,
#[no_mangle]
pub extern fn sovrin_build_claim_def_txn(command_handle: i32,
submitter_did: *const c_char,
xref: *const c_char,
xref: i32,
signature_type: *const c_char,
data: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
request_result_json: *const c_char)>) -> ErrorCode {
check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam2);
check_useful_c_str!(xref, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(signature_type, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(data, ErrorCode::CommonInvalidParam5);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
Expand Down Expand Up @@ -440,6 +443,7 @@ pub extern fn sovrin_build_claim_def_txn(command_handle: i32,
/// submitter_did: Id of Identity stored in secured Wallet.
/// xref: Seq. number of schema
/// signature_type: signature type (only CL supported now)
/// origin
/// cb: Callback that takes command result as parameter.
///
/// #Returns
Expand All @@ -450,20 +454,22 @@ pub extern fn sovrin_build_claim_def_txn(command_handle: i32,
#[no_mangle]
pub extern fn sovrin_build_get_claim_def_txn(command_handle: i32,
submitter_did: *const c_char,
xref: *const c_char,
xref: i32,
signature_type: *const c_char,
origin: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
request_json: *const c_char)>) -> ErrorCode {
check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam2);
check_useful_c_str!(xref, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(signature_type, ErrorCode::CommonInvalidParam4);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam5);
check_useful_c_str!(origin, ErrorCode::CommonInvalidParam4);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);

let result = CommandExecutor::instance()
.send(Command::Ledger(LedgerCommand::BuildGetClaimDefRequest(
submitter_did,
xref,
signature_type,
origin,
Box::new(move |result| {
let (err, request_json) = result_to_err_code_1!(result, String::new());
let request_json = CStringUtils::string_to_cstring(request_json);
Expand Down
7 changes: 5 additions & 2 deletions src/api/signus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ use self::libc::c_char;
/// command_handle: command handle to map callback to user context.
/// did_json: Identity information as json. Example:
/// {
/// "did": string, (optional; if not provided then the first 16 bit of the verkey will be used
/// as a new DID; if provided, then keys will be replaced - key rotation use case)
/// "did": string, (optional;
/// if not provided and cid param is false then the first 16 bit of the verkey will be used as a new DID;
/// if not provided and cid is true then the full verkey will be used as a new DID;
/// if provided, then keys will be replaced - key rotation use case)
/// "seed": string, (optional; if not provide then a random one will be created)
/// "crypto_type": string, (optional; if not set then ed25519 curve is used;
/// currently only 'ed25519' value is supported for this field)
/// "cid": string, (optional; if not set then false is used;)
/// }
/// cb: Callback that takes command result as parameter.
///
Expand Down
26 changes: 16 additions & 10 deletions src/commands/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,20 @@ pub enum LedgerCommand {
Box<Fn(Result<String, SovrinError>) + Send>),
BuildGetSchemaRequest(
String, // submitter did
String, // dest
String, // data
Box<Fn(Result<String, SovrinError>) + Send>),
BuildClaimDefRequest(
String, // submitter did
String, // xref
i32, // xref
String, // signature_type
String, // data
Box<Fn(Result<String, SovrinError>) + Send>),
BuildGetClaimDefRequest(
String, // submitter did
String, // xref
i32, // xref
String, // signature_type
String, // origin
Box<Fn(Result<String, SovrinError>) + Send>),
BuildNodeRequest(
String, // submitter did
Expand Down Expand Up @@ -161,17 +163,17 @@ impl LedgerCommandExecutor {
info!(target: "ledger_command_executor", "BuildSchemaRequest command received");
self.build_schema_request(&submitter_did, &data, cb);
}
LedgerCommand::BuildGetSchemaRequest(submitter_did, data, cb) => {
LedgerCommand::BuildGetSchemaRequest(submitter_did, dest, data, cb) => {
info!(target: "ledger_command_executor", "BuildGetSchemaRequest command received");
self.build_get_schema_request(&submitter_did, &data, cb);
self.build_get_schema_request(&submitter_did, &dest, &data, cb);
}
LedgerCommand::BuildClaimDefRequest(submitter_did, xref, signature_type, data, cb) => {
info!(target: "ledger_command_executor", "BuildClaimDefRequest command received");
self.build_claim_def_request(&submitter_did, &xref, &signature_type, &data, cb);
self.build_claim_def_request(&submitter_did, xref, &signature_type, &data, cb);
}
LedgerCommand::BuildGetClaimDefRequest(submitter_did, xref, signature_type, cb) => {
LedgerCommand::BuildGetClaimDefRequest(submitter_did, xref, signature_type, origin, cb) => {
info!(target: "ledger_command_executor", "BuildGetClaimDefRequest command received");
self.build_get_claim_def_request(&submitter_did, &xref, &signature_type, cb);
self.build_get_claim_def_request(&submitter_did, xref, &signature_type, &origin, cb);
}
LedgerCommand::BuildNodeRequest(submitter_did, target_did, data, cb) => {
info!(target: "ledger_command_executor", "BuildNodeRequest command received");
Expand Down Expand Up @@ -298,16 +300,18 @@ impl LedgerCommandExecutor {

fn build_get_schema_request(&self,
submitter_did: &str,
dest: &str,
data: &str,
cb: Box<Fn(Result<String, SovrinError>) + Send>) {
cb(self.ledger_service.build_get_schema_request(submitter_did,
dest,
data
).map_err(|err| SovrinError::CommonError(err)))
}

fn build_claim_def_request(&self,
submitter_did: &str,
xref: &str,
xref: i32,
signature_type: &str,
data: &str,
cb: Box<Fn(Result<String, SovrinError>) + Send>) {
Expand All @@ -320,12 +324,14 @@ impl LedgerCommandExecutor {

fn build_get_claim_def_request(&self,
submitter_did: &str,
xref: &str,
xref: i32,
signature_type: &str,
origin: &str,
cb: Box<Fn(Result<String, SovrinError>) + Send>) {
cb(self.ledger_service.build_get_claim_def_request(submitter_did,
xref,
signature_type
signature_type,
origin
).map_err(|err| SovrinError::CommonError(err)))
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/signus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl SignusCommandExecutor {
let identity_info: MyIdentityInfo = MyIdentityInfo::from_json(identity_json)
.map_err(|_| CommonError::InvalidStructure(format!("Invalid identity json")))?;

let did_info = MyDidInfo::new(Some(did.to_string()), identity_info.seed, identity_info.crypto_type);
let did_info = MyDidInfo::new(Some(did.to_string()), identity_info.seed, identity_info.crypto_type, None);

let my_did = self.signus_service.create_my_did(&did_info)?;
let my_did_json = my_did.to_json()
Expand Down
26 changes: 13 additions & 13 deletions src/services/anoncreds/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Issuer {
info!(target: "anoncreds_service", "Issuer generate primary keys for Schema {:?} -> start", &schema);
let mut ctx = BigNumber::new_context()?;

if schema.attr_names.len() == 0 {
if schema.keys.len() == 0 {
return Err(CryptoError::InvalidStructure(format!("List of attribute names is required to setup claim definition")))
}

Expand All @@ -92,7 +92,7 @@ impl Issuer {
let xz = Issuer::_gen_x(&p_prime, &q_prime)?;
let mut r: HashMap<String, BigNumber> = HashMap::new();

for attribute in &schema.attr_names {
for attribute in &schema.keys {
let random = Issuer::_gen_x(&p_prime, &q_prime)?;
r.insert(attribute.to_string(), s.mod_exp(&random, &n, Some(&mut ctx))?);
}
Expand Down Expand Up @@ -508,7 +508,7 @@ mod tests {
fn generate_claim_definition_does_not_works_with_empty_attributes() {
let issuer = Issuer::new();
let mut schema = mocks::get_gvt_schema();
schema.attr_names = HashSet::new();
schema.keys = HashSet::new();

let signature_type = None;
let create_non_revoc = false;
Expand Down Expand Up @@ -573,29 +573,29 @@ pub mod mocks {
}

pub fn get_gvt_schema() -> Schema {
let mut attr_names: HashSet<String> = HashSet::new();
attr_names.insert("name".to_string());
attr_names.insert("age".to_string());
attr_names.insert("height".to_string());
attr_names.insert("sex".to_string());
let mut keys: HashSet<String> = HashSet::new();
keys.insert("name".to_string());
keys.insert("age".to_string());
keys.insert("height".to_string());
keys.insert("sex".to_string());

Schema {
name: "gvt".to_string(),
version: "1.0".to_string(),
attr_names: attr_names,
keys: keys,
seq_no: 1
}
}

pub fn get_xyz_schema() -> Schema {
let mut attr_names: HashSet<String> = HashSet::new();
attr_names.insert("status".to_string());
attr_names.insert("period".to_string());
let mut keys: HashSet<String> = HashSet::new();
keys.insert("status".to_string());
keys.insert("period".to_string());

Schema {
name: "xyz".to_string(),
version: "1.0".to_string(),
attr_names: attr_names,
keys: keys,
seq_no: 2
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/anoncreds/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl Prover {
let vtilde = BigNumber::rand(LARGE_VTILDE)?;

let unrevealed_attrs: Vec<String> =
schema.attr_names
schema.keys
.difference(&HashSet::from_iter(revealed_attrs.iter().cloned()))
.map(|attr| attr.clone())
.collect::<Vec<String>>();
Expand Down
6 changes: 3 additions & 3 deletions src/services/anoncreds/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,16 +1075,16 @@ impl RequestedProofJson {
pub struct Schema {
pub name: String,
pub version: String,
pub attr_names: HashSet<String>,
pub keys: HashSet<String>,
pub seq_no: i32
}

impl Schema {
pub fn new(name: String, version: String, attr_names: HashSet<String>, seq_no: i32) -> Schema {
pub fn new(name: String, version: String, keys: HashSet<String>, seq_no: i32) -> Schema {
Schema {
name: name,
version: version,
attr_names: attr_names,
keys: keys,
seq_no: seq_no
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/anoncreds/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Verifier {
use std::iter::FromIterator;

let unrevealed_attrs: Vec<String> =
schema.attr_names
schema.keys
.difference(&HashSet::from_iter(proof.revealed_attrs.keys().cloned()))
.map(|attr| attr.clone())
.collect::<Vec<String>>();
Expand Down
Loading

0 comments on commit eea8420

Please sign in to comment.