Skip to content

Commit

Permalink
Merge branch 'master' of github.com:paritytech/frontier
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas committed Jun 14, 2021
2 parents bc211bd + 76b8b04 commit edfdbbb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
2 changes: 2 additions & 0 deletions primitives/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ sp_api::decl_runtime_apis! {
/// For a given account address and index, returns pallet_evm::AccountStorages.
fn storage_at(address: H160, index: U256) -> H256;
/// Returns a frame_ethereum::call response. If `estimate` is true,
#[skip_initialize_block]
fn call(
from: H160,
to: H160,
Expand All @@ -75,6 +76,7 @@ sp_api::decl_runtime_apis! {
estimate: bool,
) -> Result<fp_evm::CallInfo, sp_runtime::DispatchError>;
/// Returns a frame_ethereum::create response.
#[skip_initialize_block]
fn create(
from: H160,
data: Vec<u8>,
Expand Down
12 changes: 10 additions & 2 deletions template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::cli::{Cli, Subcommand};
use crate::service;
use sc_cli::{SubstrateCli, RuntimeVersion, Role, ChainSpec};
use sc_service::PartialComponents;
use crate::service::new_partial;
use crate::service::{frontier_database_dir, new_partial};

impl SubstrateCli for Cli {
fn impl_name() -> String {
Expand Down Expand Up @@ -88,7 +88,15 @@ pub fn run() -> sc_cli::Result<()> {
},
Some(Subcommand::PurgeChain(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.database))
runner.sync_run(|config| {
// Remove Frontier offchain db
let frontier_database_config = sc_service::DatabaseConfig::RocksDb {
path: frontier_database_dir(&config),
cache_size: 0,
};
cmd.run(frontier_database_config)?;
cmd.run(config.database)
})
},
Some(Subcommand::Revert(cmd)) => {
let runner = cli.create_runner(cmd)?;
Expand Down
8 changes: 5 additions & 3 deletions template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,20 @@ impl ProvideInherentData for MockTimestampInherentDataProvider {
}
}

pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {
pub fn frontier_database_dir(config: &Configuration) -> std::path::PathBuf {
let config_dir = config.base_path.as_ref()
.map(|base_path| base_path.config_dir(config.chain_spec.id()))
.unwrap_or_else(|| {
BasePath::from_project("", "", &crate::cli::Cli::executable_name())
.config_dir(config.chain_spec.id())
});
let database_dir = config_dir.join("frontier").join("db");
config_dir.join("frontier").join("db")
}

pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {
Ok(Arc::new(fc_db::Backend::<Block>::new(&fc_db::DatabaseSettings {
source: fc_db::DatabaseSettingsSrc::RocksDb {
path: database_dir,
path: frontier_database_dir(&config),
cache_size: 0,
}
})?))
Expand Down
3 changes: 3 additions & 0 deletions ts-tests/contracts/Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ contract Test {
function multiply(uint a) public pure returns(uint d) {
return a * 7;
}
function currentBlock() public view returns(uint) {
return block.number;
}
}
12 changes: 12 additions & 0 deletions ts-tests/tests/test-contract-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ describeWithFrontier("Frontier RPC (Contract Methods)", (context) => {

expect(await contract.methods.multiply(3).call()).to.equal("21");
});
it("should get correct environmental block number", async function () {
// Solidity `block.number` is expected to return the same height at which the runtime call was made.
const contract = new context.web3.eth.Contract(TEST_CONTRACT_ABI, FIRST_CONTRACT_ADDRESS, {
from: GENESIS_ACCOUNT,
gasPrice: "0x01",
});
let block = await context.web3.eth.getBlock("latest");
expect(await contract.methods.currentBlock().call()).to.eq(block.number.toString());
await createAndFinalizeBlock(context.web3);
block = await context.web3.eth.getBlock("latest");
expect(await contract.methods.currentBlock().call()).to.eq(block.number.toString());
});

// Requires error handling
it.skip("should fail for missing parameters", async function () {
Expand Down
2 changes: 1 addition & 1 deletion ts-tests/tests/test-gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describeWithFrontier("Frontier RPC (Gas)", (context) => {
from: GENESIS_ACCOUNT,
data: Test.bytecode,
})
).to.equal(149143);
).to.equal(159715);
});

it.skip("block gas limit over 5M", async function () {
Expand Down

0 comments on commit edfdbbb

Please sign in to comment.