Skip to content

Commit

Permalink
e2e_test: Check receipts in smoke tests (#263)
Browse files Browse the repository at this point in the history
I needed to update chai due to chaijs/chai#1652
  • Loading branch information
karlb authored Dec 9, 2024
1 parent f102315 commit e649949
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
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

0 comments on commit e649949

Please sign in to comment.