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

hardhat-exposed

v0.3.15

Published

Automatically expose internal functions for smart contract testing

Downloads

3,268

Readme

hardhat-exposed

NPM Package

A Hardhat plugin to automatically expose internal functions for smart contract testing.

Installation

npm install -D hardhat-exposed

Add to hardhat.config.js:

require('hardhat-exposed');

Note: After setting up for the first time, you may need to recompile with hardhat compile --force once.

Usage

The plugin will create "exposed" versions of your contracts that will be prefixed with the symbol $, and its internal functions will be exposed as external functions with a $ prefix as well.

These exposed contracts will be created in a contracts-exposed directory. We strongly suggest adding this directory to .gitignore.

If you have a contract called Foo, with an internal function called _get:

const Foo = ethers.getContractFactory('$Foo');
// or const Foo = artifacts.require('$Foo');

const foo = Foo.deploy();
await foo.$_get();

The plugin will also generate a constructor to initialize your abstract contracts.

For example, in this set of contracts notice that C is abstract because it doesn't call B's constructor.

contract A {
    constructor(uint a) {}
}
contract B {
    constructor(uint b) {}
}
contract C is A, B {
    constructor(uint c) A(0) {}
}

In the plugin-generated exposed version of C, there will be an additional parameter to initialize B.

contract $C is C {
    constructor(uint256 b, uint256 c) B(b) C(c) {}
}

The order of parameters in this generated constructor will be according to the linearization of the parent contracts, starting with the most base contract and ending with the most derived one. This order can be unintuitive, so in these cases make sure you test the contract was initialized as desired.

Note that if a contract is abstract because it's missing an implementation for a virtual function, the exposed contract will remain abstract too.

Storage Pointers

Some internal functions may contain storage pointers in arguments or return values.

Return values are converted to memory pointers (as long as they're not mappings, in this case it's not possible to expose the function), so a struct for example is copied to return data and readable from the tests.

Arguments that are storage pointers are replaced with an integer that is used as an index into a storage array. This allows to test function calls that act on storage such as data structures.

Configuration

Include an exposed field in your Hardhat config.

exposed: {
  include?: string[] = ['**/*'],
  exclude?: string[] = [],
  outDir?: string = 'contracts-exposed',
  prefix?: string = '$',
},