-
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
- Loading branch information
1 parent
4e36311
commit db9dc58
Showing
66 changed files
with
717 additions
and
663 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,47 @@ | ||
//! Benchmarking setup for pallet-move | ||
use frame_benchmarking::v2::*; | ||
use frame_system::{Config as SysConfig, RawOrigin}; | ||
use sp_runtime::traits::Zero; | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use crate::balance::BalanceOf; | ||
use crate::{script_transaction, no_type_args, Pallet, Config}; | ||
use frame_benchmarking::*; | ||
use frame_system::{Call, Config as SysConfig, RawOrigin}; | ||
use move_vm_backend_common::types::ScriptTransaction; | ||
use sp_core::{crypto::Ss58Codec, sr25519::Public}; | ||
use sp_runtime::{AccountId32, traits::Zero}; | ||
use sp_std::vec; | ||
|
||
use crate::{balance::BalanceOf, Config, *}; | ||
const BOB_ADDR: &str = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"; | ||
|
||
fn addr32_from_ss58(ss58addr: &str) -> AccountId32 { | ||
let (pk, _) = Public::from_ss58check_with_version(ss58addr).unwrap(); | ||
pk.into() | ||
} | ||
|
||
#[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() { | ||
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(), | ||
); | ||
} | ||
let script = crate::mock::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 {} | ||
|
||
#[benchmark] | ||
fn publish_module() { | ||
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); | ||
} | ||
let module = crate::mock::assets::read_module_from_project("using_stdlib_natives", "Vector"); | ||
}: _(RawOrigin::Signed(caller), module, 500_000) | ||
verify {} | ||
|
||
#[benchmark] | ||
fn publish_module_bundle() { | ||
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); | ||
} | ||
let bundle = crate::mock::assets::read_bundle_from_project("using_stdlib_natives", "using_stdlib_natives"); | ||
}: _(RawOrigin::Signed(caller), bundle, 1_500_000) | ||
verify {} | ||
|
||
impl_benchmark_test_suite!(MovePallet, crate::mock::new_test_ext(), crate::mock::Test); | ||
impl_benchmark_test_suite!(Pallet, 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
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. | ||
pub mod address; | ||
pub mod balance; | ||
pub mod example; | ||
pub mod execute; | ||
pub mod modules; | ||
pub mod publish; | ||
pub mod signer; | ||
pub mod update_stdlib; |
Oops, something went wrong.