Skip to content

Conversation

@Unisay
Copy link
Contributor

@Unisay Unisay commented Nov 19, 2025

Context

  • What: Add end-to-end tests for PlutusV3 array builtin functions (CIP-0138)
  • Why: Validate on-chain behavior of indexArray, lengthOfArray, and listToArray builtins introduced in Plutus Core Batch 6
  • Issue: Related to plutus-private#1921, plutus-private#1922
  • Dependency: BLOCKED until Protocol Version 11 support is added to cardano-node-tests (expected early next week per Martin)

Approach

Implemented E2E tests following the established pattern from Batch 5 builtins (bitwise, RIPEMD-160). Key design decisions:

Test Organization:

  • Created separate TestPlutusBatch6V3Builtins class (array builtins are Batch 6 per Plutus Core spec)
  • Tests will gracefully skip with clear message until PV11 is available: "Array builtins require PV11+ (currently not supported in cardano-node-tests)"

Script Source:

  • Generated from plutus-scripts-e2e PR [QA] - Update stake pool parameters (margin, pledge, tax) #12 (yura/add-array-builtin-scripts branch)
  • All three validators are minting policies (standard pattern for testing pure computational builtins)
  • Validators use hardcoded test data internally (no external redeemer parameters needed)

Why Minting Policies:
Array builtins are pure computational functions that don't require transaction context, datum management, or UTxO state. Minting policies provide:

  • Simpler setup (1-step vs 3-step for spending validators)
  • Better test isolation (no UTxO state between tests)
  • Easier parallelization
  • Consistency with 58 other V3 builtin tests

Changes

Test Scripts (Binary)

  • succeedingIndexArrayPolicyScriptV3.plutus (299 bytes) - Tests indexArray arr 2 == 3 for [1,2,3,4,5]
  • succeedingLengthOfArrayPolicyScriptV3.plutus (286 bytes) - Tests lengthOfArray arr == 3 for [10,20,30]
  • succeedingListToArrayPolicyScriptV3.plutus (360 bytes) - Tests conversion + boundary access for [100,200,300,400]

Script Definitions (plutus_common.py:467-493)

  • Added 3 PlutusScriptData definitions with PV11 requirement documented
  • Execution costs initialized to (0, 0) placeholders (will be updated after PV11 testing)
  • Created SUCCEEDING_MINTING_ARRAY_SCRIPTS_V3 tuple for parametrized testing

Test Class (test_mint_build.py:190-317)

  • TestPlutusBatch6V3Builtins - New test class with comprehensive docstring explaining PV11 blocker
  • skip_bootstrap fixture checks for PV11+ (currently skips all tests)
  • test_array_builtins - Parametrized test covering all 3 array scripts
  • Follows same pattern as Batch 5: minting transaction, collateral management, token verification
  • Marked as @pytest.mark.smoke for quick validation once PV11 available

How to Test

Current Status: Tests will skip until PV11 support added. To verify test infrastructure:

# Verify tests are present and properly skip
pytest -k "array_builtins" cardano_node_tests/tests/tests_plutus_v3/test_mint_build.py -v

# Expected output:
# SKIPPED [1] Array builtins require PV11+ (currently not supported in cardano-node-tests)

After PV11 Support Available:

  1. Ensure cluster is running PV11+ with updated PlutusV3 cost model:

    source ./prepare_test_env.sh conway
    ./dev_workdir/conway_fast/start-cluster
    # Verify: cardano-cli query protocol-parameters | jq '.protocolVersion.major'
    # Should show: 11
  2. Run array builtin tests:

    pytest -k "array_builtins" cardano_node_tests/tests/tests_plutus_v3/test_mint_build.py -v
  3. Extract execution costs from test output:

    • Look for actual per_time and per_space values in test logs
    • Update plutus_common.py:472,479,486 with measured costs
    • Verify costs reflect CIP-0138 performance expectations:
      • indexArray: O(1) constant time/memory
      • lengthOfArray: O(1) constant time/memory
      • listToArray: O(n) linear time/memory
  4. Run full smoke test suite:

    pytest -m "smoke" cardano_node_tests/tests/tests_plutus_v3/test_mint_build.py

Expected Results:

  • All 3 array builtin tests pass
  • Tokens successfully minted using array policies
  • Execution costs within ±15% tolerance of updated values

Performance Expectations (CIP-0138)

Builtin Complexity Expected Cost Pattern
indexArray O(1) Constant, ~500K per_time
lengthOfArray O(1) Constant, ~300K per_time
listToArray O(n) Linear in array size

Dependencies

Author's Checklist

  • Self-reviewed code
  • Followed established test patterns (Batch 5 builtins)
  • Created separate test class for Batch 6 (correct organization)
  • Documented PV11 requirement prominently
  • Added graceful skip logic until PV11 available
  • Used minting policies (appropriate for pure builtin testing)
  • Marked as smoke tests for quick validation
  • Added execution cost measurements (blocked until PV11)
  • Verified tests pass on PV11 cluster (blocked until PV11)

Post-PV11 Follow-up

Once PV11 support is available:

  1. Run tests on PV11 cluster
  2. Update execution costs with measured values
  3. Verify costs match CIP-0138 performance expectations
  4. Consider adding failing test variants (out-of-bounds, empty arrays, etc.)

Closes #3227

@Unisay Unisay self-assigned this Nov 19, 2025
Implement end-to-end tests for PlutusV3 array builtin functions:
- indexArray: O(1) array element access
- lengthOfArray: O(1) array length retrieval
- listToArray: O(n) list-to-array conversion

**Test Organization:**
- Created TestPlutusBatch6V3Builtins class (array builtins are Plutus Core Batch 6, not Batch 5)
- Follows established pattern from bitwise/RIPEMD-160 tests
- Parametrized tests for all 3 array scripts
- Marked as smoke tests for quick validation

**Script Definitions (plutus_common.py):**
- MINTING_INDEXARRAY_V3 (299 bytes)
- MINTING_LENGTHOFARRAY_V3 (286 bytes)
- MINTING_LISTTOARRAY_V3 (360 bytes)
- All use minting policy pattern (standard for pure builtin testing)

**Scripts Generated From:**
- plutus-scripts-e2e PR #12 (yura/add-array-builtin-scripts branch)
- Validators use hardcoded test data (no external redeemer parameters)

⚠️ **IMPORTANT: Array builtins require Protocol Version 11**

Tests are currently **BLOCKED** until PV11 support is added to cardano-node-tests.
Tests will skip with message: "Array builtins require PV11+ (currently not supported)"

Expected timeline: PV11 support in testnet cluster beginning of next week (per Martin).

Initial execution costs set to (0, 0) placeholders.
Will be updated with actual measured values once PV11 cluster is available.

- plutus-private#1920: Array builtin validators (implemented in plutus-scripts-e2e)
- plutus-private#1921: E2E tests for array builtins (this implementation)
- plutus-private#1922: Related array builtin work

- CIP-0138: Array builtins specification
- Plutus Core Spec: Batch 6 builtin functions
- plutus-scripts-e2e PR #12: mkoura/plutus-scripts-e2e#12
@Unisay Unisay force-pushed the yura/issue-1921-array-builtin-e2e-tests branch from 994238b to d61865c Compare November 19, 2025 15:59
@Unisay Unisay changed the title feat(plutus): add E2E tests for array builtins (CIP-0138, Batch 6) E2E tests for array builtins (CIP-0138, Batch 6, PV 11) Nov 19, 2025
@kwxm
Copy link
Contributor

kwxm commented Nov 19, 2025

Please don't merge this just yet! I've been working on some other tests that will conflict with this a little. I'll open a PR shortly.

Move array builtin scripts to v3/batch6/ subdirectory to align with
Kenneth's organizational structure for all PV11 builtins.

This makes it easier to:
- Locate all Batch 6 (PV11) builtins in one place
- Distinguish from earlier batch builtins
- Integrate with other PV11 features (dropList, etc.)

Related: PR #3228 (dropList tests)
Expand array builtin tests to cover all Plutus version combinations at PV11:
- Plutus versions: V1, V2, V3
- Language versions: 1.0.0, 1.1.0
- Functions: indexArray, lengthOfArray, listToArray
- Total: 18 test cases (3 × 3 × 2)

## Implementation

**Programmatic Script Generation (plutus_common.py):**
- Replace hardcoded definitions with loop-based generation
- 18 script combinations defined in ~40 lines vs 180+ if hardcoded
- Easy to extend: just add to ARRAY_FUNCTIONS list
- Clear test IDs: INDEXARRAY_V3_1_1_0, etc.

**Directory Structure:**
- Organized by version and language: v1/batch6/1.0.0/, v1/batch6/1.1.0/, etc.
- Scripts renamed with version suffix for clarity
- README.md in each directory documenting missing scripts

**Test Matrix:**
- Single test method expands to 18 test instances via parametrization
- Backward compatible: existing V3/1.1.0 names preserved
- Clear documentation of what's tested and what's missing

## Current Status

**Existing:** 3 of 18 scripts (V3/1.1.0 only)
**Missing:** 15 scripts need generation in plutus-scripts-e2e

Missing scripts will cause test failures until generated. READMEs document
exact files needed and generation instructions.

## Benefits

- Complete coverage when all scripts generated (~3-5 hours effort)
- Same pattern applies to other batch6 builtins (dropList, etc.)
- Maintainable: programmatic approach scales easily
- Clear test names show exactly which combination failed

Related: Kenneth's PR #3228 (dropList, establishes batch6 directory pattern)
@Unisay Unisay closed this Nov 25, 2025
@Unisay Unisay deleted the yura/issue-1921-array-builtin-e2e-tests branch November 25, 2025 10:57
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.

3 participants