Skip to content

Commit 5c9e4e8

Browse files
committed
fix rebase
1 parent 32f0acf commit 5c9e4e8

146 files changed

Lines changed: 8045 additions & 1840 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CLAUDE.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,57 @@ Format and clippy checks across the entire codebase.
197197
- **`program-tests/`**: Integration tests requiring Solana runtime, depend on `light-test-utils`
198198
- **`sdk-tests/`**: SDK-specific integration tests
199199
- **Special case**: `zero-copy-derive-test` in `program-tests/` only to break cyclic dependencies
200+
201+
### Test Assertion Pattern
202+
203+
When testing account state, use borsh deserialization with a single `assert_eq` against an expected reference account:
204+
205+
```rust
206+
use borsh::BorshDeserialize;
207+
use light_ctoken_types::state::{
208+
AccountState, CToken, ExtensionStruct, PausableAccountExtension,
209+
PermanentDelegateAccountExtension,
210+
};
211+
212+
// Deserialize the account
213+
let ctoken = CToken::deserialize(&mut &account.data[..])
214+
.expect("Failed to deserialize CToken account");
215+
216+
// Extract runtime-specific values from deserialized account
217+
let compression_info = ctoken
218+
.extensions
219+
.as_ref()
220+
.and_then(|exts| {
221+
exts.iter().find_map(|e| match e {
222+
ExtensionStruct::Compressible(info) => Some(info.clone()),
223+
_ => None,
224+
})
225+
})
226+
.expect("Should have Compressible extension");
227+
228+
// Build expected account for comparison
229+
let expected_ctoken = CToken {
230+
mint: mint_pubkey.to_bytes().into(),
231+
owner: payer.pubkey().to_bytes().into(),
232+
amount: 0,
233+
delegate: None,
234+
state: AccountState::Frozen,
235+
is_native: None,
236+
delegated_amount: 0,
237+
close_authority: None,
238+
extensions: Some(vec![
239+
ExtensionStruct::Compressible(compression_info),
240+
ExtensionStruct::PausableAccount(PausableAccountExtension),
241+
ExtensionStruct::PermanentDelegateAccount(PermanentDelegateAccountExtension),
242+
]),
243+
};
244+
245+
// Single assert comparing full account state
246+
assert_eq!(ctoken, expected_ctoken, "CToken account should match expected");
247+
```
248+
249+
**Benefits:**
250+
- Type-safe assertions using actual struct fields instead of magic byte offsets
251+
- Maintainable - if account layout changes, deserialization handles it
252+
- Readable - clear field names vs `account.data[108]`
253+
- Single assertion point for the entire account state

0 commit comments

Comments
 (0)