-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: restructure pallet part 1, unit tests and internal mockup (#154)
- Loading branch information
1 parent
ca7e176
commit 4536e8e
Showing
67 changed files
with
779 additions
and
1,012 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,73 +1,42 @@ | ||
//! Benchmarking setup for pallet-move | ||
//! Benchmarking setup for pallet-move. | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use frame_benchmarking::v2::*; | ||
use frame_benchmarking::*; | ||
use frame_system::{Config as SysConfig, RawOrigin}; | ||
use sp_runtime::traits::Zero; | ||
use sp_runtime::{traits::Zero, AccountId32}; | ||
use sp_std::vec; | ||
|
||
use crate::{balance::BalanceOf, Config, *}; | ||
use crate::{balance::BalanceOf, mock::*, *}; | ||
|
||
#[benchmarks( | ||
where | ||
benchmarks! { | ||
where_clause { where | ||
T: Config + SysConfig, | ||
T::AccountId: From<AccountId32>, | ||
BalanceOf<T>: From<u128> + Into<u128>, | ||
)] | ||
mod benchmarks { | ||
use sp_core::{crypto::Ss58Codec, sr25519::Public}; | ||
use sp_runtime::AccountId32; | ||
|
||
use super::*; | ||
|
||
const BOB_ADDR: &str = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; | ||
|
||
fn addr32_from_ss58(ss58addr: &str) -> AccountId32 { | ||
let (pk, _) = Public::from_ss58check_with_version(ss58addr).unwrap(); | ||
pk.into() | ||
} | ||
|
||
#[benchmark] | ||
fn execute() { | ||
let caller: T::AccountId = addr32_from_ss58(BOB_ADDR).into(); | ||
let module = | ||
include_bytes!("../tests/assets/move-projects/move-basics/build/move-basics/bytecode_scripts/empty_scr.mv") | ||
.to_vec(); | ||
let transaction = ScriptTransaction { | ||
bytecode: module, | ||
type_args: vec![], | ||
args: vec![], | ||
}; | ||
let transaction_bc = bcs::to_bytes(&transaction).unwrap(); | ||
#[extrinsic_call] | ||
execute( | ||
RawOrigin::Signed(caller), | ||
transaction_bc, | ||
100_000, | ||
BalanceOf::<T>::zero(), | ||
); | ||
} | ||
|
||
#[benchmark] | ||
fn publish_module() { | ||
let caller: T::AccountId = addr32_from_ss58(BOB_ADDR).into(); | ||
let module = include_bytes!( | ||
"../tests/assets/move-projects/using_stdlib_natives/build/using_stdlib_natives/bytecode_modules/Vector.mv" | ||
) | ||
.to_vec(); | ||
#[extrinsic_call] | ||
publish_module(RawOrigin::Signed(caller), module, 500_000); | ||
} | ||
|
||
#[benchmark] | ||
fn publish_module_bundle() { | ||
let caller: T::AccountId = addr32_from_ss58(BOB_ADDR).into(); | ||
let module = include_bytes!( | ||
"../tests/assets/move-projects/using_stdlib_natives/build/using_stdlib_natives/bundles/using_stdlib_natives.mvb" | ||
) | ||
.to_vec(); | ||
#[extrinsic_call] | ||
publish_module_bundle(RawOrigin::Signed(caller), module, 1_500_000); | ||
} | ||
|
||
impl_benchmark_test_suite!(MovePallet, crate::mock::new_test_ext(), crate::mock::Test); | ||
execute { | ||
let caller: T::AccountId = addr32_from_ss58(BOB_ADDR).unwrap().into(); | ||
let script = assets::read_script_from_project("move-basics", "empty_scr"); | ||
let transaction_bc = script_transaction!(script, no_type_args!()); | ||
}: _(RawOrigin::Signed(caller), transaction_bc, 100_000, BalanceOf::<T>::zero()) | ||
verify {} | ||
|
||
publish_module { | ||
let caller: T::AccountId = addr32_from_ss58(BOB_ADDR).unwrap().into(); | ||
let module = assets::read_module_from_project("using_stdlib_natives", "Vector"); | ||
}: _(RawOrigin::Signed(caller), module, 500_000) | ||
verify {} | ||
|
||
publish_module_bundle { | ||
let caller: T::AccountId = addr32_from_ss58(BOB_ADDR).unwrap().into(); | ||
let bundle = assets::read_bundle_from_project("using_stdlib_natives", "using_stdlib_natives"); | ||
}: _(RawOrigin::Signed(caller), bundle, 1_500_000) | ||
verify {} | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Pallet, | ||
crate::mock::ExtBuilder::default().build(), | ||
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
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,10 @@ | ||
//! Container module for all test modules. | ||
mod address; | ||
mod balance; | ||
mod example; | ||
mod execute; | ||
mod modules; | ||
mod publish; | ||
mod signer; | ||
mod update_stdlib; |
Oops, something went wrong.