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

Mock Testing Price Fetcher #308

Open
bh2smith opened this issue Jul 3, 2023 · 0 comments
Open

Mock Testing Price Fetcher #308

bh2smith opened this issue Jul 3, 2023 · 0 comments
Labels
good first issue Good for newcomers

Comments

@bh2smith
Copy link
Contributor

bh2smith commented Jul 3, 2023

I know this fixes this issue and LGTM. But, we really shouldn't be relying on external APIs in our unit tests. Also, we have to update this test in 6 months, again.

I suggest we use the mock decorator from the unittest library. This is all that would be needed to fix this permanently:

from unittest import TestCase, mock

class TestSplitTransfers(TestCase):
    # Existing code...

    @mock.patch('src.models.split_transfers.token_in_eth')
    def test_process_with_overdraft_exceeding_eth_not_cow(self, mock_token_in_eth):
        eth_amount = 2 * ONE_ETH
        cow_reward = 100_000 * ONE_ETH
        slippage_amount = -3 * ONE_ETH
        accounting = self.construct_split_transfers_and_process(
            solvers=[self.solver],
            eth_amounts=[eth_amount],
            cow_rewards=[cow_reward],
            slippage_amounts=[slippage_amount],
            redirects=self.redirect_map,
        )
        
        # Configure the mock to return the desired value
        cow_deduction = cow_reward - 25369802491025623613440 or whatever value is correct here
        mock_token_in_eth.return_value = cow_deduction
        
        # Assertions and test logic...

Originally posted by @gentrexha in #306 (review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant