Skip to content

Commit 507cce4

Browse files
committed
add common errors update integration tests
1 parent 1612fdf commit 507cce4

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

COMMON_ERRORS.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1. │ ERROR: Not enough accounts. Requested 'burn change account owner' at index 3 but only 0 accounts available. programs/compressed-token/program/src/mint_action/burn.rs:142:41
2+
- means that packed accounts doesn't contain enough accounts
3+
-
4+
2. `NotEnoughSigners`
5+
- `create_and_send_transaction(&[instruction], &payer.pubkey(), &signers)`
6+
- needs more signers
7+
- signers must be unique you must not pass the same twice it will result in an error
8+
3. `CompressedAccountError::ZeroCopyExpectedAddress => 12017`
9+
- when setting output compressed accounts in a zero copy we expect an address to be provided the address is allocated as Some by the ZeroCopyConfig but None is provided
10+
- any error that contains Expected and is an CompressedAccountError means this for the specied compressed account field
11+
4. `Signer/Program cannot write into an account it doesn't own.`
12+
```mode Small
13+
│ Signer/Program cannot write into an account it doesn't own. Write access check failed, compressed account owner [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] != invoking_program_id [9, 21, 163, 87, 35, 121, 78, 143, 182, 93, 7, 91, 107, 114, 105, 156, 56, 221, 2, 229, 148, 139, 117, 176, 229, 160, 65, 142, 128, 151, 91, 68].
14+
│ Program SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7 consumed 17422 of 1186879 compute units
15+
│ Program SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7 failed: custom program error: 0x177d
16+
│ Program cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m consumed 230543 of 1400000 compute units
17+
│ Program cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m failed: custom program error: 0x177d
18+
```
19+
- the compressed output account owner is not set
20+
5. ` Program SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7 failed: custom program error: 0x179a`
21+
-
22+
- the index for a state Merkle tree in the packed accounts is wrong

INTEGRATION_TESTING.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ program-tests/
3131
**All programs in `programs/**` have corresponding integration test programs:**
3232

3333
- **Account Compression Program** (`programs/account-compression/`) → `program-tests/account-compression-test/`
34-
- **Compressed Token Program** (`programs/compressed-token/`) → `program-tests/compressed-token-test/`
34+
- **Compressed Token Program** (`programs/compressed-token/`) → `program-tests/compressed-token-test/`
3535
- **Registry Program** (`programs/registry/`) → `program-tests/registry-test/`
3636
- **System Program** (`programs/system/`) → `program-tests/system-test/`
3737

@@ -86,7 +86,7 @@ pub async fn assert_mint_operation(
8686
) {
8787
// Get actual state
8888
let actual = get_actual_state(rpc, operation_params).await;
89-
89+
9090
// Single comprehensive assertion
9191
assert_eq!(actual, expected_output);
9292
}
@@ -102,14 +102,14 @@ pub async fn assert_mint_operation(
102102
#[tokio::test]
103103
async fn test_complete_token_lifecycle() {
104104
// 1. Create mint
105-
// 2. Mint tokens
105+
// 2. Mint tokens
106106
// 3. Transfer tokens
107107
// 4. Compress/decompress
108108
// Each step verified with assertions
109109
}
110110
```
111111

112-
### Error Test Coverage
112+
### Error Test Coverage
113113
**Every error condition must have a failing test**
114114

115115
```rust
@@ -139,14 +139,14 @@ assert_eq!(actual_state, expected_end_state);
139139
{
140140
// Parse complete state before operation
141141
let mut expected_after_state = parse_state_before(&state_data_before);
142-
142+
143143
// Apply the expected changes to the before state
144144
expected_after_state.field1 = new_value; // Only change what should change
145145
expected_after_state.amount -= transfer_amount;
146-
146+
147147
// Parse actual state after operation
148148
let actual_after_state = parse_state_after(&state_data_after);
149-
149+
150150
// Single comprehensive assertion: after = before + changes
151151
assert_eq!(actual_after_state, expected_after_state);
152152
}
@@ -165,7 +165,7 @@ From `/program-tests/utils/src/assert_decompressed_token_transfer.rs`:
165165
spl_token_2022::state::Account::unpack(&recipient_data_before[..165]).unwrap();
166166
recipient_token_before.amount += transfer_amount;
167167

168-
// Parse as SPL token accounts first
168+
// Parse as SPL token accounts first
169169
let sender_account_after =
170170
spl_token_2022::state::Account::unpack(&sender_account_data.data[..165]).unwrap();
171171
let recipient_account_after =
@@ -181,6 +181,12 @@ This pattern ensures you're testing **exact state transitions** rather than arbi
181181

182182
### **❌ Assertion Anti-Patterns to Avoid**
183183

184+
The test indexer in combination with litesvm LightProgram does not need time to catch up it is local.
185+
```rust
186+
// Give test indexer time to catch up
187+
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
188+
```
189+
184190
```rust
185191
// ❌ WRONG: Individual field assertions
186192
assert_eq!(actual.field1, expected_field1);
@@ -265,10 +271,10 @@ async fn create_mint_helper(rpc: &mut RPC) -> Result<Signature, RpcError> {
265271
**✅ CORRECT: Use borsh deserialization for easier type handling**
266272
```rust
267273
// Parse complete structs using borsh for easier handling
268-
let mint_data: CompressedMint =
274+
let mint_data: CompressedMint =
269275
BorshDeserialize::deserialize(&mut account_data.as_slice())
270276
.expect("Failed to deserialize CompressedMint");
271-
277+
272278
// Work with the complete struct
273279
assert_eq!(actual_mint, expected_mint);
274280
```
@@ -296,29 +302,29 @@ use light_test_utils::assert_operation_result;
296302
#[serial]
297303
async fn test_functional_flow() {
298304
let mut rpc = setup_test_environment().await;
299-
305+
300306
// Execute operation
301307
let result = perform_operation(&mut rpc, test_params).await.unwrap();
302-
308+
303309
// Assert complete expected outcome
304310
let expected = ExpectedOperationResult {
305311
transaction_signature: result.signature,
306312
modified_accounts: expected_account_changes,
307313
emitted_events: expected_events,
308314
// ... all expected outputs
309315
};
310-
316+
311317
assert_operation_result(&mut rpc, &expected).await;
312318
}
313319

314320
#[tokio::test]
315-
#[serial]
321+
#[serial]
316322
async fn test_operation_fails_with_invalid_input() {
317323
let mut rpc = setup_test_environment().await;
318324
let invalid_params = create_invalid_test_params();
319-
325+
320326
let result = perform_operation(&mut rpc, invalid_params).await;
321-
327+
322328
assert!(result.is_err());
323329
assert_eq!(
324330
result.unwrap_err().to_string(),
@@ -337,11 +343,11 @@ async fn test_operation_fails_with_invalid_input() {
337343
## Key Principles
338344

339345
### 1. Comprehensive Coverage
340-
- **Integration tests**: Every user workflow
346+
- **Integration tests**: Every user workflow
341347
- **Error tests**: Every error condition
342348
- **Edge cases**: Boundary conditions and invalid inputs
343349

344-
### 2. Clear Test Structure
350+
### 2. Clear Test Structure
345351
- **Arrange**: Set up test data and environment
346352
- **Act**: Execute the operation under test
347353
- **Assert**: Verify complete expected outcome using assertion helpers
@@ -409,4 +415,4 @@ Features:
409415
7. **Include all required signers** in transaction calls
410416
8. **Handle multi-signer scenarios** correctly
411417
9. **Test with realistic amounts** not just trivial values
412-
10. **Verify amount conservation** in transfer operations
418+
10. **Verify amount conservation** in transfer operations

0 commit comments

Comments
 (0)