Skip to content

Commit

Permalink
Fix failing e2e tests in test_viem_tx (#293)
Browse files Browse the repository at this point in the history
* Fix failing e2e tests in test_viem_tx

* Add timeout for some failing tests

* Add comments about new sleep in e2e test

* Add sleep in test_token_duality

* Revert adding sleep in e2e tests

* Fix price coefficient of tx which can't be replaced in test_viem_tx e2e test
  • Loading branch information
Kourin1996 authored Dec 17, 2024
1 parent d981efb commit e49dd9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
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 () => {
// 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");
}).timeout(10_000);
});

Expand Down

0 comments on commit e49dd9e

Please sign in to comment.