Skip to content

Commit a7ce99c

Browse files
5016: Fix invalid cancel_reservations args r=zajko a=wojcik91 Fix `cancel_reservations` args typing in remaining places. Co-authored-by: Maciej Wójcik <maciek@wjck.pl>
2 parents 73b3205 + 9f1282a commit a7ce99c

6 files changed

Lines changed: 24 additions & 15 deletions

File tree

node/src/types/transaction/arg_handling.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::marker::PhantomData;
44
use casper_types::{
55
account::AccountHash,
66
bytesrepr::FromBytes,
7-
system::auction::{Reservation, ARG_VALIDATOR},
7+
system::auction::{DelegatorKind, Reservation, ARG_VALIDATOR},
88
CLType, CLTyped, CLValue, CLValueError, InvalidTransactionV1, PublicKey, RuntimeArgs,
99
TransactionArgs, URef, U512,
1010
};
@@ -53,7 +53,7 @@ const ADD_RESERVATIONS_ARG_RESERVATIONS: RequiredArg<Vec<Reservation>> =
5353
RequiredArg::new("reservations");
5454

5555
const CANCEL_RESERVATIONS_ARG_VALIDATOR: RequiredArg<PublicKey> = RequiredArg::new("validator");
56-
const CANCEL_RESERVATIONS_ARG_DELEGATORS: RequiredArg<Vec<PublicKey>> =
56+
const CANCEL_RESERVATIONS_ARG_DELEGATORS: RequiredArg<Vec<DelegatorKind>> =
5757
RequiredArg::new("delegators");
5858

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

11701170
// Missing "validator".
11711171
let args = runtime_args! {
1172-
CANCEL_RESERVATIONS_ARG_DELEGATORS.name => rng.random_vec::<Range<usize>, PublicKey>(0..100),
1172+
CANCEL_RESERVATIONS_ARG_DELEGATORS.name => rng.random_vec::<Range<usize>, DelegatorKind>(0..100),
11731173
};
11741174
let expected_error = InvalidTransactionV1::MissingArg {
11751175
arg_name: CANCEL_RESERVATIONS_ARG_VALIDATOR.name.to_string(),
@@ -1199,7 +1199,7 @@ mod tests {
11991199
// Wrong "validator" type.
12001200
let args = runtime_args! {
12011201
CANCEL_RESERVATIONS_ARG_VALIDATOR.name => rng.random_vec::<Range<usize>, PublicKey>(0..100),
1202-
CANCEL_RESERVATIONS_ARG_DELEGATORS.name => rng.random_vec::<Range<usize>, PublicKey>(0..100),
1202+
CANCEL_RESERVATIONS_ARG_DELEGATORS.name => rng.random_vec::<Range<usize>, DelegatorKind>(0..100),
12031203
};
12041204
let expected_error = InvalidTransactionV1::UnexpectedArgType {
12051205
arg_name: CANCEL_RESERVATIONS_ARG_VALIDATOR.name.to_string(),
@@ -1218,7 +1218,7 @@ mod tests {
12181218
};
12191219
let expected_error = InvalidTransactionV1::UnexpectedArgType {
12201220
arg_name: CANCEL_RESERVATIONS_ARG_DELEGATORS.name.to_string(),
1221-
expected: vec![CLType::List(Box::new(CLType::PublicKey))],
1221+
expected: vec![CLType::List(Box::new(CLType::Any))],
12221222
got: CLType::U8,
12231223
};
12241224
assert_eq!(
@@ -1252,5 +1252,13 @@ mod tests {
12521252
has_valid_redelegate_args(&args).as_ref(),
12531253
Err(&expected_error)
12541254
);
1255+
assert_eq!(
1256+
has_valid_add_reservations_args(&args).as_ref(),
1257+
Err(&expected_error)
1258+
);
1259+
assert_eq!(
1260+
has_valid_cancel_reservations_args(&args).as_ref(),
1261+
Err(&expected_error)
1262+
);
12551263
}
12561264
}

smart_contracts/contracts/client/cancel-reservations/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn cancel_reservations(validator: PublicKey, delegators: Vec<DelegatorKind>) {
2727
// Issues a cancel_reservations request to the auction contract.
2828
#[no_mangle]
2929
pub extern "C" fn call() {
30-
let delegators: Vec<DelegatorKind> = runtime::get_named_arg(auction::ARG_DELEGATORS);
30+
let delegators = runtime::get_named_arg(auction::ARG_DELEGATORS);
3131
let validator = runtime::get_named_arg(auction::ARG_VALIDATOR);
3232

3333
cancel_reservations(validator, delegators);

storage/src/data_access_layer/auction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl AuctionMethod {
307307
max_delegators_per_validator: u32,
308308
) -> Result<Self, AuctionMethodError> {
309309
let validator = Self::get_named_argument(runtime_args, auction::ARG_VALIDATOR)?;
310-
let delegators = Self::get_named_argument(runtime_args, auction::ARG_DELEGATOR_KINDS)?;
310+
let delegators = Self::get_named_argument(runtime_args, auction::ARG_DELEGATORS)?;
311311

312312
Ok(Self::CancelReservations {
313313
validator,

types/src/system/auction/constants.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ pub const ARG_DELEGATOR: &str = "delegator";
3232
pub const ARG_DELEGATOR_PURSE: &str = "delegator_purse";
3333
/// Named constant for `delegators`.
3434
pub const ARG_DELEGATORS: &str = "delegators";
35-
/// Named constant for `delegator_kinds`.
36-
pub const ARG_DELEGATOR_KINDS: &str = "delegator_kinds";
3735
/// Named constant for `reservations`.
3836
pub const ARG_RESERVATIONS: &str = "reservations";
3937
/// Named constant for `validator_purse`.

types/src/system/auction/entry_points.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use crate::{
1212
use alloc::boxed::Box;
1313

1414
use super::{
15-
Reservation, ARG_MAXIMUM_DELEGATION_AMOUNT, ARG_MINIMUM_DELEGATION_AMOUNT, ARG_NEW_PUBLIC_KEY,
16-
ARG_RESERVATIONS, ARG_REWARDS_MAP, METHOD_ADD_RESERVATIONS, METHOD_CANCEL_RESERVATIONS,
17-
METHOD_CHANGE_BID_PUBLIC_KEY,
15+
DelegatorKind, Reservation, ARG_MAXIMUM_DELEGATION_AMOUNT, ARG_MINIMUM_DELEGATION_AMOUNT,
16+
ARG_NEW_PUBLIC_KEY, ARG_RESERVATIONS, ARG_REWARDS_MAP, METHOD_ADD_RESERVATIONS,
17+
METHOD_CANCEL_RESERVATIONS, METHOD_CHANGE_BID_PUBLIC_KEY,
1818
};
1919

2020
/// Creates auction contract entry points.
@@ -186,7 +186,10 @@ pub fn auction_entry_points() -> EntryPoints {
186186
METHOD_CANCEL_RESERVATIONS,
187187
vec![
188188
Parameter::new(ARG_VALIDATOR, PublicKey::cl_type()),
189-
Parameter::new(ARG_DELEGATORS, CLType::List(Box::new(PublicKey::cl_type()))),
189+
Parameter::new(
190+
ARG_DELEGATORS,
191+
CLType::List(Box::new(DelegatorKind::cl_type())),
192+
),
190193
],
191194
CLType::Unit,
192195
EntryPointAccess::Public,

types/src/transaction/transaction_entry_point.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub enum TransactionEntryPoint {
182182
///
183183
/// Requires the following runtime args:
184184
/// * "validator": `PublicKey`
185-
/// * "delegators": `Vec<PublicKey>`
185+
/// * "delegators": `Vec<DelegatorKind>`
186186
#[cfg_attr(
187187
feature = "json-schema",
188188
schemars(

0 commit comments

Comments
 (0)