Skip to content

Commit

Permalink
Merge pull request #1633 from radixdlt/feature/clean-up-code
Browse files Browse the repository at this point in the history
Misc: clean up code
  • Loading branch information
iamyulong authored Oct 24, 2023
2 parents 95da402 + cb9f32c commit ef6993d
Show file tree
Hide file tree
Showing 50 changed files with 123 additions and 262 deletions.
10 changes: 6 additions & 4 deletions monkey-tests/tests/fuzz_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,12 @@ fn kernel_fuzz<F: FnMut(&mut KernelFuzzer) -> Vec<KernelFuzzAction>>(
let database_updates = state_updates.create_database_updates::<SpreadPrefixKeyMapper>();
substate_db.commit(&database_updates);
let mut checker = KernelDatabaseChecker::new();
checker.check_db(&substate_db).expect(&format!(
"Database is not consistent at seed: {:?} actions: {:?}",
seed, actions
));
checker.check_db(&substate_db).unwrap_or_else(|_| {
panic!(
"Database is not consistent at seed: {:?} actions: {:?}",
seed, actions
)
});
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-common/benches/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct SimpleStruct {
pub fn get_simple_dataset(repeat: usize) -> SimpleStruct {
let mut data = SimpleStruct {
number: 12345678901234567890,
string: "dummy".repeat(repeat).to_owned(),
string: "dummy".repeat(repeat),
bytes: vec![123u8; repeat],
vector: vec![12345u16; repeat],
enumeration: vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,10 @@ impl FromStr for NonFungibleLocalId {
type Err = ParseNonFungibleLocalIdError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let local_id = if s.starts_with("<") && s.ends_with(">") {
Self::string(s[1..s.len() - 1].to_string())
let local_id = if s.starts_with('<') && s.ends_with('>') {
Self::string(&s[1..s.len() - 1])
.map_err(ParseNonFungibleLocalIdError::ContentValidationError)?
} else if s.starts_with("#") && s.ends_with("#") {
} else if s.starts_with('#') && s.ends_with('#') {
let digits = &s[1..s.len() - 1];
if !is_canonically_formatted_integer(digits) {
return Err(ParseNonFungibleLocalIdError::InvalidInteger);
Expand All @@ -544,13 +544,13 @@ impl FromStr for NonFungibleLocalId {
u64::from_str_radix(&s[1..s.len() - 1], 10)
.map_err(|_| ParseNonFungibleLocalIdError::InvalidInteger)?,
)
} else if s.starts_with("[") && s.ends_with("]") {
} else if s.starts_with('[') && s.ends_with(']') {
NonFungibleLocalId::bytes(
hex::decode(&s[1..s.len() - 1])
.map_err(|_| ParseNonFungibleLocalIdError::InvalidBytes)?,
)
.map_err(ParseNonFungibleLocalIdError::ContentValidationError)?
} else if s.starts_with("{") && s.ends_with("}") {
} else if s.starts_with('{') && s.ends_with('}') {
let chars: Vec<char> = s[1..s.len() - 1].chars().collect();
if chars.len() == 32 * 2 + 3 && chars[16] == '-' && chars[33] == '-' && chars[50] == '-'
{
Expand Down Expand Up @@ -627,7 +627,7 @@ mod tests {
let validation_result =
NonFungibleLocalId::string(string_of_length(1 + NON_FUNGIBLE_LOCAL_ID_MAX_LENGTH));
assert_eq!(validation_result, Err(ContentValidationError::TooLong));
let validation_result = NonFungibleLocalId::string("".to_string());
let validation_result = NonFungibleLocalId::string("");
assert_eq!(validation_result, Err(ContentValidationError::Empty));

let validation_result =
Expand All @@ -649,7 +649,7 @@ mod tests {
#[test]
fn test_non_fungible_string_validation() {
let valid_id_string = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWZYZ_0123456789";
let validation_result = NonFungibleLocalId::string(valid_id_string.to_owned());
let validation_result = NonFungibleLocalId::string(valid_id_string);
assert!(matches!(validation_result, Ok(_)));

test_invalid_char('.');
Expand Down
15 changes: 13 additions & 2 deletions radix-engine-common/src/math/bnum_integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ macro_rules! types {
#[doc = "`" $t "` will have the same methods and traits as"]
/// the built-in counterpart.
#[cfg_attr(feature = "radix_engine_fuzzing", derive(Arbitrary, Serialize, Deserialize))]
#[derive(Clone , Copy , Eq , Hash)]
#[derive(Clone , Copy)]
#[repr(transparent)]
pub struct $t(pub $wrap);

Expand Down Expand Up @@ -113,9 +113,20 @@ macro_rules! types {
}
}

// The following three trait implementations must be aligned.

impl PartialEq for $t {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
self.0.eq(&other.0)
}
}

impl Eq for $t {
}

impl sbor::rust::hash::Hash for $t {
fn hash<H>(&self, state: &mut H) where H: sbor::rust::hash::Hasher {
self.0.hash(state)
}
}
)*
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-common/src/math/precise_decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ impl fmt::Display for PreciseDecimal {

impl fmt::Debug for PreciseDecimal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string())
write!(f, "{}", self)
}
}

Expand Down
2 changes: 1 addition & 1 deletion radix-engine-common/src/time/utc_date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl UtcDateTime {
minute: u8,
second: u8,
) -> Result<Self, DateTimeError> {
if year <= 0 {
if year == 0 {
return Err(DateTimeError::InvalidYear);
}

Expand Down
6 changes: 2 additions & 4 deletions radix-engine-derive/src/manifest_sbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ pub fn handle_manifest_sbor(input: TokenStream) -> Result<TokenStream> {
input.clone(),
context_custom_value_kind.clone(),
)?;
let decode = sbor_derive_common::decode::handle_decode(
input.clone(),
context_custom_value_kind.clone(),
)?;
let decode =
sbor_derive_common::decode::handle_decode(input, context_custom_value_kind.clone())?;

let output = quote! {
#categorize
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ pub struct AccessControllerCreateInput {
pub address_reservation: Option<GlobalAddressReservation>,
}

impl Clone for AccessControllerCreateInput {
fn clone(&self) -> Self {
Self {
controlled_asset: Bucket(self.controlled_asset.0),
rule_set: self.rule_set.clone(),
timed_recovery_delay_in_minutes: self.timed_recovery_delay_in_minutes.clone(),
address_reservation: self.address_reservation.clone(),
}
}
}

pub type AccessControllerCreateGlobalOutput = Global<AccessControllerObjectTypeInfo>;

//================================
Expand Down
34 changes: 1 addition & 33 deletions radix-engine-interface/src/blueprints/resource/auth_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ use crate::blueprints::resource::*;
use crate::data::scrypto::model::*;
use crate::math::Decimal;
use crate::*;
use radix_engine_common::data::scrypto::*;
use radix_engine_common::types::*;
use radix_engine_interface::constants::RESOURCE_PACKAGE;
use sbor::rust::collections::IndexSet;
use sbor::rust::fmt::Debug;
use sbor::rust::prelude::*;
use sbor::rust::vec::Vec;
use sbor::*;

pub const AUTH_ZONE_BLUEPRINT: &str = "AuthZone";

Expand All @@ -27,14 +24,6 @@ pub struct AuthZonePushInput {
pub proof: Proof,
}

impl Clone for AuthZonePushInput {
fn clone(&self) -> Self {
Self {
proof: Proof(self.proof.0),
}
}
}

pub type AuthZonePushOutput = ();

pub const AUTH_ZONE_CREATE_PROOF_OF_AMOUNT_IDENT: &str = "create_proof_of_amount";
Expand Down Expand Up @@ -103,26 +92,5 @@ pub struct AuthZoneAssertAccessRuleInput {

pub type AuthZoneAssertAccessRuleOutput = ();

#[derive(Debug, Eq, PartialEq, ScryptoCategorize, ScryptoEncode, ScryptoDecode)]
#[sbor(transparent)]
#[derive(Debug, Eq, PartialEq)]
pub struct AuthZoneRef(pub NodeId);

impl Describe<ScryptoCustomTypeKind> for AuthZoneRef {
const TYPE_ID: RustTypeId =
RustTypeId::Novel(const_sha1::sha1("OwnedAuthZone".as_bytes()).as_bytes());

fn type_data() -> TypeData<ScryptoCustomTypeKind, RustTypeId> {
TypeData {
kind: TypeKind::Custom(ScryptoCustomTypeKind::Own),
metadata: TypeMetadata::no_child_names("OwnedAuthZone"),
validation: TypeValidation::Custom(ScryptoCustomTypeValidation::Own(
OwnValidation::IsTypedObject(
Some(RESOURCE_PACKAGE),
AUTH_ZONE_BLUEPRINT.to_string(),
),
)),
}
}

fn add_all_dependencies(_aggregator: &mut TypeAggregator<ScryptoCustomTypeKind>) {}
}
8 changes: 0 additions & 8 deletions radix-engine-interface/src/blueprints/resource/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ pub struct BucketPutInput {

pub type BucketPutOutput = ();

impl Clone for BucketPutInput {
fn clone(&self) -> Self {
Self {
bucket: Bucket(self.bucket.0),
}
}
}

pub const BUCKET_GET_AMOUNT_IDENT: &str = "get_amount";

#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl FungibleResourceRoles {
withdrawer_updater => rule!(deny_all);
},
deposit_roles: deposit_roles! {
depositor => access_rule.clone();
depositor => access_rule;
depositor_updater => rule!(deny_all);
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl NonFungibleResourceRoles {
withdrawer_updater => rule!(deny_all);
},
deposit_roles: deposit_roles! {
depositor => access_rule.clone();
depositor => access_rule;
depositor_updater => rule!(deny_all);
},
}
Expand Down
8 changes: 0 additions & 8 deletions radix-engine-interface/src/blueprints/resource/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ pub struct VaultPutInput {

pub type VaultPutOutput = ();

impl Clone for VaultPutInput {
fn clone(&self) -> Self {
Self {
bucket: Bucket(self.bucket.0),
}
}
}

pub const VAULT_TAKE_IDENT: &str = "take";

#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor)]
Expand Down
8 changes: 0 additions & 8 deletions radix-engine-interface/src/blueprints/resource/worktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ pub struct WorktopPutInput {

pub type WorktopPutOutput = ();

impl Clone for WorktopPutInput {
fn clone(&self) -> Self {
Self {
bucket: Bucket(self.bucket.0),
}
}
}

pub const WORKTOP_TAKE_IDENT: &str = "Worktop_take";

#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod tests {

// ROLE ASSIGNMENT
let resource_or_non_fungible_1 = ResourceOrNonFungible::Resource(XRD);
let resource_or_non_fungible_2 = ResourceOrNonFungible::NonFungible(nf_global_id.clone());
let resource_or_non_fungible_2 = ResourceOrNonFungible::NonFungible(nf_global_id);
let resource_or_non_fungible_list = vec![
resource_or_non_fungible_1.clone(),
resource_or_non_fungible_2.clone(),
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-tests/benches/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn bench_transfer(c: &mut Criterion) {
vm.clone(),
&CostingParameters::default(),
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
&TestTransaction::new_from_nonce(manifest.clone(), 1)
&TestTransaction::new_from_nonce(manifest, 1)
.prepare()
.unwrap()
.get_executable(btreeset![NonFungibleGlobalId::from_public_key(&public_key)]),
Expand Down
16 changes: 4 additions & 12 deletions radix-engine-tests/tests/account_authorized_depositors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ fn try_authorized_deposit_or_refund_performs_a_refund_when_badge_is_not_in_depos
.call_method(
account1,
ACCOUNT_ADD_AUTHORIZED_DEPOSITOR,
AccountAddAuthorizedDepositorInput {
badge: badge.clone(),
},
AccountAddAuthorizedDepositorInput { badge: badge },
)
.build(),
vec![NonFungibleGlobalId::from_public_key(&pk1)],
Expand Down Expand Up @@ -324,9 +322,7 @@ fn try_authorized_deposit_batch_or_refund_performs_a_refund_when_badge_is_not_in
.call_method(
account1,
ACCOUNT_ADD_AUTHORIZED_DEPOSITOR,
AccountAddAuthorizedDepositorInput {
badge: badge.clone(),
},
AccountAddAuthorizedDepositorInput { badge: badge },
)
.build(),
vec![NonFungibleGlobalId::from_public_key(&pk1)],
Expand Down Expand Up @@ -485,9 +481,7 @@ fn try_authorized_deposit_or_abort_performs_an_abort_when_badge_is_not_in_deposi
.call_method(
account1,
ACCOUNT_ADD_AUTHORIZED_DEPOSITOR,
AccountAddAuthorizedDepositorInput {
badge: badge.clone(),
},
AccountAddAuthorizedDepositorInput { badge: badge },
)
.build(),
vec![NonFungibleGlobalId::from_public_key(&pk1)],
Expand Down Expand Up @@ -646,9 +640,7 @@ fn try_authorized_deposit_batch_or_abort_performs_an_abort_when_badge_is_not_in_
.call_method(
account1,
ACCOUNT_ADD_AUTHORIZED_DEPOSITOR,
AccountAddAuthorizedDepositorInput {
badge: badge.clone(),
},
AccountAddAuthorizedDepositorInput { badge: badge },
)
.build(),
vec![NonFungibleGlobalId::from_public_key(&pk1)],
Expand Down
4 changes: 2 additions & 2 deletions radix-engine-tests/tests/balance_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn test_balance_changes_when_success() {
.build(),
vec![
NonFungibleGlobalId::from_public_key(&public_key),
owner_badge_addr.clone(),
owner_badge_addr,
],
);
let component_address = receipt.expect_commit(true).new_component_addresses()[0];
Expand Down Expand Up @@ -119,7 +119,7 @@ fn test_balance_changes_when_failure() {
.build(),
vec![
NonFungibleGlobalId::from_public_key(&public_key),
owner_badge_addr.clone(),
owner_badge_addr,
],
);
let component_address = receipt.expect_commit(true).new_component_addresses()[0];
Expand Down
Loading

0 comments on commit ef6993d

Please sign in to comment.