Skip to content

Commit

Permalink
Fix effectiveGasPrice computation for eth_getTransactionReceipt (#2610)
Browse files Browse the repository at this point in the history
  • Loading branch information
elfedy authored Jan 16, 2024
1 parent efd724e commit 6e83cb7
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 23 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

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

54 changes: 54 additions & 0 deletions test/suites/dev/test-eth-rpc/test-eth-rpc-transaction-receipt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { describeSuite, expect, beforeAll } from "@moonwall/cli";
import { ApiPromise } from "@polkadot/api";
import { BALTATHAR_ADDRESS, createViemTransaction, extractFee } from "@moonwall/util";

describeSuite({
id: "D1206",
title: "Ethereum RPC - eth_getTransactionReceipt",
foundationMethods: "dev",
testCases: ({ it, context, log }) => {
let polkadotJs: ApiPromise;

beforeAll(() => {
polkadotJs = context.polkadotJs();
});

it({
id: "T01",
title:
"should have correct effectiveGasPrice when fee multiplier changes in consecutive blocks",
test: async function () {
const prevBlockNextFeeMultiplier = (
await polkadotJs.query.transactionPayment.nextFeeMultiplier()
).toBigInt();

const { result } = await context.createBlock(
await createViemTransaction(context, {
gas: 21_000n,
maxFeePerGas: 1_000_000_000_000_000n,
maxPriorityFeePerGas: 1n,
type: "eip1559",
to: BALTATHAR_ADDRESS,
})
);
const txHash = result?.hash;
const txFee = extractFee(result?.events)!.amount.toBigInt();

const txReceipt = await context.viem().getTransactionReceipt({ hash: txHash });
const txReceiptFee = txReceipt.effectiveGasPrice * txReceipt.gasUsed;

const txBlockNextFeeMultiplier = (
await polkadotJs.query.transactionPayment.nextFeeMultiplier()
).toBigInt();

// NOTE: fee multiplier needs to be different to ensure the test does not
// yield a false positive. If some conditions make these values equal, some
// extra transactions need to be added to the second block to make the
// values differ.
expect(prevBlockNextFeeMultiplier).not.toEqual(txBlockNextFeeMultiplier);

expect(txReceiptFee).toEqual(txFee);
},
});
},
});

0 comments on commit 6e83cb7

Please sign in to comment.