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
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/txpool/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
return err
}
if tx.GasTipCapIntCmp(minTip) < 0 {
return fmt.Errorf("%w: gas tip cap %v, minimum needed %v", ErrUnderpriced, tx.GasTipCap(), opts.MinTip)
return fmt.Errorf("%w: gas tip cap %v, minimum needed %v", ErrUnderpriced, tx.GasTipCap(), minTip)
}
if tx.Type() == types.BlobTxType {
// Ensure the blob fee cap satisfies the minimum blob gas price
Expand Down
31 changes: 19 additions & 12 deletions e2e_test/js-tests/test_viem_tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
} from "viem";
import { publicClient, walletClient } from "./viem_setup.mjs"

// 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 :)

const rate = await getRate(feeCurrency);
const b = await publicClient.getBlock();
const tipInFeeCurrency = rate.toFeeCurrency(tip);
return [rate.toFeeCurrency(b.baseFeePerGas) + tipInFeeCurrency, tipInFeeCurrency];
const convertedTip = rate.toFeeCurrency(tip);
return [ rate.toFeeCurrency(b.baseFeePerGas)+convertedTip, convertedTip];
}

const testNonceBump = async (
Expand Down Expand Up @@ -99,14 +99,21 @@ describe("viem send tx", () => {
}).timeout(10_000);

it("send fee currency tx with explicit gas fields and check receipt", async () => {
const [maxFeePerGas, tip] = await getGasFees(publicClient, 2n, process.env.FEE_CURRENCY);
// Our execution nodes are configured by default with a min tip of 1 wei in
// celo, which when converted to fee currency could be a higher value, so
// we need to ensure we use the min tip in fee currency when submitting a
// tx with fee a fee currency.
const [maxFeePerGasInFeeCurrency, tipInFeeCurrency] = await getGasFees(publicClient, process.env.FEE_CURRENCY, 1n);

const request = await walletClient.prepareTransactionRequest({
to: "0x00000000000000000000000000000000DeaDBeef",
value: 2,
gas: 171000,
feeCurrency: process.env.FEE_CURRENCY,
maxFeePerGas: maxFeePerGas,
maxPriorityFeePerGas: tip,
// We multiply the maxFeePerGas by 10 here to account for fluctuations in
// the base fee, since these tests can be run against a live network.
maxFeePerGas: maxFeePerGasInFeeCurrency*10n,
maxPriorityFeePerGas: tipInFeeCurrency,
});
const signature = await walletClient.signTransaction(request);
const hash = await walletClient.sendRawTransaction({
Expand Down Expand Up @@ -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.

const priceNearBump = 1.09; // slightly lower percentage than the price bump

const rate = await getRate(process.env.FEE_CURRENCY);
// Native to FEE_CURRENCY
const nativeCap = 30_000_000_000;
const bumpCurrencyCap = rate.toFeeCurrency(BigInt(Math.round(nativeCap * priceBump)));
const bumpCurrencyCap = rate.toFeeCurrency(BigInt(Math.ceil(nativeCap * priceBump)));
const failToBumpCurrencyCap = rate.toFeeCurrency(BigInt(
Math.round(nativeCap * priceNearBump)
Math.floor(nativeCap * priceNearBump)
));
const tokenCurrency = process.env.FEE_CURRENCY;
const nativeCurrency = null;
Expand All @@ -224,9 +231,9 @@ describe("viem send tx", () => {

// FEE_CURRENCY to Native
const currencyCap = 60_000_000_000;
const bumpNativeCap = rate.toNative(BigInt(Math.round(currencyCap * priceBump)));
const bumpNativeCap = rate.toNative(BigInt(Math.ceil(currencyCap * priceBump)));
const failToBumpNativeCap = rate.toNative(BigInt(
Math.round(currencyCap * priceNearBump)
Math.floor(currencyCap * priceNearBump)
));
await testNonceBump(
currencyCap,
Expand Down
Loading