aptos-move-testing

$npx mdskill add eric861129/SKILLS_All-in-one/aptos-move-testing

Tests Move smart contracts on Aptos with unit, integration, and formal verification.

  • Debug test failures and improve coverage for Move contracts.
  • Uses aptos move test CLI and Move Prover for verification.
  • Analyzes test attributes, abort codes, and signer patterns.
  • Provides test commands, patterns, and debugging strategies.

SKILL.md

.github/skills/aptos-move-testingView on GitHub ↗
---
name: aptos-move-testing
description: Expert on testing Move smart contracts including unit tests, integration tests, Move Prover formal verification, debugging strategies, test coverage, and CI/CD integration for Aptos development.
allowed-tools: Read, Write, Edit, Grep, Glob, Bash
model: sonnet
license: MIT
metadata:
  author: raintree
  version: "1.0"
---

# Aptos Move Testing Expert

Expert on testing Move smart contracts on Aptos blockchain.

## Triggers

- move test, unit test, integration test
- move prover, formal verification
- debug, coverage, assert, expect
- test failure, debugging

## Test Attributes

```move
#[test]
fun test_basic() { }

#[test(account = @0x1)]
fun test_with_signer(account: &signer) { }

#[test(alice = @0x123, bob = @0x456)]
fun test_multi_signer(alice: &signer, bob: &signer) { }

#[test]
#[expected_failure(abort_code = ERROR_CODE)]
fun test_should_fail() { }

#[test_only]
fun helper_function() { }
```

## Basic Testing Pattern

```move
#[test(account = @0x123)]
fun test_resource_creation(account: &signer) {
    let addr = signer::address_of(account);
    
    // Create resource
    create_resource(account);
    
    // Verify exists
    assert!(exists<MyResource>(addr), 0);
    
    // Verify state
    let resource = borrow_global<MyResource>(addr);
    assert!(resource.value == expected, 1);
}
```

## Test Commands

```bash
# Run all tests
aptos move test

# Run specific test
aptos move test --filter test_name

# With coverage
aptos move test --coverage

# With gas profiling
aptos move test --gas

# Verbose
aptos move test --verbose
```

## Multi-Signer Testing

```move
#[test(alice = @0x123, bob = @0x456)]
fun test_transfer(alice: &signer, bob: &signer) {
    let alice_addr = signer::address_of(alice);
    let bob_addr = signer::address_of(bob);
    
    initialize(alice);
    initialize(bob);
    
    transfer(alice, bob_addr, 100);
    
    assert!(get_balance(alice_addr) == 900, 0);
    assert!(get_balance(bob_addr) == 100, 1);
}
```

## Error Testing

```move
#[test]
#[expected_failure(abort_code = ERROR_INSUFFICIENT_BALANCE)]
fun test_insufficient_balance() {
    transfer(from, to, amount_too_large);
}

#[test]
#[expected_failure]  // Any failure
fun test_any_failure() {
    assert!(false, 0);
}
```

## Test-Only Helpers

```move
#[test_only]
module test_helpers {
    public fun setup_account(account: &signer): address {
        let addr = signer::address_of(account);
        // Setup logic
        addr
    }
}
```

## Debugging

```move
#[test_only]
use std::debug;

#[test]
fun test_with_debug() {
    debug::print(&b"Value:");
    debug::print(&value);
}
```

## Move Prover Specs

```move
spec transfer {
    requires sender_balance >= amount;
    ensures global<Balance>(sender).value == 
            old(global<Balance>(sender).value) - amount;
    aborts_if sender_balance < amount;
}

spec module {
    invariant forall addr: address:
        exists<Balance>(addr) ==> global<Balance>(addr).value >= 0;
}
```

```bash
# Run prover
aptos move prove
aptos move prove --filter MyModule
```

## Coverage Goals

Test coverage should include:
- All public functions
- All abort conditions
- All state transitions
- All access control checks
- Edge cases (zero, max values, empty)

## Common Issues

### Resource Already Exists

```move
// Check existence first
if (!exists<Resource>(addr)) {
    move_to(account, Resource {});
}
```

### Need Signer

```move
// Use test parameter
#[test(account = @0x1)]
fun test_with_signer(account: &signer) { }
```

### Test Timeout

```move
// Reduce iterations
#[test]
fun test_optimized() {
    for (i in 0..100) { }  // Not 1000000
}
```

## CI/CD Integration

```yaml
name: Move Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install Aptos CLI
        run: curl -fsSL "https://aptos.dev/scripts/install_cli.py" | python3
      - name: Run Tests
        run: aptos move test --coverage
      - name: Run Prover
        run: aptos move prove
```

## Best Practices

- Test all public functions
- Test all error conditions
- Use specific abort codes
- Break complex tests into smaller ones
- Use test-only helpers for setup
- Profile gas usage in tests
- Run prover for critical code

More from eric861129/SKILLS_All-in-one

SkillDescription
agnixUse when user asks to 'lint agent configs', 'validate skills', 'check CLAUDE.md', 'validate hooks', 'lint MCP'. Validates agent configuration files against 231 rules across 10+ AI tools.
anthropic-expertExpert on Anthropic Claude API, models, prompt engineering, function calling, vision, and best practices. Triggers on anthropic, claude, api, prompt, function calling, vision, messages api, embeddings
aptos-cliExpert in Aptos CLI for account management, contract deployment, transaction submission, and node operations. Use when using the Aptos CLI to initialize profiles, deploy Move contracts, submit transactions, manage accounts, or operate Aptos nodes.
aptos-coreExpert in Aptos blockchain core architecture: consensus (AptosBFT), execution (Block-STM), and networking. Use when analyzing Aptos protocol design, the Rust codebase, validator operations, or understanding how Block-STM parallel execution works.
aptos-dapp-integrationExpert on building Aptos dApps with frontend integration. Covers wallet connectivity (Petra, Martian, Pontem), wallet adapter patterns, TypeScript SDK, transaction building and submission, account management, and React/Next.js integration.
aptos-frameworkExpert on Aptos Framework (0x1 standard library) modules including account, coin, fungible_asset, object, timestamp, table, smart_table, event, randomness, aggregator, and resource_account. Essential for all Aptos development.
aptos-gas-optimizationAptos gas optimization expert for Move smart contracts. Covers storage costs, execution efficiency, inline functions, aggregators for parallel execution, Table vs SmartTable vs vector tradeoffs, event optimization, struct packing, and gas profiling tools.
aptos-indexerExpert in Aptos Indexer architecture and GraphQL API for querying blockchain data. Use when querying NFTs, coin balances, or transaction history via GraphQL, designing custom processors, or optimizing data retrieval from the Aptos blockchain.
aptos-move-languageExpert on Move programming language fundamentals including abilities (copy/drop/store/key), generics, phantom types, references, global storage operations (move_to/move_from/borrow_global), signer pattern, visibility modifiers, and advanced type system features.
aptos-object-modelExpert on Aptos Object Model for composable, transferable on-chain assets. Use when working with ObjectCore, Object wrappers, ConstructorRef, ExtendRef, DeleteRef, TransferRef capabilities, or implementing composable asset patterns on Aptos blockchain.