From 252d9d1a3efb47b78ecd1664909300eb503cea51 Mon Sep 17 00:00:00 2001 From: kourin Date: Tue, 10 Dec 2024 22:30:37 +0900 Subject: [PATCH 1/6] Fix failing e2e tests in test_viem_tx --- e2e_test/js-tests/test_viem_tx.mjs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/e2e_test/js-tests/test_viem_tx.mjs b/e2e_test/js-tests/test_viem_tx.mjs index a15dd8cf1b..82d9686c69 100644 --- a/e2e_test/js-tests/test_viem_tx.mjs +++ b/e2e_test/js-tests/test_viem_tx.mjs @@ -189,7 +189,7 @@ 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 () => { + it("send overlapping nonce tx in different currencies", async () => { const priceBump = 1.1; const rate = await getRate(process.env.FEE_CURRENCY); @@ -197,7 +197,7 @@ describe("viem send tx", () => { 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 / priceBump) )); const tokenCurrency = process.env.FEE_CURRENCY; const nativeCurrency = null; @@ -220,7 +220,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 / priceBump) )); await testNonceBump( currencyCap, @@ -236,7 +236,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({ @@ -263,7 +263,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 @@ -302,8 +302,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); }); From b0ef601695457c4845c4bb52cfaff989a8044a54 Mon Sep 17 00:00:00 2001 From: kourin Date: Wed, 11 Dec 2024 00:35:27 +0900 Subject: [PATCH 2/6] Add timeout for some failing tests --- e2e_test/js-tests/test_ethers_tx.mjs | 10 +++++----- e2e_test/run_all_tests.sh | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/e2e_test/js-tests/test_ethers_tx.mjs b/e2e_test/js-tests/test_ethers_tx.mjs index 3faf2d9cdf..5cffdb9f69 100644 --- a/e2e_test/js-tests/test_ethers_tx.mjs +++ b/e2e_test/js-tests/test_ethers_tx.mjs @@ -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", () => { @@ -22,7 +22,7 @@ describe("ethers.js compatibility tests with state", () => { // These assertions trigger on undefined or null assert.notEqual(block, null); assert.notEqual(block.gasLimit, null); - }); + }) it("EIP-1559 transactions supported (can get feeData)", async () => { const feeData = await provider.getFeeData(); @@ -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", [ @@ -40,7 +40,7 @@ describe("ethers.js compatibility tests with state", () => { true, ]); assert.isTrue(fullBlock.hasOwnProperty("gasLimit")); - }); + }) it("block has baseFeePerGas", async () => { const fullBlock = await provider.send("eth_getBlockByNumber", [ @@ -48,5 +48,5 @@ describe("ethers.js compatibility tests with state", () => { true, ]); assert.isTrue(fullBlock.hasOwnProperty("baseFeePerGas")); - }); + }) }); diff --git a/e2e_test/run_all_tests.sh b/e2e_test/run_all_tests.sh index 9d0675abd1..952c18d6e3 100755 --- a/e2e_test/run_all_tests.sh +++ b/e2e_test/run_all_tests.sh @@ -31,6 +31,8 @@ cd "$SCRIPT_DIR" || exit 1 # To work around this, send a transaction before running tests cast send --json --private-key "$ACC_PRIVKEY" "$TOKEN_ADDR" 'transfer(address to, uint256 value) returns (bool)' 0x000000000000000000000000000000000000dEaD 100 > /dev/null || true +sleep 5 + failures=0 tests=0 echo "Globbing with \"$TEST_GLOB\"" From c6dca3d25f26b9756cb82a9d310ed045d2ef2042 Mon Sep 17 00:00:00 2001 From: kourin Date: Wed, 11 Dec 2024 00:49:10 +0900 Subject: [PATCH 3/6] Add comments about new sleep in e2e test --- e2e_test/run_all_tests.sh | 2 +- e2e_test/test_base_fee_recipient.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e_test/run_all_tests.sh b/e2e_test/run_all_tests.sh index 952c18d6e3..8141cac8e6 100755 --- a/e2e_test/run_all_tests.sh +++ b/e2e_test/run_all_tests.sh @@ -31,7 +31,7 @@ cd "$SCRIPT_DIR" || exit 1 # To work around this, send a transaction before running tests cast send --json --private-key "$ACC_PRIVKEY" "$TOKEN_ADDR" 'transfer(address to, uint256 value) returns (bool)' 0x000000000000000000000000000000000000dEaD 100 > /dev/null || true -sleep 5 +sleep 5 # Wait for the account nonce to be updated failures=0 tests=0 diff --git a/e2e_test/test_base_fee_recipient.sh b/e2e_test/test_base_fee_recipient.sh index 030c130bf2..02ee0fe97e 100755 --- a/e2e_test/test_base_fee_recipient.sh +++ b/e2e_test/test_base_fee_recipient.sh @@ -8,6 +8,7 @@ source shared.sh # Send token and check balance tx_json=$(cast send --json --private-key $ACC_PRIVKEY $TOKEN_ADDR 'transfer(address to, uint256 value) returns (bool)' 0x000000000000000000000000000000000000dEaD 100) block_number=$(echo $tx_json | jq -r '.blockNumber' | cast to-dec) +sleep 5 # Wait for a block to be confirmed block=$(cast block --json --full $block_number) gas_used=$(echo $block | jq -r '.gasUsed' | cast to-dec) base_fee=$(echo $block | jq -r '.baseFeePerGas' | cast to-dec) From 9b1e9871f628659a2e730326a0f4c83579a22ab8 Mon Sep 17 00:00:00 2001 From: kourin Date: Wed, 11 Dec 2024 01:09:51 +0900 Subject: [PATCH 4/6] Add sleep in test_token_duality --- e2e_test/test_token_duality.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/e2e_test/test_token_duality.sh b/e2e_test/test_token_duality.sh index 355afef8c7..84cbf654b7 100755 --- a/e2e_test/test_token_duality.sh +++ b/e2e_test/test_token_duality.sh @@ -7,6 +7,9 @@ source shared.sh # Send token and check balance balance_before=$(cast balance 0x000000000000000000000000000000000000dEaD) cast send --private-key $ACC_PRIVKEY $TOKEN_ADDR 'transfer(address to, uint256 value) returns (bool)' 0x000000000000000000000000000000000000dEaD 100 + +sleep 5 + balance_after=$(cast balance 0x000000000000000000000000000000000000dEaD) echo "Balance change: $balance_before -> $balance_after" [[ $((balance_before + 100)) -eq $balance_after ]] || (echo "Balance did not change as expected"; exit 1) From 2e5aca31f22ec5152bd581f74c2a7b8152770759 Mon Sep 17 00:00:00 2001 From: kourin Date: Wed, 11 Dec 2024 01:21:28 +0900 Subject: [PATCH 5/6] Revert adding sleep in e2e tests --- e2e_test/js-tests/test_ethers_tx.mjs | 6 +++--- e2e_test/run_all_tests.sh | 2 -- e2e_test/test_base_fee_recipient.sh | 1 - e2e_test/test_token_duality.sh | 3 --- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/e2e_test/js-tests/test_ethers_tx.mjs b/e2e_test/js-tests/test_ethers_tx.mjs index 5cffdb9f69..979150af9f 100644 --- a/e2e_test/js-tests/test_ethers_tx.mjs +++ b/e2e_test/js-tests/test_ethers_tx.mjs @@ -22,7 +22,7 @@ describe("ethers.js compatibility tests with state", () => { // These assertions trigger on undefined or null assert.notEqual(block, null); assert.notEqual(block.gasLimit, null); - }) + }); it("EIP-1559 transactions supported (can get feeData)", async () => { const feeData = await provider.getFeeData(); @@ -40,7 +40,7 @@ describe("ethers.js compatibility tests with state", () => { true, ]); assert.isTrue(fullBlock.hasOwnProperty("gasLimit")); - }) + }); it("block has baseFeePerGas", async () => { const fullBlock = await provider.send("eth_getBlockByNumber", [ @@ -48,5 +48,5 @@ describe("ethers.js compatibility tests with state", () => { true, ]); assert.isTrue(fullBlock.hasOwnProperty("baseFeePerGas")); - }) + }); }); diff --git a/e2e_test/run_all_tests.sh b/e2e_test/run_all_tests.sh index 8141cac8e6..9d0675abd1 100755 --- a/e2e_test/run_all_tests.sh +++ b/e2e_test/run_all_tests.sh @@ -31,8 +31,6 @@ cd "$SCRIPT_DIR" || exit 1 # To work around this, send a transaction before running tests cast send --json --private-key "$ACC_PRIVKEY" "$TOKEN_ADDR" 'transfer(address to, uint256 value) returns (bool)' 0x000000000000000000000000000000000000dEaD 100 > /dev/null || true -sleep 5 # Wait for the account nonce to be updated - failures=0 tests=0 echo "Globbing with \"$TEST_GLOB\"" diff --git a/e2e_test/test_base_fee_recipient.sh b/e2e_test/test_base_fee_recipient.sh index 02ee0fe97e..030c130bf2 100755 --- a/e2e_test/test_base_fee_recipient.sh +++ b/e2e_test/test_base_fee_recipient.sh @@ -8,7 +8,6 @@ source shared.sh # Send token and check balance tx_json=$(cast send --json --private-key $ACC_PRIVKEY $TOKEN_ADDR 'transfer(address to, uint256 value) returns (bool)' 0x000000000000000000000000000000000000dEaD 100) block_number=$(echo $tx_json | jq -r '.blockNumber' | cast to-dec) -sleep 5 # Wait for a block to be confirmed block=$(cast block --json --full $block_number) gas_used=$(echo $block | jq -r '.gasUsed' | cast to-dec) base_fee=$(echo $block | jq -r '.baseFeePerGas' | cast to-dec) diff --git a/e2e_test/test_token_duality.sh b/e2e_test/test_token_duality.sh index 84cbf654b7..355afef8c7 100755 --- a/e2e_test/test_token_duality.sh +++ b/e2e_test/test_token_duality.sh @@ -7,9 +7,6 @@ source shared.sh # Send token and check balance balance_before=$(cast balance 0x000000000000000000000000000000000000dEaD) cast send --private-key $ACC_PRIVKEY $TOKEN_ADDR 'transfer(address to, uint256 value) returns (bool)' 0x000000000000000000000000000000000000dEaD 100 - -sleep 5 - balance_after=$(cast balance 0x000000000000000000000000000000000000dEaD) echo "Balance change: $balance_before -> $balance_after" [[ $((balance_before + 100)) -eq $balance_after ]] || (echo "Balance did not change as expected"; exit 1) From 69234e496c0acc4d02aacb7663ac8a00e004c26b Mon Sep 17 00:00:00 2001 From: kourin Date: Fri, 13 Dec 2024 00:34:42 +0900 Subject: [PATCH 6/6] Fix price coefficient of tx which can't be replaced in test_viem_tx e2e test --- e2e_test/js-tests/test_viem_tx.mjs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/e2e_test/js-tests/test_viem_tx.mjs b/e2e_test/js-tests/test_viem_tx.mjs index 82d9686c69..e42c7ba793 100644 --- a/e2e_test/js-tests/test_viem_tx.mjs +++ b/e2e_test/js-tests/test_viem_tx.mjs @@ -21,7 +21,6 @@ const testNonceBump = async ( shouldReplace, ) => { const syncBarrierRequest = await walletClient.prepareTransactionRequest({ - to: "0x00000000000000000000000000000000DeaDBeef", value: 2, gas: 22000, @@ -189,15 +188,22 @@ describe("viem send tx", () => { assert.equal(receipt.status, "success", "receipt status 'failure'"); }).timeout(10_000); + // 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 () => { - const priceBump = 1.1; + // 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) + Math.round(nativeCap * priceNearBump) )); const tokenCurrency = process.env.FEE_CURRENCY; const nativeCurrency = null; @@ -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) + Math.round(currencyCap * priceNearBump) )); await testNonceBump( currencyCap,