Skip to content

Commit

Permalink
Added call to set_fruniques_do_spawn for afloatfinish_take_sell_trans…
Browse files Browse the repository at this point in the history
…action benchmark, replaced unwraps with assert_ok for calls to helpers functions that dont return a value in afloat benchmarks
  • Loading branch information
Dreyhh committed Apr 4, 2024
1 parent 7f9cf81 commit bd05e7f
Showing 1 changed file with 49 additions and 47 deletions.
96 changes: 49 additions & 47 deletions pallets/afloat/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ mod benchmarks {
fn initial_setup() {
let admin: T::AccountId = account("admin", 0, SEED);
let creator: T::AccountId = account("creator", 0, SEED);
set_max_balance::<T>(admin.clone()).unwrap();
set_max_balance::<T>(creator.clone()).unwrap();
set_rbac_assign_role_to_user_worst_case::<T>(admin.clone(), 0, true).unwrap();
assert_ok!(set_max_balance::<T>(admin.clone()));
assert_ok!(set_max_balance::<T>(creator.clone()));
assert_ok!(set_rbac_assign_role_to_user_worst_case::<T>(admin.clone(), 0, true));
let asset_id: T::AssetId = T::AfloatBenchHelper::asset(0);
let min_balance: T::Balance = T::AfloatBenchHelper::balance(1);
let asset: CreateAsset<T> = CreateAsset::New { asset_id, min_balance };
Expand All @@ -367,7 +367,7 @@ mod benchmarks {

#[benchmark]
fn kill_storage() {
init::<T>().unwrap();
assert_ok!(init::<T>());
assert!(Afloat::<T>::marketplace_id().is_some());
assert!(Afloat::<T>::collection_id().is_some());
assert!(Afloat::<T>::asset_id().is_some());
Expand All @@ -387,8 +387,8 @@ mod benchmarks {
let sign_up_args = SignUpArgs::BuyerOrSeller { cid: cid.clone(), cid_creator, group };
let user: T::AccountId = account("user", 0, SEED);

init::<T>().unwrap();
set_rbac_assign_role_to_user_worst_case::<T>(user.clone(), 1, false).unwrap();
assert_ok!(init::<T>());
assert_ok!(set_rbac_assign_role_to_user_worst_case::<T>(user.clone(), 1, false));

#[extrinsic_call]
_(RawOrigin::Signed(user.clone()), sign_up_args);
Expand All @@ -398,7 +398,7 @@ mod benchmarks {

#[benchmark]
fn update_user_info() {
init::<T>().unwrap();
assert_ok!(init::<T>());

let user: T::AccountId = account("user", 0, SEED);
register_user::<T>(user.clone(), "user").unwrap();
Expand All @@ -412,7 +412,7 @@ mod benchmarks {

let update_user_info_args = UpdateUserArgs::Delete;

set_rbac_assign_role_to_user_worst_case::<T>(user.clone(), 1, false).unwrap();
assert_ok!(set_rbac_assign_role_to_user_worst_case::<T>(user.clone(), 1, false));

let admin: T::AccountId = account("admin", 0, SEED);
#[extrinsic_call]
Expand All @@ -424,8 +424,8 @@ mod benchmarks {
#[benchmark]
fn create_tax_credit(a: Linear<0, { <T as pallet_fruniques::Config>::MaxAttributes::get() }>) {
let user: T::AccountId = account("user", 0, SEED);
init::<T>().unwrap();
register_user::<T>(user.clone(), "user").unwrap();
assert_ok!(init::<T>());
assert_ok!(register_user::<T>(user.clone(), "user"));

let attributes: Attributes<T> = create_sized_attributes::<T>(
a,
Expand All @@ -436,7 +436,7 @@ mod benchmarks {
create_sized_description::<T>(<T as pallet_uniques::Config>::StringLimit::get());
let parent_info = create_sized_parent_info::<T>(0, 0, MAX_U32, true);
assert_eq!(attributes.len() as u32, a);
set_up_fruniques_do_spawn_worst_case::<T>(user.clone()).unwrap();
assert_ok!(set_up_fruniques_do_spawn_worst_case::<T>(user.clone()));

#[extrinsic_call]
_(RawOrigin::Signed(user.clone()), description, Some(attributes), Some(parent_info));
Expand All @@ -445,9 +445,9 @@ mod benchmarks {
#[benchmark]
fn create_offer() {
let user: T::AccountId = account("user", 0, SEED);
init::<T>().unwrap();
register_user::<T>(user.clone(), "user").unwrap();
add_tax_credit::<T>(user.clone()).unwrap();
assert_ok!(init::<T>());
assert_ok!(register_user::<T>(user.clone(), "user"));
assert_ok!(add_tax_credit::<T>(user.clone()));
let args = CreateOfferArgs::Sell {
tax_credit_amount: MAX_TAX_CREDIT_AMOUNT,
tax_credit_id: T::AfloatBenchHelper::item(0),
Expand All @@ -463,12 +463,12 @@ mod benchmarks {
fn start_take_sell_order() {
let user: T::AccountId = account("user", 0, SEED);
let other_user: T::AccountId = account("other_user", 0, SEED);
set_max_balance::<T>(other_user.clone()).unwrap();
set_max_balance::<T>(user.clone()).unwrap();
init::<T>().unwrap();
register_user::<T>(user.clone(), "user").unwrap();
register_user::<T>(other_user.clone(), "other_user").unwrap();
add_tax_credit::<T>(user.clone()).unwrap();
assert_ok!(set_max_balance::<T>(other_user.clone()));
assert_ok!(set_max_balance::<T>(user.clone()));
assert_ok!(init::<T>());
assert_ok!(register_user::<T>(user.clone(), "user"));
assert_ok!(register_user::<T>(other_user.clone(), "other_user"));
assert_ok!(add_tax_credit::<T>(user.clone()));
let offer_id = add_sell_order::<T>(user.clone()).unwrap();
let offer = AfloatOffers::<T>::get(offer_id).unwrap();
let offer_trxs = offer.transactions.clone();
Expand All @@ -481,7 +481,7 @@ mod benchmarks {
T::Balance::max_value().into(),
);

set_start_take_sell_offer_worst_case::<T>(other_user.clone(), offer_id.clone()).unwrap();
assert_ok!(set_start_take_sell_offer_worst_case::<T>(other_user.clone(), offer_id.clone()));

#[extrinsic_call]
_(RawOrigin::Signed(other_user), offer_id, MAX_U32.into());
Expand All @@ -496,19 +496,19 @@ mod benchmarks {
fn confirm_sell_transaction() {
let user: T::AccountId = account("user", 0, SEED);
let other_user: T::AccountId = account("other_user", 0, SEED);
set_max_balance::<T>(other_user.clone()).unwrap();
set_max_balance::<T>(user.clone()).unwrap();
init::<T>().unwrap();
register_user::<T>(user.clone(), "user").unwrap();
register_user::<T>(other_user.clone(), "other_user").unwrap();
add_tax_credit::<T>(user.clone()).unwrap();
assert_ok!(set_max_balance::<T>(other_user.clone()));
assert_ok!(set_max_balance::<T>(user.clone()));
assert_ok!(init::<T>());
assert_ok!(register_user::<T>(user.clone(), "user"));
assert_ok!(register_user::<T>(other_user.clone(), "other_user"));
assert_ok!(add_tax_credit::<T>(user.clone()));
let offer_id = add_sell_order::<T>(user.clone()).unwrap();

let transaction_id = add_start_take_sell_order::<T>(other_user.clone(), offer_id).unwrap();
let transaction = AfloatTransactions::<T>::get(transaction_id).unwrap();
assert_eq!(transaction.confirmed, false);

set_gm_do_enlist_sell_offer_worst_case::<T>(other_user.clone(), offer_id).unwrap();
assert_ok!(set_gm_do_enlist_sell_offer_worst_case::<T>(other_user.clone(), offer_id));

#[extrinsic_call]
_(RawOrigin::Signed(user.clone()), transaction_id);
Expand All @@ -521,15 +521,17 @@ mod benchmarks {
fn finish_take_sell_transaction() {
let user: T::AccountId = account("user", 0, SEED);
let other_user: T::AccountId = account("other_user", 0, SEED);
set_max_balance::<T>(other_user.clone()).unwrap();
set_max_balance::<T>(user.clone()).unwrap();
init::<T>().unwrap();
register_user::<T>(user.clone(), "user").unwrap();
register_user::<T>(other_user.clone(), "other_user").unwrap();
add_tax_credit::<T>(user.clone()).unwrap();
assert_ok!(set_max_balance::<T>(other_user.clone()));
assert_ok!(set_max_balance::<T>(user.clone()));
assert_ok!(init::<T>());
assert_ok!(register_user::<T>(user.clone(), "user"));
assert_ok!(register_user::<T>(other_user.clone(), "other_user"));
assert_ok!(add_tax_credit::<T>(user.clone()));
let offer_id = add_sell_order::<T>(user.clone()).unwrap();
let transaction_id = add_start_take_sell_order::<T>(other_user.clone(), offer_id).unwrap();
add_confirm_sell_transaction::<T>(user.clone(), transaction_id).unwrap();
// used internally by gm do_take_sell_offer when tax credit amount < 100
assert_ok!(set_up_fruniques_do_spawn_worst_case::<T>(other_user.clone()));
assert_ok!(add_confirm_sell_transaction::<T>(user.clone(), transaction_id));
let transaction = AfloatTransactions::<T>::get(transaction_id).unwrap();
assert_eq!(transaction.completed, false);

Expand All @@ -543,9 +545,9 @@ mod benchmarks {
#[benchmark]
fn set_afloat_balance() {
let user: T::AccountId = account("user", 0, SEED);
set_max_balance::<T>(user.clone()).unwrap();
init::<T>().unwrap();
register_user::<T>(user.clone(), "user").unwrap();
assert_ok!(set_max_balance::<T>(user.clone()));
assert_ok!(init::<T>());
assert_ok!(register_user::<T>(user.clone(), "user"));
let admin: T::AccountId = account("admin", 0, SEED);
let amount = T::AfloatBenchHelper::balance(MAX_U64);
assert_eq!(
Expand All @@ -560,9 +562,9 @@ mod benchmarks {
#[benchmark]
fn cancel_offer() {
let user: T::AccountId = account("user", 0, SEED);
init::<T>().unwrap();
register_user::<T>(user.clone(), "user").unwrap();
add_tax_credit::<T>(user.clone()).unwrap();
assert_ok!(init::<T>());
assert_ok!(register_user::<T>(user.clone(), "user"));
assert_ok!(add_tax_credit::<T>(user.clone()));
let offer_id = add_sell_order::<T>(user.clone()).unwrap();
let offer = AfloatOffers::<T>::get(offer_id).unwrap();
assert_eq!(offer.status, OfferStatus::CREATED);
Expand All @@ -576,9 +578,9 @@ mod benchmarks {
fn add_afloat_admin() {
let user: T::AccountId = account("user", 0, SEED);
let admin: T::AccountId = account("admin", 0, SEED);
init::<T>().unwrap();
register_user::<T>(user.clone(), "user").unwrap();
set_rbac_assign_role_to_user_worst_case::<T>(user.clone(), 2, false).unwrap();
assert_ok!(init::<T>());
assert_ok!(register_user::<T>(user.clone(), "user"));
assert_ok!(set_rbac_assign_role_to_user_worst_case::<T>(user.clone(), 2, false));
assert!(!Afloat::<T>::is_admin(user.clone()).unwrap());
#[extrinsic_call]
_(RawOrigin::Signed(admin.clone()), user.clone());
Expand All @@ -589,9 +591,9 @@ mod benchmarks {
fn assign_user_to_role() {
let user: T::AccountId = account("user", 0, SEED);
let admin: T::AccountId = account("admin", 0, SEED);
init::<T>().unwrap();
register_user::<T>(user.clone(), "user").unwrap();
set_rbac_assign_role_to_user_worst_case::<T>(user.clone(), 2, false).unwrap();
assert_ok!(init::<T>());
assert_ok!(register_user::<T>(user.clone(), "user"));
assert_ok!(set_rbac_assign_role_to_user_worst_case::<T>(user.clone(), 2, false));
let role: AfloatRole = AfloatRole::CPA;
assert!(!Afloat::<T>::is_cpa(user.clone()).unwrap());
#[extrinsic_call]
Expand Down

0 comments on commit bd05e7f

Please sign in to comment.