Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support integer u64 in eth_feeHistory #3018

Merged
merged 7 commits into from
Oct 31, 2024
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
52 changes: 26 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 61 additions & 28 deletions test/suites/dev/moonbase/test-eth-fee/test-eth-fee-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describeSuite({

async function createBlocks(
block_count: number,
reward_percentiles: number[],
priority_fees: number[],
max_fee_per_gas: string
) {
Expand All @@ -45,7 +44,7 @@ describeSuite({
}
}

function get_percentile(percentile: number, array: number[]) {
function getPercentile(percentile: number, array: number[]) {
array.sort(function (a, b) {
return a - b;
});
Expand All @@ -57,6 +56,30 @@ describeSuite({
}
}

function matchExpectations(
feeResults: FeeHistory,
block_count: number,
reward_percentiles: number[]
) {
expect(
feeResults.baseFeePerGas.length,
"baseFeePerGas should always the requested block range + 1 (the next derived base fee)"
).toBe(block_count + 1);
expect(feeResults.gasUsedRatio).to.be.deep.eq(Array(block_count).fill(0.0105225));
expect(
feeResults.reward.length,
"should return two-dimensional reward list for the requested block range"
).to.be.eq(block_count);

const failures = feeResults.reward.filter((item) => {
item.length !== reward_percentiles.length;
});
expect(
failures.length,
"each block has a reward list which's size is the requested percentile list"
).toBe(0);
}

it({
id: "T01",
title: "result length should match spec",
Expand All @@ -83,31 +106,9 @@ describeSuite({
});
});

await createBlocks(
block_count,
reward_percentiles,
priority_fees,
parseGwei("10").toString()
);

const feeResults = await feeHistory;
expect(
feeResults.baseFeePerGas.length,
"baseFeePerGas should always the requested block range + 1 (the next derived base fee)"
).toBe(block_count + 1);
expect(feeResults.gasUsedRatio).to.be.deep.eq(Array(block_count).fill(0.0105225));
expect(
feeResults.reward.length,
"should return two-dimensional reward list for the requested block range"
).to.be.eq(block_count);
await createBlocks(block_count, priority_fees, parseGwei("10").toString());

const failures = feeResults.reward.filter((item) => {
item.length !== reward_percentiles.length;
});
expect(
failures.length,
"each block has a reward list which's size is the requested percentile list"
).toBe(0);
matchExpectations(await feeHistory, block_count, reward_percentiles);
},
});

Expand Down Expand Up @@ -139,11 +140,11 @@ describeSuite({
});
});

await createBlocks(block_count, reward_percentiles, priority_fees, max_fee_per_gas);
await createBlocks(block_count, priority_fees, max_fee_per_gas);

const feeResults = await feeHistory;
const localRewards = reward_percentiles
.map((percentile) => get_percentile(percentile, priority_fees))
.map((percentile) => getPercentile(percentile, priority_fees))
.map((reward) => numberToHex(reward));
// We only test if BaseFee update is enabled.
//
Expand All @@ -165,5 +166,37 @@ describeSuite({
).toBe(0);
},
});

it({
id: "T03",
title: "result length should match spec using an integer block count",
timeout: 40_000,
test: async function () {
const block_count = 2;
const reward_percentiles = [20, 50, 70];
const priority_fees = [1, 2, 3];
const startingBlock = await context.viem().getBlockNumber();

const feeHistory = new Promise<FeeHistory>((resolve, reject) => {
const unwatch = context.viem().watchBlocks({
onBlock: async (block) => {
if (Number(block.number! - startingBlock) == block_count) {
const result = (await customDevRpcRequest("eth_feeHistory", [
block_count,
"latest",
reward_percentiles,
])) as FeeHistory;
unwatch();
resolve(result);
}
},
});
});

await createBlocks(block_count, priority_fees, parseGwei("10").toString());

matchExpectations(await feeHistory, block_count, reward_percentiles);
},
});
},
});
Loading