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

hardlydifficult-test-helpers

v0.4.0

Published

Test helpers for Ethereum.

Downloads

14

Readme

HardlyDifficult Truffle Test Helpers

Test helpers for Ethereum.

Test Contracts

These helpers which will deploy contracts for testing using the exact bytecode and configuration as they have on mainnet, with the exception that you are the owner to enable privileged actions such as mint.

You can deploy these to Ganache or any network for testing. The scripts simply use your current web3 configuration.

Using these will give you an accurate representation of gas costs, error conditions, and any oddities to their specific implementation.

Take a look at the tests for a more complete example of each use case

Tokens

  • DAI: ERC-20 with 18 decimals and a mint function
  • USDC: an upgradable ERC-20 with 6 decimals and mint and blacklist functions

Usage example:

const { tokens } = require("hardlydifficult-test-helpers");
const daiOwner = accounts[0];

// Deploy a DAI contract for testing
const dai = await tokens.dai.deploy(web3, daiOwner);

// Mint tokens
await dai.mint(accounts[1], 100, { from: daiOwner });

Protocols

Unlock-Protocol

unlock-protocol.com:

Unlock is a membership protocol, built on a blockchain. It enables creators to monetize their content or software without relying on a middleman. It lets consumers manage all of their subscriptions in a consistent way, as well as earn discounts when they share the best content and applications they use.

Usage example:

const { protocols } = require("hardlydifficult-test-helpers");
const unlockOwner = accounts[0];

// Deploy the protocol
const unlockProtocol = await protocols.unlock.deploy(web3, unlockOwner);

// Create a new Lock
const tx = await unlockProtocol.createLock(
  60 * 60 * 24, // expirationDuration (in seconds) of 1 day
  web3.utils.padLeft(0, 40), // tokenAddress for ETH
  web3.utils.toWei("0.01", "ether"), // keyPrice
  100, // maxNumberOfKeys
  "Test Lock", // lockName
  {
    from: accounts[1]
  });
const lock = await protocols.unlock.getLock(
  web3,
  tx.logs[1].args.newLockAddress
);

// Buy a Key to that Lock
await lock.purchaseFor(accounts[2], {
  from: accounts[2],
  value: await lock.keyPrice()
});

Fairmint continous organizations (not yet launched)

Fairmint.co:

The continuous financing model enables organizations to finance themselves in a permission-less and non-dilutive way by continuously issuing tokens called FAIR while aligning stakeholders to their financial success.

Usage example:

const { protocols } = require("hardlydifficult-test-helpers");
const control = accounts[1];

// Deploy a new c-org (see test for complete list of call options)
const contracts = await protocols.cOrg.deploy(web3, {
  control
});

// You must simulate KYC for to enable new accounts
await contracts.whitelist.approve(accounts[9], true, { from: control })

// Buy FAIR tokens
await dat.buy(accounts[9], "10000000000000", 1, {
  from: accounts[9],
  value: "10000000000000"
});

Uniswap DEX

docs.Uniswap.io:

Designed with simplicity in mind, the Uniswap protocol provides an interface for seamless exchange of ERC20 tokens on Ethereum.

Usage example:

const { tokens, protocols } = require("hardlydifficult-test-helpers");
const protocolOwner = accounts[0];

// Deploy uniswap
const uniswap = await protocols.uniswap.deploy(web3, protocolOwner);
// And a token for testing
const dai = await tokens.dai.deploy(web3, protocolOwner);

// Create an exchange
const tx = await uniswap.createExchange(dai.address, { from: protocolOwner });
const exchange = await protocols.uniswap.getExchange(
  web3,
  tx.logs[0].args.exchange
);

// Mint some tokens for testing and approve the exchange
await dai.mint(protocolOwner, "10000000000", { from: protocolOwner });
await dai.approve(exchange.address, -1, { from: protocolOwner });

// Add liquidity to the exchange
await exchange.addLiquidity(
  "1",
  "10000000000",
  Math.round(Date.now() / 1000) + 60,
  {
    from: protocolOwner,
    value: "10000000000"
  }
);

// ...now you can trade!