Skip to content

Commit

Permalink
Merge pull request #274 from KitHat/master
Browse files Browse the repository at this point in the history
TOK-332 Add name of txn usage for SET_FEES
  • Loading branch information
mattraffel authored Aug 14, 2018
2 parents 21ae481 + 4279f7f commit 38c24cc
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 15 deletions.
4 changes: 2 additions & 2 deletions devops/aws-codebuild/Jenkinsfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pipelineWrapper({
// not accurate (it concatenates them):
// debian package version: <src_version>+<release_version>
// debian package name: <src_version><release_version>
def sovtoken_deb_version = "0.8.043.70"
def sovtokenfees_deb_version = "0.8.043.70"
def sovtoken_deb_version = "0.8.044.71"
def sovtokenfees_deb_version = "0.8.044.71"

sh """
cd ./devops/docker/ci/xenial/
Expand Down
2 changes: 1 addition & 1 deletion devops/docker/ci/xenial/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ COPY libsovtoken-ci-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["libsovtoken-ci-entrypoint.sh"]


ENV LIBSOVTOKEN_CI_ENV_VERSION=0.29.0
ENV LIBSOVTOKEN_CI_ENV_VERSION=0.30.0

2 changes: 1 addition & 1 deletion libsovtoken/src/logic/config/set_fees_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub type SetFeesMap = HashMap<String, TokenAmount>;
pub struct SetFees {
#[serde(rename = "type")]
txn_type: &'static str,
fees: SetFeesMap,
pub fees: SetFeesMap,
}

impl SetFees {
Expand Down
16 changes: 8 additions & 8 deletions libsovtoken/src/logic/parsers/parse_get_utxo_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#![allow(unused_variables)]
#![allow(unused_imports)]

use rust_base58::ToBase58;
use base64;
use indy::ErrorCode;
use libc::c_char;
use logic::parsers::common::{ResponseOperations, TXO, StateProof, ParsedSP, KeyValuesInSP,
KeyValueSimpleData, extract_result_and_state_proof_from_node_reply};
use logic::parsers::error_code_parser;
use utils::json_conversion::{JsonSerialize, JsonDeserialize};
use indy::ErrorCode;
use libc::c_char;
use serde_json;
use base64;
use utils::ffi_support::c_pointer_from_string;
use utils::constants::txn_fields::OUTPUTS;
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
31 changes: 28 additions & 3 deletions libsovtoken/src/logic/set_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ use serde_json;
use utils::constants::general::{JsonCallback, JsonCallbackUnwrapped};
use utils::ffi_support::string_from_char_ptr;

const NYM: &'static str = "1";
const ATTRIB: &'static str = "100";
const SCHEMA: &'static str = "101";
const CRED_DEF: &'static str = "102";
const REVOC_REG_DEF: &'static str = "113";
const REVOC_REG_ENTRY: &'static str = "114";
const XFER_PUBLIC: &'static str = "10001";

fn txn_name_to_code(txn: &str) -> String {
match txn {
"NYM" => NYM.to_string(),
"ATTRIB" => ATTRIB.to_string(),
"SCHEMA" => SCHEMA.to_string(),
"CRED_DEF" => CRED_DEF.to_string(),
"REVOC_REG_DEF" => REVOC_REG_DEF.to_string(),
"REVOC_REG_ENTRY" => REVOC_REG_ENTRY.to_string(),
"XFER_PUBLIC" => XFER_PUBLIC.to_string(),
val @ _ => val.to_string()
}
}

type DeserializedArguments<'a> = (Did<'a>, SetFees, JsonCallbackUnwrapped);

Expand All @@ -31,6 +51,9 @@ pub fn deserialize_inputs<'a>(
let set_fees_map: SetFeesMap = serde_json::from_str(&set_fees_json).map_err(map_err_err!())
.or(Err(ErrorCode::CommonInvalidStructure))?;

let set_fees_map: SetFeesMap = set_fees_map.iter()
.map(|(key, val)| (txn_name_to_code(key), val.clone())).collect();

let set_fees = SetFees::new(set_fees_map)
.validate().map_err(map_err_err!())
.or(Err(ErrorCode::CommonInvalidStructure))?;
Expand Down Expand Up @@ -111,15 +134,17 @@ mod test_deserialize_inputs {
}

#[test]
fn deserialize_invalid_fees_key_not_string_int() {
fn deserialize_fees_key_not_string_int() {
let invalid_fees = json_c_pointer!({
"XFER_PUBLIC": 5,
"3": 1,
});

let result = call_deserialize_inputs(None, Some(invalid_fees), None);
let (_, fees, _) = call_deserialize_inputs(None, Some(invalid_fees), None).unwrap();

assert_eq!(ErrorCode::CommonInvalidStructure, result.unwrap_err());
assert_eq!(fees.fees.len(), 2);
assert_eq!(fees.fees.get("10001"), Some(&5));
assert_eq!(fees.fees.get("3"), Some(&1));
}

#[test]
Expand Down
36 changes: 36 additions & 0 deletions libsovtoken/tests/build_fees_txn_handler_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,39 @@ pub fn build_and_submit_set_fees() {
fees::set_fees(pool_handle, wallet.handle, &payment_method, &fees, &dids);

}


#[test]
pub fn build_and_submit_set_fees_with_names() {
let payment_method = sovtoken::utils::constants::general::PAYMENT_METHOD_NAME;
let wallet = Wallet::new();
let setup = Setup::new(&wallet, SetupConfig {
num_addresses: 0,
num_trustees: 4,
num_users: 0,
mint_tokens: None,
fees: None,
});
let pool_handle = setup.pool_handle;
let dids = setup.trustees.dids();

let fees = json!({
"NYM": 1,
"ATTRIB": 2
}).to_string();

fees::set_fees(pool_handle, wallet.handle, &payment_method, &fees, &dids);
let current_fees = fees::get_fees(&wallet, pool_handle, dids[0]);
let current_fees_value: serde_json::Value = serde_json::from_str(&current_fees).unwrap();

assert_eq!(current_fees_value["1"].as_u64().unwrap(), 1);
assert_eq!(current_fees_value["100"].as_u64().unwrap(), 2);

let fees = json!({
"NYM": 0,
"ATTRIB": 0
}).to_string();

fees::set_fees(pool_handle, wallet.handle, &payment_method, &fees, &dids);

}

0 comments on commit 38c24cc

Please sign in to comment.