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

Changing TransactionV1 structure follwing https://github.com/casper-network/casper-node/pull/4890 #191

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
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,29 @@ default = ["async-trait", "clap", "clap_complete", "std-fs-io"]
std-fs-io = ["casper-types/std-fs-io"]

[dependencies]
async-trait = { version = "0.1.59", default-features = false, optional = true }
async-trait = { version = "0.1.74", default-features = false, optional = true }
base16 = "0.2.1"
casper-types = { version = "5.0.0", features = ["std", "json-schema"] }
clap = { version = "~4.4", features = ["cargo", "deprecated"], optional = true }
clap_complete = { version = "~4.4", default-features = false, optional = true }
hex-buffer-serde = "0.4.0"
humantime = "2"
itertools = "0.11.0"
humantime = "2.1.0"
itertools = "0.12.0"
jsonrpc-lite = "0.6.0"
num-traits = "0.2.15"
once_cell = "1"
once_cell = "1.18.0"
rand = "0.8.5"
reqwest = { version = "0.12.5", features = ["json"] }
schemars = "0.8.13"
schemars = "0.8.18"
serde = { version = "1", default-features = false, features = ["derive"] }
serde-map-to-array = "1.1.1"
serde_json = { version = "1", features = ["preserve_order"] }
thiserror = "1"
tokio = { version = "1.38.0", features = ["macros", "rt", "sync", "time"] }
uint = "0.9.4"
tokio = { version = "1.39.3", features = ["macros", "rt", "sync", "time"] }
uint = "0.9.5"

[dev-dependencies]
tempfile = "3.7.1"
tempfile = "3.8.1"

[patch.crates-io]
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
Expand Down
4 changes: 0 additions & 4 deletions lib/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
error: casper_types::addressable_entity::FromStrError,
},

/// Failed to parse an [`AddressableEntityHash`] from a formatted string.

Check warning on line 47 in lib/cli/error.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-20.04)

unresolved link to `AddressableEntityHash`
#[error("failed to parse {context} as an addressable entity hash: {error}")]
FailedToParseAddressableEntityHash {
/// Contextual description of where this error occurred.
Expand Down Expand Up @@ -184,10 +184,6 @@
#[error("Failed to parse a transfer target")]
FailedToParseTransferTarget,

/// Failed to parse transaction category.
#[error("Failed to parse a transaction category")]
FailedToParseTransactionCategory,

/// Failed to parse a validator public key.
#[error("Failed to parse a validator public key")]
FailedToParseValidatorPublicKey,
Expand Down
117 changes: 93 additions & 24 deletions lib/cli/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,72 +824,85 @@ pub(super) fn public_key(public_key: &str) -> Result<Option<PublicKey>, CliError

pub(super) fn pricing_mode(
pricing_mode_identifier_str: &str,
maybe_payment_amount_str: &str,
maybe_gas_price_tolerance_str: &str,
maybe_standard_payment_str: &str,
payment_amount_str: &str,
gas_price_tolerance_str: &str,
additional_computation_factor_str: &str,
standard_payment_str: &str,
maybe_receipt: Option<Digest>,
) -> Result<PricingMode, CliError> {
match pricing_mode_identifier_str.to_lowercase().as_str() {
"classic" => {
if maybe_gas_price_tolerance_str.is_empty() {
if gas_price_tolerance_str.is_empty() {
return Err(CliError::InvalidArgument {
context: "gas_price_tolerance",
error: "Gas price tolerance is required".to_string(),
});
}
if maybe_payment_amount_str.is_empty() {
if payment_amount_str.is_empty() {
return Err(CliError::InvalidArgument {
context: "payment_amount",
error: "Payment amount is required".to_string(),
});
}
if maybe_standard_payment_str.is_empty() {
if standard_payment_str.is_empty() {
return Err(CliError::InvalidArgument {
context: "standard_payment",
error: "Standard payment flag is required".to_string(),
});
}
let gas_price_tolerance =
maybe_gas_price_tolerance_str
.parse::<u8>()
.map_err(|error| CliError::FailedToParseInt {
context: "gas_price_tolerance",
error,
})?;
let payment_amount = maybe_payment_amount_str.parse::<u64>().map_err(|error| {
let gas_price_tolerance = gas_price_tolerance_str.parse::<u8>().map_err(|error| {
CliError::FailedToParseInt {
context: "payment_amount",
context: "gas_price_tolerance",
error,
}
})?;
let standard_payment = maybe_standard_payment_str
.parse::<bool>()
.map_err(|error| CliError::FailedToParseBool {
let payment_amount =
payment_amount_str
.parse::<u64>()
.map_err(|error| CliError::FailedToParseInt {
context: "payment_amount",
error,
})?;
let standard_payment = standard_payment_str.parse::<bool>().map_err(|error| {
CliError::FailedToParseBool {
context: "standard_payment",
error,
})?;
}
})?;
Ok(PricingMode::Classic {
payment_amount,
gas_price_tolerance,
standard_payment,
})
}
"fixed" => {
if maybe_gas_price_tolerance_str.is_empty() {
if gas_price_tolerance_str.is_empty() {
return Err(CliError::InvalidArgument {
context: "gas_price_tolerance",
error: "Gas price tolerance is required".to_string(),
});
}
let gas_price_tolerance =
maybe_gas_price_tolerance_str
let gas_price_tolerance = gas_price_tolerance_str.parse::<u8>().map_err(|error| {
CliError::FailedToParseInt {
context: "gas_price_tolerance",
error,
}
})?;

// Additional Computation Factor defaults to 0 if the string is empty
let additional_computation_factor = if additional_computation_factor_str.is_empty() {
u8::default()
} else {
additional_computation_factor_str
.parse::<u8>()
.map_err(|error| CliError::FailedToParseInt {
context: "gas_price_tolerance",
context: "additional_computation_factor",
error,
})?;
})?
};
Ok(PricingMode::Fixed {
gas_price_tolerance,
additional_computation_factor,
})
}
"reserved" => {
Expand Down Expand Up @@ -1689,32 +1702,63 @@ mod tests {
let pricing_mode_str = "fixed";
let payment_amount = "";
let gas_price_tolerance = "10";
let additional_computation_factor = "1";
let standard_payment = "";
let parsed = pricing_mode(
pricing_mode_str,
payment_amount,
gas_price_tolerance,
additional_computation_factor,
standard_payment,
None,
)
.unwrap();
assert_eq!(
parsed,
PricingMode::Fixed {
additional_computation_factor: 1,
gas_price_tolerance: 10,
}
);
}

#[test]
fn should_parse_fixed_pricing_mode_identifier_without_additional_computation_factor() {
let pricing_mode_str = "fixed";
let payment_amount = "";
let gas_price_tolerance = "10";
let additional_computation_factor = "";
let standard_payment = "";
let parsed = pricing_mode(
pricing_mode_str,
payment_amount,
gas_price_tolerance,
additional_computation_factor,
standard_payment,
None,
)
.unwrap();
assert_eq!(
parsed,
PricingMode::Fixed {
additional_computation_factor: 0,
gas_price_tolerance: 10,
}
);
}

#[test]
fn should_parse_reserved_pricing_mode() {
let pricing_mode_str = "reserved";
let payment_amount = "";
let gas_price_tolerance = "";
let additional_computation_factor = "0";
let standard_payment = "";
let parsed = pricing_mode(
pricing_mode_str,
payment_amount,
gas_price_tolerance,
additional_computation_factor,
standard_payment,
Some(Digest::from_hex(VALID_HASH).unwrap()),
)
Expand All @@ -1732,10 +1776,12 @@ mod tests {
let payment_amount = "10";
let standard_payment = "true";
let gas_price_tolerance = "10";
let additional_computation_factor = "0";
let parsed = pricing_mode(
pricing_mode_str,
payment_amount,
gas_price_tolerance,
additional_computation_factor,
standard_payment,
None,
)
Expand All @@ -1756,27 +1802,50 @@ mod tests {
let payment_amount = "10";
let standard_payment = "true";
let gas_price_tolerance = "10";
let additional_computation_factor = "0";
let parsed = pricing_mode(
pricing_mode_str,
payment_amount,
gas_price_tolerance,
additional_computation_factor,
standard_payment,
None,
);
assert!(parsed.is_err());
assert!(matches!(parsed, Err(CliError::InvalidArgument { .. })));
}

#[test]
fn should_fail_to_parse_invalid_additional_computation_factor() {
let pricing_mode_str = "fixed";
let payment_amount = "10";
let standard_payment = "true";
let gas_price_tolerance = "10";
let additional_computation_factor = "invalid";
let parsed = pricing_mode(
pricing_mode_str,
payment_amount,
gas_price_tolerance,
additional_computation_factor,
standard_payment,
None,
);
assert!(parsed.is_err());
assert!(matches!(parsed, Err(CliError::FailedToParseInt { .. })));
}

#[test]
fn should_fail_to_parse_classic_without_amount() {
let pricing_mode_str = "classic";
let payment_amount = "";
let standard_payment = "true";
let gas_price_tolerance = "10";
let additional_computation_factor = "0";
let parsed = pricing_mode(
pricing_mode_str,
payment_amount,
gas_price_tolerance,
additional_computation_factor,
standard_payment,
None,
);
Expand Down
Loading
Loading