Skip to content

Commit

Permalink
Update macro use and optimize storage collection (paritytech#13970)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou authored and athei committed Apr 21, 2023
1 parent 18bb7c7 commit bcff60a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "runtime-benchmarks", recursion_limit = "1024")]

#[macro_use]
mod gas;
mod benchmarking;
mod exec;
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/storage/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ where
.total_deposit
.saturating_add(&absorbed.total_deposit)
.saturating_add(&own_deposit);
self.charges.extend_from_slice(&absorbed.charges);
if !own_deposit.is_zero() {
self.charges.extend_from_slice(&absorbed.charges);
self.charges.push(Charge {
contract: contract.clone(),
amount: own_deposit,
Expand Down
26 changes: 13 additions & 13 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,19 @@ frame_support::construct_runtime!(
}
);

#[macro_use]
macro_rules! assert_return_code {
( $x:expr , $y:expr $(,)? ) => {{
assert_eq!(u32::from_le_bytes($x.data[..].try_into().unwrap()), $y as u32);
}};
}

macro_rules! assert_refcount {
( $code_hash:expr , $should:expr $(,)? ) => {{
let is = crate::OwnerInfoOf::<Test>::get($code_hash).map(|m| m.refcount()).unwrap();
assert_eq!(is, $should);
}};
}

pub mod test_utils {
use super::{Balances, Hash, SysConfig, Test};
use crate::{
Expand Down Expand Up @@ -108,18 +120,6 @@ pub mod test_utils {
pub fn hash<S: Encode>(s: &S) -> <<Test as SysConfig>::Hashing as Hash>::Output {
<<Test as SysConfig>::Hashing as Hash>::hash_of(s)
}
macro_rules! assert_return_code {
( $x:expr , $y:expr $(,)? ) => {{
assert_eq!(u32::from_le_bytes($x.data[..].try_into().unwrap()), $y as u32);
}};
}

macro_rules! assert_refcount {
( $code_hash:expr , $should:expr $(,)? ) => {{
let is = crate::OwnerInfoOf::<Test>::get($code_hash).map(|m| m.refcount()).unwrap();
assert_eq!(is, $should);
}};
}
}

impl Test {
Expand Down

0 comments on commit bcff60a

Please sign in to comment.