Skip to content

Latest commit

 

History

History
416 lines (316 loc) · 9.72 KB

File metadata and controls

416 lines (316 loc) · 9.72 KB

Devnet Testing Guide

This guide explains how to test the Kamino Borrow program on Solana Devnet.

✅ What Can Be Tested on Devnet

The program is fully testable on devnet with the following capabilities:

✅ Fully Functional

  • Account Creation: Initialize user positions and delegations
  • State Management: All state updates work correctly
  • Delegation System: Create, update, and use delegations
  • Health Calculations: LTV and health factor calculations
  • Access Control: Ownership and authorization checks
  • Error Handling: All error conditions can be tested
  • Mock Oracles: Returns consistent test prices ($60,000 for cbBTC)

⚠️ Limited (Placeholder Mode)

  • ⚠️ Kamino CPI: Logs messages but doesn't interact with actual Kamino protocol
  • ⚠️ Token Transfers: Works with any SPL token (not actual cbBTC)
  • ⚠️ Oracle Prices: Uses mock prices instead of real Pyth feeds

Prerequisites

1. Solana CLI & Wallet

Check your configuration:

solana config get

Should show:

RPC URL: https://api.devnet.solana.com
Keypair Path: ~/.config/solana/id.json

If not on devnet:

solana config set --url devnet

2. Get Devnet SOL

You need ~2.5 SOL for deployment.

Option A: Airdrop (Rate Limited)

solana airdrop 2
# Wait 30 seconds if rate limited, then:
solana airdrop 1

Option B: Web Faucet

  1. Get your wallet address: solana address
  2. Visit: https://faucet.solana.com/
  3. Enter your address and request SOL

Option C: QuickNode Faucet

  1. Visit: https://faucet.quicknode.com/solana/devnet
  2. Enter your wallet address
  3. Request devnet SOL

Check balance:

solana balance

3. Build the Program

cd /Users/ijerkovic/Dev/kamino_borrow
anchor build

Deployment to Devnet

Step 1: Deploy Program

anchor deploy --provider.cluster devnet

Expected output:

Deploying cluster: https://api.devnet.solana.com
Deploying program "kamino_borrow"...
Program Id: HSRgc6SRLDLWiEiXHgha6erEyg7vZPGGqttSafUdYAB1

Deploy success

Step 2: Verify Deployment

solana program show HSRgc6SRLDLWiEiXHgha6erEyg7vZPGGqttSafUdYAB1 --url devnet

Running Tests on Devnet

Update Test Configuration

The test file is already configured to work with devnet. Just run:

anchor test --provider.cluster devnet --skip-local-validator

Expected Test Results

  kamino_borrow
    Position Management
      ✔ Initializes a user position (1234ms)
      ✔ Gets loan health for a position (567ms)
    Delegation Management
      ✔ Creates a delegation authorization (890ms)
      ✔ Updates delegation parameters (654ms)
      ✔ Deactivates delegation (432ms)
      ✔ Reactivates delegation (445ms)
    Integration Tests
      ✔ Shows complete borrowing workflow (234ms)
    Account Information
      ✔ Displays all account details (123ms)

  8 passing (4.5s)

Manual Testing with Anchor CLI

1. Initialize a Position

anchor run initialize-position \
  --provider.cluster devnet

2. Create a Delegation

# Coming soon - example scripts

What Gets Tested

✅ Core Functionality Tests

Position Initialization

  • Creates PDA with correct seeds
  • Initializes all fields correctly
  • Sets proper ownership
  • Verifies account structure

Delegation Management

  • Creates delegation auth accounts
  • Sets correct permission levels
  • Updates max borrow amounts
  • Toggles active status

State Management

  • Tracks collateral and borrowed amounts
  • Updates timestamps correctly
  • Maintains delegation counters
  • Enforces PDA constraints

Health Calculations

  • Calculates LTV correctly with mock prices
  • Computes health factors accurately
  • Determines position health status
  • Returns comprehensive health data

⚠️ Mock/Placeholder Behavior

Oracle Prices

// Always returns:
cbBTC price: $60,000 (with 8 decimals)
Borrow token price: $60,000 (with 8 decimals)

// Logs:
"WARNING: Using mock oracle price - DO NOT USE IN PRODUCTION"

Kamino CPI Calls

// Logs instead of executing:
"CPI: Depositing 1000000 liquidity to Kamino reserve"
"Note: Kamino CPI is a placeholder - implement with actual Kamino SDK"

// No actual:
- Token transfers to Kamino
- Borrowing from Kamino reserves
- Interest accrual

Testing Scenarios

Scenario 1: Basic Position Flow

// 1. Initialize position
await program.methods
  .initializePosition()
  .accounts({ /* ... */ })
  .rpc();

// 2. Check it exists
const position = await program.account.userPosition.fetch(userPositionPda);
console.log("Collateral:", position.collateralDeposited.toString()); // 0
console.log("Borrowed:", position.amountBorrowed.toString()); // 0

Scenario 2: Delegation Workflow

// 1. Create delegation
await program.methods
  .createDelegation(delegatePubkey, new BN(1_000_000))
  .accounts({ /* ... */ })
  .rpc();

// 2. Update delegation
await program.methods
  .updateDelegation(delegatePubkey, new BN(2_000_000), null)
  .accounts({ /* ... */ })
  .rpc();

// 3. Verify update
const delegation = await program.account.delegationAuth.fetch(delegationPda);
console.log("Max Borrow:", delegation.maxBorrowAmount.toString()); // 2000000

Scenario 3: Health Monitoring

// Get health data (view function)
const healthData = await program.methods
  .getLoanHealth()
  .accounts({ /* ... */ })
  .view();

console.log("LTV:", healthData.ltvBps, "bps");
console.log("Health Factor:", healthData.healthFactorBps, "bps");
console.log("Is Healthy:", healthData.isHealthy);

Scenario 4: Error Conditions

Test that errors are properly thrown:

// Should fail: unauthorized owner
try {
  await program.methods
    .repay(new BN(100))
    .accounts({
      userPosition: someonePda,
      owner: wrongOwner, // Not the actual owner
      /* ... */
    })
    .signers([wrongOwner])
    .rpc();

  assert.fail("Should have thrown error");
} catch (err) {
  assert.include(err.message, "UnauthorizedOwner");
}

// Should fail: zero borrow amount
try {
  await program.methods
    .depositAndBorrow(new BN(0), new BN(0))
    .accounts({ /* ... */ })
    .rpc();

  assert.fail("Should have thrown error");
} catch (err) {
  assert.include(err.message, "ZeroBorrowAmount");
}

Limitations on Devnet

1. No Real Kamino Integration

  • The program won't interact with actual Kamino protocol
  • No real borrowing or lending happens
  • No interest accrual
  • Token transfers are simulated (placeholders)

2. Mock Oracle Prices

  • All prices are hardcoded ($60,000)
  • No price fluctuations
  • No staleness checks
  • No confidence intervals

3. Token Considerations

  • You can use any SPL token for testing (not real cbBTC)
  • Create test tokens on devnet for testing
  • Actual cbBTC integration requires mainnet

Creating Test Tokens on Devnet

To test token transfers:

# Install SPL Token CLI
cargo install spl-token-cli

# Create a test token (mock cbBTC)
spl-token create-token --decimals 8

# Create token account
spl-token create-account <TOKEN_MINT>

# Mint test tokens
spl-token mint <TOKEN_MINT> 1000000

Monitoring Devnet Transactions

Solana Explorer

View transactions at:

https://explorer.solana.com/?cluster=devnet

View Program Account

https://explorer.solana.com/address/HSRgc6SRLDLWiEiXHgha6erEyg7vZPGGqttSafUdYAB1?cluster=devnet

Check Logs

solana logs HSRgc6SRLDLWiEiXHgha6erEyg7vZPGGqttSafUdYAB1 --url devnet

Debugging

View Program Logs

# Stream logs in real-time
solana logs -u devnet | grep kamino_borrow

Check Account Data

# View a user position
solana account <USER_POSITION_PDA> --url devnet --output json

Decode Account Data

Use Anchor's account decoder:

anchor account userPosition <PDA_ADDRESS> --provider.cluster devnet

Common Issues

Issue: "Account does not exist"

Solution: The account hasn't been initialized yet. Run initialize_position first.

Issue: "Custom program error: 0x1770"

Solution: This is error code 6000 (InsufficientCollateral). Check your LTV calculations.

Issue: "Transaction simulation failed"

Solution: Check the error logs with anchor test --skip-deploy --skip-build

Issue: "Insufficient SOL for deployment"

Solution: Request more devnet SOL from faucets (see Prerequisites section)

Next Steps After Devnet Testing

Once devnet testing is complete:

  1. ✅ Verify all account structures work correctly
  2. ✅ Confirm state transitions are accurate
  3. ✅ Validate delegation logic
  4. ✅ Test error conditions
  5. ⏭️ Implement real Pyth oracle integration
  6. ⏭️ Implement real Kamino CPI calls
  7. ⏭️ Security audit
  8. ⏭️ Mainnet deployment

Support Resources

Current Status

Last Build: Successful ✅ Warnings: 59 (unused variables in placeholder code) Devnet Deployment: Ready (need 2.5 SOL in wallet) Tests: Ready to run Mock Mode: Active (safe for testing)


Quick Start Checklist

  • Solana CLI configured for devnet
  • Wallet has 2.5+ SOL
  • Program built with anchor build
  • Program deployed with anchor deploy --provider.cluster devnet
  • Tests run with anchor test --provider.cluster devnet --skip-local-validator
  • Verified on Solana Explorer
  • Tested position creation
  • Tested delegation system
  • Tested health calculations
  • Reviewed transaction logs

Ready to deploy when you have sufficient devnet SOL! 🚀