> ## Documentation Index
> Fetch the complete documentation index at: https://docs.exponent.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Testing & Debugging

> Inspect vault and market state, simulate transactions, and debug common issues

These utilities help developers inspect onchain state and simulate transactions before sending them. They are useful for debugging failed transactions, verifying protocol state, and building monitoring dashboards.

## Check Vault State

Inspect the current state of a vault, including token mints, exchange rate, supply, and expiration.

```typescript theme={null}
async function inspectVaultState() {
  await vault.reload();

  console.log("Vault State:");
  console.log(`  Mint SY: ${vault.mintSy.toString()}`);
  console.log(`  Mint PT: ${vault.mintPt.toString()}`);
  console.log(`  Mint YT: ${vault.mintYt.toString()}`);
  console.log(`  Exchange Rate: ${vault.state.lastSeenSyExchangeRate}`);
  console.log(`  PT Supply: ${vault.state.ptSupply.toString()}`);
  console.log(`  YT Supply: ${vault.state.ytSupply.toString()}`);
  console.log(`  Total SY Escrowed: ${vault.state.totalSyInEscrow.toString()}`);
  console.log(`  SY for PT: ${vault.state.syForPt.toString()}`);
  console.log(`  Expiration: ${new Date(vault.state.expirationTs * 1000).toISOString()}`);
}
```

## Check Market State

Inspect the CLMM market, including current tick, price, liquidity, and reserves.

```typescript theme={null}
async function inspectMarketState() {
  await market.reload();

  console.log("Market State:");
  console.log(`  Current Tick: ${market.state.currentTick}`);
  console.log(`  Sqrt Price: ${market.state.sqrtPrice.toString()}`);
  console.log(`  Liquidity: ${market.state.liquidity.toString()}`);
  console.log(`  Fee Rate: ${market.state.feeRate}bp`);
  console.log(`  PT Reserve: ${market.state.ptReserve.toString()}`);
  console.log(`  SY Reserve: ${market.state.syReserve.toString()}`);
}
```

## Simulate Transaction

Simulate a transaction before sending it to catch errors early and check compute unit consumption.

```typescript theme={null}
async function simulateBeforeSend(ix: TransactionInstruction) {
  const tx = new Transaction().add(ix);
  tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
  tx.feePayer = user;

  const simulation = await connection.simulateTransaction(tx);

  if (simulation.value.err) {
    console.error("Simulation failed:", simulation.value.err);
    console.error("Logs:", simulation.value.logs);
    throw new Error("Transaction would fail");
  }

  console.log("Simulation successful");
  console.log(`  Compute units: ${simulation.value.unitsConsumed}`);

  return simulation;
}
```
