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

smartweave-testing

v0.2.0

Published

A testing client for SmartWeave contracts.

Downloads

5

Readme

SmartWeave Testing

A testing client for SmartWeave contracts. You can execute any kind of interactWrite input against your contract. It does not require any connection to Arweave. This enables fast and reliable testing. The new state of the contract will be stored and by this enabling multi input testing.

Installation

yarn add --dev smartweave-testing

Usage

import SmartWeaveTester from "smartweave-testing"
import { handle } from [my-contract]

const caller = "..." // -> e.g your Arweave Address
const initialState = {}
const smartweave = new SmartWeaveTester(handle, initialState, caller)

Executing an action

input = { function: "my_function" };
result = await smartweave.execute(input); // -> state of the contract

In case you don't want to update the state of your contract use execute({}, false)

Manipulating block height

If your contract uses SmartWeave.block.height, the client will make use of it's internal block logic. Every time you execute an action, the block height will increase by 1. You can use smartweave.block.height = ... to manually adjust the block height.

Setting transaction information

If you want to use custom transaction information like tags, quantity or a target, you can add these into the constructor or the execute function:

import {TransactionInput} from "smartweave-testing/faces";

const txInformation: TransactionInput = {
  quantity: {winston: "1"} // -> quantity in winston,
  target: "...."
} 
result = await smartweave.execute(input, true, txInformation);

Examples

import SmartWeaveTester from "smartweave-testing"
import { handle } from [my-contract]

const caller = "..." // -> e.g your Arweave Address

const initialState = {
  balances: {}
}

const smartweave = new SmartWeaveTester(handle, initialState, caller)

let input, result;

// the dispense function increases the callers balance by 100
input = { function: "dispense" };
result = await smartweave.execute(input);
if (result.balances[caller] !== 100) throw Error("Dispense does not work")

// be rerunning the action, the old state is preserved and get's updated
input = { function: "dispense" };
result = await smartweave.execute(input);
if (result.balances[caller] !== 200) throw Error("Dispense does not work")