Skip to content

A suite of foundry tooling to debug reverting transactions and other blockchain data

Notifications You must be signed in to change notification settings

teller-protocol/teller-tx-debug-suite

Repository files navigation

Teller Tx Debug Suite

Running tests

yarn contracts test

Running fork tests

# Start anvil fork at a specific block
anvil --fork-url https://rpc.katana.network --fork-block-number 12345678
anvil --fork-url https://rpc.hyperliquid.xyz/evm --fork-block-number 12345678

# Run fork tests
yarn contracts test_forked --match-contract XXXX

How-To Guide

Quick Start

  1. Start Anvil Fork at the target block:

    anvil --fork-url https://base-mainnet.g.alchemy.com/v2/YOUR_API_KEY --fork-block-number 41323464
  2. Run Tests:

    # Run all fork tests
    yarn test_forked
    
    # Run specific test contract
    yarn test_forked --match-contract YearnRedeemTest
    
    # Run with verbose output (recommended for debugging)
    yarn test_forked --match-contract YearnRedeemTest -vvvv

Creating a New Test

Create a new file in tests_fork/:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { TxSimulator } from "./TxSimulator.sol";
import "forge-std/console.sol";

contract MyTransactionTest is TxSimulator {
    address constant TARGET = 0x...;
    address constant USER = 0x...;

    function setUp() public {
        setupChainConfig();  // Required for ABI fetching
    }

    function test_my_transaction() public {
        SimTx memory txn = SimTx({
            to: TARGET,
            from: USER,
            data: abi.encodeWithSelector(...),
            value: 0
        });

        logPreState(txn);

        (SimResult memory result, address[] memory involvedContracts) =
            simulateTxWithContracts(txn);

        logPostStateWithContracts(txn, result, involvedContracts);

        assertTrue(result.success, "Transaction should succeed");
    }
}

Using Raw Calldata

If you have raw transaction data from a failed transaction:

function test_with_raw_calldata() public {
    bytes memory callData = hex"ba087652000000000000000000000000...";

    SimTx memory txn = SimTx({
        to: TARGET,
        from: USER,
        data: callData,
        value: 0
    });

    (SimResult memory result, address[] memory involvedContracts) =
        simulateTxWithContracts(txn);

    logPostStateWithContracts(txn, result, involvedContracts);
}

Debugging a Failed Transaction

  1. Get transaction details from block explorer (target contract, from address, block number, input data)

  2. Start anvil at that block:

    anvil --fork-url https://base-mainnet.g.alchemy.com/v2/KEY --fork-block-number 41323464
  3. Create test file with the transaction details

  4. Run test:

    yarn test_forked --match-test test_my_transaction -vvvv
  5. Analyze output: Check decoded error message, review involved contracts, examine state differences

Configuration

Create a .env file with your API keys:

ETHERSCANV2_VERIFY_API_KEY=your_api_key_here

Fetched ABIs are cached in ./cache/abi/. To clear cache: rm -rf ./cache/abi/


For more details, see FORK_TESTING.md.

About

A suite of foundry tooling to debug reverting transactions and other blockchain data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published