npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

forge-deep

v0.2.2

Published

Codegen pretty-printing and deep equality Solidity functions for the Forge testing framework

Downloads

5

Readme

forge-deep

forge-deep generates pretty-printing and deep equality Solidity functions for the Forge testing framework.

Usage

Requirements

forge-deep is built on bun.

# Install bun (for macOS, Linux, and WSL)
curl -fsSL https://bun.sh/install | bash

Your Solidity repository needs to be using forge and have forge-std and solady installed (and updated if necessary):

# `forge-std` is installed on `forge init` 
forge install foundry-rs/forge-std # ^1.5.5
forge install Vectorized/solady # ^0.0.90

Config

You will need a forge-deep.toml file in your repository's root directory. For example:

# The generated code will be written to this file
dest = 'lib/DeepTest.sol'
# Directory to look for Solidity compiler artifacts (forge uses 'out' by default)
artifacts = 'out'
# forge-deep will generate functions for all user-defined value types, enums, structs, and array types used in these contracts
contracts = ['src/Zoo.sol']
# forge-deep will generate functions for the following types, which may be defined outside of the contracts listed above
types = ['Plants.Cactus', 'Zoo.Animal']

For each contract listed in contracts, forge-deep will find every user-defined value type, enum, and struct defined in that contract, as well as any static or dynamic array types used anywhere in the contract generating pretty-print and deep equality functions for each one.

For more fine-grained control over which types to generate code for, you can use types. forge-deep will look for those specific user-defined value types, enums, structs, and array types in the artifacts directory.

If forge-deep encounters an array element or struct members which is itself a user-defined value type, enum, struct, or array, it will recursively look for the definition and generate code for that type.

Codegen

# Compile existing contracts
forge build
# Generate `DeepTest.sol`
bunx --bun forge-deep

And that's it –– a contract containing the generated prettyPrint and assertDeepEq functions now exists at the dest specified in forge-deep.toml.

Provided Solidity functions

forge-deep generates an abstract contract, whose name is determined by dest in forge-deep.toml.

abstract contract DeepTest is Test {
    using LibString for *;
    
    ...

For each type processed by forge-deep, it generates internal functions with the following signatures (Zoo.Habitat is a struct in the code below, other types work similarly):

    function prettyPrint(Zoo.Habitat memory a)
        internal
        pure
        returns (string memory)

    function assertDeepEq(Zoo.Habitat memory a, Zoo.Habitat memory b)
        internal

To use these functions in your tests, simply have the test contract inherit DeepTest and call these functions. Note that forge test must be run with verbosity at least -vv to show logs.

Development

Requirements

forge-deep is built on bun.

# Install bun (for macOS, Linux, and WSL)
curl -fsSL https://bun.sh/install | bash

Install Foundry is you don't already have it.

Test

# We'll be generating this ourselves
rm lib/DeepTest.sol
# Compile but ignore our test contract, which uses `DeepTest.sol`
forge build --skip test
# Generate `DeepTest.sol`
bun run --bun generate
# Run test
forge test -vv