Skip to content

Commit

Permalink
fix teeracle too
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Jul 19, 2024
1 parent bb4f5e1 commit 92252e4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
5 changes: 3 additions & 2 deletions teeracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ hex-literal = { workspace = true, optional = true }
pallet-timestamp = { workspace = true, optional = true }
pallet-aura = { workspace = true, optional = true }
test-utils = { default-features = false, path = "../test-utils", optional = true }
sp-consensus-aura = { workspace = true, optional = true }

[dev-dependencies]
sp-externalities = { workspace = true }
sp-consensus-aura = { workspace = true }
frame-benchmarking = { workspace = true, features = ["std"] }
hex-literal = { workspace = true }
sp-keyring = { workspace = true }
Expand All @@ -57,7 +57,7 @@ std = [
"pallet-teerex/std",
"parity-scale-codec/std",
"scale-info/std",
"sp-consensus-aura/std",
"sp-consensus-aura?/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
Expand All @@ -81,6 +81,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-consensus-aura",
"sp-runtime/runtime-benchmarks",
]

Expand Down
14 changes: 11 additions & 3 deletions teeracle/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ use test_utils::{
};

benchmarks! {
where_clause { where T::AccountId: From<[u8; 32]>, T::Hash: From<[u8; 32]> }
where_clause {
where
T::AccountId: From<[u8; 32]>,
T::Hash: From<[u8; 32]>,
T: pallet_aura::Config,
T::Moment: CheckedConversion,
}
update_exchange_rate {
//pallet_aura::CurrentSlot::<T>::put(264649964u64.into());
<pallet_aura::CurrentSlot<T> as StorageValue<Slot>>::put(Slot::from(TEST4_SETUP.timestamp.saturating_div(T::SlotDuration::get().checked_into().unwrap())));
pallet_timestamp::Pallet::<T>::set_timestamp(TEST4_SETUP.timestamp.checked_into().unwrap());
let signer: T::AccountId = get_signer(TEST4_SETUP.signer_pub);
let trading_pair: TradingPairString = "DOT/USD".into();
Expand All @@ -61,8 +67,8 @@ benchmarks! {
}

update_oracle {
<pallet_aura::CurrentSlot<T> as StorageValue<Slot>>::put(Slot::from(TEST4_SETUP.timestamp.saturating_div(T::SlotDuration::get().checked_into().unwrap())));
pallet_timestamp::Pallet::<T>::set_timestamp(TEST4_SETUP.timestamp.checked_into().unwrap());
//pallet_aura::CurrentSlot::<T>::put(264649964.into());
let signer: T::AccountId = get_signer(TEST4_SETUP.signer_pub);
let oracle_name = OracleDataName::from("Test_Oracle_Name");
let data_source = DataSource::from("Test_Source_Name");
Expand Down Expand Up @@ -109,6 +115,8 @@ use crate::{Config, Pallet as PalletModule};

#[cfg(test)]
use frame_benchmarking::impl_benchmark_test_suite;
use frame_support::{traits::Get, StorageValue};
use sp_consensus_aura::Slot;

#[cfg(test)]
impl_benchmark_test_suite!(PalletModule, crate::mock::new_test_ext(), crate::mock::Test,);
18 changes: 10 additions & 8 deletions teeracle/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ frame_support::construct_runtime!(
}
);

impl pallet_aura::Config for Test {
type AuthorityId = AuraId;
type DisabledValidators = ();
type MaxAuthorities = ConstU32<32>;
type AllowMultipleBlocksPerSlot = ConstBool<false>;
type SlotDuration = pallet_aura::MinimumPeriodTimesTwo<Test>;
}

parameter_types! {
pub const BlockHashCount: u32 = 250;
}
Expand Down Expand Up @@ -97,6 +89,16 @@ impl frame_system::Config for Test {
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

parameter_types! {
pub const SlotDuration: u64 = 6000;
}
impl pallet_aura::Config for Test {
type AuthorityId = AuraId;
type DisabledValidators = ();
type MaxAuthorities = ConstU32<32>;
type AllowMultipleBlocksPerSlot = ConstBool<false>;
type SlotDuration = SlotDuration;
}
pub type Balance = u64;

parameter_types! {
Expand Down
15 changes: 11 additions & 4 deletions teeracle/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
use crate::{mock::*, ExchangeRates};
use frame_support::{assert_err, assert_noop, assert_ok};
use frame_support::{assert_err, assert_noop, assert_ok, StorageValue};
use hex_literal::hex;
use pallet_teerex::Error;
use sp_consensus_aura::Slot;
use sp_runtime::DispatchError::BadOrigin;
use substrate_fixed::types::U32F32;
use teeracle_primitives::*;
Expand All @@ -38,7 +39,7 @@ fn get_signer(pubkey: &[u8; 32]) -> AccountId {
}

fn register_ias_enclave_and_add_oracle_to_whitelist_ok(src: &str) {
Timestamp::set_timestamp(TEST4_TIMESTAMP);
set_timestamp(TEST4_TIMESTAMP);
let signer = get_signer(TEST4_SIGNER_PUB);
assert_ok!(Teerex::register_sgx_enclave(
RuntimeOrigin::signed(signer.clone()),
Expand All @@ -60,6 +61,12 @@ fn update_exchange_rate_dot_dollars_ok(src: &str, rate: Option<U32F32>) {
));
}

fn set_timestamp(moment: u64) {
<pallet_aura::CurrentSlot<Test> as StorageValue<Slot>>::put(Slot::from(
moment / SlotDuration::get(),
));
Timestamp::set_timestamp(moment);
}
#[test]
fn update_exchange_rate_works() {
new_test_ext().execute_with(|| {
Expand Down Expand Up @@ -222,7 +229,7 @@ fn update_oracle_from_not_registered_enclave_fails() {
#[test]
fn update_exchange_rate_from_not_whitelisted_oracle_fails() {
new_test_ext().execute_with(|| {
Timestamp::set_timestamp(TEST4_TIMESTAMP);
set_timestamp(TEST4_TIMESTAMP);
let signer = get_signer(TEST4_SIGNER_PUB);
assert_ok!(Teerex::register_sgx_enclave(
RuntimeOrigin::signed(signer.clone()),
Expand All @@ -247,7 +254,7 @@ fn update_exchange_rate_from_not_whitelisted_oracle_fails() {
#[test]
fn update_oracle_from_not_whitelisted_oracle_fails() {
new_test_ext().execute_with(|| {
Timestamp::set_timestamp(TEST4_TIMESTAMP);
set_timestamp(TEST4_TIMESTAMP);
let signer = get_signer(TEST4_SIGNER_PUB);
assert_ok!(Teerex::register_sgx_enclave(
RuntimeOrigin::signed(signer.clone()),
Expand Down

0 comments on commit 92252e4

Please sign in to comment.