This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
646 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! Benchmarking setup for pallet-template | ||
#![cfg(feature = "runtime-benchmarks")] | ||
use super::*; | ||
|
||
#[allow(unused)] | ||
use crate::Pallet as WithdrawTeleport; | ||
use frame_benchmarking::{impl_benchmark_test_suite, v2::*}; | ||
use frame_support::traits::Currency; | ||
use frame_system::RawOrigin; | ||
use sp_std::prelude::*; | ||
|
||
#[benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn withdraw_and_teleport() -> Result<(), BenchmarkError> { | ||
let fee_amount = 1_000; | ||
let asset: MultiAsset = (MultiLocation::new(0, Here), fee_amount.clone()).into(); | ||
let recipient = [0u8; 32]; | ||
let versioned_dest: VersionedMultiLocation = T::ReachableDest::get() | ||
.ok_or(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))? | ||
.into(); | ||
let versioned_beneficiary: VersionedMultiLocation = | ||
AccountId32 { network: None, id: recipient.into() }.into(); | ||
let versioned_assets: VersionedMultiAssets = asset.into(); | ||
let amount: u32 = 1_000; | ||
let caller = whitelisted_caller(); | ||
T::Currency::make_free_balance_be(&caller, 100_000_000u32.into()); | ||
let initial_balance = T::Currency::free_balance(&caller); | ||
|
||
#[extrinsic_call] | ||
withdraw_and_teleport( | ||
RawOrigin::Signed(caller.clone()), | ||
Box::new(versioned_dest), | ||
Box::new(versioned_beneficiary), | ||
amount.into(), | ||
Box::new(versioned_assets), | ||
); | ||
|
||
let remaining_balance = initial_balance - amount.into() - (fee_amount as u32).into(); | ||
// Send or execution error would derive on balances amounts not being deducted from caller. | ||
assert_eq!(T::Currency::free_balance(&caller), remaining_balance); | ||
Ok(()) | ||
} | ||
|
||
impl_benchmark_test_suite!(WithdrawTeleport, crate::mock::new_test_ext(), crate::mock::Test); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.