Skip to content

Commit

Permalink
chore: added max limit to the oracle stores
Browse files Browse the repository at this point in the history
Signed-off-by: s-h-ubham <[email protected]>
  • Loading branch information
s-h-ubham committed Aug 7, 2024
1 parent c051cde commit b2e8fa8
Show file tree
Hide file tree
Showing 8 changed files with 2,173 additions and 2,096 deletions.
44 changes: 36 additions & 8 deletions frame/esg/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,63 @@
#![cfg(feature = "runtime-benchmarks")]

use super::*;
use crate::{Pallet as Esg, *};
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_support::WeakBoundedVec;
use sp_std::vec::Vec;
use scale_info::prelude::vec::Vec;
use frame_system::RawOrigin;

// const MAX_NUM_OF_SUDO_ORACLES: u32 = MaxNumOfSudoOracles::get();
// const MAX_NUM_OF_NON_SUDO_ORACLES: u32 = Esg::<{T as Esg::Config}>::MaxNumOfNonSudoOracles::get();
const MAX_NUM_OF_SUDO_ORACLES: u32 = 5;
const MAX_NUM_OF_NON_SUDO_ORACLES: u32 = 100;

fn create_oracle<T: Config>(
string: &'static str,
n: u32,
) -> T::AccountId {
let oracle = account(string, n, 0);
oracle
}

fn register_oracles<T: Config>() {
for i in 0 .. (MAX_NUM_OF_SUDO_ORACLES - 1) {
Esg::<T>::register_an_oracle(RawOrigin::Root.into(), create_oracle::<T>("oracle", u32::MAX - i), true);
}

for j in 0 .. (MAX_NUM_OF_NON_SUDO_ORACLES - 1) {
Esg::<T>::register_an_oracle(RawOrigin::Root.into(), create_oracle::<T>("oracle", u32::MAX - j), false);
}
}

benchmarks! {

register_an_oracle {
let account: T::AccountId = whitelisted_caller();
}: _(RawOrigin::Root, account.clone(), true)
let oracle_account: T::AccountId = whitelisted_caller();
register_oracles::<T>();

}: _(RawOrigin::Root, oracle_account.clone(), true)
verify {
assert_eq!(Esg::<T>::get_oracle_sudo().contains(&account), true);
assert_eq!(Esg::<T>::get_oracle_sudo().contains(&oracle_account), true);
}

deregister_an_oracle {
let account1: T::AccountId = whitelisted_caller();
let fn_mutate = |oracles: &mut Vec<<T as frame_system::Config>::AccountId>| oracles.push(account1.clone());
let oracle_account: T::AccountId = whitelisted_caller();
let fn_mutate = |oracles: &mut Vec<<T as frame_system::Config>::AccountId>| oracles.push(oracle_account.clone());
<SudoOraclesStore<T>>::mutate(fn_mutate);
register_oracles::<T>();

}: _(RawOrigin::Root, account1.clone(), true)
}: _(RawOrigin::Root, oracle_account.clone(), true)
verify {
assert_eq!(Esg::<T>::get_oracle_sudo().contains(&account1), false);
assert_eq!(Esg::<T>::get_oracle_sudo().contains(&oracle_account), false);
}

upsert_esg_scores {

let caller1: T::AccountId = whitelisted_caller();
let fn_mutate = |oracles: &mut Vec<<T as frame_system::Config>::AccountId>| oracles.push(caller1.clone());
<SudoOraclesStore<T>>::mutate(fn_mutate);
register_oracles::<T>();
let company1: T::AccountId = account("apple", 0, 0);
let company2: T::AccountId = account("microsoft", 1, 1);

Expand Down
Loading

0 comments on commit b2e8fa8

Please sign in to comment.