From d520c6e5d391d8cb43d27a1f68e053eb2ce77628 Mon Sep 17 00:00:00 2001 From: Karl Bartel Date: Wed, 23 Oct 2024 15:01:40 +0200 Subject: [PATCH] e2e_test: Check receipts in smoke tests I needed to update chai due to https://github.com/chaijs/chai/issues/1652 --- e2e_test/js-tests/package-lock.json | 18 +++++++++--------- e2e_test/js-tests/package.json | 2 +- e2e_test/js-tests/test_viem_smoketest.mjs | 22 ++++++++++++++++------ e2e_test/js-tests/test_viem_tx.mjs | 5 ++++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/e2e_test/js-tests/package-lock.json b/e2e_test/js-tests/package-lock.json index 9f5835a566..6c7d7ab2e5 100644 --- a/e2e_test/js-tests/package-lock.json +++ b/e2e_test/js-tests/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "chai": "^5.0.0", + "chai": "^5.1.2", "ethers": "^6.10.0", "mocha": "^10.2.0", "viem": "^2.21.18" @@ -252,14 +252,14 @@ } }, "node_modules/chai": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/chai/-/chai-5.0.0.tgz", - "integrity": "sha512-HO5p0oEKd5M6HEcwOkNAThAE3j960vIZvVcc0t2tI06Dd0ATu69cEnMB2wOhC5/ZyQ6m67w3ePjU/HzXsSsdBA==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/chai/-/chai-5.1.2.tgz", + "integrity": "sha512-aGtmf24DW6MLHHG5gCx4zaI3uBq3KRtxeVs0DjFH6Z0rDNbsvTxFASFvdj79pxjxZ8/5u3PIiN3IwEIQkiiuPw==", "dependencies": { "assertion-error": "^2.0.1", - "check-error": "^2.0.0", + "check-error": "^2.1.1", "deep-eql": "^5.0.1", - "loupe": "^3.0.0", + "loupe": "^3.1.0", "pathval": "^2.0.0" }, "engines": { @@ -293,9 +293,9 @@ } }, "node_modules/check-error": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.0.0.tgz", - "integrity": "sha512-tjLAOBHKVxtPoHe/SA7kNOMvhCRdCJ3vETdeY0RuAc9popf+hyaSV6ZEg9hr4cpWF7jmo/JSWEnLDrnijS9Tog==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz", + "integrity": "sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==", "engines": { "node": ">= 16" } diff --git a/e2e_test/js-tests/package.json b/e2e_test/js-tests/package.json index c09c0fc483..16167bf83a 100644 --- a/e2e_test/js-tests/package.json +++ b/e2e_test/js-tests/package.json @@ -9,7 +9,7 @@ "author": "", "license": "MIT", "dependencies": { - "chai": "^5.0.0", + "chai": "^5.1.2", "ethers": "^6.10.0", "mocha": "^10.2.0", "viem": "^2.21.18" diff --git a/e2e_test/js-tests/test_viem_smoketest.mjs b/e2e_test/js-tests/test_viem_smoketest.mjs index 50b2d1a810..ce7cdaa1c5 100644 --- a/e2e_test/js-tests/test_viem_smoketest.mjs +++ b/e2e_test/js-tests/test_viem_smoketest.mjs @@ -12,11 +12,16 @@ const testContractJSON = JSON.parse(fs.readFileSync(process.env.COMPILED_TEST_CO // check checks that the receipt has status success and that the transaction // type matches the expected type, since viem sometimes mangles the type when // building txs. -async function check(txHash, type) { +async function check(txHash, tx_checks, receipt_checks) { const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash }); assert.equal(receipt.status, "success", "receipt status 'failure'"); const transaction = await publicClient.getTransaction({ hash: txHash }); - assert.equal(transaction.type, type, "transaction type does not match"); + for (const [key, expected] of Object.entries(tx_checks ?? {})) { + assert.equal(transaction[key], expected, `transaction ${key} does not match`); + } + for (const [key, expected] of Object.entries(receipt_checks ?? {})) { + assert.equal(receipt[key], expected, `receipt ${key} does not match`); + } } // sendTypedTransaction sends a transaction with the given type and an optional @@ -59,18 +64,23 @@ async function sendTypedCreateTransaction(type, feeCurrency) { ["legacy", "eip2930", "eip1559", "cip64"].forEach(function (type) { describe("viem smoke test, tx type " + type, () => { - const feeCurrency = type == "cip64" ? process.env.FEE_CURRENCY : undefined; + const feeCurrency = type == "cip64" ? process.env.FEE_CURRENCY.toLowerCase() : undefined; + let l1Fee = 0n; + if (!process.env.NETWORK) { + // Local dev chain does not have L1 fees (Optimism is unset) + l1Fee = undefined; + } it("send tx", async () => { const send = await sendTypedTransaction(type, feeCurrency); - await check(send, type); + await check(send, {type, feeCurrency}, {l1Fee}); }); it("send create tx", async () => { const create = await sendTypedCreateTransaction(type, feeCurrency); - await check(create, type); + await check(create, {type, feeCurrency}, {l1Fee}); }); it("send contract interaction tx", async () => { const contract = await sendTypedSmartContractTransaction(type, feeCurrency); - await check(contract, type); + await check(contract, {type, feeCurrency}, {l1Fee}); }); }); }); diff --git a/e2e_test/js-tests/test_viem_tx.mjs b/e2e_test/js-tests/test_viem_tx.mjs index 07832fe8ac..a15dd8cf1b 100644 --- a/e2e_test/js-tests/test_viem_tx.mjs +++ b/e2e_test/js-tests/test_viem_tx.mjs @@ -286,13 +286,14 @@ describe("viem send tx", () => { if (convertedBaseFee >= block.baseFeePerGas) { assert.fail(`Converted base fee (${convertedBaseFee}) not less than native base fee (${block.baseFeePerGas})`); } + const maxFeePerGas = convertedBaseFee + 2n; const request = await walletClient.prepareTransactionRequest({ to: "0x00000000000000000000000000000000DeaDBeef", value: 2, gas: 171000, feeCurrency: process.env.FEE_CURRENCY, feeCurrency: fc, - maxFeePerGas: convertedBaseFee +2n, + maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: 2n, }); const signature = await walletClient.signTransaction(request); @@ -301,6 +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"); }).timeout(10_000); });