Payment testing infrastructure improvements#2282
Conversation
|
Contract comparison - from 18fab3e to 01580e2
|
There was a problem hiding this comment.
Pull request overview
This PR modernizes and expands the payment construction/testing flow by introducing a composable .payment(...) mechanism in Tx, broadening numeric/token-id conversion support, and updating contracts + tests to use the new APIs.
Changes:
- Introduces
TxPaymentComposeand refactorsTx::payment(...)to support composition (enabling fluent multi-payment building) while deprecating legacyesdt/multi_esdthelpers. - Expands conversion ergonomics for
NonZeroBigUintandTokenId, and updates proxy generation + send wrappers to use.payment(...). - Updates a wide set of contract modules and feature/scenario tests to use
Payment::try_new(...)and the new composition pattern.
Reviewed changes
Copilot reviewed 27 out of 28 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| framework/scenario/tests/non_zero_big_uint_test.rs | Extends NonZeroBigUint conversion tests (including NonZero<T> sources). |
| framework/derive/src/generate/proxy_gen.rs | Switches generated multi-payment initialization from .multi_esdt(...) to .payment(...). |
| framework/base/src/types/managed/wrapped/token/token_id.rs | Adds additional From<...> conversions for TokenId (incl. EsdtTokenIdentifier, String, TestTokenIdentifier). |
| framework/base/src/types/managed/wrapped/token/payment.rs | Adds extensive Payment docs and introduces Payment::try_new(...) for flexible construction. |
| framework/base/src/types/managed/wrapped/num/non_zero_big_uint.rs | Adds TryFrom for more unsigned ints and From<NonZero<T>> conversions. |
| framework/base/src/types/managed/wrapped/managed_byte_array.rs | Adds TypeAbiFrom coverage for [u8; N] inputs. |
| framework/base/src/types/interaction/tx_payment/tx_payment_payment.rs | Implements TxPayment for Payment and composition into PaymentVec. |
| framework/base/src/types/interaction/tx_payment.rs | Adds the new TxPaymentCompose trait (composition contract). |
| framework/base/src/types/interaction/tx.rs | Refactors .payment(...) to use composition; deprecates legacy ESDT helpers; adds (currently stubbed) id(). |
| framework/base/src/types/interaction/expr/test_token_identifier.rs | Adds to_token_id() convenience. |
| framework/base/src/types/interaction/expr/test_esdt_transfer.rs | Deprecates TestEsdtTransfer in favor of Payment::try_new(...).unwrap(). |
| framework/base/src/types/interaction/expr.rs | Re-exports TestEsdtTransfer from expr module. |
| framework/base/src/contract_base/wrappers/send_wrapper.rs | Migrates async ESDT send helper to build Payment and call .payment(...). |
| contracts/modules/src/bonding_curve/utils/user_endpoints.rs | Migrates .multi_esdt(...) usage to .payment(...). |
| contracts/modules/src/bonding_curve/utils/owner_endpoints.rs | Migrates .multi_esdt(...) usage to .payment(...). |
| contracts/feature-tests/use-module/tests/token_merge_module_whitebox_test.rs | Updates multi-payment test flows to chained .payment(Payment::try_new(...)). |
| contracts/feature-tests/use-module/tests/staking_module_whitebox_test.rs | Replaces TestEsdtTransfer with Payment::try_new(...).unwrap(). |
| contracts/feature-tests/use-module/tests/gov_module_whitebox_test.rs | Replaces TestEsdtTransfer with Payment::try_new(...).unwrap(). |
| contracts/feature-tests/payable-features/tests/payable_blackbox_test.rs | Adds blackbox coverage for composing 0/1/2 payments; keeps legacy path test. |
| contracts/feature-tests/composability/vault/src/vault.rs | Makes retrieve_funds amount non-zero (NonZeroBigUint) and uses Payment for ESDT transfers. |
| contracts/feature-tests/composability/transfer-role-features/tests/transfer_role_whitebox_test.rs | Replaces TestEsdtTransfer with Payment::try_new(...).unwrap(). |
| contracts/feature-tests/composability/tests/forwarder_whitebox_test.rs | Migrates .esdt(...)/TestEsdtTransfer usages to .payment(Payment::try_new(...)). |
| contracts/feature-tests/composability/tests/forwarder_whitebox_legacy_test.rs | Same migration as above for legacy forwarder tests. |
| contracts/feature-tests/composability/local-esdt-and-nft/src/lib.rs | Migrates ESDT async send helper to Payment::new(...) + .payment(...). |
| contracts/feature-tests/composability/forwarder-legacy/src/fwd_call_sync_legacy.rs | Updates forwarder legacy call signature to require NonZeroBigUint amount. |
| contracts/feature-tests/composability/forwarder-legacy/src/fwd_call_async_legacy.rs | Updates forwarder legacy call signature to require NonZeroBigUint amount. |
| contracts/feature-tests/basic-features/interact/tests/bf_interact_cs_test.rs | Simplifies imports and migrates ESDT send to Payment::try_new(...).unwrap(). |
| Cargo.lock | Removes chrono entry (lockfile update). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 41 out of 42 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
framework/base/src/types/interaction/expr/test_token_identifier.rs
Outdated
Show resolved
Hide resolved
contracts/feature-tests/composability/forwarder-interactor/src/interact.rs
Outdated
Show resolved
Hide resolved
contracts/feature-tests/composability/forwarder-interactor/src/interact.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 53 out of 54 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Summary: Payment System Unification and Type Safety Improvements
Target Branch:
rc/v0.65Overview
This PR introduces a unified payment syntax for transaction building, enhances type safety across payment types, and improves the developer experience with better documentation and more convenient APIs.
Major Changes
1. Unified Payment Syntax 🎯
Motivation: Simplify transaction building with a single, composable
.payment()method.New
TxPaymentComposeTrait.payment(x).payment(y).payment(z)automatically composes paymentsTransaction Builder Updates
.esdt()and.multi_esdt()methods.payment()method that works with all payment typesExample:
2. Payment Type Enhancements 📦
Enhanced Constructors
Payment::new<T, A>(token_id, nonce, amount)- Generic withIntoconversionsTokenId<M>andNonZeroBigUint<M>Payment::try_new<T, A, E>(token_id, nonce, amount)- Fallible versionResult<Payment, E>for zero-amount handlingTriple Tuple Syntax
tx_payment_triple.rs(TokenId, u64, Amount)tuples as paymentsTxPaymentandTxPaymentComposefor tuple syntax.payment(("TOKEN-123", 0, 1000u64))Comprehensive Documentation
Added extensive documentation including:
3.
NonZeroBigUintImprovements 🔢New Conversions
NonZero<T>primitives:NonZeroU8,NonZeroU16,NonZeroU32,NonZeroU64,NonZeroU128,NonZeroUsizeu8,u16,u32,u64,u128,usizeNew Constructor
NonZeroBigUint::one()- Convenient constructor for the common case of value1Comparison Operators
non_zero_big_uint_cmp.rsPartialEqandPartialOrdbetweenNonZeroBigUintandBigUint4.
EsdtTokenPaymentEnhancements 💳New Conversion Method
into_payment()- ConvertsEsdtTokenPaymenttoPaymentType Alias Additions
EsdtTokenPaymentVec<Api>as preferred aliasMultiEsdtPayment<Api>for deprecation (in favor ofEsdtTokenPaymentVec)5. Safety Improvements 🛡️
Removed Unsafe Transmutations
Payment::as_egld_or_esdt_payment()(unsafe transmute)EsdtTokenPayment::as_egld_or_esdt_payment()(unsafe transmute)into_egld_or_esdt_payment()This eliminates potential undefined behavior from type punning while maintaining conversion capabilities.
6. Test API Improvements 🧪
TestTokenIdentifierUpdatesto_token_identifier()(incorrectly named)to_esdt_token_identifier()- for ESDT-only scenariosto_token_id()- for general token ID conversionTest Migration
TestPaymenttypeTestEsdtTransferexprmodule for better organization7. Contract Updates 🔧
Updated contracts to use the new unified syntax:
composabilityexamples and testsforwardercontracts and interactorspayable-featurestests (95 lines added)8. Additional Enhancements
New Test Coverage
payment_test.rs- comprehensive payment type testsnon_zero_big_uint_test.rs- additional conversion and comparison testsbig_num_ops_cmp.scen.json- big number comparison testsDocumentation
Breaking Changes⚠️
Deprecated APIs:
Tx::esdt()- use.payment()insteadTx::multi_esdt()- use.payment()insteadTestTokenIdentifier::to_token_identifier()- use.to_token_id()or.to_esdt_token_identifier()Removed Methods:
Payment::as_egld_or_esdt_payment()- unsafe, use.into_egld_or_esdt_payment()EsdtTokenPayment::as_egld_or_esdt_payment()- unsafe method removedEsdtTokenPayment::into_multi_egld_or_esdt_payment()- renamed tointo_egld_or_esdt_payment()Type Changes:
Payment::new()andPayment::try_new()are now generic over argument typesMigration Guide
Updating Transaction Builders
Updating Payment Conversions
Updating TestTokenIdentifier Usage
Benefits
Testing
Files Modified by Category
Framework Core (12 files)
Contracts (28 files)
Tests (15 files)
Note: This PR maintains backward compatibility for most use cases through deprecation warnings. Direct breaking changes are limited to unsafe methods that should not be widely used.