Skip to content

Commit 2b90a3e

Browse files
authored
fix: fix integration tests local (#97)
* Still need to figure out the ATA creation, de-hardcode recipient #2 * Ata creation done, all common function in utils, some cleanup + update doc * Updated readme + claude based on pr comments
1 parent 211f3ff commit 2b90a3e

File tree

12 files changed

+645
-151
lines changed

12 files changed

+645
-151
lines changed

CLAUDE.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,69 @@ make lint-fix-all
5252
# Run unit tests
5353
make test
5454

55+
# Setup test environment (for integration tests)
56+
make setup-test-env
57+
5558
# Run integration tests
5659
make test-integration
5760

5861
# Run all tests
5962
cargo test --workspace
6063
```
6164

65+
#### Integration Test Environment Setup
66+
67+
Integration tests require a local validator and test account setup:
68+
69+
1. **Start local validator:**
70+
```bash
71+
solana-test-validator --reset --quiet
72+
```
73+
74+
2. **Start local Kora Server:**
75+
```bash
76+
make run
77+
```
78+
79+
3. **Run integration tests:**
80+
```bash
81+
make test-integration
82+
```
83+
This will initialize a test environment (cargo run -p tests --bin setup-test-env):
84+
- Verify test validator is running
85+
- Create and fund test accounts
86+
- Set up USDC mint and token accounts
87+
- Display account summary
88+
89+
And run all integration tests (cargo test --test integration)
90+
91+
#### Customize Test Environment
92+
93+
The test suite uses environment variables for configuration (checked before falling back to defaults):
94+
95+
| Variable | Description | Default |
96+
|----------|-------------|---------|
97+
| `RPC_URL` | Solana RPC endpoint | `http://127.0.0.1:8899` |
98+
| `TEST_SERVER_URL` | Kora RPC server URL | `http://127.0.0.1:8080` |
99+
| `TEST_SENDER_KEYPAIR` | Base58 encoded test sender keypair | Built-in test keypair |
100+
| `TEST_RECIPIENT_PUBKEY` | Test recipient public key | Built-in test pubkey |
101+
| `KORA_PRIVATE_KEY` | Kora fee payer private key | Built-in test keypair |
102+
| `TEST_USDC_MINT_KEYPAIR` | Test USDC mint keypair | Built-in test mint |
103+
| `TEST_USDC_MINT_DECIMALS` | USDC mint decimals | `6` |
104+
105+
Make sure to update kora.toml to reflect the public key of TEST_USDC_MINT_KEYPAIR.
106+
107+
**Example with custom test configuration:**
108+
```bash
109+
# Create .env file for custom test setup
110+
echo "RPC_URL=https://api.devnet.solana.com" > .env
111+
echo "TEST_SENDER_KEYPAIR=your_base58_keypair" >> .env
112+
echo "KORA_PRIVATE_KEY=your_fee_payer_keypair" >> .env
113+
114+
# Run tests with custom config
115+
make test-integration
116+
```
117+
62118
### Running Services
63119

64120
```bash

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: check fmt lint test build run clean all regen-tk fix-all generate-ts-client
1+
.PHONY: check fmt lint test build run clean all regen-tk fix-all generate-ts-client setup-test-env test-integration
22

33
# Default target
44
all: check test build
@@ -27,8 +27,13 @@ lint:
2727
test:
2828
cargo test --lib
2929

30+
# Setup test environment
31+
setup-test-env:
32+
cargo run -p tests --bin setup-test-env
33+
3034
# Run integration tests
3135
test-integration:
36+
cargo run -p tests --bin setup-test-env
3237
cargo test --test integration
3338

3439
# Build all binaries

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,63 @@ make build
418418
# Run all tests
419419
make test
420420

421+
# Setup test environment (for integration tests)
422+
make setup-test-env
423+
421424
# Run integration tests
422-
make test-integrations
425+
make test-integration
426+
```
427+
428+
#### Integration Test Environment Setup
429+
430+
Integration tests require additional setup for test accounts and local validator:
431+
432+
1. **Start local validator:**
433+
```bash
434+
solana-test-validator --reset
435+
```
436+
437+
2. **Start local Kora Server:**
438+
```bash
439+
make run
440+
```
441+
442+
3. **Run integration tests:**
443+
```bash
444+
make test-integration
445+
```
446+
This will initialize a test environment (cargo run -p tests --bin setup-test-env):
447+
- Verify test validator is running
448+
- Create and fund test accounts
449+
- Set up USDC mint and token accounts
450+
- Display account summary
451+
452+
And run all integration tests (cargo test --test integration)
453+
454+
#### Customize Test Environment
455+
456+
You can customize test behavior by setting environment variables:
457+
458+
| Variable | Description | Default |
459+
|----------|-------------|---------|
460+
| `RPC_URL` | Solana RPC endpoint | `http://127.0.0.1:8899` |
461+
| `TEST_SERVER_URL` | Kora RPC server URL | `http://127.0.0.1:8080` |
462+
| `TEST_SENDER_KEYPAIR` | Base58 encoded test sender keypair | Built-in test keypair |
463+
| `TEST_RECIPIENT_PUBKEY` | Test recipient public key | Built-in test pubkey |
464+
| `KORA_PRIVATE_KEY` | Kora fee payer private key | Built-in test keypair |
465+
| `TEST_USDC_MINT_KEYPAIR` | Test USDC mint keypair | Built-in test mint |
466+
| `TEST_USDC_MINT_DECIMALS` | USDC mint decimals | `6` |
467+
468+
Make sure to update kora.toml to reflect the public key of TEST_USDC_MINT_KEYPAIR.
469+
470+
**Example with custom environment:**
471+
```bash
472+
# Create .env file
473+
echo "RPC_URL=https://api.devnet.solana.com" > .env
474+
echo "TEST_SENDER_KEYPAIR=your_base58_keypair" >> .env
475+
476+
# Run tests
477+
make test-integration
423478
```
424479

425480
### Running

crates/lib/src/token/token22.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::interface::{TokenInterface, TokenState};
22
use async_trait::async_trait;
3-
use solana_program::{program_pack::Pack, pubkey::Pubkey};
3+
use solana_program::pubkey::Pubkey;
44
use solana_sdk::instruction::Instruction;
55
use spl_associated_token_account::{
66
get_associated_token_address_with_program_id, instruction::create_associated_token_account,

crates/lib/src/transaction/validator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl TransactionValidator {
163163
Ok(())
164164
}
165165

166+
#[allow(dead_code)]
166167
fn validate_fee_payer_usage(&self, message: &Message) -> Result<(), KoraError> {
167168
// Check if fee payer is first account
168169
if message.account_keys.first() != Some(&self.fee_payer_pubkey) {

kora.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ max_allowed_lamports = 1000000
66
max_signatures = 10
77
price_source = "Mock"
88
allowed_programs = [
9-
"11111111111111111111111111111111", # System Program
9+
"11111111111111111111111111111111", # System Program
1010
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", # Token Program
1111
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
1212
]
1313
allowed_tokens = [
14-
"4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU", # USDC devnet
14+
"9BgeTKqmFsPVnfYscfM6NvsgmZxei7XfdciShQ6D3bxJ", # Test USDC mint for local testing
1515
]
1616
allowed_spl_paid_tokens = [
17-
"4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU", # USDC devnet
18-
]
19-
disallowed_accounts = []
17+
"9BgeTKqmFsPVnfYscfM6NvsgmZxei7XfdciShQ6D3bxJ", # Test USDC mint for local testing
18+
]
19+
disallowed_accounts = []

tests/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ path = "api_integration_tests.rs"
1515
name = "token_integration"
1616
path = "token_integration_tests.rs"
1717

18+
[[bin]]
19+
name = "setup-test-env"
20+
path = "setup-test-env.rs"
21+
1822
[dependencies]
1923
kora-lib = { path = "../crates/lib" }
2024
solana-sdk = { workspace = true }
@@ -28,4 +32,5 @@ dotenv = { workspace = true }
2832
jsonrpsee = { workspace = true }
2933
serde_json = { workspace = true }
3034
tokio = { workspace = true }
31-
hex = { workspace = true }
35+
hex = { workspace = true }
36+
testing-utils = { path = "testing-utils" }

0 commit comments

Comments
 (0)