"""
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 EthStakingApi
from binance_sdk_staking.rest_api.models import EthStakingAccountResponse
from binance_sdk_staking.rest_api.models import GetCurrentEthStakingQuotaResponse
from binance_sdk_staking.rest_api.models import GetEthRedemptionHistoryResponse
from binance_sdk_staking.rest_api.models import GetEthStakingHistoryResponse
from binance_sdk_staking.rest_api.models import GetWbethRateHistoryResponse
from binance_sdk_staking.rest_api.models import GetWbethRewardsHistoryResponse
from binance_sdk_staking.rest_api.models import GetWbethUnwrapHistoryResponse
from binance_sdk_staking.rest_api.models import GetWbethWrapHistoryResponse
from binance_sdk_staking.rest_api.models import RedeemEthResponse
from binance_sdk_staking.rest_api.models import SubscribeEthStakingResponse
from binance_sdk_staking.rest_api.models import WrapBethResponse


class TestEthStakingApi:
    @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 = EthStakingApi(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_eth_staking_account_success(self, mock_get_signature):
        """Test eth_staking_account() successfully with required parameters only."""

        expected_response = {
            "holdingInETH": "1.22330928",
            "holdings": {"wbethAmount": "1.10928781", "bethAmount": "1.90002112"},
            "thirtyDaysProfitInETH": "0.22330928",
            "profit": {"amountFromWBETH": "0.12330928", "amountFromBETH": "0.1"},
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.eth_staking_account()

        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/v2/eth-staking/account" 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(EthStakingAccountResponse)

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

        assert response.data() == expected

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

        params = {"recv_window": 5000}

        expected_response = {
            "holdingInETH": "1.22330928",
            "holdings": {"wbethAmount": "1.10928781", "bethAmount": "1.90002112"},
            "thirtyDaysProfitInETH": "0.22330928",
            "profit": {"amountFromWBETH": "0.12330928", "amountFromBETH": "0.1"},
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.eth_staking_account(**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/v2/eth-staking/account" 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(EthStakingAccountResponse)

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

        assert response.data() == expected

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

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

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

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

        expected_response = {
            "leftStakingPersonalQuota": "1000",
            "leftRedemptionPersonalQuota": "1000",
            "minStakeAmount": "0.00010000",
            "minRedeemAmount": "0.00000001",
            "redeemPeriod": 20,
            "stakeable": True,
            "redeemable": True,
            "commissionFee": "0.05000000",
            "calculating": False,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_current_eth_staking_quota()

        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/eth-staking/eth/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(GetCurrentEthStakingQuotaResponse)

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

        assert response.data() == expected

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

        params = {"recv_window": 5000}

        expected_response = {
            "leftStakingPersonalQuota": "1000",
            "leftRedemptionPersonalQuota": "1000",
            "minStakeAmount": "0.00010000",
            "minRedeemAmount": "0.00000001",
            "redeemPeriod": 20,
            "stakeable": True,
            "redeemable": True,
            "commissionFee": "0.05000000",
            "calculating": False,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_current_eth_staking_quota(**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/eth-staking/eth/quota" 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(GetCurrentEthStakingQuotaResponse)

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

        assert response.data() == expected

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

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

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

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

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

        response = self.client.get_eth_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/eth-staking/eth/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(GetEthRedemptionHistoryResponse)

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

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_eth_redemption_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_eth_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": "WBETH",
                    "amount": "21312.23223",
                    "distributeAsset": "ETH",
                    "distributeAmount": "21338.0699",
                    "conversionRatio": "1.00121234",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_eth_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/eth-staking/eth/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(GetEthRedemptionHistoryResponse)

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

        assert response.data() == expected

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

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

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

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

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

        response = self.client.get_eth_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/eth-staking/eth/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(GetEthStakingHistoryResponse)

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

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_eth_staking_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_eth_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": "ETH",
                    "amount": "21312.23223",
                    "distributeAsset": "WBETH",
                    "distributeAmount": "21286.42584",
                    "conversionRatio": "1.00121234",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_eth_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/eth-staking/eth/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(GetEthStakingHistoryResponse)

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

        assert response.data() == expected

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

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

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

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

        expected_response = {
            "rows": [
                {
                    "annualPercentageRate": "0.00006408",
                    "exchangeRate": "1.00121234",
                    "time": 1577233578000,
                }
            ],
            "total": "1",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_wbeth_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/eth-staking/eth/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(GetWbethRateHistoryResponse)

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

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_get_wbeth_rate_history_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test get_wbeth_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.00121234",
                    "time": 1577233578000,
                }
            ],
            "total": "1",
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_wbeth_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/eth-staking/eth/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(GetWbethRateHistoryResponse)

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

        assert response.data() == expected

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

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

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

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

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

        response = self.client.get_wbeth_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/eth-staking/eth/history/wbethRewardsHistory"
            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(GetWbethRewardsHistoryResponse)

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

        assert response.data() == expected

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

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

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

        response = self.client.get_wbeth_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/eth-staking/eth/history/wbethRewardsHistory"
            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(GetWbethRewardsHistoryResponse)

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

        assert response.data() == expected

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

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

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

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

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "fromAsset": "WBETH",
                    "fromAmount": "21312.23223",
                    "toAsset": "BETH",
                    "toAmount": "21312.23223",
                    "exchangeRate": "1.01243253",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.get_wbeth_unwrap_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/eth-staking/wbeth/history/unwrapHistory" 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(GetWbethUnwrapHistoryResponse)

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

        assert response.data() == expected

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

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

        expected_response = {
            "rows": [
                {
                    "time": 1575018510000,
                    "fromAsset": "WBETH",
                    "fromAmount": "21312.23223",
                    "toAsset": "BETH",
                    "toAmount": "21312.23223",
                    "exchangeRate": "1.01243253",
                    "status": "SUCCESS",
                }
            ],
            "total": 1,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

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

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

        assert "url" in request_kwargs
