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

Fix cyclic dependency between test-utils and hyperdrive-math crates #92

Merged
merged 8 commits into from
May 13, 2024

Conversation

sentilesdal
Copy link
Contributor

@sentilesdal sentilesdal commented May 9, 2024

Description

hyperdrive-math was depending on test-utils and vice versa. The culprit is the Agent struct in test_utils that required a lot of things in hyperdrive-math for the Agent methods. hyperdrive-math then imported the Agent to run tests.

This PR removes the cyclic dependency by extending the Agent struct in hyperdrive-math with it's own HyperdriveMathAgent in test_utils/agent.rs. The agent module is #[cfg(test)] decorated so it only compiles for tests and isn't included in the release binary.

One caveat to this approach though is that other crates will not be able to import the HyperdriveMathAgent, including the tests/ directory, so I had to move tests/integration_tests.rs to src/test_utils/integration_tests.rs

Review Checklists

Please check each item before approving the pull request. While going
through the checklist, it is recommended to leave comments on items that are
referenced in the checklist to make sure that they are reviewed.

  • Testing
    • Are there new or updated unit or integration tests?
    • Do the tests cover the happy paths?
    • Do the tests cover the unhappy paths?
    • Are there an adequate number of fuzz tests to ensure that we are
      covering the full input space?
    • If matching Solidity behavior, are there differential fuzz tests that
      ensure that Rust matches Solidity?

hyperdrive-math can depend on test-utils, but test-utils shouldn't
depend on hyperdrive-math.
@sentilesdal sentilesdal force-pushed the matt/fix-cyclic-dependencies branch 2 times, most recently from adcbf9f to 3eb9046 Compare May 12, 2024 16:58
@sentilesdal sentilesdal changed the title fix cyclic dependency Fix cyclic dependency between test-utils and hyperdrive-math crates May 12, 2024
moves all the methods for Agent that require hyeprdrive-math things to
hyperdrive-math/test_utils/agent.rs
@sentilesdal sentilesdal force-pushed the matt/fix-cyclic-dependencies branch from 3eb9046 to 3c49c8c Compare May 12, 2024 17:56
@sentilesdal sentilesdal force-pushed the matt/fix-cyclic-dependencies branch from 3c49c8c to fb64273 Compare May 12, 2024 18:39
in order to use the cfg(test) code, this needs to be internal to the
crate
@sentilesdal sentilesdal force-pushed the matt/fix-cyclic-dependencies branch from fb64273 to 582ebc5 Compare May 12, 2024 19:10
need access to the members, might as well make them public
crates/hyperdrive-math/Cargo.toml Outdated Show resolved Hide resolved
crates/test-utils/src/agent.rs Outdated Show resolved Hide resolved
Copy link
Member

@dpaiton dpaiton left a comment

Choose a reason for hiding this comment

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

minor confusion/questions but in general this is a great improvement! Thanks

@sentilesdal sentilesdal force-pushed the matt/fix-cyclic-dependencies branch from d2bdc5b to c2edaf5 Compare May 13, 2024 17:37
@sentilesdal sentilesdal merged commit 1ac04dc into main May 13, 2024
8 checks passed
@sentilesdal sentilesdal deleted the matt/fix-cyclic-dependencies branch May 13, 2024 18:06
ryangoree added a commit that referenced this pull request May 17, 2024
# Resolved Issues

Related to #92

# Description

This refactors the crates to remove all cyclic dependencies. Below is an
illustration of the dependency tree before and after with a few notes:


![hyperdrive-rs-dep-trees](https://github.com/delvtech/hyperdrive-rs/assets/3289505/1ac060aa-58c9-4694-bf49-3ceff5aa2547)

# Review Checklists

Please check each item **before approving** the pull request. While
going
through the checklist, it is recommended to leave comments on items that
are
referenced in the checklist to make sure that they are reviewed.

- [ ] **Testing**
    - [ ] Are there new or updated unit or integration tests?
    - [ ] Do the tests cover the happy paths?
    - [ ] Do the tests cover the unhappy paths?
- [ ] Are there an adequate number of fuzz tests to ensure that we are
          covering the full input space?
- [ ] If matching Solidity behavior, are there differential fuzz tests
that
          ensure that Rust matches Solidity?
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