-
Notifications
You must be signed in to change notification settings - Fork 52
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
test: Remove mock
crate
#711
Conversation
d3b6d59
to
3730e4b
Compare
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 work, testing helpers/mocks have been needing some love for a while now. I left some comments. Most are questions regarding why moving something from mock to a specific subcrate instead of another one.
miden-tx/src/lib.rs
Outdated
@@ -21,6 +21,8 @@ mod compiler; | |||
pub use compiler::{ScriptTarget, TransactionCompiler}; | |||
|
|||
mod executor; | |||
#[cfg(feature = "testing")] | |||
pub use executor::testing::MockDataStore; |
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.
should we export a testing
module like in other crates?
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.
This was replaced by the flatter structure
miden-lib/src/testing/mod.rs
Outdated
|
||
// HELPER FUNCTIONS | ||
// ================================================================================================ | ||
|
||
fn build_dummy_tx_program() -> Program { | ||
let operations = vec![Operation::Push(ZERO), Operation::Drop]; | ||
let span = miden_objects::vm::CodeBlock::new_span(operations); | ||
Program::new(span) | ||
} |
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 noticed this was moved to miden_objects, but considering this is a tx_program, wouldn't it also make sense to keep in miden_tx
?
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.
Agreed, I had it in miden-lib
at first but Operation
was not available there, so I moved it down because miden-lib
did not have miden-tx
as a dependenciy. But since I added it as a dev dependency now, I think I can move it there.
EDIT: Nvm, can't do this because this is not test code, so the dev dependency does not apply.
miden-lib/src/testing/mod.rs
Outdated
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.
Why was this moved into miden-lib
instead of miden-tx
(seemed weird considering that it was previously under mock/transactions.rs
)
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.
miden-lib
uses code from miden-tx
to test code there (like MockDataStore
, etc.). Because of this, the functions could not be originally used on miden-lib
. However I later introduced it as a dev dependency so they can be moved now, going to test soon.
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.
Looks good! Thank you! I left a few small comments inline. A couple of general comments:
In all cases, the code is behind the
testing
flag and behind a newtesting
module on their respective locations. I was thinking the name of the module could bemock
but it feels like it's easier to relate the modules to their features directly by name
Yes, this makes sense.
The hierarchy of modules is such that each module contains a
testing
submodule where applicable. For instance, mock'sNoteBuilder
now exists onmiden_objects::notes::testing::NoteBuilder
. This was based off of the fact that some of the structs already contained mock code behind the feature flag.
There is another way to do it: we could just have a single testing
module per crate and have sub-modules under it for specific use cases. This would be a bit cleaner as all testing code would be isolated in one place rather than being throughout the crate. But I also haven't looked deeply enough into this to see if it causes any issues.
Because
miden-lib
has many kernel tests which end up using these structs, a new dev dependency formiden-tx
was introduced.
This causes a circular dependency - but I'm guessing this is not a problem? An alternative would be to move all tests which require miden-tx
to miden-tx
crate.
Correct, it does not right now. I thought of moving the tests although then the code that is meant to test mainly the kernel would be located somewhere else.
Yeah, I originally did it like this because some code was already there with that hierarchy, but I think this makes more sense. |
Let's go with the more "self-contained" approach then (i.e., a single |
I ended up moving all tests that required |
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.
Looks good! Thank you! I left a few small comments inline.
…nto igamigo-tests-fixes
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.
Looks good! Thank you! I left one small comment inline.
* test: Remove mock crate * Test file * Fix added test * Move code * Fix tests * Fix build * Set vm-processor feature * Changelog and docs * Changelog and docs * Address reviews * Move some more code around * Move some more code around * Move kernel tests to miden-tx * Remove file * Lints * Move MockHost (this is unused) * Correct kernel path * Address reviews * Remove unnecessary assignment * change kernel tests guard
Addresses #700
This PR removes the
mock
crate, and moves its code into one of the other crates. Some details worth mentioning:testing
flag and behind a newtesting
module on their respective locations. I was thinking the name of the module could bemock
but it feels like it's easier to relate the modules to their features directly by name, but I can change it tomock
if we want to keep that nomenclature. The alternative is also that we introduce a new featuremock
, in case we want to decouple the previously-existingtesting
features from the new code, but I think it's unnecessary at this point.testing
submodule where applicable. For instance, mock'sNoteBuilder
now exists onmiden_objects::notes::testing::NoteBuilder
. This was based off of the fact that some of the structs already contained mock code behind the feature flag.objects
since it's directly related to the domain structs. Some of it is moved tomiden-tx
, like code related toMockHost
andMockDataStore
, and some other tomiden-lib
(depending mainly on the dependencies of the moved code). Becausemiden-lib
has many kernel tests which end up using these structs, a new dev dependency formiden-tx
was introduced.mock_block_header
in favor ofBlockHeader::mock()
, for example).mock
binary was removed as well as it's not being used anywhere.The idea is for the next PR to introduce some refactors to the tests and refactor code .