-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix effectiveGasPrice computation for eth_getTransactionReceipt (#2610)
- Loading branch information
Showing
2 changed files
with
77 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
test/suites/dev/test-eth-rpc/test-eth-rpc-transaction-receipt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}); | ||
}, | ||
}); |