lamports += to checked_add (#16841)
This commit is contained in:
parent
47ca7063f2
commit
3887169db0
|
@ -686,7 +686,9 @@ pub fn withdraw<S: std::hash::BuildHasher>(
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
vote_account.try_account_ref_mut()?.lamports -= lamports;
|
vote_account.try_account_ref_mut()?.lamports -= lamports;
|
||||||
to_account.try_account_ref_mut()?.lamports += lamports;
|
to_account
|
||||||
|
.try_account_ref_mut()?
|
||||||
|
.checked_add_lamports(lamports)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5449,7 +5449,10 @@ pub(crate) mod tests {
|
||||||
if let Ok(instruction) = bincode::deserialize(data) {
|
if let Ok(instruction) = bincode::deserialize(data) {
|
||||||
match instruction {
|
match instruction {
|
||||||
MockInstruction::Deduction => {
|
MockInstruction::Deduction => {
|
||||||
keyed_accounts[1].account.borrow_mut().lamports += 1;
|
keyed_accounts[1]
|
||||||
|
.account
|
||||||
|
.borrow_mut()
|
||||||
|
.checked_add_lamports(1)?;
|
||||||
keyed_accounts[2].account.borrow_mut().lamports -= 1;
|
keyed_accounts[2].account.borrow_mut().lamports -= 1;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -9868,7 +9871,7 @@ pub(crate) mod tests {
|
||||||
let mut to_account = keyed_accounts[1].try_account_ref_mut()?;
|
let mut to_account = keyed_accounts[1].try_account_ref_mut()?;
|
||||||
let mut dup_account = keyed_accounts[2].try_account_ref_mut()?;
|
let mut dup_account = keyed_accounts[2].try_account_ref_mut()?;
|
||||||
dup_account.lamports -= lamports;
|
dup_account.lamports -= lamports;
|
||||||
to_account.lamports += lamports;
|
to_account.checked_add_lamports(lamports).unwrap();
|
||||||
}
|
}
|
||||||
keyed_accounts[0]
|
keyed_accounts[0]
|
||||||
.try_account_ref_mut()?
|
.try_account_ref_mut()?
|
||||||
|
@ -10359,7 +10362,7 @@ pub(crate) mod tests {
|
||||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||||
assert_eq!(42, keyed_accounts[0].lamports().unwrap());
|
assert_eq!(42, keyed_accounts[0].lamports().unwrap());
|
||||||
let mut account = keyed_accounts[0].try_account_ref_mut()?;
|
let mut account = keyed_accounts[0].try_account_ref_mut()?;
|
||||||
account.lamports += 1;
|
account.checked_add_lamports(1)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1828,7 +1828,10 @@ mod tests {
|
||||||
MockSystemInstruction::Correct => Ok(()),
|
MockSystemInstruction::Correct => Ok(()),
|
||||||
MockSystemInstruction::AttemptCredit { lamports } => {
|
MockSystemInstruction::AttemptCredit { lamports } => {
|
||||||
keyed_accounts[0].account.borrow_mut().lamports -= lamports;
|
keyed_accounts[0].account.borrow_mut().lamports -= lamports;
|
||||||
keyed_accounts[1].account.borrow_mut().lamports += lamports;
|
keyed_accounts[1]
|
||||||
|
.account
|
||||||
|
.borrow_mut()
|
||||||
|
.checked_add_lamports(lamports)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
// Change data in a read-only account
|
// Change data in a read-only account
|
||||||
|
@ -2005,11 +2008,13 @@ mod tests {
|
||||||
let mut to_account = keyed_accounts[1].try_account_ref_mut()?;
|
let mut to_account = keyed_accounts[1].try_account_ref_mut()?;
|
||||||
let mut dup_account = keyed_accounts[2].try_account_ref_mut()?;
|
let mut dup_account = keyed_accounts[2].try_account_ref_mut()?;
|
||||||
dup_account.lamports -= lamports;
|
dup_account.lamports -= lamports;
|
||||||
to_account.lamports += lamports;
|
to_account.checked_add_lamports(lamports)?;
|
||||||
dup_account.set_data(vec![data]);
|
dup_account.set_data(vec![data]);
|
||||||
}
|
}
|
||||||
keyed_accounts[0].try_account_ref_mut()?.lamports -= lamports;
|
keyed_accounts[0].try_account_ref_mut()?.lamports -= lamports;
|
||||||
keyed_accounts[1].try_account_ref_mut()?.lamports += lamports;
|
keyed_accounts[1]
|
||||||
|
.try_account_ref_mut()?
|
||||||
|
.checked_add_lamports(lamports)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ fn transfer_verified(
|
||||||
}
|
}
|
||||||
|
|
||||||
from.try_account_ref_mut()?.lamports -= lamports;
|
from.try_account_ref_mut()?.lamports -= lamports;
|
||||||
to.try_account_ref_mut()?.lamports += lamports;
|
to.try_account_ref_mut()?.checked_add_lamports(lamports)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue