Running Tests Locally with Narya CLI

The Narya CLI tool is a powerful command-line interface that enables you to build and test your smart contract project, and interact with Narya services. In this guide, we'll show you how to install and use Narya CLI to run tests locally.

Installation

To install Narya CLI, simply run the following command in your terminal:

curl -L https://raw.githubusercontent.com/NaryaAI/narya-cli/main/script/install | bash

This command downloads and installs Narya CLI to your machine, and adds it to your $PATH.

If you need to upgrade Narya CLI to the latest version, you can run:

narya upgrade

This command will upgrade Narya CLI to the latest version available.

Usage

Initializing your Narya project

To initialize your Narya project, run:

narya init

This command installs the dependencies and Narya SDK, creates a test/invariants directory, and sets up remapping to use the Narya SDK.

Running Tests

To run invariant and property tests, run:

narya test

This command compiles your project and runs the tests automatically.

The output will show you the status of the tests, including whether they have passed or failed. For example:

$ narya test
Building project...
Testing...

Tests (4)
[√] test/invariants/FundLossTest_1671121896.sol:FundLossTest:invariantCheckFund()
[√] test/invariants/FundLossTest_1671156195.sol:FundLossTest:invariantCheckFund()
[√] test/invariants/FundLossTest_1671181213.sol:FundLossTest:invariantCheckFund()

[✕] test/invariants/OwnerNotChangedTest_1672380141.sol:OwnerNotChangedTest:invariantOwnerNotChanged()
  [3057] OwnerNotChangedTest::invariantOwnerNotChanged()
    ├─ [194] OwnerNotChangedTest::getOwner()
    │   └─ ← 0x0000000000000000000000000000000000000000
    └─ ← "Ownership changes!"


Total: 4, Success: 3, Fail: 1
Time: 26s

The following invariant(s) reverted, it's likely the Narya engine will also fail if push as-is.
• File: test/invariants/OwnerNotChangedTest_1672380141.sol, Contract: OwnerNotChangedTest, Function: invariantOwnerNotChanged()

A Test report generated at ./reports/report_1672973405.zip. To view the report, visit the following URL and upload the report zip file:

https://app.narya.ai/debugger

Please refer to the call trace for more information and try running the test again after fixing the issue.

Working with Narya templates

To work with Narya templates, you can use the narya template subcommand. Narya templates are pre-written invariant tests that you can use to test your smart contract.

To list available templates, run:

narya template

To install a specific Narya template, run:

narya template --install <template_name>

Data collection and metrics

Narya CLI collects anonymous usage data and metrics to help improve the tool. If you prefer to opt-out of metrics upload, run:

touch ~/.narya/.metrics_disabled

Alternatively, you can set the environment variable NARYA_DISABLE_METRICS to true:

export NARYA_DISABLE_METRICS

Next step

Now it's time to push the code and run the tests on the powerful cloud engine to battle test your contracts!