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

Derive Default for MmrPeaks #218

Closed
wants to merge 3 commits into from
Closed

Derive Default for MmrPeaks #218

wants to merge 3 commits into from

Conversation

plafer
Copy link
Contributor

@plafer plafer commented Nov 9, 2023

Useful to create a dummy MmrPeaks value in tests

Copy link
Contributor

@hackaugusto hackaugusto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm, I had intentionally not derived Default for this struct. Since I initially thought it wasn't a useful value. However, after our discussions about the Mmr lagging for a block, the genesis block must have a commitment to an the empty peaks.

I think we should also add some tests with this value, to make sure that are no off-by-one bugs lurking in the codebase.

@plafer
Copy link
Contributor Author

plafer commented Nov 9, 2023

@hackaugusto I changed it so that Default is only derived in tests. It would allow us to derive(Default) on structs that contain an MmrPeaks in tests when we don't care about the MmrPeaks value for a given test

@hackaugusto
Copy link
Contributor

IMO for testing we should use the mock utilities: https://github.com/0xPolygonMiden/miden-base/tree/main/mock/src/mock

These functions should take care of removing the boilerplate for data generation, while generating valid values.

@bobbinth
Copy link
Contributor

bobbinth commented Nov 9, 2023

I would also prefer to avoid implementing Default for testing purposes only if there is a different way.

Also, I believe using #[cfg_attr(test, derive(Default))] would make the implementation local to this crate (i.e., when the crate is imported, it won't have Default implemented.

If however, doing #[cfg_attr(test)] works, I'd probably prefer adding an explicit dummy() constructor (or something like that) with this attribute, and then this constructor could be used in tests.

Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@plafer
Copy link
Contributor Author

plafer commented Nov 13, 2023

If however, doing #[cfg_attr(test)] works, I'd probably prefer adding an explicit dummy() constructor

Ah, you're right, items annotated with [cfg(test)] are not exported, even when the crate is a dev-dependency.

IMO for testing we should use the mock utilities

Agreed

@plafer plafer closed this Nov 13, 2023
@hackaugusto hackaugusto deleted the plafer-mmrpeaks-default branch November 13, 2023 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants