Skip to content

Commit

Permalink
fix(trace): only throw when no receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Jan 3, 2025
1 parent 4912a90 commit a510911
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
node-version: 22
cache: yarn

- uses: foundry-rs/foundry-toolchain@v1.2.0
- uses: foundry-rs/foundry-toolchain@v1

- run: yarn --frozen-lockfile

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"lodash.kebabcase": "^4.1.1",
"semantic-release": "^24.2.0",
"typescript": "^5.7.2",
"viem": "^2.21.54",
"viem": "^2.22.2",
"viem-deal": "^2.0.4",
"vitest": "^2.1.8"
},
Expand Down
9 changes: 6 additions & 3 deletions src/format.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync, writeFileSync } from "node:fs";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { dirname, join } from "node:path";
import colors from "colors/safe";
import {
type Address,
Expand Down Expand Up @@ -189,7 +189,10 @@ export async function formatFullTrace(
signatures.events[sig as Hex] = match;
});

writeFileSync(getSignaturesCachePath(), JSON.stringify(signatures));
const path = getSignaturesCachePath();
if (!existsSync(path)) mkdirSync(dirname(path), { recursive: true });

writeFileSync(path, JSON.stringify(signatures));
} else {
console.warn(
`Failed to fetch signatures for unknown selectors: ${unknownFunctionSelectors},${unknownEventSelectors}`,
Expand Down
5 changes: 2 additions & 3 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ export function traced<transport extends Transport>(
await new Promise((resolve) => setTimeout(resolve, 250));
}

if (receipt?.status === "0x0") throw await traceCall();

throw new WaitForTransactionReceiptTimeoutError({ hash: res as Hash });
if (!receipt) throw new WaitForTransactionReceiptTimeoutError({ hash: res as Hash });
if (receipt.status === "0x0") throw await traceCall();
} catch (error) {
if (error instanceof ExecutionRevertedTraceError) throw error;

Expand Down
12 changes: 6 additions & 6 deletions test/traceCall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe("traceCall", () => {
0 ↳ CALL (0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48).transfer(0xf39Fd6…0xf3, 100000000) -> ERC20: transfer amount exceeds balance
1 ↳ DELEGATECALL (0x43506849d7c04f9138d1a2050bbf3a0c054402dd).transfer(0xf39Fd6…0xf3, 100000000) -> ERC20: transfer amount exceeds balance
Version: viem@2.21.54]
Version: viem@2.22.2]
`);
});

Expand All @@ -108,7 +108,7 @@ describe("traceCall", () => {
0 ↳ CALL (0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48).transfer(0xf39Fd6…0xf3, 100000000) -> ERC20: transfer from the zero address
1 ↳ DELEGATECALL (0x43506849d7c04f9138d1a2050bbf3a0c054402dd).transfer(0xf39Fd6…0xf3, 100000000) -> ERC20: transfer from the zero address
Version: viem@2.21.54]
Version: viem@2.22.2]
`);
});

Expand All @@ -133,7 +133,7 @@ describe("traceCall", () => {
sender: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
Docs: https://viem.sh/docs/contract/writeContract
Version: viem@2.21.54]
Version: viem@2.22.2]
`);

client.transport.tracer.failed = true;
Expand Down Expand Up @@ -173,7 +173,7 @@ describe("traceCall", () => {
0 ↳ CALL (0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48).transfer(0xf39Fd6…0xf3, 100000000) -> ERC20: transfer amount exceeds balance
1 ↳ DELEGATECALL (0x43506849d7c04f9138d1a2050bbf3a0c054402dd).transfer(0xf39Fd6…0xf3, 100000000) -> ERC20: transfer amount exceeds balance
Version: viem@2.21.54]
Version: viem@2.22.2]
`);
});

Expand Down Expand Up @@ -232,7 +232,7 @@ describe("traceCall", () => {
sender: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
Docs: https://viem.sh/docs/contract/writeContract
Version: viem@2.21.54]
Version: viem@2.22.2]
`);

await expect(
Expand Down Expand Up @@ -270,7 +270,7 @@ describe("traceCall", () => {
0 ↳ CALL (0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48).transfer(0xf39Fd6…0xf3, 100000000) -> ERC20: transfer amount exceeds balance
1 ↳ DELEGATECALL (0x43506849d7c04f9138d1a2050bbf3a0c054402dd).transfer(0xf39Fd6…0xf3, 100000000) -> ERC20: transfer amount exceeds balance
Version: viem@2.21.54]
Version: viem@2.22.2]
`);
});
});
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3496,10 +3496,10 @@ onetime@^7.0.0:
dependencies:
mimic-function "^5.0.0"

ox@0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ox/-/ox-0.1.2.tgz#0f791be2ccabeaf4928e6d423498fe1c8094e560"
integrity sha512-ak/8K0Rtphg9vnRJlbOdaX9R7cmxD2MiSthjWGaQdMk3D7hrAlDoM+6Lxn7hN52Za3vrXfZ7enfke/5WjolDww==
ox@0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/ox/-/ox-0.6.0.tgz#ba8f89d68b5e8afe717c8a947ffacc0669ea155d"
integrity sha512-blUzTLidvUlshv0O02CnLFqBLidNzPoAZdIth894avUAotTuWziznv6IENv5idRuOSSP3dH8WzcYw84zVdu0Aw==
dependencies:
"@adraffy/ens-normalize" "^1.10.1"
"@noble/curves" "^1.6.0"
Expand Down Expand Up @@ -4688,18 +4688,18 @@ viem-deal@^2.0.4:
resolved "https://registry.yarnpkg.com/viem-deal/-/viem-deal-2.0.4.tgz#308f8817893c4342182cdc944667e2acdabced13"
integrity sha512-gd1+pnLissjxYbaJ8u2UtdOOpv0o4W8RsVlSwy5w+SEasi/f5VJvrCVmE8cBrcHpvWYqoaxwj4VfJG45oLPnyQ==

viem@^2.21.54:
version "2.21.54"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.21.54.tgz#76d6f86ab8809078f1ac140ac1a2beadbc86b9f6"
integrity sha512-G9mmtbua3UtnVY9BqAtWdNp+3AO+oWhD0B9KaEsZb6gcrOWgmA4rz02yqEMg+qW9m6KgKGie7q3zcHqJIw6AqA==
viem@^2.22.2:
version "2.22.2"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.22.2.tgz#ec25affced2491ea3984cc8ce5d3d4b760ae85b1"
integrity sha512-HNATy2rwkQcC1JRYBJJujJTtVtDkWlQEB7GvAtn4GBXdbBROnjs8pGXwJAWhb/crErVk5yJ/Fh50yGtA9VZh8A==
dependencies:
"@noble/curves" "1.7.0"
"@noble/hashes" "1.6.1"
"@scure/bip32" "1.6.0"
"@scure/bip39" "1.5.0"
abitype "1.0.7"
isows "1.0.6"
ox "0.1.2"
ox "0.6.0"
webauthn-p256 "0.0.10"
ws "8.18.0"

Expand Down

0 comments on commit a510911

Please sign in to comment.