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

e2e_test: Check receipts in smoke tests #263

Merged
merged 1 commit into from
Dec 9, 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
18 changes: 9 additions & 9 deletions e2e_test/js-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e_test/js-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 16 additions & 6 deletions e2e_test/js-tests/test_viem_smoketest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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});
});
});
});
5 changes: 4 additions & 1 deletion e2e_test/js-tests/test_viem_tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});

Expand Down
Loading