Skip to content

Commit

Permalink
Use skip_initialize_block for call and create (polkadot-evm#406)
Browse files Browse the repository at this point in the history
* Use `skip_initialize_block` for `call` and `create`

* Test contract has an additional method now, bump creation gas cost
  • Loading branch information
tgmichel authored Jun 11, 2021
1 parent a13d76d commit 76b8b04
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
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
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 76b8b04

Please sign in to comment.