mevlog 0.9.3

EVM transactions monitoring and querying CLI/TUI powered by Revm
Documentation
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
#[cfg(test)]
pub mod tests {
    use std::process::Command;

    use eyre::Result;

    fn tracing_modes() -> Vec<String> {
        vec!["rpc".to_string(), "revm".to_string()]
    }

    // cargo run --bin mevlog search -b 22045570 -p 0 --rpc-url $ETH_RPC_URL --evm-trace rpc --format json-pretty
    #[test]
    fn test_cli_search() -> Result<()> {
        for tracing_mode in tracing_modes() {
            let cmd = Command::new("cargo")
                .env("RUST_LOG", "off")
                .arg("run")
                .arg("--bin")
                .arg("mevlog")
                .arg("search")
                .arg("-b")
                .arg("22045570")
                .arg("-p")
                .arg("0")
                .arg("--rpc-url")
                .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
                .arg("--evm-trace")
                .arg(tracing_mode)
                .arg("--format")
                .arg("json-pretty")
                .output()
                .expect("failed to execute CLI");

            let output = String::from_utf8(cmd.stdout).unwrap();
            let expected_content = ["\"full_tx_cost\""];
            for expected in expected_content {
                assert!(
                    output.contains(expected),
                    "Expected:\n{expected}\n\nGot:\n{output}"
                );
            }
        }

        Ok(())
    }

    // cargo run --bin mevlog tx 0x06fed3f7dc71194fe3c2fd379ef1e8aaa850354454ea9dd526364a4e24853660 --rpc-url $ETH_RPC_URL --evm-trace rpc --format json-pretty
    #[test]
    fn test_cli_tx() -> Result<()> {
        for tracing_mode in tracing_modes() {
            let cmd = Command::new("cargo")
                .env("RUST_LOG", "off")
                .arg("run")
                .arg("--bin")
                .arg("mevlog")
                .arg("tx")
                .arg("0x06fed3f7dc71194fe3c2fd379ef1e8aaa850354454ea9dd526364a4e24853660")
                .arg("--rpc-url")
                .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
                .arg("--evm-trace")
                .arg(tracing_mode)
                .arg("--format")
                .arg("json-pretty")
                .output()
                .expect("failed to execute CLI");

            let output = String::from_utf8(cmd.stdout).unwrap();
            let expected_content = ["\"full_tx_cost\""];
            for expected in expected_content {
                assert!(
                    output.contains(expected),
                    "Expected:\n{expected}\n\nGot:\n{output}"
                );
            }
        }

        Ok(())
    }

    // cargo run --bin mevlog search -b 33410345 -p 0 --rpc-url $BASE_RPC_URL --format json-pretty
    #[test]
    fn test_sig_overwrite() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("33410345")
            .arg("-p")
            .arg("0")
            .arg("--rpc-url")
            .arg(std::env::var("BASE_RPC_URL").expect("BASE_RPC_URL must be set"))
            .arg("--format")
            .arg("json-pretty")
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let expected_content = ["setL1BlockValuesIsthmus"];
        for expected in expected_content {
            assert!(
                output.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{output}"
            );
        }
    }

    // cargo run --bin mevlog search -b 22045570 -p 0:3 --rpc-url $ETH_RPC_URL --evm-trace rpc --format json-pretty --touching 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640
    #[test]
    fn test_cli_search_touching() {
        for tracing_mode in tracing_modes() {
            let cmd = Command::new("cargo")
                .env("RUST_LOG", "off")
                .arg("run")
                .arg("--bin")
                .arg("mevlog")
                .arg("search")
                .arg("-b")
                .arg("22045570")
                .arg("-p")
                .arg("0:3")
                .arg("--rpc-url")
                .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
                .arg("--evm-trace")
                .arg(tracing_mode)
                .arg("--format")
                .arg("json-pretty")
                .arg("--touching")
                .arg("0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640")
                .arg("--logs")
                .output()
                .expect("failed to execute CLI");
            let output = String::from_utf8(cmd.stdout).unwrap();
            let expected_content = [
                "\"tx_hash\": \"0x06fed3f7dc71194fe3c2fd379ef1e8aaa850354454ea9dd526364a4e24853660\"",
            ];
            for expected in expected_content {
                assert!(
                    output.contains(expected),
                    "Expected:\n{expected}\n\nGot:\n{output}"
                );
            }
            assert!(
                output.contains("\"logs\":"),
                "Expected logs to be present when --logs is set.\n\nGot:\n{output}"
            );
        }
    }

    // cargo run --bin mevlog search -b 23070298 -p 0:8 --from jaredfromsubway.eth --format json-pretty --ens --rpc-url $ETH_RPC_URL
    #[test]
    fn test_cli_search_from_ens() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("23070298")
            .arg("-p")
            .arg("0:8")
            .arg("--from")
            .arg("jaredfromsubway.eth")
            .arg("--format")
            .arg("json-pretty")
            .arg("--ens")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let expected_content = [
            "\"tx_hash\": \"0x71e7d6bb2fc19848cbedbda49f4c49c1ac32bafae0ee0dacd5540b84ca0b7937\"",
            "\"from_ens\": \"jaredfromsubway.eth\"",
            "\"to_ens\": null",
        ];
        for expected in expected_content {
            assert!(
                output.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{output}"
            );
        }
    }

    // cargo run --bin mevlog search -b 16733027 --to jaredfromsubway.eth --format json-pretty --ens --rpc-url $ETH_RPC_URL
    #[test]
    fn test_cli_search_to_ens() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("16733027")
            .arg("--to")
            .arg("jaredfromsubway.eth")
            .arg("--format")
            .arg("json-pretty")
            .arg("--ens")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let expected_content = [
            "\"tx_hash\": \"0x5b5d7168a89bf036b3e2a2b7ce130f5437fd6a60bb4da6f6c719813b3953e01c\"",
            "\"to_ens\": \"jaredfromsubway.eth\"",
            "\"from_ens\": null",
        ];
        for expected in expected_content {
            assert!(
                output.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{output}"
            );
        }
    }

    // cargo run --bin mevlog search -b 23070298 -p 2 --from jaredfromsubway.eth --format json-pretty --ens --rpc-url $ETH_RPC_URL
    #[test]
    fn test_cli_search_symbols_cache() {
        // Populate symbols cache
        let _ = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("23070298")
            .arg("-p")
            .arg("2")
            .arg("--from")
            .arg("jaredfromsubway.eth")
            .arg("--format")
            .arg("json-pretty")
            .arg("--ens")
            .arg("--erc20-symbols")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .output()
            .expect("failed to execute CLI");

        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("23070298")
            .arg("-p")
            .arg("2")
            .arg("--from")
            .arg("jaredfromsubway.eth")
            .arg("--format")
            .arg("json-pretty")
            .arg("--ens")
            .arg("--logs")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let expected_content = ["\"symbol\": \"WETH\""];
        for expected in expected_content {
            assert!(
                output.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{output}"
            );
        }
    }

    // cargo run --bin mevlog search -b 22045570 -p 0:50 --rpc-url $ETH_RPC_URL --format json-pretty --sort gas-price --limit 1
    #[test]
    fn test_cli_search_sort_limit() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("22045570")
            .arg("-p")
            .arg("0:50")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .arg("--format")
            .arg("json-pretty")
            .arg("--sort")
            .arg("gas-price")
            .arg("--limit")
            .arg("1")
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let expected_content =
            ["\"tx_hash\": \"0x3e8e989819cfc004f7fe58283bf4cc7b39d2ecea5b30e92dc891e06a653371f6\""];
        for expected in expected_content {
            assert!(
                output.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{output}"
            );
        }
    }

    // cargo run --bin mevlog search -b 22045570 -p 0:50 --rpc-url $ETH_RPC_URL --format json-pretty --sort gas-price --sort-dir asc --limit 1
    #[test]
    fn test_cli_search_sort_limit_asc() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("22045570")
            .arg("-p")
            .arg("0:50")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .arg("--format")
            .arg("json-pretty")
            .arg("--sort")
            .arg("gas-price")
            .arg("--sort-dir")
            .arg("asc")
            .arg("--limit")
            .arg("1")
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let expected_content =
            ["\"tx_hash\": \"0x06fed3f7dc71194fe3c2fd379ef1e8aaa850354454ea9dd526364a4e24853660\""];
        for expected in expected_content {
            assert!(
                output.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{output}"
            );
        }
    }

    // cargo run --bin mevlog chain-info --chain-id 1 --format json-pretty --skip-urls
    #[test]
    fn test_cli_format_chain_info() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("chain-info")
            .arg("--chain-id")
            .arg("1")
            .arg("--format")
            .arg("json-pretty")
            .arg("--skip-rpcs")
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let expected_content = ["\"chain_id\": 1", "\"name\": \"Ethereum Mainnet\""];
        for expected in expected_content {
            assert!(
                output.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{output}"
            );
        }
    }

    // cargo run --bin mevlog chain-info --chain-id 0 --format json-pretty
    #[test]
    fn test_cli_format_chain_info_error() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("chain-info")
            .arg("--chain-id")
            .arg("0")
            .arg("--format")
            .arg("json-pretty")
            .output()
            .expect("failed to execute CLI");

        let err = String::from_utf8(cmd.stderr).unwrap();
        assert!(err.contains("\"error\": \"Chain ID 0 not found\""));
    }

    // cargo run --bin mevlog chains --filter arbitrum --format json-pretty
    #[test]
    fn test_cli_chains_filter_json() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("chains")
            .arg("--filter")
            .arg("arbitrum")
            .arg("--format")
            .arg("json-pretty")
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let expected_content = ["\"name\": \"Arbitrum One\""];
        for expected in expected_content {
            assert!(
                output.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{output}"
            );
        }
    }

    // cargo run --bin mevlog search -b 0 --rpc-url $ETH_RPC_URL --format json-pretty
    #[test]
    fn test_cli_format_search() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("0")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .arg("--format")
            .arg("json-pretty")
            .output()
            .expect("failed to execute CLI");

        let err = String::from_utf8(cmd.stderr).unwrap();
        let expected_content = ["\"error\": \"Invalid block number: 0\""];
        for expected in expected_content {
            assert!(
                err.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{err}"
            );
        }
    }

    // cargo run --bin mevlog search -b 22045570 -p 0:3 --rpc-url $ETH_RPC_URL --format json-pretty
    #[test]
    fn test_cli_format_search_position_range() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("22045570")
            .arg("-p")
            .arg("0:3")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .arg("--format")
            .arg("json-pretty")
            .output()
            .expect("failed to execute CLI");

        let err = String::from_utf8(cmd.stderr).unwrap();
        assert!(cmd.status.success(), "CLI failed:\n{err}");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let json: serde_json::Value = serde_json::from_str(&output).unwrap();
        let txs = json["result"]
            .as_array()
            .expect("result should be an array");
        assert_eq!(txs.len(), 4);
    }

    // cargo run --bin mevlog tx 0x7138e07de04d486f99f0117de27026272f33786a5aeeffc0913aef7951dfb1c8 --rpc-url $ETH_RPC_URL --format json-pretty
    #[test]
    fn test_cli_format_tx_create_addr() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("tx")
            .arg("0x7138e07de04d486f99f0117de27026272f33786a5aeeffc0913aef7951dfb1c8")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .arg("--format")
            .arg("json-pretty")
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let json: serde_json::Value = serde_json::from_str(&output).unwrap();
        let txs = json["result"]
            .as_array()
            .expect("result should be an array");
        assert_eq!(txs.len(), 1, "Expected one transaction, got:\n{output}");
        assert_eq!(
            txs[0]["to"].as_str(),
            Some("0x7290f841536a3f73835ffad72d27b8c905e1b497"),
            "Expected CREATE destination address in envelope, got:\n{output}"
        );
        assert_eq!(
            txs[0]["signature"].as_str(),
            Some("CREATE()"),
            "Expected CREATE signature in envelope, got:\n{output}"
        );
        assert_eq!(
            json["query"]["command"].as_str(),
            Some("tx"),
            "Expected tx query metadata in envelope, got:\n{output}"
        );
    }

    // cargo run --bin mevlog search -b 23305021:23305023 --rpc-url $ETH_RPC_URL --format json-pretty --sort 'erc20Transfer|0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
    #[test]
    fn test_cli_format_search_erc20_transfer() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("-b")
            .arg("23305021:23305023")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .arg("--format")
            .arg("json-pretty")
            .arg("--sort")
            .arg("erc20Transfer|0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")
            .output()
            .expect("failed to execute CLI");

        let expected_content =
            ["\"tx_hash\": \"0xc09b81a9817686083b401b33c8c2df6b09ae4263b15395636bf53e212a0756f4\""];

        let output = String::from_utf8(cmd.stdout).unwrap();
        for expected in expected_content {
            assert!(
                output.contains(expected),
                "Expected:\n{expected}\n\nGot:\n{output}",
            );
        }

        assert!(
            !output.contains("\"logs\":"),
            "Expected logs to be omitted by default in json format.\n\nGot:\n{output}",
        );
    }

    // cargo run --bin mevlog search --to 0x9008D19f58AAbD9eD0D60971565AA8510560ab41 -b 23632775:23632875 --sort 'erc20Transfer|0x6982508145454ce325ddbe47a25d4ec3d2311933' --limit 1 --chain-id 1 --format json --rpc-url $ETH_RPC_URL
    #[test]
    fn test_cli_erc20_transfer_filters() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("search")
            .arg("--to")
            .arg("0x9008D19f58AAbD9eD0D60971565AA8510560ab41")
            .arg("-b")
            .arg("23632775:23632875")
            .arg("--sort")
            .arg("erc20Transfer|0x6982508145454ce325ddbe47a25d4ec3d2311933")
            .arg("--limit")
            .arg("1")
            .arg("--chain-id")
            .arg("1")
            .arg("--format")
            .arg("json")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let json: serde_json::Value = serde_json::from_str(&output).expect("should be valid JSON");
        let txs = json["result"]
            .as_array()
            .expect("result should be an array");
        assert!(txs.is_empty(), "Expected empty txs array, got:\n{output}");
    }

    // cargo run --bin mevlog tx 0x71b78307c2e604576efe962cc49e1b64f69409aac5eef0466302add48fe25b0e --rpc-url $ETH_RPC_URL --evm-ops --evm-trace revm --format json-pretty
    #[test]
    fn test_cli_opcodes_tracing() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("tx")
            .arg("0x71b78307c2e604576efe962cc49e1b64f69409aac5eef0466302add48fe25b0e")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .arg("--evm-ops")
            .arg("--evm-trace")
            .arg("revm")
            .arg("--format")
            .arg("json-pretty")
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let json: serde_json::Value = serde_json::from_str(&output).expect("should be valid JSON");
        let txs = json["result"]
            .as_array()
            .expect("result should be an array");
        assert!(!txs.is_empty(), "Expected at least one transaction");
        assert!(
            txs[0].get("evm_opcodes").is_some(),
            "Expected evm_opcodes field in transaction:\n{output}"
        );
        let opcodes = txs[0]["evm_opcodes"]
            .as_array()
            .expect("evm_opcodes should be an array");
        assert!(!opcodes.is_empty(), "Expected non-empty evm_opcodes array");
        assert_eq!(
            opcodes[0]["op"].as_str(),
            Some("PUSH1"),
            "Expected first opcode to be PUSH1"
        );
    }

    // cargo run --bin mevlog tx 0xe7657d9eac810efacf20a1715013edb02f7811270f11feaa040ded37c8ec2bd9 --rpc-url $BASE_RPC_URL --evm-ops --evm-trace revm --format json-pretty
    #[test]
    fn test_op_stack_opcodes_tracing() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("tx")
            .arg("0xe7657d9eac810efacf20a1715013edb02f7811270f11feaa040ded37c8ec2bd9")
            .arg("--rpc-url")
            .arg(std::env::var("BASE_RPC_URL").expect("BASE_RPC_URL must be set"))
            .arg("--evm-ops")
            .arg("--evm-trace")
            .arg("revm")
            .arg("--format")
            .arg("json-pretty")
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        let json: serde_json::Value = serde_json::from_str(&output).expect("should be valid JSON");
        let txs = json["result"]
            .as_array()
            .expect("result should be an array");
        assert!(!txs.is_empty(), "Expected at least one transaction");
        assert!(
            txs[0].get("evm_opcodes").is_some(),
            "Expected evm_opcodes field in transaction:\n{output}"
        );
        let opcodes = txs[0]["evm_opcodes"]
            .as_array()
            .expect("evm_opcodes should be an array");
        assert!(!opcodes.is_empty(), "Expected non-empty evm_opcodes array");
        assert_eq!(
            opcodes[0]["op"].as_str(),
            Some("PUSH1"),
            "Expected first opcode to be PUSH1"
        );
    }

    // cargo run --bin mevlog debug-available --rpc-url $ETH_RPC_URL
    #[test]
    fn test_cli_debug_available_true() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("debug-available")
            .arg("--rpc-url")
            .arg(std::env::var("ETH_RPC_URL").expect("ETH_RPC_URL must be set"))
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        assert!(output.trim() == "true", "Expected: true\n\nGot:\n{output}");
    }

    // cargo run --bin mevlog debug-available --rpc-url https://eth.merkle.io
    #[test]
    fn test_cli_debug_available_false() {
        let cmd = Command::new("cargo")
            .env("RUST_LOG", "off")
            .arg("run")
            .arg("--bin")
            .arg("mevlog")
            .arg("debug-available")
            .arg("--rpc-url")
            .arg("https://eth.merkle.io")
            .output()
            .expect("failed to execute CLI");

        let output = String::from_utf8(cmd.stdout).unwrap();
        assert!(
            output.trim() == "false",
            "Expected: false\n\nGot:\n{output}"
        );
    }
}