diff --git a/client/rpc/src/eth/mod.rs b/client/rpc/src/eth/mod.rs index fa77d11111..f1f63d76f7 100644 --- a/client/rpc/src/eth/mod.rs +++ b/client/rpc/src/eth/mod.rs @@ -38,7 +38,7 @@ use sc_client_api::backend::{Backend, StateBackend, StorageProvider}; use sc_network::{ExHashT, NetworkService}; use sc_transaction_pool::{ChainApi, Pool}; use sc_transaction_pool_api::{InPoolTransaction, TransactionPool}; -use sp_api::{Core, ProvideRuntimeApi}; +use sp_api::{Core, HeaderT, ProvideRuntimeApi}; use sp_block_builder::BlockBuilder as BlockBuilderApi; use sp_blockchain::HeaderBackend; use sp_core::hashing::keccak_256; @@ -476,12 +476,19 @@ where .map(|in_pool_tx| in_pool_tx.data().clone()) .collect::::Extrinsic>>(); // Manually initialize the overlay. - let header = client.header(best).unwrap().unwrap(); - api.initialize_block(&best, &header) - .map_err(|e| internal_err(format!("Runtime api access error: {:?}", e)))?; - // Apply the ready queue to the best block's state. - for xt in xts { - let _ = api.apply_extrinsic(&best, xt); - } - Ok(api) + if let Ok(Some(header)) = client.header(best) { + let parent_hash = BlockId::Hash(*header.parent_hash()); + api.initialize_block(&parent_hash, &header) + .map_err(|e| internal_err(format!("Runtime api access error: {:?}", e)))?; + // Apply the ready queue to the best block's state. + for xt in xts { + let _ = api.apply_extrinsic(&best, xt); + } + Ok(api) + } else { + Err(internal_err(format!( + "Cannot get header for block {:?}", + best + ))) + } } diff --git a/ts-tests/tests/test-balance.ts b/ts-tests/tests/test-balance.ts index ac39b9b136..4afd52eb82 100644 --- a/ts-tests/tests/test-balance.ts +++ b/ts-tests/tests/test-balance.ts @@ -12,6 +12,7 @@ describeWithFrontier("Frontier RPC (Balance)", (context) => { }); step("balance to be updated after transfer", async function () { + await createAndFinalizeBlock(context.web3); this.timeout(15000); const value = "0x200"; // 512, must be higher than ExistentialDeposit diff --git a/ts-tests/tests/test-contract.ts b/ts-tests/tests/test-contract.ts index d353f038cb..dcdb8b80fa 100644 --- a/ts-tests/tests/test-contract.ts +++ b/ts-tests/tests/test-contract.ts @@ -15,6 +15,7 @@ describeWithFrontier("Frontier RPC (Contract)", (context) => { // to spin up a frontier node, it saves a lot of time. it("contract creation should return transaction hash", async function () { + await createAndFinalizeBlock(context.web3); this.timeout(15000); const tx = await context.web3.eth.accounts.signTransaction( {