|
15 | 15 | // along with Moonbeam. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 |
|
17 | 17 | use crate::mock::{ |
18 | | - events, roll_to, roll_to_round_begin, set_points, ExtBuilder, PCall, ParachainStaking, |
19 | | - Precompiles, PrecompilesValue, Runtime, RuntimeCall, RuntimeOrigin, |
| 18 | + events, roll_to, roll_to_round_begin, set_points, AccountId, ExtBuilder, PCall, |
| 19 | + ParachainStaking, Precompiles, PrecompilesValue, Runtime, RuntimeCall, RuntimeOrigin, |
20 | 20 | }; |
| 21 | +use crate::ParachainStakingPrecompile; |
21 | 22 | use core::str::from_utf8; |
22 | 23 | use fp_evm::MAX_TRANSACTION_GAS_LIMIT; |
23 | 24 | use frame_support::assert_ok; |
| 25 | +use frame_support::pallet_prelude::MaxEncodedLen; |
24 | 26 | use frame_support::sp_runtime::Percent; |
| 27 | +use frame_support::traits::fungible::Inspect; |
25 | 28 | use pallet_evm::Call as EvmCall; |
26 | 29 | use pallet_parachain_staking::Event as StakingEvent; |
| 30 | +use pallet_parachain_staking::{Bond, Config as StakingConfig, DelegatorStatus}; |
| 31 | +use parity_scale_codec::{Compact, Encode}; |
27 | 32 | use precompile_utils::{prelude::*, testing::*}; |
28 | 33 | use sp_core::{H160, U256}; |
29 | 34 | use sp_runtime::traits::Dispatchable; |
@@ -1746,3 +1751,26 @@ fn test_deprecated_solidity_selectors_are_supported() { |
1746 | 1751 | } |
1747 | 1752 | } |
1748 | 1753 | } |
| 1754 | + |
| 1755 | +/// Mirrors the proof-size composition in [`ParachainStakingPrecompile::delegator_state_storage_read_proof_size`] |
| 1756 | +/// so this test fails if the helper drifts from the SCALE upper-bound model. |
| 1757 | +#[test] |
| 1758 | +fn delegator_state_storage_read_proof_size_matches_scale_upper_bound() { |
| 1759 | + type Bal = |
| 1760 | + <<Runtime as pallet_parachain_staking::Config>::Currency as Inspect<AccountId>>::Balance; |
| 1761 | + |
| 1762 | + const TWOX64_CONCAT_PREFIX_LEN: usize = 8; |
| 1763 | + let max_d = <Runtime as StakingConfig>::MaxDelegationsPerDelegator::get(); |
| 1764 | + let expected = TWOX64_CONCAT_PREFIX_LEN |
| 1765 | + .saturating_add(AccountId::max_encoded_len()) |
| 1766 | + .saturating_add(AccountId::max_encoded_len()) |
| 1767 | + .saturating_add(Compact(max_d).encode().len()) |
| 1768 | + .saturating_add((max_d as usize).saturating_mul(Bond::<AccountId, Bal>::max_encoded_len())) |
| 1769 | + .saturating_add(Bal::max_encoded_len()) |
| 1770 | + .saturating_add(Bal::max_encoded_len()) |
| 1771 | + .saturating_add(DelegatorStatus::max_encoded_len()); |
| 1772 | + |
| 1773 | + let charged = ParachainStakingPrecompile::<Runtime>::delegator_state_storage_read_proof_size(); |
| 1774 | + |
| 1775 | + assert_eq!(charged, expected); |
| 1776 | +} |
0 commit comments