-
Notifications
You must be signed in to change notification settings - Fork 7
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
234 refactor dia implementation #387
Conversation
cf6a7bf
to
47e4896
Compare
70317ba
to
13fd08b
Compare
I now figured out why the vault registry tests were suddenly failing. The reason is that I replaced the thread_local() implementation with a I find this Does anyone have some ideas how to approach this without the |
This reverts commit de0c453.
e508da1
to
f95ece5
Compare
Thanks for your comment @gianfra-t. I decided not to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aside from the conflicts, I have no complaints.
pallets/oracle/src/lib.rs
Outdated
} | ||
} | ||
<OracleKeys<T>>::put(oracle_keys.clone()); | ||
Ok(()) | ||
} | ||
|
||
// public only for testing purposes | ||
#[cfg(feature = "testing-utils")] | ||
pub fn _clear_values() -> DispatchResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a rule about when to use underscore prefix function names?
Currently I had this impression of using such function/method only internally... and I mean only on the same lib/mod. However, the _clear_values()
is liberally called in other pallets like issue
and vault-registry
.
examples:
- the
fn _offchain_worker()
inpallet/vault-registry
- the
fn _withdraw_collateral()
inpallet/nomination
- the
fn _request_issue()
inpallet/issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. We did not discuss this yet and I just used the underscore prefix because it is used by the other 'testing-utils' functions. But you are right that it's used in other pallets as well.
Soooo... @pendulum-chain/devs what's your opinion on _function()
names? I would use them for functions that are supposed to be used 'module-only' or helper functions. Thus, I would need to change the naming to clear_values()
in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now renamed all three functions because all of them are used in other pallets as well.
I ran the tests and clippy locally and it worked fine so I'll merge this before waiting for CI to finish. |
This PR creates a re-usable definition for the DIA oracle mock, which is moving the implementation from
pallets/oracle/src/mock.rs
to a new modulepallets/oracle/src/testing_utils
and adding some other trait definitions that make it reusable.The duplicated definitions are then removed from the other pallets and testchain.
Notes
oracle::testing_utils
module is now 'no_std'. This is important to prevent compilation issues when re-using this module in the other crates.spin
crate is used for no_std Mutex supportonce_cell
crate is used for thread-safe and synchronized static variables. Usinglazy_static
is not sufficient because it does not prevent the multi-threaded tests initialize the static variable at the same time, leading to race conditions. We have to use a struct ofonce_cell
s 'race' module because only these are no_std, see the FAQ here.LOCK
contained in theoracle::testing_utils
is supposed to be used in tests that need to access the oracle mock data. It effectively makes all tests (that use this lock) execute sequentially instead of in parallel, similar to theserial_test::serial
macro. But I did not want us to put the#[serial]
macro to every test because it's ugly and a little more error-prone IMO.Closes #234.