Skip to content

Commit

Permalink
Add 10% buffer to base fee in just enough test
Browse files Browse the repository at this point in the history
Not that this test is running on live networks we need to account for
the case where the base fee could increase, we do this by adding a 10%
buffer.

Also ensures that we use FEE_CURRENCY2 when running local tests.

And finally adds a check to fail the test if the value of the fee
currency is not sufficiently greater than the value of celo.
  • Loading branch information
piersy committed Oct 21, 2024
1 parent 67093b9 commit 6a80458
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions e2e_test/js-tests/test_viem_tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,30 @@ describe("viem send tx", () => {
// value greater than celo, so that the base fee in fee currency becomes a
// number significantly lower than the base fee in celo. If the server
// doesn't take into account the fee currency then it will reject the
// transaction because the maxFeePerGas will be too low. Currently we use
// USDC as the fee currency and it is worth more than celo, we may need to
// update this test if that situation changes in the future.
const rate = await getRate(process.env.FEE_CURRENCY);
// transaction because the maxFeePerGas will be too low.

// If we are running local tests we use FEE_CURRENCY2 since it is worth
// double the value of celo, otherwise we use FEE_CURRENCY which is USDC
// end currently worth roughly double the value of celo.
const fc = process.env.NETWORK == null ? process.env.FEE_CURRENCY2 : process.env.FEE_CURRENCY;
const rate = await getRate(fc);
const block = await publicClient.getBlock({});
const maxFeePerGas = rate.toFeeCurrency(block.baseFeePerGas)+2n;
// We increment the base fee by 10% to cover the case where the base fee increases next block.
const convertedBaseFee = rate.toFeeCurrency(block.baseFeePerGas * 11n/10n);

// Check that the converted base fee value is still below the native base
// fee value, if this check fails we will need to consider an alternative
// fee currency to USDC for network tests.
if (convertedBaseFee >= block.baseFeePerGas) {
assert.fail(`Converted base fee (${convertedBaseFee}) not less than native base fee (${block.baseFeePerGas})`);
}
const request = await walletClient.prepareTransactionRequest({
account,
to: "0x00000000000000000000000000000000DeaDBeef",
value: 2,
gas: 171000,
feeCurrency: process.env.FEE_CURRENCY,
maxFeePerGas: maxFeePerGas,
maxFeePerGas: convertedBaseFee +2n,
maxPriorityFeePerGas: 2n,
});
const signature = await walletClient.signTransaction(request);
Expand Down

0 comments on commit 6a80458

Please sign in to comment.