"""
Binance Staking REST API

OpenAPI Specification for the Binance Staking REST API
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

import json
import pytest
import requests

from unittest.mock import MagicMock, patch
from urllib.parse import parse_qs

from binance_common.configuration import ConfigurationRestAPI
from binance_common.errors import RequiredError
from binance_common.utils import normalize_query_values, is_one_of_model, snake_to_camel

from binance_sdk_staking.rest_api.api import SolStakingApi
from binance_sdk_staking.rest_api.models import ClaimBoostRewardsResponse
from binance_sdk_staking.rest_api.models import GetBnsolRateHistoryResponse
from binance_sdk_staking.rest_api.models import GetBnsolRewardsHistoryResponse
from binance_sdk_staking.rest_api.models import GetBoostRewardsHistoryResponse
from binance_sdk_staking.rest_api.models import GetSolRedemptionHistoryResponse
from binance_sdk_staking.rest_api.models import GetSolStakingHistoryResponse
from binance_sdk_staking.rest_api.models import GetSolStakingQuotaDetailsResponse
from binance_sdk_staking.rest_api.models import GetUnclaimedRewardsResponse
from binance_sdk_staking.rest_api.models import RedeemSolResponse
from binance_sdk_staking.rest_api.models import SolStakingAccountResponse
from binance_sdk_staking.rest_api.models import SubscribeSolStakingResponse


class TestSolStakingApi:
    @pytest.fixture(autouse=True)
    def setup_client(self):
        """Setup a client instance with mocked session before each test method."""
        self.mock_session = MagicMock(spec=requests.Session)
        config = ConfigurationRestAPI(
            api_key="test-api-key",
            api_secret="test-api-secret",
        )
        self.client = SolStakingApi(configuration=config, session=self.mock_session)

    def set_mock_response(self, data: dict = {}, status_code=200, headers=None):
        """Helper method to setup mock response for the client's session request."""
        if headers is None:
            headers = {}

        mock_response = MagicMock()
        mock_response.status_code = status_code
        mock_response.json.return_value = data
        mock_response.text = json.dumps(data)
        mock_response.headers = headers

        self.mock_session.request.return_value = mock_response

    @patch("binance_common.utils.get_signature")
    def test_claim_boost_rewards_success(self, mock_get_signature):
        """Test claim_boost_rewards() successfully with required parameters only."""

        expected_response = {"success": True}
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.claim_boost_rewards()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/sol-staking/sol/claim" in request_kwargs["url"]
        assert request_kwargs["method"] == "POST"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(ClaimBoostRewardsResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(ClaimBoostRewardsResponse, "from_dict"):
            expected = ClaimBoostRewardsResponse.from_dict(expected_response)
        else:
            expected = ClaimBoostRewardsResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_claim_boost_rewards_success_with_optional_params(self, mock_get_signature):
        """Test claim_boost_rewards() successfully with optional parameters."""

        params = {"recv_window": 5000}

        expected_response = {"success": True}
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.claim_boost_rewards(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/sol-staking/sol/claim" in request_kwargs["url"]
        assert request_kwargs["method"] == "POST"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(ClaimBoostRewardsResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(ClaimBoostRewardsResponse, "from_dict"):
            expected = ClaimBoostRewardsResponse.from_dict(expected_response)
        else:
            expected = ClaimBoostRewardsResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_claim_boost_rewards_server_error(self):
        """Test that claim_boost_rewards() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.claim_boost_rewards = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.claim_boost_rewards()

    @patch("binance_common.utils.get_signature")
    def test_get_bnsol_rate_history_success(self, mock_get_signature):
        """Test get_bnsol_rate_history() successfully with required parameters only."""

        expected_response = {
            "rows": [
                {
                    "annualPercentageRate": "0.00006408",
                    "exchangeRate": "1.001212343432",
                    "boostRewards": [
                        {"boostAPR": "0.12000000", "rewardsAsset": "SOL"},
                        {"boostAPR": "0.00200000", "rewardsAsset": "BNB"},
                    ],
                    "time": 1577233578000,
                }
            ],
            "total": "1",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_bnsol_rate_history()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/sol-staking/sol/history/rateHistory" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetBnsolRateHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(GetBnsolRateHistoryResponse, "from_dict"):
            expected = GetBnsolRateHistoryResponse.from_dict(expected_response)
        else:
            expected = GetBnsolRateHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_bnsol_rate_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_bnsol_rate_history() successfully with optional parameters."""

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "size": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "annualPercentageRate": "0.00006408",
                    "exchangeRate": "1.001212343432",
                    "boostRewards": [
                        {"boostAPR": "0.12000000", "rewardsAsset": "SOL"},
                        {"boostAPR": "0.00200000", "rewardsAsset": "BNB"},
                    ],
                    "time": 1577233578000,
                }
            ],
            "total": "1",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_bnsol_rate_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/sol-staking/sol/history/rateHistory" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetBnsolRateHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(GetBnsolRateHistoryResponse, "from_dict"):
            expected = GetBnsolRateHistoryResponse.from_dict(expected_response)
        else:
            expected = GetBnsolRateHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_get_bnsol_rate_history_server_error(self):
        """Test that get_bnsol_rate_history() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.get_bnsol_rate_history = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.get_bnsol_rate_history()

    @patch("binance_common.utils.get_signature")
    def test_get_bnsol_rewards_history_success(self, mock_get_signature):
        """Test get_bnsol_rewards_history() successfully with required parameters only."""

        expected_response = {
            "estRewardsInSOL": "1.23230920",
            "rows": [
                {
                    "time": 1575018510000,
                    "amountInSOL": "0.23223",
                    "holding": "2.3223",
                    "holdingInSOL": "2.4231",
                    "annualPercentageRate": "0.5",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_bnsol_rewards_history()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert (
            "/sapi/v1/sol-staking/sol/history/bnsolRewardsHistory"
            in request_kwargs["url"]
        )
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetBnsolRewardsHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof or is_list or hasattr(GetBnsolRewardsHistoryResponse, "from_dict")
        ):
            expected = GetBnsolRewardsHistoryResponse.from_dict(expected_response)
        else:
            expected = GetBnsolRewardsHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_bnsol_rewards_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_bnsol_rewards_history() successfully with optional parameters."""

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "size": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "estRewardsInSOL": "1.23230920",
            "rows": [
                {
                    "time": 1575018510000,
                    "amountInSOL": "0.23223",
                    "holding": "2.3223",
                    "holdingInSOL": "2.4231",
                    "annualPercentageRate": "0.5",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_bnsol_rewards_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert (
            "/sapi/v1/sol-staking/sol/history/bnsolRewardsHistory"
            in request_kwargs["url"]
        )
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetBnsolRewardsHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof or is_list or hasattr(GetBnsolRewardsHistoryResponse, "from_dict")
        ):
            expected = GetBnsolRewardsHistoryResponse.from_dict(expected_response)
        else:
            expected = GetBnsolRewardsHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_get_bnsol_rewards_history_server_error(self):
        """Test that get_bnsol_rewards_history() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.get_bnsol_rewards_history = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.get_bnsol_rewards_history()

    @patch("binance_common.utils.get_signature")
    def test_get_boost_rewards_history_success(self, mock_get_signature):
        """Test get_boost_rewards_history() successfully with required parameters only."""

        params = {
            "type": "CLAIM",
        }

        expected_response = {
            "rows": [
                {
                    "time": 1729520680,
                    "token": "SOL",
                    "amount": "1.20291028",
                    "bnsolHolding": "2.0928798",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_boost_rewards_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs
        parsed_params = parse_qs(request_kwargs["params"])
        camel_case_params = {snake_to_camel(k): v for k, v in params.items()}
        normalized = normalize_query_values(parsed_params, camel_case_params)

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert (
            "/sapi/v1/sol-staking/sol/history/boostRewardsHistory"
            in request_kwargs["url"]
        )
        assert request_kwargs["method"] == "GET"
        assert normalized["type"] == "CLAIM"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetBoostRewardsHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof or is_list or hasattr(GetBoostRewardsHistoryResponse, "from_dict")
        ):
            expected = GetBoostRewardsHistoryResponse.from_dict(expected_response)
        else:
            expected = GetBoostRewardsHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_boost_rewards_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_boost_rewards_history() successfully with optional parameters."""

        params = {
            "type": "CLAIM",
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "size": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "time": 1729520680,
                    "token": "SOL",
                    "amount": "1.20291028",
                    "bnsolHolding": "2.0928798",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_boost_rewards_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert (
            "/sapi/v1/sol-staking/sol/history/boostRewardsHistory"
            in request_kwargs["url"]
        )
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetBoostRewardsHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof or is_list or hasattr(GetBoostRewardsHistoryResponse, "from_dict")
        ):
            expected = GetBoostRewardsHistoryResponse.from_dict(expected_response)
        else:
            expected = GetBoostRewardsHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_get_boost_rewards_history_missing_required_param_type(self):
        """Test that get_boost_rewards_history() raises RequiredError when 'type' is missing."""
        params = {
            "type": "CLAIM",
        }
        params["type"] = None

        with pytest.raises(RequiredError, match="Missing required parameter 'type'"):
            self.client.get_boost_rewards_history(**params)

    def test_get_boost_rewards_history_server_error(self):
        """Test that get_boost_rewards_history() raises an error when the server returns an error."""

        params = {
            "type": "CLAIM",
        }

        mock_error = Exception("ResponseError")
        self.client.get_boost_rewards_history = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.get_boost_rewards_history(**params)

    @patch("binance_common.utils.get_signature")
    def test_get_sol_redemption_history_success(self, mock_get_signature):
        """Test get_sol_redemption_history() successfully with required parameters only."""

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "arrivalTime": 1575018510000,
                    "asset": "BNSOL",
                    "amount": "21312.23223",
                    "distributeAsset": "SOL",
                    "distributeAmount": "21338.0699",
                    "exchangeRate": "1.00121234",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_sol_redemption_history()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert (
            "/sapi/v1/sol-staking/sol/history/redemptionHistory"
            in request_kwargs["url"]
        )
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetSolRedemptionHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof or is_list or hasattr(GetSolRedemptionHistoryResponse, "from_dict")
        ):
            expected = GetSolRedemptionHistoryResponse.from_dict(expected_response)
        else:
            expected = GetSolRedemptionHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_sol_redemption_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_sol_redemption_history() successfully with optional parameters."""

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "size": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "arrivalTime": 1575018510000,
                    "asset": "BNSOL",
                    "amount": "21312.23223",
                    "distributeAsset": "SOL",
                    "distributeAmount": "21338.0699",
                    "exchangeRate": "1.00121234",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_sol_redemption_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert (
            "/sapi/v1/sol-staking/sol/history/redemptionHistory"
            in request_kwargs["url"]
        )
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetSolRedemptionHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof or is_list or hasattr(GetSolRedemptionHistoryResponse, "from_dict")
        ):
            expected = GetSolRedemptionHistoryResponse.from_dict(expected_response)
        else:
            expected = GetSolRedemptionHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_get_sol_redemption_history_server_error(self):
        """Test that get_sol_redemption_history() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.get_sol_redemption_history = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.get_sol_redemption_history()

    @patch("binance_common.utils.get_signature")
    def test_get_sol_staking_history_success(self, mock_get_signature):
        """Test get_sol_staking_history() successfully with required parameters only."""

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "asset": "SOL",
                    "amount": "21312.23223",
                    "distributeAsset": "BNSOL",
                    "distributeAmount": "21286.42584",
                    "exchangeRate": "1.00121234",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_sol_staking_history()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert (
            "/sapi/v1/sol-staking/sol/history/stakingHistory" in request_kwargs["url"]
        )
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetSolStakingHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(GetSolStakingHistoryResponse, "from_dict"):
            expected = GetSolStakingHistoryResponse.from_dict(expected_response)
        else:
            expected = GetSolStakingHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_sol_staking_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_sol_staking_history() successfully with optional parameters."""

        params = {
            "start_time": 1623319461670,
            "end_time": 1641782889000,
            "current": 1,
            "size": 10,
            "recv_window": 5000,
        }

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "asset": "SOL",
                    "amount": "21312.23223",
                    "distributeAsset": "BNSOL",
                    "distributeAmount": "21286.42584",
                    "exchangeRate": "1.00121234",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_sol_staking_history(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert (
            "/sapi/v1/sol-staking/sol/history/stakingHistory" in request_kwargs["url"]
        )
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetSolStakingHistoryResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(GetSolStakingHistoryResponse, "from_dict"):
            expected = GetSolStakingHistoryResponse.from_dict(expected_response)
        else:
            expected = GetSolStakingHistoryResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_get_sol_staking_history_server_error(self):
        """Test that get_sol_staking_history() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.get_sol_staking_history = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.get_sol_staking_history()

    @patch("binance_common.utils.get_signature")
    def test_get_sol_staking_quota_details_success(self, mock_get_signature):
        """Test get_sol_staking_quota_details() successfully with required parameters only."""

        expected_response = {
            "leftStakingPersonalQuota": "1000",
            "leftRedemptionPersonalQuota": "1000",
            "minStakeAmount": "0.01000000",
            "minRedeemAmount": "0.00000001",
            "redeemPeriod": 4,
            "stakeable": True,
            "redeemable": True,
            "soldOut": False,
            "commissionFee": "0.25000000",
            "nextEpochTime": 725993969475,
            "calculating": False,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_sol_staking_quota_details()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/sapi/v1/sol-staking/sol/quota" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(GetSolStakingQuotaDetailsResponse)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof
            or is_list
            or hasattr(GetSolStakingQuotaDetailsResponse, "from_dict")
        ):
            expected = GetSolStakingQuotaDetailsResponse.from_dict(expected_response)
        else:
            expected = GetSolStakingQuotaDetailsResponse.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_sol_staking_quota_details_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_sol_staking_quota_details() successfully with optional parameters."""

        params = {"recv_window": 5000}

        expected_response = {
