Skip to content

Commit 3f821ef

Browse files
authored
37 rent get cheatcode, extend ptoken_domain_data test (#42)
* update `mir-semantics` submodule (`Rent::get()` cheatcode etc) * extend/modify `ptoken_domain_data` test to use the new cheatcode Fixes #37
1 parent 363954a commit 3f821ef

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

p-token/src/entrypoint-runtime-verification.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,6 @@ use pinocchio::sysvars::rent::Rent;
333333
// special test for basic domain data access
334334
#[inline(never)]
335335
fn test_ptoken_domain_data(acc: &AccountInfo, mint: &AccountInfo, rent: &AccountInfo) {
336-
cheatcode_is_rent(rent);
337-
let prent = unsafe {
338-
let test = rent.borrow_data_unchecked();
339-
Rent::from_bytes_unchecked(test)
340-
};
341-
// cannot call any functions that use f64 in any way
342-
// assume burn_percent value <=100 and calculate with it
343-
let rent_collected = 10;
344-
let (burnt, distributed) = prent.calculate_burn(rent_collected);
345-
assert!(burnt <= rent_collected && distributed <= rent_collected); // fails if burn_percent > 100
346-
347336
cheatcode_is_mint(&mint);
348337
unsafe {
349338
let test = mint.borrow_mut_data_unchecked();
@@ -368,6 +357,23 @@ fn test_ptoken_domain_data(acc: &AccountInfo, mint: &AccountInfo, rent: &Account
368357
let owner = acc.owner();
369358
assert!(acc.is_owned_by(owner));
370359
// QUESTION: is pinocchio::Account ever written to through AccountInfo?
360+
361+
// test the system's Rent sysvar
362+
let sysrent = Rent::get().unwrap();
363+
let rent_collected = 10;
364+
let (burnt, distributed) = sysrent.calculate_burn(rent_collected);
365+
assert!(sysrent.burn_percent > 100 || burnt <= rent_collected && distributed <= rent_collected);
366+
367+
cheatcode_is_rent(rent);
368+
let prent = unsafe {
369+
let test = rent.borrow_data_unchecked();
370+
Rent::from_bytes_unchecked(test)
371+
};
372+
// cannot call any functions that use f64 in any way
373+
// assume burn_percent value <=100 and calculate with it
374+
let rent_collected = 10;
375+
let (burnt, distributed) = prent.calculate_burn(rent_collected);
376+
assert!(prent.burn_percent > 100 || burnt <= rent_collected && distributed <= rent_collected);
371377
}
372378

373379
// wrapper to ensure the above test is in the SMIR JSON
Submodule mir-semantics updated 45 files

0 commit comments

Comments
 (0)