Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
5016: Fix invalid cancel_reservations args r=zajko a=wojcik91

Fix `cancel_reservations` args typing in remaining places.


Co-authored-by: Maciej Wójcik <[email protected]>
  • Loading branch information
casperlabs-bors-ng[bot] and Maciej Wójcik authored Dec 11, 2024
2 parents 73b3205 + 9f1282a commit a7ce99c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
20 changes: 14 additions & 6 deletions node/src/types/transaction/arg_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::marker::PhantomData;
use casper_types::{
account::AccountHash,
bytesrepr::FromBytes,
system::auction::{Reservation, ARG_VALIDATOR},
system::auction::{DelegatorKind, Reservation, ARG_VALIDATOR},
CLType, CLTyped, CLValue, CLValueError, InvalidTransactionV1, PublicKey, RuntimeArgs,
TransactionArgs, URef, U512,
};
Expand Down Expand Up @@ -53,7 +53,7 @@ const ADD_RESERVATIONS_ARG_RESERVATIONS: RequiredArg<Vec<Reservation>> =
RequiredArg::new("reservations");

const CANCEL_RESERVATIONS_ARG_VALIDATOR: RequiredArg<PublicKey> = RequiredArg::new("validator");
const CANCEL_RESERVATIONS_ARG_DELEGATORS: RequiredArg<Vec<PublicKey>> =
const CANCEL_RESERVATIONS_ARG_DELEGATORS: RequiredArg<Vec<DelegatorKind>> =
RequiredArg::new("delegators");

struct RequiredArg<T> {
Expand Down Expand Up @@ -428,7 +428,7 @@ pub fn has_valid_add_reservations_args(args: &TransactionArgs) -> Result<(), Inv
#[cfg(test)]
pub fn new_cancel_reservations_args(
validator: PublicKey,
delegators: Vec<PublicKey>,
delegators: Vec<DelegatorKind>,
) -> Result<RuntimeArgs, CLValueError> {
let mut args = RuntimeArgs::new();
CANCEL_RESERVATIONS_ARG_VALIDATOR.insert(&mut args, validator)?;
Expand Down Expand Up @@ -1169,7 +1169,7 @@ mod tests {

// Missing "validator".
let args = runtime_args! {
CANCEL_RESERVATIONS_ARG_DELEGATORS.name => rng.random_vec::<Range<usize>, PublicKey>(0..100),
CANCEL_RESERVATIONS_ARG_DELEGATORS.name => rng.random_vec::<Range<usize>, DelegatorKind>(0..100),
};
let expected_error = InvalidTransactionV1::MissingArg {
arg_name: CANCEL_RESERVATIONS_ARG_VALIDATOR.name.to_string(),
Expand Down Expand Up @@ -1199,7 +1199,7 @@ mod tests {
// Wrong "validator" type.
let args = runtime_args! {
CANCEL_RESERVATIONS_ARG_VALIDATOR.name => rng.random_vec::<Range<usize>, PublicKey>(0..100),
CANCEL_RESERVATIONS_ARG_DELEGATORS.name => rng.random_vec::<Range<usize>, PublicKey>(0..100),
CANCEL_RESERVATIONS_ARG_DELEGATORS.name => rng.random_vec::<Range<usize>, DelegatorKind>(0..100),
};
let expected_error = InvalidTransactionV1::UnexpectedArgType {
arg_name: CANCEL_RESERVATIONS_ARG_VALIDATOR.name.to_string(),
Expand All @@ -1218,7 +1218,7 @@ mod tests {
};
let expected_error = InvalidTransactionV1::UnexpectedArgType {
arg_name: CANCEL_RESERVATIONS_ARG_DELEGATORS.name.to_string(),
expected: vec![CLType::List(Box::new(CLType::PublicKey))],
expected: vec![CLType::List(Box::new(CLType::Any))],
got: CLType::U8,
};
assert_eq!(
Expand Down Expand Up @@ -1252,5 +1252,13 @@ mod tests {
has_valid_redelegate_args(&args).as_ref(),
Err(&expected_error)
);
assert_eq!(
has_valid_add_reservations_args(&args).as_ref(),
Err(&expected_error)
);
assert_eq!(
has_valid_cancel_reservations_args(&args).as_ref(),
Err(&expected_error)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn cancel_reservations(validator: PublicKey, delegators: Vec<DelegatorKind>) {
// Issues a cancel_reservations request to the auction contract.
#[no_mangle]
pub extern "C" fn call() {
let delegators: Vec<DelegatorKind> = runtime::get_named_arg(auction::ARG_DELEGATORS);
let delegators = runtime::get_named_arg(auction::ARG_DELEGATORS);
let validator = runtime::get_named_arg(auction::ARG_VALIDATOR);

cancel_reservations(validator, delegators);
Expand Down
2 changes: 1 addition & 1 deletion storage/src/data_access_layer/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl AuctionMethod {
max_delegators_per_validator: u32,
) -> Result<Self, AuctionMethodError> {
let validator = Self::get_named_argument(runtime_args, auction::ARG_VALIDATOR)?;
let delegators = Self::get_named_argument(runtime_args, auction::ARG_DELEGATOR_KINDS)?;
let delegators = Self::get_named_argument(runtime_args, auction::ARG_DELEGATORS)?;

Ok(Self::CancelReservations {
validator,
Expand Down
2 changes: 0 additions & 2 deletions types/src/system/auction/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ pub const ARG_DELEGATOR: &str = "delegator";
pub const ARG_DELEGATOR_PURSE: &str = "delegator_purse";
/// Named constant for `delegators`.
pub const ARG_DELEGATORS: &str = "delegators";
/// Named constant for `delegator_kinds`.
pub const ARG_DELEGATOR_KINDS: &str = "delegator_kinds";
/// Named constant for `reservations`.
pub const ARG_RESERVATIONS: &str = "reservations";
/// Named constant for `validator_purse`.
Expand Down
11 changes: 7 additions & 4 deletions types/src/system/auction/entry_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::{
use alloc::boxed::Box;

use super::{
Reservation, ARG_MAXIMUM_DELEGATION_AMOUNT, ARG_MINIMUM_DELEGATION_AMOUNT, ARG_NEW_PUBLIC_KEY,
ARG_RESERVATIONS, ARG_REWARDS_MAP, METHOD_ADD_RESERVATIONS, METHOD_CANCEL_RESERVATIONS,
METHOD_CHANGE_BID_PUBLIC_KEY,
DelegatorKind, Reservation, ARG_MAXIMUM_DELEGATION_AMOUNT, ARG_MINIMUM_DELEGATION_AMOUNT,
ARG_NEW_PUBLIC_KEY, ARG_RESERVATIONS, ARG_REWARDS_MAP, METHOD_ADD_RESERVATIONS,
METHOD_CANCEL_RESERVATIONS, METHOD_CHANGE_BID_PUBLIC_KEY,
};

/// Creates auction contract entry points.
Expand Down Expand Up @@ -186,7 +186,10 @@ pub fn auction_entry_points() -> EntryPoints {
METHOD_CANCEL_RESERVATIONS,
vec![
Parameter::new(ARG_VALIDATOR, PublicKey::cl_type()),
Parameter::new(ARG_DELEGATORS, CLType::List(Box::new(PublicKey::cl_type()))),
Parameter::new(
ARG_DELEGATORS,
CLType::List(Box::new(DelegatorKind::cl_type())),
),
],
CLType::Unit,
EntryPointAccess::Public,
Expand Down
2 changes: 1 addition & 1 deletion types/src/transaction/transaction_entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub enum TransactionEntryPoint {
///
/// Requires the following runtime args:
/// * "validator": `PublicKey`
/// * "delegators": `Vec<PublicKey>`
/// * "delegators": `Vec<DelegatorKind>`
#[cfg_attr(
feature = "json-schema",
schemars(
Expand Down

0 comments on commit a7ce99c

Please sign in to comment.