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

Fix e2e tests on alfajores #320

Open
wants to merge 5 commits into
base: celo11
Choose a base branch
from
Open

Fix e2e tests on alfajores #320

wants to merge 5 commits into from

Conversation

piersy
Copy link

@piersy piersy commented Feb 4, 2025

The e2e tests were consistently failing during their cron CI workflow to run them against Alfajores.

The explicit gas fields test was failing due to having too low a gas price. This was likely because the test was using the base fee from the last block as the base fee, and the tip was small enough that when converted to fee currency it was 0. To prevent this happening again the max fee cap is set to the last block baseFee * 10 and a constant tip of 1 is set.

The overlapping nonce tx test was also failing due to replacement transactions being underpriced. I suspect this could be due to some loss of precision when during price bump adjustment and currency conversion. Modifying the price bump to be 1.11 instead of 1.1 seems to have solved this.

The explicit gas fields test was failing due to having too low a gas
price. This was likely because the test was using the base fee from the
last block as the base fee, and the tip was small enough that when
converted to fee currency it was 0. To prevent this happening again the
max fee cap is set to the last block baseFee
* 10 and a constant tip of 1 is set.

The overlapping nonce tx test was also failing due to replacement
transactions being underpriced. I suspect this could be due to some loss
of precision when during price bump adjustment and currency conversion.
Modifying the price bump to be 1.11 instead of 1.1 seems to have solved
this.
@piersy piersy requested review from ezdac and Kourin1996 February 4, 2025 18:11
maxFeePerGas: maxFeePerGas,
maxPriorityFeePerGas: tip,
maxFeePerGas: baseFeeForFeeCurrency*10n,
maxPriorityFeePerGas: 1n,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're still getting a failure here in CI.
This is because the node has a min-tip of 1 configured - however since this is denominated in fee-currency
you also have to convert the min-tip into the fee-currency.
In this case this is 2 - the log message is misleading because the unconverted value is logged as the expected value. I pushed a fix for this to this branch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, so I need to set a tip here of 2 or more?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't look up the rate, but the next CI run will reveal this. I got 2 locally so I assume the rate is 1 : 2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok instead I'll just convert to the fee currency, it's safer.

The tip needs to be convered to fee currency to meet the min tip
requirements.
Copy link

@ezdac ezdac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should be more loose with the testing conditions for bumping just to make it work better on Alfajores. To me it seems like the precision loss is on the JS side, and the Alfajores specific failure is more influenced by Alfajores exchange rates being different than on the local devnet.

Also, we should update the test to be compatible with the new version of viem.
When I run this locally with the 2.22.21 version, I get a failure:

  viem send tx
    ✔ send basic tx and check receipt (39ms)
    ✔ send basic tx using viem gas estimation and check receipt
    ✔ send fee currency tx with explicit gas fields and check receipt
    1) test gas price difference for fee currency
    ✔ send fee currency with gas estimation tx and check receipt
    ✔ send overlapping nonce tx in different currencies (40ms)
    ✔ send tx with unregistered fee currency
    ✔ send fee currency tx with just high enough gas price


  7 passing (133ms)
  1 failing

  1) viem send tx
       test gas price difference for fee currency:

      AssertionError: expected 1174566684n to equal 1409480020n
      + expected - actual

      -1174566684n
      +1409480020n

      at Context.<anonymous> (file:///Users/maximilian/code/op-geth-develop/e2e_test/js-tests/test_viem_tx.mjs:171:12)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The reason for this is explained in the test-comment, since the new version of viem includes the required fix:

// TODO fix this when viem is fixed - https://github.com/celo-org/viem/pull/20
// The expected value for the max fee should be the (baseFeePerGas * multiplier) + maxPriorityFeePerGas
// Instead what is currently returned is (maxFeePerGas * multiplier) + maxPriorityFeePerGas

// Returns the base fee per gas for the current block multiplied by 2 to account for any increase in the subsequent block.
async function getGasFees(publicClient, tip, feeCurrency) {
// Returns the base fee per gas for the current block in the given fee currency.
async function getGasFees(publicClient, feeCurrency, tip) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in the function are not really necessary anymore :)

@@ -195,15 +202,15 @@ describe("viem send tx", () => {
// more liable to result in a failure.
it("send overlapping nonce tx in different currencies", async () => {
// Note the threshold for a price bump to be accepted is 10%, i.e >= oldPrice * 1.1
const priceBump = 1.1; // minimum bump percentage to replace a transaction
const priceBump = 1.11; // minimum bump percentage to replace a transaction
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also likely that the precision loss comes from the test's rate.toFeeCurrency code not using BigInt exclusively as well as the prior usage of 64bit floating point double multiplication for the bumping.

I'd rather try to make the tests calculation more accurate before tweaking the values.

When converting the tip to fee currency the result can be zero, sending
a transaction with a zero tip even if that is the result of converting
the required 1 wei to a fee currency results in a transaction that is
not processed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants