Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Added oracle register/remove events to facilitate tracking through event indexers #630

Merged
merged 1 commit into from Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions crates/oracle/src/lib.rs
Expand Up @@ -82,6 +82,13 @@ pub mod pallet {
oracle_id: T::AccountId,
values: Vec<(OracleKey, T::UnsignedFixedPoint)>,
},
OracleAdded {
oracle_id: T::AccountId,
name: Vec<u8>,
},
OracleRemoved {
oracle_id: T::AccountId,
},
}

#[pallet::error]
Expand Down Expand Up @@ -217,7 +224,11 @@ pub mod pallet {
name: Vec<u8>,
) -> DispatchResult {
ensure_root(origin)?;
Self::insert_oracle(account_id, name);
Self::insert_oracle(account_id.clone(), name.clone());
Self::deposit_event(Event::OracleAdded {
oracle_id: account_id,
name,
});
Ok(())
}

Expand All @@ -229,7 +240,8 @@ pub mod pallet {
#[transactional]
pub fn remove_authorized_oracle(origin: OriginFor<T>, account_id: T::AccountId) -> DispatchResult {
ensure_root(origin)?;
<AuthorizedOracles<T>>::remove(account_id);
<AuthorizedOracles<T>>::remove(account_id.clone());
Self::deposit_event(Event::OracleRemoved { oracle_id: account_id });
Ok(())
}
}
Expand Down
14 changes: 8 additions & 6 deletions crates/oracle/src/tests.rs
Expand Up @@ -273,19 +273,20 @@ fn insert_authorized_oracle_succeeds() {
let oracle = 1;
let key = OracleKey::ExchangeRate(Token(DOT));
let rate = FixedU128::checked_from_rational(1, 1).unwrap();
let name = Vec::<u8>::new();
assert_err!(
Oracle::feed_values(Origin::signed(oracle), vec![]),
TestError::InvalidOracleSource
);
assert_err!(
Oracle::insert_authorized_oracle(Origin::signed(oracle), oracle, Vec::<u8>::new()),
Oracle::insert_authorized_oracle(Origin::signed(oracle), oracle, name.clone()),
DispatchError::BadOrigin
);
assert_ok!(Oracle::insert_authorized_oracle(
Origin::root(),
oracle,
Vec::<u8>::new()
));
assert_ok!(Oracle::insert_authorized_oracle(Origin::root(), oracle, name.clone()));
assert_emitted!(Event::OracleAdded {
oracle_id: 1,
name: name
});
assert_ok!(Oracle::feed_values(Origin::signed(oracle), vec![(key, rate)]));
});
}
Expand All @@ -300,6 +301,7 @@ fn remove_authorized_oracle_succeeds() {
DispatchError::BadOrigin
);
assert_ok!(Oracle::remove_authorized_oracle(Origin::root(), oracle,));
assert_emitted!(Event::OracleRemoved { oracle_id: 1 });
});
}

Expand Down