diff --git a/Cargo.lock b/Cargo.lock index fdd3316..186c670 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7899,6 +7899,7 @@ dependencies = [ name = "pallet-migrations" version = "0.1.0" dependencies = [ + "cumulus-primitives-core", "environmental", "frame-benchmarking", "frame-support", diff --git a/pallets/author-mapping/src/mock.rs b/pallets/author-mapping/src/mock.rs index f5064ea..6f649f5 100644 --- a/pallets/author-mapping/src/mock.rs +++ b/pallets/author-mapping/src/mock.rs @@ -172,6 +172,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/pallets/foreign-asset-creator/src/mock.rs b/pallets/foreign-asset-creator/src/mock.rs index 871f08a..7577a74 100644 --- a/pallets/foreign-asset-creator/src/mock.rs +++ b/pallets/foreign-asset-creator/src/mock.rs @@ -130,6 +130,7 @@ impl pallet_assets::Config for Test { type CallbackHandle = (); type WeightInfo = (); type RemoveItemsLimit = ConstU32<1000>; + type Holder = (); pallet_assets::runtime_benchmarks_enabled! { type BenchmarkHelper = (); } @@ -237,6 +238,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/pallets/migrations/Cargo.toml b/pallets/migrations/Cargo.toml index f6ff890..fb6dd6c 100644 --- a/pallets/migrations/Cargo.toml +++ b/pallets/migrations/Cargo.toml @@ -23,6 +23,7 @@ sp-core = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } +cumulus-primitives-core = { workspace = true } # Benchmarks frame-benchmarking = { workspace = true, optional = true } diff --git a/pallets/migrations/src/mock.rs b/pallets/migrations/src/mock.rs index c3de245..de0f5c3 100644 --- a/pallets/migrations/src/mock.rs +++ b/pallets/migrations/src/mock.rs @@ -122,17 +122,31 @@ parameter_types! { pub const InstantAllowed: bool = false; } +// Taken from frame scheduller mock +parameter_types! { + pub BlockWeights: frame_system::limits::BlockWeights = + frame_system::limits::BlockWeights::simple_max( + Weight::from_parts(frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), + cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64), + ); +} + +parameter_types! { + pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block; +} + impl pallet_scheduler::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; type PalletsOrigin = OriginCaller; type RuntimeCall = RuntimeCall; - type MaximumWeight = (); + type MaximumWeight = MaximumSchedulerWeight; type ScheduleOrigin = EnsureRoot; type MaxScheduledPerBlock = (); - type WeightInfo = (); + type WeightInfo = pallet_scheduler::weights::SubstrateWeight; type OriginPrivilegeCmp = EqualPrivilegeOnly; // TODO : Simplest type, maybe there is better ? type Preimages = (); + type BlockNumberProvider = (); } parameter_types! { diff --git a/pallets/randomness/src/mock.rs b/pallets/randomness/src/mock.rs index 5894eb7..fa0b494 100644 --- a/pallets/randomness/src/mock.rs +++ b/pallets/randomness/src/mock.rs @@ -214,6 +214,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/pallets/relay-storage-roots/src/mock.rs b/pallets/relay-storage-roots/src/mock.rs index 13d6db9..1a0beb4 100644 --- a/pallets/relay-storage-roots/src/mock.rs +++ b/pallets/relay-storage-roots/src/mock.rs @@ -183,6 +183,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/precompiles/assets-erc20/src/mock.rs b/precompiles/assets-erc20/src/mock.rs index 0435517..40c69c6 100644 --- a/precompiles/assets-erc20/src/mock.rs +++ b/precompiles/assets-erc20/src/mock.rs @@ -194,6 +194,8 @@ impl pallet_evm::Config for Runtime { type GasLimitStorageGrowthRatio = (); type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); } type ForeignAssetInstance = pallet_assets::Instance1; @@ -241,6 +243,7 @@ impl pallet_assets::Config for Runtime { type AssetIdParameter = AssetId; type CreateOrigin = AsEnsureOriginWithArg>; type CallbackHandle = (); + type Holder = (); pallet_assets::runtime_benchmarks_enabled! { type BenchmarkHelper = BenchmarkHelper; } @@ -282,6 +285,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/precompiles/assets-erc20/src/tests.rs b/precompiles/assets-erc20/src/tests.rs index 05d1f82..b72a0f3 100644 --- a/precompiles/assets-erc20/src/tests.rs +++ b/precompiles/assets-erc20/src/tests.rs @@ -245,7 +245,7 @@ fn approve() { value: 500.into(), }, ) - .expect_cost(37024756) + .expect_cost(30211756) .expect_log(log3( ForeignAssetId(0u128), SELECTOR_LOG_APPROVAL, @@ -286,7 +286,7 @@ fn approve_saturating() { value: U256::MAX, }, ) - .expect_cost(37024756) + .expect_cost(30211756) .expect_log(log3( ForeignAssetId(0u128), SELECTOR_LOG_APPROVAL, @@ -415,7 +415,7 @@ fn transfer() { value: 400.into(), }, ) - .expect_cost(50509756) // 1 weight => 1 gas in mock + .expect_cost(40921756) // 1 weight => 1 gas in mock .expect_log(log3( ForeignAssetId(0u128), SELECTOR_LOG_TRANSFER, @@ -542,7 +542,7 @@ fn transfer_from() { value: 400.into(), }, ) - .expect_cost(70172756) // 1 weight => 1 gas in mock + .expect_cost(60468756) // 1 weight => 1 gas in mock .expect_log(log3( ForeignAssetId(0u128), SELECTOR_LOG_TRANSFER, @@ -620,7 +620,7 @@ fn transfer_from_non_incremental_approval() { value: 500.into(), }, ) - .expect_cost(37024756) + .expect_cost(30211756) .expect_log(log3( ForeignAssetId(0u128), SELECTOR_LOG_APPROVAL, @@ -643,7 +643,7 @@ fn transfer_from_non_incremental_approval() { value: 300.into(), }, ) - .expect_cost(76042756) + .expect_cost(61543756) .expect_log(log3( ForeignAssetId(0u128), SELECTOR_LOG_APPROVAL, @@ -751,7 +751,7 @@ fn transfer_from_self() { value: 400.into(), }, ) - .expect_cost(50509756) // 1 weight => 1 gas in mock + .expect_cost(40921756) // 1 weight => 1 gas in mock .expect_log(log3( ForeignAssetId(0u128), SELECTOR_LOG_TRANSFER, @@ -898,7 +898,7 @@ fn permit_valid() { s: H256::from(rs.s.b32()), }, ) - .expect_cost(37023000) + .expect_cost(30210000) .expect_log(log3( ForeignAssetId(0u128), SELECTOR_LOG_APPROVAL, @@ -1007,7 +1007,7 @@ fn permit_valid_named_asset() { s: H256::from(rs.s.b32()), }, ) - .expect_cost(37023000) + .expect_cost(30210000) .expect_log(log3( ForeignAssetId(0u128), SELECTOR_LOG_APPROVAL, @@ -1485,7 +1485,7 @@ fn permit_valid_with_metamask_signed_data() { s: H256::from(s_real), }, ) - .expect_cost(37023000) + .expect_cost(30210000) .expect_log(log3( ForeignAssetId(1u128), SELECTOR_LOG_APPROVAL, diff --git a/precompiles/balances-erc20/src/mock.rs b/precompiles/balances-erc20/src/mock.rs index 341103b..c41ca61 100644 --- a/precompiles/balances-erc20/src/mock.rs +++ b/precompiles/balances-erc20/src/mock.rs @@ -143,6 +143,8 @@ impl pallet_evm::Config for Runtime { type GasLimitStorageGrowthRatio = (); type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); } // Configure a mock runtime to test the pallet. @@ -205,6 +207,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/precompiles/balances-erc20/src/tests.rs b/precompiles/balances-erc20/src/tests.rs index f8f715d..95109cd 100644 --- a/precompiles/balances-erc20/src/tests.rs +++ b/precompiles/balances-erc20/src/tests.rs @@ -280,7 +280,7 @@ fn transfer() { value: 400.into(), }, ) - .expect_cost(176106756) // 1 weight => 1 gas in mock + .expect_cost(173835756) // 1 weight => 1 gas in mock .expect_log(log3( Precompile1, SELECTOR_LOG_TRANSFER, @@ -370,7 +370,7 @@ fn transfer_from() { value: 400.into(), }, ) - .expect_cost(176106756) // 1 weight => 1 gas in mock + .expect_cost(173835756) // 1 weight => 1 gas in mock .expect_log(log3( Precompile1, SELECTOR_LOG_TRANSFER, @@ -466,7 +466,7 @@ fn transfer_from_self() { value: 400.into(), }, ) - .expect_cost(176106756) // 1 weight => 1 gas in mock + .expect_cost(173835756) // 1 weight => 1 gas in mock .expect_log(log3( Precompile1, SELECTOR_LOG_TRANSFER, diff --git a/precompiles/batch/src/mock.rs b/precompiles/batch/src/mock.rs index eb02e28..aafe2e9 100644 --- a/precompiles/batch/src/mock.rs +++ b/precompiles/batch/src/mock.rs @@ -158,6 +158,8 @@ impl pallet_evm::Config for Runtime { type GasLimitStorageGrowthRatio = (); type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); } parameter_types! { @@ -194,6 +196,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); @@ -204,7 +207,9 @@ impl ExtBuilder { pallet_evm::Pallet::::create_account( Revert.into(), hex_literal::hex!("1460006000fd").to_vec(), - ); + None, + ) + .expect("account creation should succeed"); }); ext } diff --git a/precompiles/batch/src/tests.rs b/precompiles/batch/src/tests.rs index a0e484c..106a706 100644 --- a/precompiles/batch/src/tests.rs +++ b/precompiles/batch/src/tests.rs @@ -1008,7 +1008,11 @@ fn batch_not_callable_by_smart_contract() { .execute_with(|| { // "deploy" SC to alice address let alice_h160: H160 = Alice.into(); - pallet_evm::Pallet::::create_account(alice_h160, vec![10u8]); + assert_ok!(pallet_evm::Pallet::::create_account( + alice_h160, + vec![10u8], + None + )); // succeeds if not called by SC, see `evm_batch_recursion_under_limit` let input = PCall::batch_all { @@ -1049,10 +1053,11 @@ fn batch_is_not_callable_by_dummy_code() { .execute_with(|| { // "deploy" dummy code to alice address let alice_h160: H160 = Alice.into(); - pallet_evm::Pallet::::create_account( + assert_ok!(pallet_evm::Pallet::::create_account( alice_h160, [0x60, 0x00, 0x60, 0x00, 0xfd].to_vec(), - ); + None, + )); // succeeds if called by dummy code, see `evm_batch_recursion_under_limit` let input = PCall::batch_all { diff --git a/precompiles/call-permit/src/mock.rs b/precompiles/call-permit/src/mock.rs index 4737bbb..fed5776 100644 --- a/precompiles/call-permit/src/mock.rs +++ b/precompiles/call-permit/src/mock.rs @@ -144,6 +144,8 @@ impl pallet_evm::Config for Runtime { type GasLimitStorageGrowthRatio = (); type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); } parameter_types! { @@ -180,6 +182,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); @@ -190,7 +193,9 @@ impl ExtBuilder { pallet_evm::Pallet::::create_account( Revert.into(), hex_literal::hex!("1460006000fd").to_vec(), - ); + None, + ) + .expect("account creation should succeed"); }); ext } diff --git a/precompiles/pallet-xcm/src/mock.rs b/precompiles/pallet-xcm/src/mock.rs index 67d8993..5952dac 100644 --- a/precompiles/pallet-xcm/src/mock.rs +++ b/precompiles/pallet-xcm/src/mock.rs @@ -186,6 +186,7 @@ impl pallet_assets::Config for Runtime { type CallbackHandle = (); type WeightInfo = (); type RemoveItemsLimit = ConstU32<1000>; + type Holder = (); pallet_assets::runtime_benchmarks_enabled! { type BenchmarkHelper = (); } @@ -276,6 +277,8 @@ impl pallet_evm::Config for Runtime { type GasLimitStorageGrowthRatio = (); type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); } parameter_types! { @@ -384,6 +387,7 @@ impl pallet_xcm::Config for Runtime { type MaxRemoteLockConsumers = ConstU32<0>; type RemoteLockConsumerIdentifier = (); type AdminOrigin = frame_system::EnsureRoot; + type AuthorizedAliasConsideration = (); } use sp_std::cell::RefCell; @@ -524,6 +528,7 @@ impl xcm_executor::Config for XcmConfig { type HrmpChannelAcceptedHandler = (); type HrmpChannelClosingHandler = (); type XcmRecorder = PolkadotXcm; + type XcmEventEmitter = (); } pub fn root_origin() -> ::RuntimeOrigin { @@ -576,6 +581,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/precompiles/proxy/src/mock.rs b/precompiles/proxy/src/mock.rs index e7d9d1b..b840be4 100644 --- a/precompiles/proxy/src/mock.rs +++ b/precompiles/proxy/src/mock.rs @@ -34,7 +34,7 @@ use sp_core::{H160, H256, U256}; use sp_io; use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; use sp_runtime::{ - codec::{Decode, Encode, MaxEncodedLen}, + codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}, BuildStorage, }; @@ -181,6 +181,8 @@ impl pallet_evm::Config for Runtime { type GasLimitStorageGrowthRatio = (); type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); } parameter_types! { @@ -195,7 +197,18 @@ impl pallet_timestamp::Config for Runtime { #[repr(u8)] #[derive( - Debug, Eq, PartialEq, Ord, PartialOrd, Decode, MaxEncodedLen, Encode, Clone, Copy, TypeInfo, + Debug, + Eq, + PartialEq, + Ord, + PartialOrd, + Decode, + MaxEncodedLen, + Encode, + DecodeWithMemTracking, + Clone, + Copy, + TypeInfo, )] pub enum ProxyType { Any = 0, @@ -253,6 +266,7 @@ impl pallet_proxy::Config for Runtime { type CallHasher = BlakeTwo256; type AnnouncementDepositBase = (); type AnnouncementDepositFactor = (); + type BlockNumberProvider = (); } /// Build test externalities, prepopulated with data for testing democracy precompiles @@ -282,6 +296,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances.clone(), + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/precompiles/proxy/src/tests.rs b/precompiles/proxy/src/tests.rs index b055d53..9e67cb5 100644 --- a/precompiles/proxy/src/tests.rs +++ b/precompiles/proxy/src/tests.rs @@ -17,8 +17,8 @@ use crate::{ assert_event_emitted, assert_event_not_emitted, mock::{ - AccountId, ExtBuilder, PCall, PrecompilesValue, ProxyType, Runtime, RuntimeCall, - RuntimeEvent, RuntimeOrigin, + AccountId, ExtBuilder, PCall, Precompiles, PrecompilesValue, ProxyType, Runtime, + RuntimeCall, RuntimeEvent, RuntimeOrigin, }, }; use frame_support::assert_ok; @@ -578,7 +578,11 @@ fn fails_if_called_by_smart_contract() { .build() .execute_with(|| { // Set code to Alice address as it if was a smart contract. - pallet_evm::Pallet::::create_account(H160::from(Alice), vec![10u8]); + assert_ok!(pallet_evm::Pallet::::create_account( + H160::from(Alice), + vec![10u8], + None + )); PrecompilesValue::get() .prepare_test( @@ -596,19 +600,19 @@ fn fails_if_called_by_smart_contract() { #[test] fn succeed_if_called_by_precompile() { + let precompiles: Vec = Precompiles::::used_addresses_h160().collect(); + ExtBuilder::default() - .with_balances(vec![(Alice.into(), 1000), (Bob.into(), 1000)]) + .with_balances(vec![ + (Alice.into(), 1000), + (Bob.into(), 1000), + (precompiles[1].into(), 1000), + ]) .build() .execute_with(|| { - // Set dummy code to Alice address as it if was a precompile. - pallet_evm::AccountCodes::::insert( - H160::from(Alice), - vec![0x60, 0x00, 0x60, 0x00, 0xfd], - ); - PrecompilesValue::get() .prepare_test( - Alice, + precompiles[1], Precompile1, PCall::add_proxy { delegate: Address(Bob.into()), @@ -776,9 +780,16 @@ fn proxy_proxy_should_fail_if_called_by_smart_contract_for_a_non_eoa_account() { .build() .execute_with(|| { // Set code to Alice & Bob addresses as if they are smart contracts. - pallet_evm::Pallet::::create_account(H160::from(Alice), vec![10u8]); - pallet_evm::Pallet::::create_account(H160::from(Bob), vec![10u8]); - + assert_ok!(pallet_evm::Pallet::::create_account( + H160::from(Alice), + vec![10u8], + None + )); + assert_ok!(pallet_evm::Pallet::::create_account( + H160::from(Bob), + vec![10u8], + None + )); // Bob allows Alice to make calls on his behalf assert_ok!(RuntimeCall::Proxy(ProxyCall::add_proxy { delegate: Alice.into(), diff --git a/precompiles/xcm-utils/src/mock.rs b/precompiles/xcm-utils/src/mock.rs index 95cf42a..0ccc02c 100644 --- a/precompiles/xcm-utils/src/mock.rs +++ b/precompiles/xcm-utils/src/mock.rs @@ -216,6 +216,7 @@ impl pallet_xcm::Config for Runtime { type MaxRemoteLockConsumers = ConstU32<0>; type RemoteLockConsumerIdentifier = (); type AdminOrigin = frame_system::EnsureRoot; + type AuthorizedAliasConsideration = (); } pub type Precompiles = PrecompileSetBuilder< @@ -278,6 +279,8 @@ impl pallet_evm::Config for Runtime { type GasLimitStorageGrowthRatio = (); type Timestamp = Timestamp; type WeightInfo = pallet_evm::weights::SubstrateWeight; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); } parameter_types! { @@ -419,6 +422,7 @@ impl xcm_executor::Config for XcmConfig { type HrmpChannelAcceptedHandler = (); type HrmpChannelClosingHandler = (); type XcmRecorder = PolkadotXcm; + type XcmEventEmitter = (); } pub(crate) struct ExtBuilder { @@ -445,6 +449,7 @@ impl ExtBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, + ..Default::default() } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); diff --git a/precompiles/xcm-utils/src/tests.rs b/precompiles/xcm-utils/src/tests.rs index 6fccf41..03ad908 100644 --- a/precompiles/xcm-utils/src/tests.rs +++ b/precompiles/xcm-utils/src/tests.rs @@ -57,7 +57,7 @@ fn test_get_account_parent() { precompiles() .prepare_test(Alice, Precompile1, input) - .expect_cost(1) + .expect_cost(2) .expect_no_logs() .execute_returns(Address(expected_address)); }); @@ -77,7 +77,7 @@ fn test_get_account_sibling() { precompiles() .prepare_test(Alice, Precompile1, input) - .expect_cost(1) + .expect_cost(2) .expect_no_logs() .execute_returns(Address(expected_address)); }); @@ -94,7 +94,7 @@ fn test_weight_message() { precompiles() .prepare_test(Alice, Precompile1, input) - .expect_cost(0) + .expect_cost(1) .expect_no_logs() .execute_returns(1000u64); }); @@ -109,7 +109,7 @@ fn test_get_units_per_second() { precompiles() .prepare_test(Alice, Precompile1, input) - .expect_cost(1) + .expect_cost(2) .expect_no_logs() .execute_returns(U256::from(1_000_000_000_000u128)); }); @@ -198,7 +198,7 @@ fn test_executor_transact() { precompiles() .prepare_test(CryptoAlith, Precompile1, input) - .expect_cost(276106001) + .expect_cost(273835001) .expect_no_logs() .execute_returns(()); @@ -221,7 +221,7 @@ fn test_send_clear_origin() { precompiles() .prepare_test(CryptoAlith, Precompile1, input) // Only the cost of TestWeightInfo - .expect_cost(100000000) + .expect_cost(100000001) .expect_no_logs() .execute_returns(()); @@ -242,7 +242,8 @@ fn execute_fails_if_called_by_smart_contract() { .build() .execute_with(|| { // Set code to Alice address as it if was a smart contract. - pallet_evm::Pallet::::create_account(H160::from(Alice), vec![10u8]); + let _ = + pallet_evm::Pallet::::create_account(H160::from(Alice), vec![10u8], None); let xcm_to_execute = VersionedXcm::<()>::from(Xcm(vec![ClearOrigin])).encode();