Skip to content

Commit

Permalink
fix gas tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ committed Jan 16, 2025
1 parent 625f14e commit 8810310
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions ts-tests/tests/test-gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describeWithFrontier("Frontier RPC (Gas)", (context) => {

it("eth_estimateGas for contract creation", async function () {
// The value returned as an estimation by the evm with estimate mode ON.
let oneOffEstimation = 196701;
let oneOffEstimation = 189139;
let binarySearchEstimation = binarySearch(oneOffEstimation);
// Sanity check expect a variance of 10%.
expect(estimationVariance(binarySearchEstimation, oneOffEstimation)).to.be.lessThan(1);
Expand Down Expand Up @@ -97,7 +97,7 @@ describeWithFrontier("Frontier RPC (Gas)", (context) => {
it("eth_estimateGas should handle AccessList alias", async function () {
// The value returned as an estimation by the evm with estimate mode ON.
// 4300 == 1900 for one key and 2400 for one storage.
let oneOffEstimation = 196701 + 4300;
let oneOffEstimation = 189139 + 4300;
let binarySearchEstimation = binarySearch(oneOffEstimation);
// Sanity check expect a variance of 10%.
expect(estimationVariance(binarySearchEstimation, oneOffEstimation)).to.be.lessThan(1);
Expand All @@ -124,7 +124,7 @@ describeWithFrontier("Frontier RPC (Gas)", (context) => {
data: Test.bytecode,
gasPrice: "0x0",
});
expect(result).to.equal(197732);
expect(result).to.equal(189620);
result = await context.web3.eth.estimateGas({
from: GENESIS_ACCOUNT,
data: Test.bytecode,
Expand Down Expand Up @@ -198,9 +198,9 @@ describeWithFrontier("Frontier RPC (Gas limit Weightv2 ref time)", (context) =>
// Block gas limit
const BLOCK_GAS_LIMIT = ETH_BLOCK_GAS_LIMIT - FIRST_CALL;
// Number of calls per block
const CALLS_PER_BLOCK = Math.floor(BLOCK_GAS_LIMIT / CALL_COST) + 1;
const CALLS_PER_BLOCK = Math.floor(BLOCK_GAS_LIMIT / CALL_COST) + 1; // +1 to count first call
// Available space left after all calls
const REMNANT = Math.floor(ETH_BLOCK_GAS_LIMIT - (CALL_COST * (CALLS_PER_BLOCK - 1) + FIRST_CALL));
const REMNANT = Math.floor(BLOCK_GAS_LIMIT - CALL_COST * (CALLS_PER_BLOCK - 1));
// Number of transfers per available space left
const TRANSFERS_PER_BLOCK = Math.floor(REMNANT / 21_000);

Expand Down Expand Up @@ -237,7 +237,7 @@ describeWithFrontier("Frontier RPC (Gas limit Weightv2 ref time)", (context) =>
to: contract.options.address,
data: data.encodeABI(),
gasPrice: "0x3B9ACA00",
gas: "0x100000",
gas: `0x${(FIRST_CALL + 5000).toString(16)}`,
nonce,
},
GENESIS_ACCOUNT_PRIVATE_KEY
Expand All @@ -247,7 +247,7 @@ describeWithFrontier("Frontier RPC (Gas limit Weightv2 ref time)", (context) =>
}
// because we are using Math.floor for everything, at the end there is room for an additional
// transfer.
for (var i = 0; i < TRANSFERS_PER_BLOCK + 1; i++) {
for (var i = 0; i < TRANSFERS_PER_BLOCK; i++) {
const tx = await context.web3.eth.accounts.signTransaction(
{
from: GENESIS_ACCOUNT,
Expand All @@ -259,14 +259,14 @@ describeWithFrontier("Frontier RPC (Gas limit Weightv2 ref time)", (context) =>
},
GENESIS_ACCOUNT_PRIVATE_KEY
);
let r = await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]);
await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]);
nonce++;
}

await createAndFinalizeBlock(context.web3);

let latest = await context.web3.eth.getBlock("latest");
expect(latest.transactions.length).to.be.eq(CALLS_PER_BLOCK + TRANSFERS_PER_BLOCK + 1);
expect(latest.transactions.length).to.be.eq(CALLS_PER_BLOCK + TRANSFERS_PER_BLOCK);
expect(latest.gasUsed).to.be.lessThanOrEqual(ETH_BLOCK_GAS_LIMIT);
expect(ETH_BLOCK_GAS_LIMIT - latest.gasUsed).to.be.lessThan(21_000);
});
Expand All @@ -276,20 +276,20 @@ describeWithFrontier("Frontier RPC (Gas limit Weightv2 pov size)", (context) =>
const STORAGE_LOOP_CONTRACT_BYTECODE = StorageLoop.bytecode;
const STORAGE_LOOP_CONTRACT_ABI = StorageLoop.abi as AbiItem[];

// Big transfer
const CONTRACT_TRANSFER_EFFECTIVE_GAS = 109_116;
// First call to contract storageLoop method
const FIRST_CALL = 752_450;
const FIRST_CALL = 611_438;
// Rest of calls
const CALL_COST = 735_350;
const CALL_COST = 594_338;
// Block gas limit
const BLOCK_GAS_LIMIT = ETH_BLOCK_GAS_LIMIT - FIRST_CALL;
const BLOCK_GAS_LIMIT = ETH_BLOCK_GAS_LIMIT - (FIRST_CALL + CONTRACT_TRANSFER_EFFECTIVE_GAS);
// Number of calls per block
const CALLS_PER_BLOCK = Math.floor(BLOCK_GAS_LIMIT / CALL_COST) + 1;
const CALLS_PER_BLOCK = Math.floor(BLOCK_GAS_LIMIT / CALL_COST) + 1; // +1 to count first call
// Available space left after all calls
const REMNANT = Math.floor(ETH_BLOCK_GAS_LIMIT - (CALL_COST * (CALLS_PER_BLOCK - 1) + FIRST_CALL));
// Big transfer
const CONTRACT_TRANSFER_EFFECTIVE_GAS = 100_520;
const REMNANT = Math.floor(BLOCK_GAS_LIMIT - CALL_COST * (CALLS_PER_BLOCK - 1));
// Number of transfers per available space left
const TRANSFERS_PER_BLOCK = Math.floor((REMNANT - CONTRACT_TRANSFER_EFFECTIVE_GAS) / 21_000);
const TRANSFERS_PER_BLOCK = Math.floor(REMNANT / 21_000) + 1; // +1 to count big transfer

let contractAddress;
before("create the contract", async function () {
Expand Down Expand Up @@ -377,7 +377,7 @@ describeWithFrontier("Frontier RPC (Gas limit Weightv2 pov size)", (context) =>
},
GENESIS_ACCOUNT_PRIVATE_KEY
);
let r = await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]);
await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]);
nonce++;
}

Expand Down

0 comments on commit 8810310

Please sign in to comment.