From bcff60a227d455d95b4712b6cb356ce56b1ff672 Mon Sep 17 00:00:00 2001 From: PG Herveou Date: Fri, 21 Apr 2023 17:24:12 +0200 Subject: [PATCH] Update macro use and optimize storage collection (#13970) --- frame/contracts/src/lib.rs | 1 - frame/contracts/src/storage/meter.rs | 2 +- frame/contracts/src/tests.rs | 26 +++++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index c067b264477e9..9573c8cca1c7f 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -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; diff --git a/frame/contracts/src/storage/meter.rs b/frame/contracts/src/storage/meter.rs index 94bca741af661..1567b4662a523 100644 --- a/frame/contracts/src/storage/meter.rs +++ b/frame/contracts/src/storage/meter.rs @@ -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, diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index ce84da743d112..5cf68a8796dcb 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -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::::get($code_hash).map(|m| m.refcount()).unwrap(); + assert_eq!(is, $should); + }}; +} + pub mod test_utils { use super::{Balances, Hash, SysConfig, Test}; use crate::{ @@ -108,18 +120,6 @@ pub mod test_utils { pub fn hash(s: &S) -> <::Hashing as Hash>::Output { <::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::::get($code_hash).map(|m| m.refcount()).unwrap(); - assert_eq!(is, $should); - }}; - } } impl Test {