mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 15:01:06 +00:00
contracts: Cap the surcharge reward by the amount of rent that way payed by a contract (#7870)
* Add rent_payed field to the contract info * Don't pay out more as reward as was spent in rent * Make successful evictions free * Add tests to check that surcharge reward is capped by rent payed * review: Fixed docs
This commit is contained in:
committed by
GitHub
parent
c2ebcae0a6
commit
ad1717293d
@@ -250,7 +250,7 @@ where
|
||||
/// Evict this contract.
|
||||
fn evict(&mut self) -> Result<(), &'static str> {
|
||||
self.set_block_num_for_eviction()?;
|
||||
Rent::<T>::snitch_contract_should_be_evicted(&self.contract.account_id, Zero::zero())?;
|
||||
Rent::<T>::try_eviction(&self.contract.account_id, Zero::zero())?;
|
||||
self.contract.ensure_tombstone()
|
||||
}
|
||||
}
|
||||
@@ -406,8 +406,14 @@ benchmarks! {
|
||||
instance.ensure_tombstone()?;
|
||||
|
||||
// the caller should get the reward for being a good snitch
|
||||
assert_eq!(
|
||||
T::Currency::free_balance(&instance.caller),
|
||||
// this is capped by the maximum amount of rent payed. So we only now that it should
|
||||
// have increased by at most the surcharge reward.
|
||||
assert!(
|
||||
T::Currency::free_balance(&instance.caller) >
|
||||
caller_funding::<T>() - instance.endowment
|
||||
);
|
||||
assert!(
|
||||
T::Currency::free_balance(&instance.caller) <
|
||||
caller_funding::<T>() - instance.endowment + <T as Config>::SurchargeReward::get(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user