Skip to content

Feature: Voucher integrations #225

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Feature: Voucher integrations #225

wants to merge 7 commits into from

Conversation

1yam
Copy link
Member

@1yam 1yam commented Aug 4, 2025

Related to ALEPH-542

This pull request introduces a new voucher service for managing and retrieving vouchers across EVM and Solana chains, along with tests for the functionality. The most significant changes include the creation of AuthenticatedVoucher and Vouchers classes, the addition of voucher-related types, configuration updates, and comprehensive unit tests.

Voucher Service Implementation:

  • src/aleph/sdk/client/services/authenticated_voucher.py: Added the AuthenticatedVoucher class, which extends Vouchers. It allows retrieval of vouchers without explicitly passing an address by using the account address as a fallback. This includes methods for fetching vouchers (get_vouchers, get_evm_vouchers, get_solana_vouchers) and resolving addresses.
  • src/aleph/sdk/client/services/voucher.py: Introduced the Vouchers class for fetching voucher data from EVM and Solana chains. It includes utilities for resolving addresses, fetching metadata, and retrieving vouchers by chain.

Voucher Types and Configuration:

  • src/aleph/sdk/types.py: Added Voucher, VoucherMetadata, and VoucherAttribute types to represent voucher data and metadata. These types encapsulate attributes like name, description, external URL, image, and traits.
  • src/aleph/sdk/conf.py: Added configuration settings for voucher metadata URLs, Solana registry URLs, and the voucher sender address. These settings are used by the voucher services to interact with external resources.

Unit Tests:

  • tests/unit/services/test_authenticated_voucher.py: Added tests for the AuthenticatedVoucher class, verifying address resolution logic and voucher retrieval for both EVM and Solana chains. Tests ensure fallback mechanisms work correctly when no address is provided.
  • tests/unit/services/test_voucher.py: Added tests for the Vouchers class, covering metadata fetching, voucher retrieval by chain, and chain detection logic for both EVM and Solana addresses.

@1yam 1yam mentioned this pull request Aug 5, 2025
5 tasks
Copy link
Member

@nesitor nesitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The are some things to change on tests and also one or 2 needed on the code.

@@ -61,6 +61,7 @@
safe_getattr,
)
from .abstract import AlephClient
from .services.voucher import Vouchers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"https://claim.twentysix.cloud/sbt/metadata/{}.json"
)
VOUCHER_SOL_REGISTRY: str = "https://api.claim.twentysix.cloud/v1/registry/sol"
VOUCHER_SENDER: str = "0xB34f25f2c935bCA437C061547eA12851d719dEFb"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that instead VOUCHER_SENDER should be something like VOUCHER_ORIGIN_ADDRESS

Suggested change
VOUCHER_SENDER: str = "0xB34f25f2c935bCA437C061547eA12851d719dEFb"
VOUCHER_ORIGIN_ADDRESS: str = "0xB34f25f2c935bCA437C061547eA12851d719dEFb"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These test are useless because are mocking everything. Instead to be useful needs to instantiate a real Account and check that method returns the result expected.

Copy link
Member Author

@1yam 1yam Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well logic of Voucher is tested,

The logic of voucher is still tested since:

  • We mocked the get_posts to return mocked_data
  • We mocked the accounts (where it's only to get address.get_address) to match the mocked address
  • We mocked the http request to metdata / solana voucher

But we do not mocked any logic of voucher they still process just with mocked data

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that on vouchers we use more logic from the account side and inside the implementation, so instead of mocking everything, it's good to test also other parts of the logic at the same time if it doesn't involve infrastructure calls like DB or HTTP calls.


@pytest.mark.asyncio
async def test_get_evm_vouchers(mock_post_response, make_mock_aiohttp_session):
mock_client = MagicMock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mocking the entire client? Instead just mock the method you need to get the results to ensure that there is not an error on the instantiation or other calls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well yeah could only mock get_posts but since it's only this func i did it light that
Will fix i

Comment on lines +41 to +43
with patch(
"aiohttp.ClientSession", side_effect=[registry_session, metadata_session]
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, if you already mock the aiohttp call, is not needed to mock the Client.

Copy link
Member Author

@1yam 1yam Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mocked this client since it's not used on that specific case
we call :
https://api.claim.twentysix.cloud/v1/registry/sol

(in evm case we call .get_posts but here client is not even used)
So did though it's was usefull to put an Actual client but i can change, it's don't have any impacts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a good pattern to mock everything, we need to mock only elements not involved on the logic we want to test, like http responses, calls to database, etc.

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

Successfully merging this pull request may close these issues.

2 participants