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

@roaminroe/koinos-mock-vm

v1.1.3

Published

Koinos-Mock-VM is a NodeJS application/package that allows you to run WASM Koinos smart contracts without deploying the contracts to the Koinos blockchain. It is a tool that you can leverage to build unit tests for your smart contracts.

Downloads

1

Readme

koinos-mock-vm

Koinos-Mock-VM is a NodeJS application/package that allows you to run WASM Koinos smart contracts without deploying the contracts to the Koinos blockchain. It is a tool that you can leverage to build unit tests for your smart contracts.

Requirements:

You need to install NodeJS v16 or higher download

Installation:

# with npm
npm install -g koinos-mock-vm

# with yarn
yarn global add koinos-mock-vm

Interact with the mock vm

koinos-mock-vm leverages the Koinos system calls to enable a wasm contract to interact with the mock vm, which means that any Koinos wasm contract can use it out of the box.

The put_object system call is used to insert mock data in the database powering the mock vm. When calling a system call, like get_entry_point, the mock vm will pull the mock data that was initially set in the database. The metadata system space is used to store the mock data. (space zone = "", space id = 0, system = true)

List of keys used to store the mock data:

  • entry_point:
    • object of type koinos.chain.value_type with the int32_value property set with the entry point
    • used by the system call get_entry_point
  • contract_arguments:
    • object of type bytes set with the contract arguments
    • used by the system call get_contract_argument
  • contract_result:
    • object of type bytes set with the contract result
    • used by the system call set_contract_result
  • contract_id:
    • object of type bytes set with the contract id
    • usde by the system call get_contract_id
  • head_info:
    • object of type koinos.chain.head_info set with the head info
    • used by the system call get_head_info
  • caller:
    • object of type koinos.chain.caller_data set with the caller data info
    • used by the system call get_caller
  • last_irreversible_block:
    • object of type koinos.chain.value_type with the uint64_value property set with the last irreversible block height
    • used by the system call get_last_irreversible_block
  • transaction:
    • object of type koinos.protocol.transaction set with the transaction info
    • used by the system calls get_transaction and get_transaction_field
  • block:
    • object of type koinos.protocol.block set with the block info
    • used by the system calls get_block and get_block_field
  • authority:
    • object of type koinos.chain.list_type. Each koinos.chain.value_type elements represent an authorization:
      • int32_value: value of the koinos.chain.authorization_type
      • bytes_value: bytes of the account address
      • bool_value: "autorized" boolean
    • used by the system call require_authority:
      • will use the require_authority arguments (type and account) to lookup the autorization in the previously set koinos.chain.list_type
  • call_contract_results:
    • object of type koinos.chain.list_type. Each koinos.chain.value_type elements represent a contract call result:
      • bytes_value: bytes of the contract call result
    • used by the system call call_contract:
      • will use the previously set koinos.chain.list_type to return a call result. The call contract results are FIFO meaning that the first call_contract will use the first element you set in the list, the second call the second element in the list, etc...
  • logs:
    • object of type koinos.chain.list_type. Each koinos.chain.value_type has its string_value set with a log
    • used by the system call log
  • events:
    • object of type koinos.chain.list_type. Each koinos.chain.value_type has its bytes_value set with a koinos.protocol.event_data object
    • used by the system call event
  • exit_code:
    • object of type koinos.chain.exit_contract_arguments
    • used by the system call exit_contract

The following keys are additional commands that allow you to interact with the mock vm's database:

  • reset:
    • whatever object as argument
    • will reset the database
  • rollback_transaction:
    • whatever object as argument
    • will restore the backup made in the previous commit_transaction
  • commit_transaction:
    • whatever object as argument
    • will save a backup of the actual state of the database (useful when trying to build unit tests around transaction reversions)

Example for setting the contract id in an AssemblyScript Koinos smart contract:

const metadataSpace = new chain.object_space();
metadataSpace.system = true;
metadataSpace.id = 0;

System.putBytes(metadataSpace, 'contract_id', Base58.decode('1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe'));

const contractId = System.getContractId();
System.log('contractId: ' + Base58.encode(contractId));
// will print contractId: 1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe

Usage as a CLI

You can execute multiple smart contracts in one run, they will be executed in the order they appear in the command parameters. The koinos-mock-vm database will be shared between each execution allowing you to build complex executions cases that involve several contracts.

koinos-mock-vm <path to contract wasm 1> <path to contract wasm 2> ... <path to contract wasm n>

Usage as a NodeJS package

See index.js file in the bin folder.

CLI Example

koinos-mock-vm contract.wasm

[Starting VM] 1 contracts to execute
[Execution started] contract.wasm
[Log] entryPoint: 3282800625
[Log] contract_arguments: myArgs
[Log] contract_id: 1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe
[Execution completed] in 16.232577ms contract.wasm
[Stopping VM] exit code 0