Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Return an error instead of panicking from `litesvm_token::get_spl_account` (and the `*Checked` token helpers that read the mint through it) when the account data is shorter than the requested state ([#433](https://github.com/LiteSVM/litesvm/pull/433)).

## [0.18.0] - 2026-10-09

### Added
Expand Down
13 changes: 5 additions & 8 deletions crates/token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ pub fn get_spl_account<T: Pack + IsInitialized>(
svm: &LiteSVM,
account: &Address,
) -> Result<T, FailedTransactionMetadata> {
let account = T::unpack(
&svm.get_account(account)
.ok_or(FailedTransactionMetadata {
err: TransactionError::AccountNotFound,
meta: Default::default(),
})?
.data[..T::LEN],
)?;
let account = svm.get_account(account).ok_or(FailedTransactionMetadata {
err: TransactionError::AccountNotFound,
meta: Default::default(),
})?;
let account = T::unpack(account.data.get(..T::LEN).unwrap_or(&account.data))?;

Ok(account)
}
Expand Down
20 changes: 20 additions & 0 deletions crates/token/tests/one_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,23 @@ fn test_with_account_keypair() {
let token_account: Account = get_spl_account(svm, &returned_pk).unwrap();
assert_eq!(token_account.state, AccountState::Initialized);
}

#[test]
fn test_get_spl_account_with_short_data() {
let svm = &mut LiteSVM::new();
let payer_kp = Keypair::new();
let payer_pk = payer_kp.pubkey();
svm.airdrop(&payer_pk, 10_000_000_000).unwrap();

let mint_pk = CreateMint::new(svm, &payer_kp).send().unwrap();

assert!(get_spl_account::<Account>(svm, &mint_pk).is_err());
assert!(get_spl_account::<Mint>(svm, &payer_pk).is_err());

let destination_pk = Keypair::new().pubkey();
assert!(
TransferChecked::new(svm, &payer_kp, &payer_pk, &destination_pk, 1)
.send()
.is_err()
);
}
Loading