From 4a3fbbe8a283c36e6449d3d159202baf9dfb48b5 Mon Sep 17 00:00:00 2001 From: Howard Xie Date: Fri, 18 Oct 2024 15:30:56 -0700 Subject: [PATCH] wallet test --- tests/factories/webhook_factory.py | 26 +++++++++++++++++++++++ tests/test_wallet.py | 33 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tests/factories/webhook_factory.py diff --git a/tests/factories/webhook_factory.py b/tests/factories/webhook_factory.py new file mode 100644 index 0000000..7729964 --- /dev/null +++ b/tests/factories/webhook_factory.py @@ -0,0 +1,26 @@ +import pytest +from cdp.webhook import Webhook, WebhookModel, WebhookEventType + +@pytest.fixture +def webhook_factory(): + """Create and return a factory for Webhook fixtures.""" + + def _create_webhook( + webhook_id="webhook-123", + network_id="base-sepolia", + notification_uri="https://example.com/webhook", + event_type=WebhookEventType.WALLET_ACTIVITY, + event_type_filter=None, + event_filters=None + ): + model = WebhookModel( + id=webhook_id, + network_id=network_id, + notification_uri=notification_uri, + event_type=event_type, + event_type_filter=event_type_filter, + event_filters=event_filters or [] + ) + return Webhook(model) + + return _create_webhook diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 41ff3a3..8bf1166 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -7,6 +7,7 @@ from cdp.client.models.create_address_request import CreateAddressRequest from cdp.client.models.create_wallet_request import CreateWalletRequest, CreateWalletRequestWallet +from cdp.client.models.create_wallet_webhook_request import CreateWalletWebhookRequest from cdp.contract_invocation import ContractInvocation from cdp.payload_signature import PayloadSignature from cdp.smart_contract import SmartContract @@ -14,6 +15,7 @@ from cdp.transfer import Transfer from cdp.wallet import Wallet from cdp.wallet_address import WalletAddress +from cdp.webhook import Webhook @patch("cdp.Cdp.use_server_signer", False) @@ -614,3 +616,34 @@ def test_wallet_deploy_multi_token_with_server_signer(wallet_factory): mock_default_address.deploy_multi_token.assert_called_once_with( "https://example.com/multi-token/{id}.json" ) + +@patch("cdp.Cdp.api_clients") +def test_create_webhook(mock_api_clients, wallet_factory, webhook_factory): + """Test Wallet create_webhook method.""" + + # Setup the mock response for create_wallet_webhook + mock_api_clients.webhooks.create_wallet_webhook.return_value = webhook_factory() + + # Create a wallet instance using the factory + wallet = wallet_factory() + + # Define the notification URI to pass into the create_webhook method + notification_uri = "https://example.com/webhook" + + # Call the create_webhook method + webhook = wallet.create_webhook(notification_uri) + + # Create the expected request object + expected_request = CreateWalletWebhookRequest(notification_uri=notification_uri) + + # Assert that the API client was called with the correct parameters + mock_api_clients.webhooks.create_wallet_webhook.assert_called_once_with( + wallet_id=wallet.id, + create_wallet_webhook_request=expected_request + ) + + # Assert that the returned webhook is an instance of Webhook + assert isinstance(webhook, Webhook) + + # Additional assertions to check the returned webhook object + assert webhook.notification_uri == notification_uri \ No newline at end of file