mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 08:27:55 +00:00
contracts: Multi block migrations (#14045)
* Frame Add translate_next This works similarly to to `translate` but only translate a single entry. This function will be useful in the context of multi-block migration. * Move to lazy migration * Updates * simplify MockMigration * wip * wip * add bench * add bench * fmt * fix bench * add . * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Scalfold v10 / v11 fix tests * PR comment * tweak pub use * wip * wip * wip * misc merge master * misc merge master * wip * rm tmp stuff * wip * wip * wip * wip * wip * fixes * add state * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * fix * fixed compilation * clean up logs * wip * Revert "Frame Add translate_next" This reverts commit 10318fc95c42b1f7f25efeb35e6d947ea02bed88. * Fix v10 logic * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * wip * fixes * exercise del_queue * bump sample size * fmt * wip * blank line * fix lint * fix rustdoc job lint * PR comment do not use dangerous into() * Ad macros for updating mod visibility * Add doc * Add max_weight to integrity_test * fix compilation * Add no migration tests * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * fix clippy * PR review * Update frame/contracts/src/lib.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Fix master merge * fix merge 2 * fix tryruntime * fix lint --------- Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: command-bot <> Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
This commit is contained in:
@@ -28,7 +28,8 @@ use crate::{
|
||||
wasm::{Determinism, PrefabWasmModule, ReturnCode as RuntimeReturnCode},
|
||||
weights::WeightInfo,
|
||||
BalanceOf, Code, CodeStorage, CollectEvents, Config, ContractInfo, ContractInfoOf, DebugInfo,
|
||||
DefaultAddressGenerator, DeletionQueueCounter, Error, Origin, Pallet, Schedule,
|
||||
DefaultAddressGenerator, DeletionQueueCounter, Error, MigrationInProgress, Origin, Pallet,
|
||||
Schedule,
|
||||
};
|
||||
use assert_matches::assert_matches;
|
||||
use codec::Encode;
|
||||
@@ -39,7 +40,7 @@ use frame_support::{
|
||||
storage::child,
|
||||
traits::{
|
||||
ConstU32, ConstU64, Contains, Currency, ExistenceRequirement, LockableCurrency, OnIdle,
|
||||
OnInitialize, WithdrawReasons,
|
||||
OnInitialize, StorageVersion, WithdrawReasons,
|
||||
},
|
||||
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
|
||||
};
|
||||
@@ -438,10 +439,11 @@ pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 102
|
||||
|
||||
pub struct ExtBuilder {
|
||||
existential_deposit: u64,
|
||||
storage_version: Option<StorageVersion>,
|
||||
}
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self { existential_deposit: ExistentialDeposit::get() }
|
||||
Self { existential_deposit: ExistentialDeposit::get(), storage_version: None }
|
||||
}
|
||||
}
|
||||
impl ExtBuilder {
|
||||
@@ -452,6 +454,10 @@ impl ExtBuilder {
|
||||
pub fn set_associated_consts(&self) {
|
||||
EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = self.existential_deposit);
|
||||
}
|
||||
pub fn set_storage_version(mut self, version: u16) -> Self {
|
||||
self.storage_version = Some(StorageVersion::new(version));
|
||||
self
|
||||
}
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
use env_logger::{Builder, Env};
|
||||
let env = Env::new().default_filter_or("runtime=debug");
|
||||
@@ -463,7 +469,15 @@ impl ExtBuilder {
|
||||
.unwrap();
|
||||
let mut ext = sp_io::TestExternalities::new(t);
|
||||
ext.register_extension(KeystoreExt::new(MemoryKeystore::new()));
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext.execute_with(|| {
|
||||
use frame_support::traits::OnGenesis;
|
||||
|
||||
Pallet::<Test>::on_genesis();
|
||||
if let Some(storage_version) = self.storage_version {
|
||||
storage_version.put::<Pallet<Test>>();
|
||||
}
|
||||
System::set_block_number(1)
|
||||
});
|
||||
ext
|
||||
}
|
||||
}
|
||||
@@ -544,6 +558,62 @@ fn calling_plain_account_fails() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn migration_in_progress_works() {
|
||||
let (wasm, code_hash) = compile_module::<Test>("dummy").unwrap();
|
||||
|
||||
ExtBuilder::default().existential_deposit(1).build().execute_with(|| {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
MigrationInProgress::<Test>::set(Some(Default::default()));
|
||||
|
||||
assert_err!(
|
||||
Contracts::upload_code(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Enforced
|
||||
),
|
||||
Error::<Test>::MigrationInProgress,
|
||||
);
|
||||
assert_err!(
|
||||
Contracts::remove_code(RuntimeOrigin::signed(ALICE), code_hash),
|
||||
Error::<Test>::MigrationInProgress,
|
||||
);
|
||||
assert_err!(
|
||||
Contracts::set_code(RuntimeOrigin::signed(ALICE), BOB.clone(), code_hash),
|
||||
Error::<Test>::MigrationInProgress,
|
||||
);
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::call(RuntimeOrigin::signed(ALICE), BOB, 0, GAS_LIMIT, None, vec![],),
|
||||
Error::<Test>::MigrationInProgress,
|
||||
);
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::instantiate_with_code(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
wasm,
|
||||
vec![],
|
||||
vec![],
|
||||
),
|
||||
Error::<Test>::MigrationInProgress,
|
||||
);
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::instantiate(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
100_000,
|
||||
GAS_LIMIT,
|
||||
None,
|
||||
code_hash,
|
||||
vec![],
|
||||
vec![],
|
||||
),
|
||||
Error::<Test>::MigrationInProgress,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instantiate_and_call_and_deposit_event() {
|
||||
let (wasm, code_hash) = compile_module::<Test>("event_and_return_on_deploy").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user