Skip to content

Commit

Permalink
helper macro
Browse files Browse the repository at this point in the history
  • Loading branch information
acatangiu committed Oct 22, 2024
1 parent d9d68a9 commit 9f1895c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ mod teleport;
mod transact;
mod treasury;
mod xcm_fee_estimation;

#[macro_export]
macro_rules! foreign_balance_on {
( $chain:ident, $id:expr, $who:expr ) => {
emulated_integration_tests_common::impls::paste::paste! {
<$chain>::execute_with(|| {
type ForeignAssets = <$chain as [<$chain Pallet>]>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance($id, $who)
})
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::imports::*;
use crate::{foreign_balance_on, imports::*};
use frame_support::traits::tokens::fungibles::Mutate;
use xcm::DoubleEncoded;
use xcm_builder::{DescribeAllTerminal, DescribeFamily, HashedDescription};
Expand Down Expand Up @@ -270,14 +270,9 @@ fn transact_from_para_to_para_through_asset_hub() {
let receiver = PenpalBReceiver::get();

// Query initial balances
let sender_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(usdt_from_asset_hub.clone(), &sender)
});
let receiver_assets_before = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(usdt_from_asset_hub.clone(), &receiver)
});
let sender_assets_before = foreign_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender);
let receiver_assets_before =
foreign_balance_on!(PenpalB, usdt_from_asset_hub.clone(), &receiver);

// Now register a new asset on PenpalB from PenpalA/sender account while paying fees using USDT
// (going through Asset Hub)
Expand Down Expand Up @@ -323,14 +318,8 @@ fn transact_from_para_to_para_through_asset_hub() {
});

// Query final balances
let sender_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(usdt_from_asset_hub.clone(), &sender)
});
let receiver_assets_after = PenpalB::execute_with(|| {
type ForeignAssets = <PenpalB as PenpalBPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(usdt_from_asset_hub, &receiver)
});
let sender_assets_after = foreign_balance_on!(PenpalA, usdt_from_asset_hub.clone(), &sender);
let receiver_assets_after = foreign_balance_on!(PenpalB, usdt_from_asset_hub, &receiver);

// Sender's balance is reduced by amount
assert_eq!(sender_assets_after, sender_assets_before - fee_amount_to_send);
Expand Down

0 comments on commit 9f1895c

Please sign in to comment.