Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
221 commits
Select commit Hold shift + click to select a range
e430211
wip
pgherveou Jul 2, 2025
b8edd12
fix build & test not handling dust yet
pgherveou Jul 2, 2025
a7adc71
add transfer_with dust
pgherveou Jul 2, 2025
578a11a
fix transfer_with_dust
pgherveou Jul 2, 2025
56eabf0
fix tests
pgherveou Jul 3, 2025
9b6f39f
use evm_balance where possible
pgherveou Jul 3, 2025
b34ebcf
port test from design
pgherveou Jul 3, 2025
c35e909
fix runtime-api macro
pgherveou Jul 3, 2025
d168cd4
fix missing test
pgherveou Jul 3, 2025
e357c74
fix benchmark tests
pgherveou Jul 3, 2025
d1d981c
Use U256 in bare_*
pgherveou Jul 4, 2025
01a91c6
make test pass again
pgherveou Jul 4, 2025
179b829
fix proc-acro
pgherveou Jul 4, 2025
b5d6bed
use native_value for clarity in tests
pgherveou Jul 4, 2025
2c05cfe
Add benchmark for eth_ extrinsics
pgherveou Jul 4, 2025
b2f3301
create the account if it does not exists
pgherveou Jul 4, 2025
18108f7
fix
pgherveou Jul 4, 2025
68e4ae4
fixes
pgherveou Jul 4, 2025
7f650f3
fixes
pgherveou Jul 4, 2025
380a1b4
fix build
pgherveou Jul 5, 2025
e0e5316
Update from github-actions[bot] running command 'bench --runtime dev …
github-actions[bot] Jul 5, 2025
8c21f11
Fix seal_call benchmark
pgherveou Jul 6, 2025
8158cea
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Jul 6, 2025
215e8a3
Update from github-actions[bot] running command 'bench --runtime dev …
github-actions[bot] Jul 6, 2025
a2aa1a1
Merge branch 'master' into pg/fix-seal-call-weights
pgherveou Jul 7, 2025
0c6059f
Merge branch 'pg/fix-seal-call-weights' into pg/eth-decimals
pgherveou Jul 7, 2025
be98709
fixes
pgherveou Jul 7, 2025
66d14f8
add migration
pgherveou Jul 7, 2025
cb06489
get rid of dust_account_id
pgherveou Jul 7, 2025
1edd2c2
fixes
pgherveou Jul 7, 2025
7840bdd
Update from github-actions[bot] running command 'bench --runtime dev …
github-actions[bot] Jul 7, 2025
3631e90
lint fix
pgherveou Jul 7, 2025
c387d13
nit updates
pgherveou Jul 7, 2025
e9e6038
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Jul 7, 2025
3ce1df7
fix pallet-xcm test
pgherveou Jul 8, 2025
a1d9b7c
fix build err
pgherveou Jul 8, 2025
3f27159
fix assets precompible build
pgherveou Jul 8, 2025
e3403f3
fix
pgherveou Jul 8, 2025
5b9c6ed
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Jul 8, 2025
f386278
Merge branch 'master' into pg/eth-decimals
pgherveou Jul 9, 2025
5f7adfa
pallet-xcm
pgherveou Jul 9, 2025
0cae21f
Update bench tests
pgherveou Jul 9, 2025
8a11d71
Update from github-actions[bot] running command 'bench --runtime dev …
github-actions[bot] Jul 9, 2025
74cb003
Update cargo files
pgherveou Jul 16, 2025
fc31a0e
store the runtime code for EVM instantiate
pgherveou Jul 16, 2025
bf2c046
wip
pgherveou Jul 17, 2025
4c3c09f
wip
pgherveou Jul 17, 2025
279c132
fix
pgherveou Jul 17, 2025
9e7ee08
fix
pgherveou Jul 17, 2025
a37dd15
PR review move has_dust and has_balance and remove pub
pgherveou Jul 18, 2025
a764344
use local function instead of closure
pgherveou Jul 18, 2025
6eb87c8
make migration
pgherveou Jul 18, 2025
2959185
scope function
pgherveou Jul 18, 2025
41c7afd
charge 0 for input_data_len on err
pgherveou Jul 18, 2025
e74ed21
comment bench_map
pgherveou Jul 18, 2025
2d8d417
use drain to remove old storage in migration
pgherveou Jul 18, 2025
bdc1365
make balance, dust private in BalanceWithDust
pgherveou Jul 18, 2025
c94be4f
Update substrate/frame/revive/src/migrations/v1.rs
pgherveou Jul 18, 2025
7d3bca0
Revert "Update substrate/frame/revive/src/migrations/v1.rs"
pgherveou Jul 18, 2025
a2a5a18
add migration unit test
pgherveou Jul 18, 2025
0dc2210
typo
pgherveou Jul 18, 2025
e8ca9fb
Add additional tests
pgherveou Jul 18, 2025
1da95a2
Merge branch 'master' into pg/eth-decimals
pgherveou Jul 18, 2025
7e9f2c9
Merge branch 'pg/eth-decimals' into pg/revm
pgherveou Jul 18, 2025
874e7c0
update lock
pgherveou Jul 18, 2025
d7eb888
wip
pgherveou Jul 19, 2025
38c2b80
add instructions
pgherveou Jul 20, 2025
a55cc7a
wip
pgherveou Jul 20, 2025
3a42cf7
split evm / pvm
pgherveou Jul 20, 2025
8af812d
basic host interaction
pgherveou Jul 20, 2025
165b7e7
fix gas
pgherveou Jul 21, 2025
ec3d84f
Merge branch 'master' into pg/revm
pgherveou Jul 22, 2025
ade709b
wip
pgherveou Jul 22, 2025
65ddd58
update lock
pgherveou Jul 22, 2025
006cb15
fix
pgherveou Jul 22, 2025
c3ff24a
rm
pgherveou Jul 22, 2025
661d251
fix
pgherveou Jul 22, 2025
8b55fe8
Update
pgherveou Jul 22, 2025
8335340
fix
pgherveou Jul 22, 2025
538bf49
comment bitwise test for now
pgherveou Jul 22, 2025
70d07b9
Add AllowEVMBytecode config
pgherveou Jul 22, 2025
364201c
wip
pgherveou Jul 23, 2025
a2edcbe
fix compile error
pgherveou Jul 23, 2025
97c00f4
fixes
pgherveou Jul 23, 2025
6edb4a1
use 0 value
pgherveou Jul 23, 2025
053c548
[pallet-revive] revm tests scaffolding (#9290)
xermicus Jul 24, 2025
b45b1a2
move back fixture to fixtures folder and generate them from build.rs
pgherveou Jul 24, 2025
27b62f7
add skeleton for fixtures
pgherveou Jul 24, 2025
acf0e6e
wip
pgherveou Jul 25, 2025
f47d7b5
fixes
pgherveou Jul 25, 2025
31c0595
update build.rs
pgherveou Jul 25, 2025
3a07569
nit
pgherveou Jul 25, 2025
9adf741
fixes
pgherveou Jul 26, 2025
b1dbf5d
add missing headers
pgherveou Jul 26, 2025
4341d6d
Merge branch 'master' into pg/revm
pgherveou Jul 27, 2025
91e59e5
add test allow_evm_bytecode_config_works
pgherveou Jul 27, 2025
da7473d
fix lock
pgherveou Jul 27, 2025
df8d71d
Update from github-actions[bot] running command 'fmt'
github-actions[bot] Jul 27, 2025
359b181
fixes
pgherveou Jul 27, 2025
58b9220
Rve/revm arithmetic instructions WIP (#9361)
0xRVE Jul 30, 2025
5b304a0
fixes gas computation of evm arithemtic instructions (#9379)
0xRVE Jul 30, 2025
8817d7e
Revert "fixes gas computation of evm arithemtic instructions (#9379)"
Aug 12, 2025
02198ce
Revert "Rve/revm arithmetic instructions WIP (#9361)"
Aug 12, 2025
bb14f1c
[pallet-revive] do not silently fail Solidity fixtures compilation (#…
xermicus Aug 12, 2025
1bfbaa8
refactor more benchmarks
pgherveou Aug 14, 2025
7f79d2e
Merge branch 'master' into pg/revm
pgherveou Aug 18, 2025
076246c
Merge branch 'master' into pg/revm
pgherveou Aug 18, 2025
b2ceaae
revm file shuffling
pgherveou Aug 18, 2025
7e68c51
fixes
pgherveou Aug 18, 2025
6ec1681
rm stuff for later
pgherveou Aug 18, 2025
c89d026
rm evm
pgherveou Aug 18, 2025
d53e0ac
rm evm stuff
pgherveou Aug 18, 2025
edde1d1
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Aug 18, 2025
4f38703
rm
pgherveou Aug 18, 2025
ab3761e
taplo fix
pgherveou Aug 18, 2025
7dadbc1
fix up cargo.lock
pgherveou Aug 18, 2025
abcd13c
try
pgherveou Aug 18, 2025
6d30298
fixes
pgherveou Aug 18, 2025
68e9a84
Merge branch 'master' into pg/revm-base
pgherveou Aug 18, 2025
551c711
rm vm/runtime.rs
pgherveou Aug 18, 2025
2c308d7
Merge branch 'pg/revm-base' into pg/revm
pgherveou Aug 18, 2025
2debf91
fix
pgherveou Aug 18, 2025
0175328
nit
pgherveou Aug 18, 2025
59e59e8
fixes
pgherveou Aug 18, 2025
f1f2ffc
nit
pgherveou Aug 18, 2025
82ea9bc
update call_with_code_per_byte
pgherveou Aug 18, 2025
20511d1
fixes
pgherveou Aug 18, 2025
e1bbcb9
added migration
pgherveou Aug 18, 2025
78c92d3
Merge branch 'master' into pg/revm-base
pgherveou Aug 19, 2025
3789665
Merge branch 'pg/revm-base' into pg/revm
pgherveou Aug 19, 2025
f8da76f
refactoring
pgherveou Aug 19, 2025
b1b1192
fix clippy
pgherveou Aug 19, 2025
a829fab
fix clippy
pgherveou Aug 19, 2025
3c4f5c4
Merge branch 'master' into pg/revm
pgherveou Aug 21, 2025
953ee61
merge fix
pgherveou Aug 21, 2025
7cee5be
simplify migration tests
pgherveou Aug 21, 2025
b8dc717
add migration
pgherveou Aug 21, 2025
81578a0
remove unneeded tests for this PR
pgherveou Aug 21, 2025
6000ed4
fixes
pgherveou Aug 21, 2025
c679776
keep these files for next PR
pgherveou Aug 21, 2025
5f839b6
comments
pgherveou Aug 21, 2025
8110392
fixes
pgherveou Aug 21, 2025
7a1c0a6
fix
pgherveou Aug 21, 2025
83ea8cd
Update from github-actions[bot] running command 'bench --runtime dev …
github-actions[bot] Aug 21, 2025
165957c
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Aug 21, 2025
2b07ca6
rename seal_to_account_id
pgherveou Aug 21, 2025
f96fa39
update PRDOC
pgherveou Aug 21, 2025
2f369ad
Merge branch 'master' into pg/revm
pgherveou Aug 21, 2025
b66b47a
fix bench
pgherveou Aug 21, 2025
4d0db7e
output.data shoudl be untouched
pgherveou Aug 22, 2025
79b84da
install solidity in job
pgherveou Aug 22, 2025
4b80099
use resolc too
pgherveou Aug 22, 2025
4b6f4d2
rm line
pgherveou Aug 22, 2025
ab15dc1
enforce evm code size limit
pgherveou Aug 23, 2025
e93c1a0
fix
pgherveou Aug 25, 2025
04d0551
fix
pgherveou Aug 25, 2025
8f8ebcc
fix
pgherveou Aug 25, 2025
dec0849
PR review
pgherveou Aug 26, 2025
dbfc430
make pristine unbounded and check PVM & EVM code size
pgherveou Aug 26, 2025
87b7b4e
nit
pgherveou Aug 26, 2025
b769010
refcount = 1 for evm
pgherveou Aug 26, 2025
0abfc74
fix
pgherveou Aug 26, 2025
6060eb4
fix
pgherveou Aug 26, 2025
2007fb5
add one more assert
pgherveou Aug 26, 2025
f219e06
nit
pgherveou Aug 26, 2025
33e9216
Remove refcount and owner for EVM CodeInfo
pgherveou Aug 26, 2025
c71b236
init
pgherveou Aug 26, 2025
f75403a
rm unused
pgherveou Aug 26, 2025
becf521
Merge branch 'pg/revm' into pg/revive-genesis
pgherveou Aug 26, 2025
7faab96
rm comments
pgherveou Aug 26, 2025
db737db
fixes
pgherveou Aug 26, 2025
49ea5e4
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Aug 26, 2025
d26d8ac
origin should be held not caller
pgherveou Aug 26, 2025
cc8cef4
Merge branch 'master' into pg/revm
pgherveou Aug 27, 2025
ebe8a8a
fixes
pgherveou Aug 27, 2025
e0a3c3d
Merge branch 'pg/revm' into pg/revive-genesis
pgherveou Aug 27, 2025
670ba44
nit
pgherveou Aug 27, 2025
e8a48a6
Update substrate/frame/revive/src/lib.rs
pgherveou Aug 27, 2025
e405e18
rollback refcount removals
pgherveou Aug 27, 2025
8b1669f
Update Cargo.toml
pgherveou Aug 27, 2025
4f86e9b
Update prdoc/pr_9285.prdoc
pgherveou Aug 27, 2025
315ae52
Update substrate/frame/revive/src/call_builder.rs
pgherveou Aug 27, 2025
3598d6f
Update substrate/frame/revive/src/benchmarking.rs
pgherveou Aug 27, 2025
3272e99
rm charge_evm_init_cost
pgherveou Aug 27, 2025
e2242a2
fix
pgherveou Aug 27, 2025
7fa6421
rm - 1
pgherveou Aug 27, 2025
ae647b6
restore legacy behaviour
pgherveou Aug 27, 2025
1a073b6
update
pgherveou Aug 28, 2025
d4d8c1a
deadcode unused for now
pgherveou Aug 28, 2025
e286c49
deposit fixes
pgherveou Aug 28, 2025
f9aebdc
add missing assert
pgherveou Aug 28, 2025
7232f99
tweak tests
pgherveou Aug 28, 2025
f175c1b
ensure pallet_account exits
pgherveou Aug 28, 2025
bf19cf0
fixes
pgherveou Aug 29, 2025
7211711
nit
pgherveou Aug 29, 2025
c1ba77d
update comment
pgherveou Aug 29, 2025
46f6dfb
Add back remove_code
pgherveou Aug 29, 2025
546d65d
nit
pgherveou Aug 29, 2025
d820477
Update substrate/frame/revive/src/lib.rs
pgherveou Aug 29, 2025
c16e6ce
mint balance in migration
pgherveou Aug 29, 2025
1541263
rm check
pgherveou Aug 29, 2025
0a8935c
fmt
pgherveou Aug 29, 2025
692abb2
fixes
pgherveou Aug 29, 2025
a504987
reject hash == 0
pgherveou Aug 29, 2025
3a9f3d7
warm up pallet_account
pgherveou Aug 29, 2025
c245621
Update substrate/frame/revive/src/migrations/v2.rs
pgherveou Aug 29, 2025
88c6b23
Update ExtBuilder
pgherveou Aug 29, 2025
3201fb2
Merge branch 'master' into pg/revm
pgherveou Aug 29, 2025
400c912
Update .github/workflows/tests-misc.yml
pgherveou Aug 29, 2025
a1178f3
Update from github-actions[bot] running command 'bench --runtime dev …
github-actions[bot] Aug 29, 2025
dc75161
Merge branch 'pg/revm' into pg/revive-genesis
pgherveou Sep 1, 2025
d502f36
fix tests-misc
pgherveou Sep 1, 2025
3c9a133
Merge branch 'pg/revm' into pg/revive-genesis
pgherveou Sep 1, 2025
a8cd0c3
fixes
pgherveou Sep 1, 2025
cc8ff2e
Merge branch 'master' into pg/revive-genesis
pgherveou Sep 1, 2025
ce51812
fix merge conflict
pgherveou Sep 1, 2025
11ecb37
fix /n
pgherveou Sep 1, 2025
8d2ff79
fix
pgherveou Sep 1, 2025
500b83e
Merge branch 'master' into pg/revive-genesis
pgherveou Sep 1, 2025
c457910
fixes
pgherveou Sep 1, 2025
f9deb02
Merge branch 'master' into pg/revive-genesis
pgherveou Sep 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion polkadot/xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ pub(crate) fn new_test_ext_with_balances_and_xcm_version(
.assimilate_storage(&mut t)
.unwrap();

pallet_revive::GenesisConfig::<Test> { mapped_accounts: vec![ALICE] }
pallet_revive::GenesisConfig::<Test> { mapped_accounts: vec![ALICE], ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
9 changes: 9 additions & 0 deletions prdoc/pr_9557.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: '[pallet-revive] Update genesis config'
doc:
- audience: Runtime Dev
description: |-
Update pallet-revive Genesis config
Make it possible to define accounts (contracts or EOA) that we want to setup at Genesis
crates:
- name: pallet-revive
bump: minor
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

},
"revive": {
"mappedAccounts": []
},
"democracy": {},
"council": {
Expand Down
9 changes: 4 additions & 5 deletions substrate/frame/revive/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ pub trait AddressMapper<T: Config>: private::Sealed {
/// `account_id` instead of the fallback account id.
fn map(account_id: &T::AccountId) -> DispatchResult;

#[cfg(feature = "runtime-benchmarks")]
fn bench_map(account_id: &T::AccountId) -> DispatchResult {
/// Map an account id without taking any deposit.
/// This is only useful for genesis configuration, or benchmarks.
fn map_no_deposit(account_id: &T::AccountId) -> DispatchResult {
Self::map(account_id)
}

Expand Down Expand Up @@ -145,9 +146,7 @@ where
Ok(())
}

/// Convenience function for benchmarking, to map an account id without taking any deposit.
#[cfg(feature = "runtime-benchmarks")]
fn bench_map(account_id: &T::AccountId) -> DispatchResult {
fn map_no_deposit(account_id: &T::AccountId) -> DispatchResult {
ensure!(!Self::is_mapped(account_id), <Error<T>>::AccountAlreadyMapped);
<OriginalAccount<T>>::insert(Self::to_address(account_id), account_id);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ mod benchmarks {
fn seal_balance_of() {
let len = <sp_core::U256 as MaxEncodedLen>::max_encoded_len();
let account = account::<T::AccountId>("target", 0, 0);
<T as Config>::AddressMapper::bench_map(&account).unwrap();
<T as Config>::AddressMapper::map_no_deposit(&account).unwrap();

let address = T::AddressMapper::to_address(&account);
let balance = Pallet::<T>::min_balance() * 2u32.into();
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/revive/src/evm/api/byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl Bytes {
impl_hex!(Byte, u8, 0u8);
impl_hex!(Bytes, Vec<u8>, vec![]);
impl_hex!(Bytes8, [u8; 8], [0u8; 8]);
impl_hex!(Bytes32, [u8; 32], [0u8; 32]);
impl_hex!(Bytes256, [u8; 256], [0u8; 256]);

#[test]
Expand Down
117 changes: 112 additions & 5 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub use crate::{
create1, create2, is_eth_derived, AccountId32Mapper, AddressMapper, TestAccountMapper,
},
exec::{Key, MomentOf, Origin},
pallet::*,
pallet::{genesis, *},
storage::{AccountInfo, ContractInfo},
};
pub use codec;
Expand Down Expand Up @@ -534,16 +534,58 @@ pub mod pallet {
#[pallet::storage]
pub(crate) type OriginalAccount<T: Config> = StorageMap<_, Identity, H160, AccountId32>;

pub mod genesis {
use super::*;
use crate::evm::Bytes32;

/// Genesis configuration for contract-specific data.
#[derive(Clone, PartialEq, Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct ContractData {
/// Contract code.
pub code: Vec<u8>,
/// Initial storage entries as 32-byte key/value pairs.
pub storage: alloc::collections::BTreeMap<Bytes32, Bytes32>,
}

/// Genesis configuration for a contract account.
#[derive(PartialEq, Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Account<T: Config> {
/// Contract address.
pub address: H160,
/// Contract balance.
#[serde(default)]
pub balance: U256,
/// Account nonce
#[serde(default)]
pub nonce: T::Nonce,
/// Contract-specific data (code and storage). None for EOAs.
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub contract_data: Option<ContractData>,
}
}

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
#[derive(Debug, PartialEq, frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
/// Genesis mapped accounts
/// List of native Substrate accounts (typically `AccountId32`) to be mapped at genesis
/// block, enabling them to interact with smart contracts.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub mapped_accounts: Vec<T::AccountId>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this? I guess for accounts that are in the pallet_balances genesis? Can we add some docs here why we have both entries?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah exactly, will add comments


/// Account entries (both EOAs and contracts)
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub accounts: Vec<genesis::Account<T>>,
}

#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T>
where
BalanceOf<T>: Into<U256> + TryFrom<U256>,
{
fn build(&self) {
use crate::{exec::Key, vm::ContractBlob};
use frame_support::traits::fungible::Mutate;

if !System::<T>::account_exists(&Pallet::<T>::account_id()) {
let _ = T::Currency::mint_into(
&Pallet::<T>::account_id(),
Expand All @@ -552,10 +594,75 @@ pub mod pallet {
}

for id in &self.mapped_accounts {
if let Err(err) = T::AddressMapper::map(id) {
if let Err(err) = T::AddressMapper::map_no_deposit(id) {
log::error!(target: LOG_TARGET, "Failed to map account {id:?}: {err:?}");
}
}

let owner = Pallet::<T>::account_id();

for genesis::Account { address, balance, nonce, contract_data } in &self.accounts {
let Ok(balance_with_dust) =
BalanceWithDust::<BalanceOf<T>>::from_value::<T>(*balance).inspect_err(|err| {
log::error!(target: LOG_TARGET, "Failed to convert balance for {address:?}: {err:?}");
})
else {
continue;
};
let account_id = T::AddressMapper::to_account_id(address);
let (value, dust) = balance_with_dust.deconstruct();

let _ = T::Currency::set_balance(&account_id, value);
frame_system::Account::<T>::mutate(&account_id, |info| {
info.nonce = (*nonce).into();
});

match contract_data {
None => {
AccountInfoOf::<T>::insert(
address,
AccountInfo { account_type: AccountType::EOA, dust },
);
},
Some(genesis::ContractData { code, storage }) => {
let blob = if code.starts_with(&polkavm_common::program::BLOB_MAGIC) {
ContractBlob::<T>::from_pvm_code( code.clone(), owner.clone()).inspect_err(|err| {
log::error!(target: LOG_TARGET, "Failed to create PVM ContractBlob for {address:?}: {err:?}");
})
} else {
ContractBlob::<T>::from_evm_runtime_code(code.clone(), account_id).inspect_err(|err| {
log::error!(target: LOG_TARGET, "Failed to create EVM ContractBlob for {address:?}: {err:?}");
})
};

let Ok(blob) = blob else {
continue;
};

let code_hash = *blob.code_hash();
let Ok(info) = <ContractInfo<T>>::new(&address, 0u32.into(), code_hash)
.inspect_err(|err| {
log::error!(target: LOG_TARGET, "Failed to create ContractInfo for {address:?}: {err:?}");
})
else {
continue;
};

AccountInfoOf::<T>::insert(
address,
AccountInfo { account_type: info.clone().into(), dust },
);

<PristineCode<T>>::insert(blob.code_hash(), code);
<CodeInfoOf<T>>::insert(blob.code_hash(), blob.code_info().clone());
for (k, v) in storage {
let _ = info.write(&Key::from_fixed(k.0), Some(v.0.to_vec()), None, false).inspect_err(|err| {
log::error!(target: LOG_TARGET, "Failed to write genesis storage for {address:?} at key {k:?}: {err:?}");
});
}
},
}
}
}
}

Expand Down
71 changes: 69 additions & 2 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ mod pvm;
mod sol;

use crate::{
self as pallet_revive, test_utils::*, AccountId32Mapper, BalanceOf, BalanceWithDust,
CodeInfoOf, Config, Origin, Pallet,
self as pallet_revive,
genesis::{Account, ContractData},
test_utils::*,
AccountId32Mapper, AddressMapper, BalanceOf, BalanceWithDust, CodeInfoOf, Config,
GenesisConfig, Origin, Pallet, PristineCode,
};
use frame_support::{
assert_ok, derive_impl,
Expand All @@ -31,7 +34,9 @@ use frame_support::{
traits::{ConstU32, ConstU64, FindAuthor, StorageVersion},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, FixedFee, IdentityFee, Weight},
};
use pallet_revive_fixtures::compile_module;
use pallet_transaction_payment::{ConstFeeMultiplier, Multiplier};
use sp_core::U256;
use sp_keystore::{testing::MemoryKeystore, KeystoreExt};
use sp_runtime::{
traits::{BlakeTwo256, Convert, IdentityLookup, One},
Expand Down Expand Up @@ -450,3 +455,65 @@ impl Default for Origin<Test> {
Self::Signed(ALICE)
}
}

#[test]
fn ext_builder_with_genesis_config_works() {
let pvm_contract = Account {
address: BOB_ADDR,
balance: U256::from(100),
nonce: 42,
contract_data: Some(ContractData {
code: compile_module("dummy").unwrap().0,
storage: [([1u8; 32].into(), [2u8; 32].into())].into_iter().collect(),
}),
};

let evm_contract = Account {
address: CHARLIE_ADDR,
balance: U256::from(100),
nonce: 43,
contract_data: Some(ContractData {
code: vec![revm::bytecode::opcode::RETURN],
storage: [([3u8; 32].into(), [4u8; 32].into())].into_iter().collect(),
}),
};

let eoa =
Account { address: ALICE_ADDR, balance: U256::from(100), nonce: 44, contract_data: None };

let config = GenesisConfig::<Test> {
mapped_accounts: vec![EVE],
accounts: vec![eoa.clone(), pvm_contract.clone(), evm_contract.clone()],
};

// Genesis serialization works
let json = serde_json::to_string(&config).unwrap();
assert_eq!(config, serde_json::from_str::<GenesisConfig<Test>>(&json).unwrap());

ExtBuilder::default().genesis_config(Some(config)).build().execute_with(|| {
// account is mapped
assert!(<Test as Config>::AddressMapper::is_mapped(&EVE));

// EOA is created
assert_eq!(Pallet::<Test>::evm_balance(&eoa.address), eoa.balance);

// Contract is created
for contract in [pvm_contract, evm_contract] {
let contract_data = contract.contract_data.unwrap();
let contract_info = test_utils::get_contract(&contract.address);
assert_eq!(
PristineCode::<Test>::get(&contract_info.code_hash).unwrap(),
contract_data.code
);
assert_eq!(Pallet::<Test>::evm_nonce(&contract.address), contract.nonce);
assert_eq!(Pallet::<Test>::evm_balance(&contract.address), contract.balance);

for (key, value) in contract_data.storage.iter() {
assert_eq!(
Pallet::<Test>::get_storage(contract.address, key.0),
Ok(Some(value.0.to_vec()))
);
}
}
});
}
Loading