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
25 changes: 16 additions & 9 deletions client/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -476,12 +476,19 @@ where
.map(|in_pool_tx| in_pool_tx.data().clone())
.collect::<Vec<<B as BlockT>::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
)))
}
}
1 change: 1 addition & 0 deletions ts-tests/tests/test-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describeWithFrontier("Frontier RPC (Balance)", (context) => {
});

step("balance to be updated after transfer", async function () {
await createAndFinalizeBlock(context.web3);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should go after the timeout line.
Also why do we need to create a block for this ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This cherry-picked solution from upstream uses parent hash for building the pending runtime api and, in the case of tests like this one, parent hash of genesis is not a valid block to initialize. Thus the need of creating one.

Tbh I don't like it and I can propose a better way of doing it upstream, which will not require modifying the tests like that.

this.timeout(15000);

const value = "0x200"; // 512, must be higher than ExistentialDeposit
Expand Down
1 change: 1 addition & 0 deletions ts-tests/tests/test-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down