Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions prdoc/pr_9988.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: '[pallet-revive] improve revive genesis config'
doc:
- audience: Runtime Dev
description: |-
GenesisConfig: make sure that contracts are brought to existence by minting e.d first
crates:
- name: pallet-revive
bump: patch
4 changes: 4 additions & 0 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ pub mod pallet {
for genesis::Account { address, balance, nonce, contract_data } in &self.accounts {
let account_id = T::AddressMapper::to_account_id(address);

if !System::<T>::account_exists(&account_id) {
let _ = T::Currency::mint_into(&account_id, T::Currency::minimum_balance());
}

frame_system::Account::<T>::mutate(&account_id, |info| {
info.nonce = (*nonce).into();
});
Expand Down
21 changes: 18 additions & 3 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl Default for Origin<Test> {
#[test]
fn ext_builder_with_genesis_config_works() {
let pvm_contract = Account {
address: BOB_ADDR,
address: crate::H160::repeat_byte(0x42),
balance: U256::from(100_000_100),
nonce: 42,
contract_data: Some(ContractData {
Expand All @@ -528,11 +528,17 @@ fn ext_builder_with_genesis_config_works() {
};

let evm_contract = Account {
address: CHARLIE_ADDR,
address: crate::H160::repeat_byte(0x43),
balance: U256::from(1_000_00_100),
nonce: 43,
contract_data: Some(ContractData {
code: vec![revm::bytecode::opcode::RETURN],
code: vec![
revm::bytecode::opcode::PUSH1,
0x00,
revm::bytecode::opcode::PUSH1,
0x00,
revm::bytecode::opcode::RETURN,
],
storage: [([3u8; 32].into(), [4u8; 32].into())].into_iter().collect(),
}),
};
Expand Down Expand Up @@ -561,6 +567,11 @@ fn ext_builder_with_genesis_config_works() {
for contract in [pvm_contract, evm_contract] {
let contract_data = contract.contract_data.unwrap();
let contract_info = test_utils::get_contract(&contract.address);

assert!(System::account_exists(&<Test as Config>::AddressMapper::to_account_id(
&contract.address
)));

assert_eq!(
PristineCode::<Test>::get(&contract_info.code_hash).unwrap(),
contract_data.code
Expand All @@ -574,6 +585,10 @@ fn ext_builder_with_genesis_config_works() {
Ok(Some(value.0.to_vec()))
);
}

// Check that we can call contract created at genesis
let result = builder::bare_call(contract.address).build_and_unwrap_result();
assert!(!result.did_revert());
}
});
}
Loading