Skip to content

Commit dbcc7ee

Browse files
Stevengrejberthold
andauthored
feat(spl): add domain data test (#72)
Co-authored-by: Jost Berthold <jost.berthold@gmail.com>
1 parent 8745132 commit dbcc7ee

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

program/src/entrypoint-runtime-verification.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,42 @@ fn get_rent(_account_info: &AccountInfo) -> solana_rent::Rent {
209209
// fn cheatcode_is_multisig(_: &AccountInfo) {}
210210
// fn cheatcode_is_rent(_: &AccountInfo) {}
211211

212+
// special test for basic domain data access (SPL types)
213+
#[inline(never)]
214+
fn test_spltoken_domain_data(acc: &AccountInfo, mint: &AccountInfo, rent: &AccountInfo) {
215+
// Mutate mint via standard unpack/pack flow; use unwraps for brevity in tests
216+
let mut m = Mint::unpack_unchecked(&mint.data.borrow()).unwrap();
217+
m.is_initialized = true;
218+
Mint::pack(m, &mut mint.data.borrow_mut()).unwrap();
219+
let m2 = Mint::unpack(&mint.data.borrow()).unwrap();
220+
assert!(m2.is_initialized);
221+
222+
// Set Account.is_native in the simplest way (parity with p-token's boolean set_native(true))
223+
let mut a = Account::unpack_unchecked(&acc.data.borrow()).unwrap();
224+
a.is_native = solana_program_option::COption::Some(0);
225+
Account::pack(a, &mut acc.data.borrow_mut()).unwrap();
226+
// Verify via the same wrapper accessor used elsewhere
227+
let iacc = get_account(acc);
228+
assert!(iacc.is_native());
229+
230+
// Basic owner self-check
231+
let owner = acc.owner;
232+
assert_eq!(acc.owner, owner);
233+
234+
// Compare Rent from Sysvar::get vs account; fallback if not a real rent sysvar
235+
let sysrent = solana_rent::Rent::get().unwrap();
236+
let min_a = sysrent.minimum_balance(10);
237+
let prent = solana_rent::Rent::from_account_info(rent).unwrap_or(sysrent);
238+
let min_b = prent.minimum_balance(10);
239+
assert_eq!(min_a, min_b);
240+
}
241+
242+
// wrapper to ensure the test is retained in SMIR/IR outputs
243+
#[no_mangle]
244+
pub unsafe extern "C" fn use_tests(acc: &AccountInfo) {
245+
test_spltoken_domain_data(acc, acc, acc);
246+
}
247+
212248
// Inline `assume` is used directly in test harnesses; no helper functions needed.
213249

214250
/// Inner instruction processor that dispatches to proof harnesses

0 commit comments

Comments
 (0)