Skip to content

Conversation

@lempira
Copy link
Collaborator

@lempira lempira commented Oct 2, 2025

Foreign Trait Testing

Implements cross-language FFI testing infrastructure using foreign traits to enable Python-side async test orchestration with Rust business logic. This allows Python tests to control async execution while delegating transaction composition to Rust's FFI Composer.

Key changes:

  • Add foreign trait pattern for cross-language testing:
    • ComposerTrait - transaction composition with all transaction types
    • ComposerFactory - factory pattern for creating fresh composer instances
    • TransactionSigner - async transaction signing interface
    • TransactionSignerGetter - retrieve signers by address
    • AlgodClientTrait - algod client operations
  • Implement Python wrapper (PythonComposer) that delegates to Rust FFI Composer
  • Add comprehensive FFI test coverage for asset freeze txn only (asset freeze/unfreeze workflows)
  • Simplify Composer API by storing dependencies internally (algod_client, signer_getter) to eliminate redundant parameter passing

Tests Passing

  • Asset freeze/unfreeze cross-language FFI tests pass
  • Python async wrapper correctly delegates to Rust Composer

from typing import List


class PythonComposer:
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the FFI Composer implements the ComposerTrait why do we need another wrapper?

joe-p and others added 5 commits October 3, 2025 10:58
Implement Foreign Trait Testing Method with control flow inversion
(Python manages async, Rust orchestrates test logic).

- Add test fixtures and asset freeze test suite
- Add register_account to TransactionSignerGetter trait
- Implement Python foreign traits (PythonAlgodClient, PythonComposerFactory)
- Fix HTTP error handling with HttpError.RequestError
Remove algod_client and signer_getter parameters from all ComposerTrait methods. These dependencies are now stored internally when the composer is created, eliminating redundant parameter passing throughout the API.
@lempira lempira force-pushed the feat/foreign_trait_testing branch from 955c757 to 47c2512 Compare October 3, 2025 15:45
@lempira lempira marked this pull request as ready for review October 3, 2025 16:37
@lempira lempira requested a review from a team as a code owner October 3, 2025 16:37
@lempira lempira requested review from aorumbayev and Copilot and removed request for a team October 3, 2025 16:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements cross-language FFI testing infrastructure using foreign traits to enable Python-side async test orchestration with Rust business logic. The changes establish a pattern where Python controls async execution while delegating transaction composition to Rust's FFI Composer.

Key changes:

  • Add foreign trait pattern for cross-language testing with traits for composition, factory pattern, signing, and algod operations
  • Implement Python wrapper (PythonComposer) that delegates to Rust FFI Composer with stateful API design
  • Add comprehensive FFI test coverage for asset freeze/unfreeze workflows

Reviewed Changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/python/algokit_utils/tests/test_utils.py Refactored test utilities with improved signer implementations and skipped existing tests
packages/python/algokit_utils/tests/test_ffi_async.py New async FFI test for asset freeze operations using foreign trait pattern
packages/python/algokit_utils/algokit_utils/ffi_composer.py Python wrapper for Rust Composer with async trait compatibility and stateful design
packages/python/algokit_utils/algokit_utils/ffi_algod_client.py Python implementation of AlgodClientTrait for async algod operations
packages/python/algokit_utils/algokit_utils.code-workspace New VS Code workspace configuration
crates/algokit_utils_ffi/src/transactions/composer.rs Major refactor removing redundant parameters and implementing foreign trait pattern
crates/algokit_utils_ffi/src/transactions/common.rs Added register_account method to TransactionSignerGetter trait
crates/algokit_utils_ffi/src/transactions/app_call.rs Reorganized imports and cleaned up parameter usage
crates/algokit_utils_ffi/src/tests/ New test infrastructure with fixtures, account management, and asset freeze tests
crates/algokit_utils_ffi/src/lib.rs Added tests module to library
crates/algokit_utils_ffi/Cargo.toml Added dependencies for testing infrastructure
Comments suppressed due to low confidence (1)

packages/python/algokit_utils/tests/test_utils.py:1

  • The variable bool_type is used but not defined in this diff. This will cause a NameError at runtime.
from typing import override

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@lempira lempira requested a review from joe-p October 3, 2025 17:13
Copy link
Collaborator

@joe-p joe-p left a comment

Choose a reason for hiding this comment

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

LGTM. Some things we definitely want to change before prod but shouldn't block this PR.

Also question: Do we want to keep the test_utils.py file now that we have the trait-based testing?

@lempira lempira merged commit dc82892 into main Oct 3, 2025
14 checks passed
@lempira lempira deleted the feat/foreign_trait_testing branch October 3, 2025 20:19
@engineering-ci
Copy link
Contributor

engineering-ci bot commented Oct 3, 2025

🎉 This PR is included in version 1.0.0-alpha.74 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants