-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
implement DummyDB functionality for tests #441
implement DummyDB functionality for tests #441
Conversation
1056df5
to
0194465
Compare
@@ -166,7 +166,7 @@ pub mod helpers { | |||
/// Dummy coins | |||
pub coins: HashMap<UtxoId, Coin>, | |||
/// Dummy contracts | |||
pub contract: HashSet<ContractId>, | |||
pub contract: HashMap<ContractId, Contract>, |
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'm assuming here that this should be a Map and not a Set.
a018cfe
to
bf605ce
Compare
bf605ce
to
4554652
Compare
Do you have any tests for this? Or how have you been testing your changes? |
Yep! I do have some tests, but they look a bit repetitive. I was trying to make them more generic, but probably the only way is by using macros. I'll commit my tests for transactions to show you what I mean @ControlCplusControlV |
unreachable!() | ||
let arc = Arc::new(value.clone()); | ||
|
||
if let Some(previous_tx) = self.data.lock().tx.insert(*key, arc) { |
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.
FYI: this method will return the old value (the replaced value) that was overwritten. That was my understanding after reading this:
https://github.com/FuelLabs/fuel-storage/blob/62f163dc21c712e2fa8dd9a6a76cf94f82ffc0d0/src/lib.rs#L27
fuel-core-interfaces/src/db.rs
Outdated
let key = value.id(); | ||
|
||
//before insert | ||
assert!(!db.contains_key(&key)?); |
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 would like to reuse all the tests below and only change the db, value and key for the specific implementation. That way, I could remove some duplication.
But not entirely sure how to do it without macros or leveraging generics. Maybe you have a better suggestion.
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'd recommend looking into rstest as we already use it in other areas. The db could be instantiated via fixture.
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.
Thanks for the info!
I added more test cases and removed most of the duplication, and also found a way to to instantiate the db without needing fixtures after all.
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.
nice and simple approach 👍🏻
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.
LGTM
[fixes #431]
Implements DummyDB functionality to be used on other tests.