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 failing e2e tests in test_viem_tx #293

Merged
merged 6 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions e2e_test/js-tests/test_ethers_tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("ethers.js send tx", () => {
value: 1,
});
const receipt = await tx.wait();
}).timeout(10_000);
}).timeout(20_000);
});

describe("ethers.js compatibility tests with state", () => {
Expand All @@ -32,7 +32,7 @@ describe("ethers.js compatibility tests with state", () => {
assert.notEqual(feeData.maxFeePerGas, null);
assert.notEqual(feeData.maxPriorityFeePerGas, null);
assert.notEqual(feeData.gasPrice, null);
});
}).timeout(5_000);;

it("block has gasLimit", async () => {
const fullBlock = await provider.send("eth_getBlockByNumber", [
Expand Down
24 changes: 15 additions & 9 deletions e2e_test/js-tests/test_viem_tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const testNonceBump = async (
shouldReplace,
) => {
const syncBarrierRequest = await walletClient.prepareTransactionRequest({

to: "0x00000000000000000000000000000000DeaDBeef",
value: 2,
gas: 22000,
Expand Down Expand Up @@ -189,15 +188,22 @@ describe("viem send tx", () => {
assert.equal(receipt.status, "success", "receipt status 'failure'");
}).timeout(10_000);

it.skip("send overlapping nonce tx in different currencies", async () => {
const priceBump = 1.1;
// The goal is this test is to ensure that fee currencies are correctly
// taken into account when performing tx replacements. As such we want the
// prices that we use for the failed and successful tx replacements to be
// close to the threshold value, such that an invalid currency conversion is
// more liable to result in a failure.
it("send overlapping nonce tx in different currencies", async () => {
Kourin1996 marked this conversation as resolved.
Show resolved Hide resolved
// 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 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 failToBumpCurrencyCap = rate.toFeeCurrency(BigInt(
Math.round(nativeCap * priceBump) - 1,
Math.round(nativeCap * priceNearBump)
));
const tokenCurrency = process.env.FEE_CURRENCY;
const nativeCurrency = null;
Expand All @@ -220,7 +226,7 @@ describe("viem send tx", () => {
const currencyCap = 60_000_000_000;
const bumpNativeCap = rate.toNative(BigInt(Math.round(currencyCap * priceBump)));
const failToBumpNativeCap = rate.toNative(BigInt(
Math.round(currencyCap * priceBump) - 1,
Math.round(currencyCap * priceNearBump)
));
await testNonceBump(
currencyCap,
Expand All @@ -236,7 +242,7 @@ describe("viem send tx", () => {
nativeCurrency,
false,
);
}).timeout(40_000);
}).timeout(60_000);

it("send tx with unregistered fee currency", async () => {
const request = await walletClient.prepareTransactionRequest({
Expand All @@ -263,7 +269,7 @@ describe("viem send tx", () => {
}
}).timeout(10_000);

it.skip("send fee currency tx with just high enough gas price", async () => {
it("send fee currency tx with just high enough gas price", async () => {
// The idea of this test is to check that the fee currency is taken into
// account by the server. We do this by using a fee currency that has a
// value greater than celo, so that the base fee in fee currency becomes a
Expand Down Expand Up @@ -302,8 +308,8 @@ describe("viem send tx", () => {
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
assert.equal(receipt.status, "success", "receipt status 'failure'");
assert.isAtMost(receipt.effectiveGasPrice, maxFeePerGas, "effective gas price is too high");
assert.isAbove(receipt.effectiveGasPrice, Number(maxFeePerGas) * 0.7, "effective gas price is too low");
assert.isAtMost(Number(receipt.effectiveGasPrice), Number(maxFeePerGas), "effective gas price is too high");
assert.isAbove(Number(receipt.effectiveGasPrice), Number(maxFeePerGas) * 0.7, "effective gas price is too low");
Kourin1996 marked this conversation as resolved.
Show resolved Hide resolved
}).timeout(10_000);
});

Expand Down