Skip to content

Commit

Permalink
wallet test
Browse files Browse the repository at this point in the history
  • Loading branch information
howard-at-cb committed Oct 18, 2024
1 parent d75acff commit 4a3fbbe
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/factories/webhook_factory.py
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

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
from cdp.trade import Trade
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)
Expand Down Expand Up @@ -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

0 comments on commit 4a3fbbe

Please sign in to comment.