Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Add test for transaction with maxFeePerGas between latest.baseFeePerG…
Browse files Browse the repository at this point in the history
…as and (higher) next.baseFeePerGas
  • Loading branch information
jeffsmale90 committed Apr 7, 2022
1 parent 940f945 commit a22238f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/chains/ethereum/ethereum/src/transaction-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export default class TransactionPool extends Emittery<{ drain: undefined }> {
);
}

// transaction maxGasPerFee must be greater or equal to baseFeePerGas _of the pending block_
// transaction maxGasPerFee must be greater or equal to baseFeePerGas _of the next block_
if ("maxFeePerGas" in transaction && !transaction.maxFeePerGas.isNull()) {
const nextBaseFee = Block.calcNextBaseFee(this.#blockchain.blocks.latest);
if (transaction.maxFeePerGas.toBigInt() < nextBaseFee) {
Expand Down
36 changes: 36 additions & 0 deletions src/chains/ethereum/ethereum/tests/transaction-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,40 @@ describe("transaction pool", async () => {
transaction.serialized.toString()
);
});

it("rejects a transaction if it's maxFeePerGas is lower than the baseFeePerGas of the next block", async () => {
/*
* even if the transaction's maxFeePerGas is greater than baseFeePerGas of "latest"
*
* we set up the chain with a "latest" block that used a lot of gas so that the gas price is driven up for the next block
* baseFeePerGas for "latest" is 875000000
* baseFeePerGas for "next" is 984378337
*/
const chain = {
...blockchain,
blocks: {
latest: { header: { baseFeePerGas: Quantity.from(875000000), gasUsed: Quantity.from(0xffff), gasLimit: Quantity.from(0xffff) } }
}
};

const txPool = new TransactionPool(options.miner, chain, origins);
const maxFeePerGasGreaterThanLatestButLessThanNext = 900000000;
const lowGasRpc: TypedRpcTransaction = {
from: from,
type: "0x2",
maxFeePerGas: "0x" + maxFeePerGasGreaterThanLatestButLessThanNext.toString(16),
gasLimit: "0xffff",
nonce: "0x0"
};
const lowGasTx = TransactionFactory.fromRpc(lowGasRpc, common);

await assert.rejects(
txPool.prepareTransaction(lowGasTx),
{
code: -32003,
message: "max fee per gas less than block base fee"
},
"transaction with maxFeePerGas lower than the maxFeePerGas of the next block should have been rejected"
);
});
});

0 comments on commit a22238f

Please sign in to comment.