Skip to content

Commit

Permalink
Merge pull request #283 from dastardlychimp/master
Browse files Browse the repository at this point in the history
Fix Compiler Warnings
  • Loading branch information
mac-arrap authored Aug 27, 2018
2 parents 04ac06e + a67ac70 commit eb0f8a9
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 88 deletions.
1 change: 0 additions & 1 deletion libsovtoken/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ extern crate rust_indy_sdk as indy; // lib-sdk project
// ------------------------------------------


#[allow(unused_variables)]
#[macro_use]
pub mod utils;
pub mod api;
Expand Down
3 changes: 0 additions & 3 deletions libsovtoken/src/logic/config/payment_address_config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! defines structure and implementation for PaymentAddressConfig which is used
//! for generating payment addresses
#![warn(unused_imports)]
#[allow(unused_imports)]

use serde_json;
use std::ffi::CString;
use utils::ffi_support::cstring_from_str;
Expand Down
14 changes: 10 additions & 4 deletions libsovtoken/src/logic/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod output_tests {
#[test]
fn deserialize_output_tuple() {
let json = json!(["pay:sov:a8QAXMjRwEGoGLmMFEc5sTcntZxEF1BpqAs8GoKFa9Ck81fo7", 10]);
let expected = Output::new(String::from("pay:sov:a8QAXMjRwEGoGLmMFEc5sTcntZxEF1BpqAs8GoKFa9Ck81fo7"), 10);
let expected = output();
assert_valid_deserialize(json, expected);
}

Expand All @@ -189,15 +189,21 @@ mod output_tests {
assert_invalid_deserialize(json, "missing field `amount`");
}

// this test ensures that the deserialized JSON is serialized correctly
#[test]
fn serialize_valid_output_object() {
let output = output();
let json = json!(["pay:sov:a8QAXMjRwEGoGLmMFEc5sTcntZxEF1BpqAs8GoKFa9Ck81fo7", 10]);
assert_valid_serialize(output, json);
}

#[test]
fn serializing_fee_struct_output_config() {
let output = Output::new(String::from("a8QAXMjRwEGoGLmMFEc5sTcntZxEF1BpqAs8GoKFa9Ck81fo7"), 10);
let output = output();

let fee: OutputConfig = OutputConfig {
ver: 1,
outputs: vec![output],
};
assert_eq!(fee.to_json().unwrap(), r#"{"ver":1,"outputs":[["a8QAXMjRwEGoGLmMFEc5sTcntZxEF1BpqAs8GoKFa9Ck81fo7",10]]}"#);
assert_eq!(fee.to_json().unwrap(), r#"{"ver":1,"outputs":[["pay:sov:a8QAXMjRwEGoGLmMFEc5sTcntZxEF1BpqAs8GoKFa9Ck81fo7",10]]}"#);
}
}
17 changes: 7 additions & 10 deletions libsovtoken/src/logic/parsers/parse_get_utxo_response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! types used for parse_get_utxo_response_handler
#![allow(unused_variables)]
#![allow(unused_imports)]
use base64;
use indy::ErrorCode;
Expand All @@ -10,11 +8,9 @@ use logic::parsers::common::{ResponseOperations, TXO, StateProof, ParsedSP, KeyV
use logic::parsers::error_code_parser;
use logic::type_aliases::{TokenAmount, TxnSeqNo, ProtocolVersion, ReqId};
use logic::address;
use rust_base58::ToBase58;
use serde_json;
use utils::constants::txn_fields::OUTPUTS;
use utils::ffi_support::c_pointer_from_string;
use utils::json_conversion::{JsonSerialize, JsonDeserialize};

type Outputs_ = Vec<(String, TxnSeqNo, TokenAmount)>;

Expand Down Expand Up @@ -83,7 +79,7 @@ pub fn from_response(base : ParseGetUtxoResponse) -> Result<ParseGetUtxoReply, E

for unspent_output in result.outputs {

let (address, seq_no, amount) = unspent_output;
let (_address, seq_no, amount) = unspent_output;

let payment_address = address::address_from_unqualified_address(&result.address.to_string())?;
let txo = (TXO { address: payment_address.clone(), seq_no }).to_libindy_string()?;
Expand Down Expand Up @@ -168,15 +164,15 @@ pub fn get_utxo_state_proof_extractor(reply_from_node: *const c_char, parsed_sp:

#[cfg(test)]
mod parse_get_utxo_responses_tests {
#[allow(unused_imports)]
use super::*;
use std::ffi::CString;

use logic::parsers::common::{ResponseOperations, UTXO, TXO, StateProof};
use logic::parsers::common::{ResponseOperations, StateProof};
use rust_base58::ToBase58;
use utils::json_conversion::{JsonDeserialize, JsonSerialize};
use utils::random::{rand_req_id, rand_string};
use utils::constants::txn_types::GET_UTXO;
use std::ffi::CString;
use utils::ffi_support::string_from_char_ptr;
use super::*;

static PARSE_GET_UTXO_RESPONSE_JSON: &'static str = r#"{
"op": "REPLY",
Expand Down Expand Up @@ -328,7 +324,8 @@ mod parse_get_utxo_responses_tests {

let response: ParseGetUtxoResponse = ParseGetUtxoResponse::from_json(PARSE_GET_UTXO_RESPONSE_JSON).unwrap();
let reply: ParseGetUtxoReply = from_response(response).unwrap();
let reply_json : String = reply.to_json().unwrap();
let reply_json = reply.to_json();
assert!(reply_json.is_ok());
}

#[test]
Expand Down
12 changes: 3 additions & 9 deletions libsovtoken/src/logic/parsers/parse_payment_response.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
//! types used for parse_payment_response_handler
#![allow(unused_variables)]
#![allow(unused_imports)]
use indy::ErrorCode;
use logic::address::add_qualifer_to_address;
use logic::parsers::common::{ResponseOperations,
UTXO,
TXO,
TransactionMetaData,
RequireSignature,
SignatureValues};
RequireSignature};
use logic::parsers::error_code_parser;
use logic::type_aliases::{TokenAmount, ProtocolVersion};
use utils::json_conversion::JsonSerialize;

/**
for parse_payment_response_handler input resp_json
Expand Down Expand Up @@ -113,10 +109,8 @@ pub fn from_response(base: ParsePaymentResponse) -> Result<ParsePaymentReply, Er

#[cfg(test)]
mod parse_payment_response_tests {
#[allow(unused_imports)]
use logic::parsers::common::{ResponseOperations, UTXO, TXO};
use utils::json_conversion::{JsonDeserialize, JsonSerialize};
use utils::random::{rand_req_id, rand_string};
use logic::parsers::common::{ResponseOperations};
use utils::json_conversion::{JsonDeserialize};
use super::*;

static PARSE_PAYMENT_RESPONSE_JSON: &'static str = r#"{
Expand Down
16 changes: 3 additions & 13 deletions libsovtoken/src/logic/parsers/parse_response_with_fees_handler.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
//! types used for parse_response_with_fees_handler
#![allow(unused_variables)]
#![allow(unused_imports)]
use logic::address::add_qualifer_to_address;
use logic::parsers::common::{ResponseOperations,
UTXO,
TXO,
TransactionMetaData,
RequireSignature,
SignatureValues};
RequireSignature};
use logic::parsers::error_code_parser;
use logic::input::Inputs;
use logic::output::{Outputs, Output};
use utils::json_conversion::JsonSerialize;
use indy::ErrorCode;
use logic::type_aliases::{ProtocolVersion, TokenAmount, TxnSeqNo, TxnVersion, ReqId};
use logic::type_aliases::{ProtocolVersion, TokenAmount, TxnSeqNo, TxnVersion};

/**
for parse_response_with_fees_handler input resp_json
Expand Down Expand Up @@ -145,11 +139,7 @@ pub fn from_response(base : ParseResponseWithFees) -> Result<ParseResponseWithFe

#[cfg(test)]
mod parse_response_with_fees_handler_tests {
#[allow(unused_imports)]

use logic::address::{ADDRESS_LEN, VERKEY_LEN, ADDRESS_CHECKSUM_LEN};
use utils::json_conversion::{JsonDeserialize, JsonSerialize};
use utils::random::{rand_req_id, rand_string};
use utils::json_conversion::{JsonDeserialize};
use super::*;

// "fees" : [ [ (3) ], [ (2) ], int ]
Expand Down
12 changes: 5 additions & 7 deletions libsovtoken/src/logic/payments.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Payments module contains functions for working with payments. :D
#![allow(unused_variables)]
#[warn(unused_imports)]
use indy::ErrorCode;
use logic::config::payment_address_config::PaymentAddressConfig;
Expand Down Expand Up @@ -98,15 +96,15 @@ mod payments_tests {
struct CreatePaymentSDKMockHandler {}

impl CryptoAPI for CreatePaymentSDKMockHandler {
fn indy_create_key(&self, wallet_id: i32, config: PaymentAddressConfig) -> Result<String, ErrorCode> {
fn indy_create_key(&self, _wallet_id: i32, _config: PaymentAddressConfig) -> Result<String, ErrorCode> {
return Ok(gen_random_base58_verkey());
}

fn indy_crypto_sign<F>(&self, _: i32, _: String, _: String, _: F) -> ErrorCode {
return ErrorCode::CommonInvalidState;
}

fn indy_create_key_async<F: 'static>(&self, wallet_id: i32, config: PaymentAddressConfig, mut closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
fn indy_create_key_async<F: 'static>(&self, _wallet_id: i32, _config: PaymentAddressConfig, mut closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
closure(ErrorCode::Success, gen_random_base58_verkey());
return ErrorCode::Success;
}
Expand Down Expand Up @@ -140,7 +138,7 @@ mod payments_tests {

let address = match handler.create_payment_address(WALLET_ID, config) {
Ok(s) => s,
Err(e) => "".to_string(),
Err(_) => "".to_string(),
};

// got our result, if its correct, it will look something like this:
Expand All @@ -167,7 +165,7 @@ mod payments_tests {
let handler = CreatePaymentHandler::new(CreatePaymentSDKMockHandler{});
let address = match handler.create_payment_address(WALLET_ID, config){
Ok(s) => s,
Err(e) => "".to_string(),
Err(_) => "".to_string(),
};

// got our result, if its correct, it will look something like this:
Expand Down Expand Up @@ -208,6 +206,6 @@ mod payments_tests {

let got_good_result = receiver.recv_timeout(Duration::from_secs(10)).unwrap();
assert_eq!(got_good_result, true);

assert_eq!(ErrorCode::Success, error_code);
}
}
43 changes: 22 additions & 21 deletions libsovtoken/src/logic/xfer_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* [`Inputs`]: Inputs
* [`Outputs`]: Outputs
*/
#![allow(unused_must_use)]


use hex::ToHex;
Expand Down Expand Up @@ -284,7 +283,6 @@ fn do_serialize_signature(v: serde_json::Value, is_top_level: bool) -> Result<St

#[cfg(test)]
mod test_xfer_payload {
#![allow(unused_variables)]
use super::*;
use logic::config::payment_address_config::PaymentAddressConfig;
use logic::output::Output;
Expand All @@ -302,7 +300,7 @@ mod test_xfer_payload {
return ErrorCode::Success;
}

fn indy_create_key_async<F: 'static>(&self, wallet_id: i32, config: PaymentAddressConfig, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
fn indy_create_key_async<F: 'static>(&self, _wallet_id: i32, _config: PaymentAddressConfig, _closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
return ErrorCode::CommonInvalidState;
}
}
Expand Down Expand Up @@ -333,7 +331,9 @@ mod test_xfer_payload {
let wallet_handle = 1;
let (sender, receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result, _| { sender.lock().unwrap().send(result); };
let cb = move |result, _| {
sender.lock().unwrap().send(result).unwrap();
};
XferPayload::sign_input(
&CryptoApiHandler{},
wallet_handle,
Expand All @@ -351,7 +351,7 @@ mod test_xfer_payload {
let wallet_handle = 1;
let (sender, receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
XferPayload::sign_inputs(&CryptoApiHandler{}, wallet_handle, inputs, outputs, &None, &None,
Box::new(cb))?;
receiver.recv().unwrap().map(|map| map.values().cloned().collect())
Expand Down Expand Up @@ -401,9 +401,9 @@ mod test_xfer_payload {
String::remove(&mut outputs[0].recipient, 5);

let payload = XferPayload::new(inputs, outputs, None);
let (sender, receiver) = channel();
let (sender, _receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
let signed_payload = payload.sign_transfer(&CryptoApiHandler{}, wallet_handle, Box::new(cb)).unwrap_err();

assert_eq!(ErrorCode::CommonInvalidStructure, signed_payload);
Expand All @@ -415,9 +415,9 @@ mod test_xfer_payload {
let (mut inputs, outputs) = inputs_outputs_valid_qualified();
String::remove(&mut inputs[0].address, 13);

let (sender, receiver) = channel();
let (sender, _receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
let signed_payload = XferPayload::new(inputs, outputs, None).sign_transfer(&CryptoApiHandler{}, wallet_handle, Box::new(cb)).unwrap_err();

assert_eq!(ErrorCode::CommonInvalidStructure, signed_payload);
Expand All @@ -428,9 +428,9 @@ mod test_xfer_payload {
let wallet_handle = 1;
let (_, outputs) = inputs_outputs_valid_qualified();

let (sender, receiver) = channel();
let (sender, _receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
let signed_payload = XferPayload::new(Vec::new(), outputs, None).sign_transfer(&CryptoApiHandler{}, wallet_handle, Box::new(cb)).unwrap_err();

assert_eq!(ErrorCode::CommonInvalidStructure, signed_payload);
Expand All @@ -441,9 +441,9 @@ mod test_xfer_payload {
let wallet_handle = 1;
let (inputs, _) = inputs_outputs_valid_qualified();

let (sender, receiver) = channel();
let (sender, _receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
let signed_payload = XferPayload::new(inputs, Vec::new(), None).sign_transfer(&CryptoApiHandler{}, wallet_handle, Box::new(cb)).unwrap_err();

assert_eq!(ErrorCode::CommonInvalidStructure, signed_payload);
Expand All @@ -454,9 +454,9 @@ mod test_xfer_payload {
let wallet_handle = 1;
let (inputs, _) = inputs_outputs_valid_qualified();

let (sender, receiver) = channel();
let (sender, _receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
let signed_payload = XferPayload::new(inputs, Vec::new(), None).sign_fees(&CryptoApiHandler{}, wallet_handle, &None, Box::new(cb));

assert!(signed_payload.is_ok());
Expand All @@ -467,9 +467,9 @@ mod test_xfer_payload {
let wallet_handle = 1;
let (inputs, outputs) = inputs_outputs_valid_qualified();

let (sender, receiver) = channel();
let (sender, _receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
let signed_payload = XferPayload::new(inputs, outputs, None).sign_fees(&CryptoApiHandler{}, wallet_handle, &None, Box::new(cb));

assert!(signed_payload.is_ok());
Expand All @@ -480,9 +480,9 @@ mod test_xfer_payload {
let wallet_handle = 1;
let (_, outputs) = inputs_outputs_valid_qualified();

let (sender, receiver) = channel();
let (sender, _receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
let signed_payload = XferPayload::new(Vec::new(), outputs, None).sign_fees(&CryptoApiHandler{}, wallet_handle, &None, Box::new(cb)).unwrap_err();

assert_eq!(ErrorCode::CommonInvalidStructure, signed_payload);
Expand Down Expand Up @@ -510,12 +510,13 @@ mod test_xfer_payload {

let (sender, receiver) = channel();
let sender = Mutex::new(sender);
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
XferPayload::new(inputs, outputs, None).sign_transfer(&CryptoApiHandler{}, wallet_handle, Box::new(cb)).unwrap();
let signed_payload = receiver.recv().unwrap().unwrap();

assert_eq!(expected_inputs, signed_payload.inputs);
assert_eq!(expected_outputs, signed_payload.outputs);
assert_eq!(expected_signatures, signed_payload.signatures);
}

/*
Expand All @@ -540,7 +541,7 @@ mod test_xfer_payload {

for _ in 0..attempts {
let sender = sender.clone();
let cb = move |result| { sender.lock().unwrap().send(result); };
let cb = move |result| { sender.lock().unwrap().send(result).unwrap(); };
payload.clone().sign_transfer(
&CryptoApiHandler{},
wallet_handle,
Expand Down
2 changes: 1 addition & 1 deletion libsovtoken/src/utils/ffi_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ mod ffi_support_tests {
#[test]
fn api_result_handler_callback_on_ok() {
static mut CALLBACK_CALLED: bool = false;
extern fn callback(ch: i32, ec: i32, val: u32) {
extern fn callback(_ch: i32, _ec: i32, val: u32) {
assert_eq!(val, 2);
unsafe { CALLBACK_CALLED = true }
}
Expand Down
1 change: 0 additions & 1 deletion libsovtoken/src/utils/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ mod general_tests {
fn success_from_right_full_string_when_exceeding_len() {
let data = "1234567890".to_string();

let len = data.len();
let copy = data.as_str();
let result = copy.from_right(75);

Expand Down
Loading

0 comments on commit eb0f8a9

Please sign in to comment.