This repository was archived by the owner on Apr 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
116 lines (95 loc) · 2.61 KB
/
index.ts
File metadata and controls
116 lines (95 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import "dotenv/config";
import * as fs from "node:fs";
import {
type Chain,
createPublicClient,
createWalletClient,
http,
parseEther,
} from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia, monadTestnet, riseTestnet } from "viem/chains";
const TEST_PRIVATE_KEY = process.env.PRIVATE_KEY as `0x${string}`;
const account = privateKeyToAccount(TEST_PRIVATE_KEY);
const LOG_FILE = "test-results.txt";
const logs: string[] = [];
function log(message: string) {
console.log(message);
logs.push(message);
}
function writeLogsToFile() {
fs.writeFileSync(LOG_FILE, logs.join("\n"));
}
type ChainConfig = {
chain: Chain;
rpcUrl?: string;
};
const CHAINS: ChainConfig[] = [
{ chain: baseSepolia },
{ chain: riseTestnet },
{ chain: monadTestnet },
];
// const TIMEOUT = 20_000;
const TIMEOUT = undefined;
async function testChain(config: ChainConfig): Promise<void> {
const { chain, rpcUrl } = config;
log(`\n${"=".repeat(60)}`);
log(`Testing: ${chain.name} (chainId: ${chain.id})`);
log("=".repeat(60));
const walletClient = createWalletClient({
account,
chain,
transport: http(rpcUrl),
});
const publicClient = createPublicClient({
chain,
transport: http(rpcUrl),
});
const startTime = Date.now();
try {
const gasPrice = await publicClient.getGasPrice();
const serializedTransaction = await walletClient.signTransaction({
account,
to: account.address,
value: parseEther("0.0001"),
gasPrice,
gas: 21000n,
});
log("Signed transaction, sending...");
const receipt = await walletClient.sendRawTransactionSync({
serializedTransaction,
timeout: TIMEOUT,
});
const elapsed = Date.now() - startTime;
log(`Status: ${receipt.status}`);
log(`Transaction hash: ${receipt.transactionHash}`);
log(`Block number: ${receipt.blockNumber}`);
log(`Elapsed: ${elapsed}ms`);
log("Result: SUCCESS");
} catch (error) {
const elapsed = Date.now() - startTime;
log(`Elapsed: ${elapsed}ms`);
log(`Result: FAILED`);
log(`Error: ${error instanceof Error ? error.message : String(error)}`);
if (error instanceof Error && error.cause) {
log(`Cause: ${JSON.stringify(error.cause, null, 2)}`);
}
}
}
async function main() {
log(`Testing sendRawTransactionSync across multiple chains`);
log(`Timestamp: ${new Date().toISOString()}`);
log(`Account: ${account.address}`);
for (const config of CHAINS) {
await testChain(config);
}
log(`\n${"=".repeat(60)}`);
log("All tests completed!");
writeLogsToFile();
console.log(`\nLogs written to ${LOG_FILE}`);
}
main().catch((error) => {
log(`Fatal error: ${error}`);
writeLogsToFile();
console.error(error);
});