December 15, 2025

I’ve been working on the CLI for my smart contract fuzzer. Its main job is to find contract files, compile them and generate Rust bindings. This involves a lot of reading and writing to the disk.

Testing this is annoying. I didn’t want to mess with temp files or clean up directories after every test. I wanted to mock the filesystem to run everything in memory. My first attempt worked but the code was hard to read. Here is how I refactored it to be cleaner.

To do this I defined a Filesystem trait. This allows me to swap between a RealFilesystem that uses std::fs for the actual app and a TestFilesystem that uses a HashMap for my tests.

My first attempt at this abstraction worked but it felt wrong. It forced me to write code that was hard to reason a…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help