LiquidApps Documentation
  • Introduction
  • 🧙‍♂️The DAPP Network
    • The DAPP Token
      • DAPP Token Overview
      • DAPP Tokens Tracks
      • Claiming DAPP Tokens
      • DAPP Tokens Distribution
      • Air-HODL
    • Cross Chain Bridges
    • Examples
      • Token bridge
      • Price Feed
      • Elemental Battles
      • LiquidChess
      • LiquidPortfolio
    • DAPP Network Resources
      • @liquidapps/dapp-client
        • vRAM
        • LiquidAccounts
        • DAPP Services
        • Air-Hodl
      • eosio-push-guarantee
      • Link Library
        • EOSIO Link
          • Tables
          • Crons
          • Macros
          • Variables
        • EVM Link - Solidity (Coming Soon)
  • ⚡Working with Zeus
    • Introduction
      • Requirements
      • Install Zeus and Unboxing
        • More on zeus-box.json
      • Get Started fast! (Zeus-IDE)
      • Docker CI/CD
      • Example Github Using Zeus
      • Getting started with AntelopeIO Contracts (formerly EOSIO)
    • Zeus Basics
      • Compiling Contracts
        • Clean CMake Files
      • Unit Testing
        • Printing Console
        • Fetching Table
        • Helper Functions
        • Example
      • Create ...
        • Contract/Unit Test
          • All DAPP Network Services
        • DSP Service
        • Contract Deployment
      • Import/Export Keys
      • Migrate Contract
      • Start local environment
        • Kill Services
      • Upgrade
      • Zeus RC File
      • Zeus Config File
    • Zeus Box Basics
      • Zeus Boxes Directory
        • Services
          • Oracles
        • Sample Boxes
        • Other Boxes
          • DAPP Network
          • SDKs
            • ETH-SDK
            • EOS SDK
          • Frontends
          • Extensions
          • Tests
          • Seeds
          • Microservices
          • Meta Boxes
          • Libraries
          • Game
          • EOS Framework
          • Economics
          • Templates
      • Add/Remove
      • Deploy
      • List Boxes
  • ⚙️DAPP Network Services
    • DAPP Network Services
      • vRAM
        • Getting Started Guide
          • Compile and Deploy
          • Staking for services
          • Test
          • Basic implementation
        • Smart Contract Macros
          • dapp::multi_index
        • Tools
          • DAPP Client Integration
            • get_vram_row
          • Zeus Commands
          • Scripts
            • Get table
            • Get ordered keys
        • Additional Features
          • Save load and reset dapp::multi_index data
          • Advanced Features
      • LiquidAccounts
        • Getting Started Guide
          • Compile and Deploy
          • Staking for services
          • Test
            • DAPP Client
          • Basic Implementation
          • DAPP Account
        • Smart Contract Macros
          • payload
          • VACCOUNTS_APPLY
          • require_vaccount
          • VACCOUNTS_DELAYED_CLEANUP
        • Tools
          • DAPP Client Integration
            • push_liquid_account_transaction
          • Zeus Commands
            • Zeus vaccounts push-action
          • Scripts
            • Deserialize Payload
        • Use between contracts
        • Use Between Chains
      • LiquidHarmony
        • Getting Started Guide
          • Compile and Deploy
          • Staking for services
          • Test
          • Basic Implementation
          • API DSP Key Storage
        • Smart Contract Macros
          • geturi
          • ORACLE_HOOK_FILTER
        • Creating an Oracle Request
          • HTTP/HTTPS GET/POST JSON
            • HTTP/HTTPS GET
            • HTTP/HTTPS GET JSON
            • HTTP/HTTPS POST
            • HTTP/HTTPS POST JSON
          • ECHO GET/POST JSON
            • ECHO GET
            • ECHO GET JSON
            • ECHO POST
            • ECHO POST JSON
          • Nodeos History Get
          • Sister Chain Fetch
            • sister_chain_block
            • sister_chain_history
            • sister_chain_info
            • sister_chain_last_irreversible
            • sister_chain_table_row
          • Foreign Chain Fetch
            • ethereum
              • endpoints
              • block_number
              • history
              • balance
              • storage
            • tron
              • endpoints
              • balance
              • block_number
              • block
              • transactions
              • transaction
            • cardano
              • endpoints
              • blocks
              • history
              • state
            • ripple
              • endpoints
              • balance
              • ledger
              • transactions
            • bitcoin
              • endpoints
              • balance
              • block
              • history
              • transaction
            • litecoin
              • endpoints
              • balance
              • block
              • history
              • transaction
            • bitcoin cash
              • endpoints
              • balance
              • block
              • history
              • transaction
          • Wolfram Alpha
          • Random Number
          • Stockfish
          • SQL
        • Additional Features
          • Pre geturi hook
          • Don't spend CPU condition
      • LiquidScheduler
        • Getting Started Guide
          • Compile and Deploy
          • Staking for Services
          • Basic Implementation
        • Smart Contract Macros
          • schedule_timer
          • remove_timer
          • timer_callback
          • start_interval
          • remove_interval
        • Additional Features
          • Don't spend CPU condition
      • LiquidStorage
        • Getting Started Guide
          • Compile and Deploy
          • Staking for Services
          • Test
          • Basic Implementation
        • Tools
          • Zeus Commands
            • zeus storage upload
            • zeus storage unpin
          • DAPP Client Integration
            • get_uri
            • unpin_public_file
            • upload_archive_to_liquidstorage
            • upload_file_to_liquidstorage
            • upload_public_file_from_vaccount
        • Example GET Static Web Page
      • LiquidLink
        • Getting Started Guide
          • Compile and Deploy
          • Staking for services
          • Test
          • Basic Implementation
        • Smart Contract Macros
          • svc_sign_signtrx
      • LiquidAuth
        • Getting Started Guide
          • Compile and Deploy
          • Staking for services
          • Test
          • Basic Implementation
        • Tools
          • DAPP Client Integration
            • invokeAuthedCall
      • DAPP Service Macros
        • CONTRACT_START
        • CONTRACT_END
        • DAPPSERVICES_ACTIONS
        • DAPPSERVICE_ACTIONS_COMMANDS
      • Additional Services
      • Smart Contract Console Log Syntax
      • Using on_notify with services
    • Packages and Staking
  • 👨‍🚀DAPP Service Providers
    • Introduction to DAPP Service Providers
    • DSPs
      • Architecture Overview
      • Setup DSP
        • Blockchain Account
        • EOSIO Node
          • Firehose Setup
        • IPFS
          • Adding peers
            • Reconnecting Peers Periodically
          • Bootsrapping from an existing IPFS Cluster
          • Running a private network
        • PostgreSQL Database Backend
          • How to wipe local database
        • Ethereum Virtual Machine Node Setup
        • DSP Node
          • Logs
            • Monitor all logs script
        • Register Package
          • Modify Package metadata
          • Enable/Disable Package
          • Update cost per action in QUOTA
          • More on Packages
          • Whitelist Stakers
        • Test Setup
        • Known attack vectors
      • DSP Maintenance
        • Upgrade DSP Node
        • Claim Rewards
        • Replay Contract
        • Cleanup IPFS and Oracle Entries
        • Consumer Pays CPU Permissions
      • DSP API Endpoints
        • Event
        • Version
        • vRAM
        • LiquidLink
        • LiquidStorage
        • LiquidAccounts
  • 👨‍💻DAPP NETWORK LABS
    • Introduction
    • DAPP Workers
    • EdgeDSPs
    • EdgeOS
  • 🌉CROSS CHAIN BRIDGES
    • Getting Started with LiquidBridge
      • EOSIO.token <> EOSIO.token Fungible Tokens
      • EOSIO.token <> ERC20 Fungible Tokens
        • EOSIO Side Setup
        • EVM Side Setup
          • Setup EVM Contracts
            • Setup EVM Token Contract
              • Initialize Token and Transfer Ownership
            • Setup EVM Tokenpeg Contract
            • Verify and Publish Source Code
              • token contract and overview
              • tokenpeg contract
        • Initialize EOSIO Side
        • Test bridge
      • EOSIO <> EOSIO Atomic Assets Non-Fungible Tokens
      • EOSIO Atomic Assets <> ERC721 Non-Fungible Tokens
        • EOSIO Side Setup
        • EVM Side Setup
          • Setup EVM ERC721 Contract
          • Setup EVM Atomictokenpeg Contract
          • Transfer Ownership
          • Verify Source Code
        • Initialize EOSIO Side
        • Test bridge
      • EOSIO Atomic Assets <> ERC1155 Non-Fungible Tokens
        • EOSIO Side Setup
        • EVM Side Setup
          • Setup Proxy Contract
          • Setup EVM ERC1155 Contract
          • Setup EVM ERC1155 Tradeable Contract
          • Transfer Ownership of ERC1155 contract to atomictokenpeg1155 contract
        • Initialize EOSIO Side
        • Test bridge
  • ⛓️LiquidX Stake Across Chains
    • Getting Started with LiquidX
      • Use DAPP Network Services
        • Smart Contract Steps
        • Add DSP on New Chain
        • Map Mainnet to New Chain
        • Map New Chain to Mainnet
      • Become a DSP on another chain
        • Editing config.toml file
        • Push DSP account mapping action
      • Example Chains to Add
        • CoVax
        • WAX
        • WAX Test
        • Telos
        • Telos Test
        • BOS
      • Add a Chain to LiquidX
        • Create accounts and set dappservicex contract
        • Register chain
  • 😷COVAX
    • Getting Started with CoVax Chain
      • Become a DAPP Service Provider
      • Become a Block Producer
  • 🗂️Blockchain Guides
    • Testnet Creation Guides
      • Create Binance Smart Chain Testnet Account
        • Add Binance Smart Chain Testnet Network to Metamask
        • Create EVM keypair
        • Get faucet funds
      • Create WAX Testnet Account
      • Creating Jungle 3 account
      • Create Mumbai Testnet Account (Matic-Polygon)
        • Get faucet funds
      • Creating CryptoKylin Account
      • Create Rinkeby Testnet Account
        • Change Metamask network to Rinkeby
        • Get faucet funds
    • Governance Guides
      • How to submit a proposal
      • How the Proposal System Works
      • Governance Rewards
      • How to Propose an MSIG
      • Update dappservices contract by msig
      • Setup MSIG Telegram Bot
      • Governance Contracts
      • Governance Frontend
      • Propose Payment by Msig
  • 🗒️Release Notes
    • Latest
    • History
      • 2.0.8191
      • 2.0.7966
      • 2.0.7931
      • 2.1.7848
      • 2.0.7735
      • 2.0.7661
      • 2.0.7644
      • 2.0.7622
      • 2.1.7420
      • 2.1.7301
      • 2.1.7111
      • 2.0.6808
      • 2.0.5328
      • 2.0.4719
      • 2.0.4002
      • 2.0.3107
      • 2.0.2812
      • 2.0.2527
  • 🙋‍♀️FAQs
    • Frequently Asked Questions The DAPP Token
    • Frequently Asked Questions DAPP Service Providers (DSPs)
    • Frequently Asked Questions vRAM
Powered by GitBook
On this page
  • Article over viewing unit tests
  • Customize your own unit tests

Was this helpful?

  1. Working with Zeus
  2. Zeus Basics

Unit Testing

Unit testing with Zeus is quick and easy. Zeus also provides support for easily integrating DAPP Network services into your contracts.

PreviousClean CMake FilesNextPrinting Console

Last updated 2 years ago

Was this helpful?

Unit testing with Zeus is highly customizable and easy to configure. The following example explains how to use the main helper functions to write your own test.

You can also test with truffle npx truffle test.

To run all of the available unit tests in the ./tests directory run:

zeus test
zeus test [contract]

test

Options:
  --version                          Show version number               [boolean]
  --storage-path                     path for persistent storage
                                                   [default: "/home/anon/.zeus"]
  --rc-file                          use rc file to load options from
                                       [default: "/home/anon/.zeus/zeusrc.json"]
  --rc-ignore                        ignore rc file             [default: false]
  --verbose, -v                                                 [default: false]
  -h, --help                         Show help                         [boolean]
  --wallet, -w                       keosd wallet to use       [default: "zeus"]
  --creator-key                      private key to set contract to
                [default: "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]
  --creator, -a                      eos account to set contract to
                                                              [default: "eosio"]
  --reset                            reset local environment     [default: true]
  --chain                            chain to work on              [default: ""]
  --network                          network to work on [default: "development"]
  --compile, -c                      compile contract(s)        [default: false]
  --stake, -s                        account staking amount     [default: "300"]
  --transfer                         account staking amount    [default: "1000"]
  --basic-env, -b                    min needed for EOSIO smart contract test
                                                                [default: false]
  --services                         service APIs to run           [default: ""]
  --backend                          backend API to stream trxs, firehose ||
                                     state_history_plugin || ""
                                               [default: "state_history_plugin"]
  --delete-logs, -d                  delete logs folder before starting test
                                                                [default: false]
  --multi-evm                        run multiple evm chains    [default: false]
  --enable-features                  enables eosio features      [default: true]
  --enable-features-list             enables eosio features, list:
                                     KV_DATABASE,ACTION_RETURN_VALUE,CONFIGURABL
                                     E_WASM_LIMITS,BLOCKCHAIN_PARAMETERS,ONLY_BI
                                     LL_FIRST_AUTHORIZER,DISALLOW_EMPTY_PRODUCER
                                     _SCHEDULE,ONLY_LINK_TO_EXISTING_PERMISSION,
                                     FIX_LINKAUTH_RESTRICTION,RAM_RESTRICTIONS,R
                                     EPLACE_DEFERRED,NO_DUPLICATE_DEFERRED_ID,RE
                                     STRICT_ACTION_TO_SELF,FORWARD_SETCODE,GET_S
                                     ENDER,WEBAUTHN_KEY,CONFIGURABLE_WASM_LIMITS
                                     2,WTMSIG_BLOCK_SIGNATURES,GET_CODE_HASH,CRY
                                     PTO_PRIMITIVES,GET_BLOCK_NUM  [default: ""]
  --single-chain                     run without LiquidX        [default: false]
  --custom-token                     custom chain token            [default: ""]
  --custom-token-precision           custom chain token permission  [default: 4]
  --evm-host                         custom evm host      [default: "127.0.0.1"]
  --evm-port                         custom evm port             [default: 8545]
  --evm-sister-host                  custom evm sister host
                                                          [default: "127.0.0.1"]
  --evm-sister-port                  custom evm sister port      [default: 8546]
  --external-evm-endpoint            external evm endpoint         [default: ""]
  --external-evm-private-key         external evm private key      [default: ""]
  --external-evm-sister-endpoint     external evm sister endpoint  [default: ""]
  --external-evm-sister-private-key  external evm sister private key
                                                                   [default: ""]
  --kill-services                    kill all current running nodes and services
                                     after running tests         [default: true]
  --legacy-cdt                       compile cmake files using cdt version <
                                     3.0.0                      [default: false]
  --docker                           enable to use docker       [default: false]
  --ipfs-postgres                    enable to use postgresql to fetch/add IPFS
                                     files                      [default: false]

Examples:
  zeus test contract
  zeus test
  zeus test --kill-services
  zeus test contract -c
  zeus test -c
  zeus test --services "ipfs,cron,oracle,sign,vaccounts"
  zeus test --chain eos --single-chain
npx truffle test

--ipfs-postgres option requires running PostgreSQL instance locally at

postgresql://postgres:password@localhost:5432/postgres with the ollowing instructions https://github.com/alanshaw/ipfs-ds-postgres#usage

Article over viewing unit tests

Customize your own unit tests

To generate this file see the section.

in zeus_boxes/tests/mycontract.spec.js

require('mocha');

const { requireBox } = require('@liquidapps/box-utils');
const { assert } = require('chai'); // Using Assert style
const { getCreateKeys } = requireBox('eos-keystore/helpers/key-utils');
const { getCreateAccount } = requireBox('seed-eos/tools/eos/utils');

const artifacts = requireBox('seed-eos/tools/eos/artifacts');
const deployer = requireBox('seed-eos/tools/eos/deployer');
const { getEosWrapper } = requireBox('seed-eos/tools/eos/eos-wrapper');

const contractCode = '<%- contractname %>';
const ctrt = artifacts.require(`./${contractCode}/`);
const { eosio } = requireBox('test-extensions/lib/index');
let deployedContract;

describe(`${contractCode} Contract`, () => {
    const code = '<%- contractname %>';
    let tableHelper;
    before(done => {
        (async () => {
            try {
                tableHelper = await deployer.deploy(ctrt, code);
                const keys = await getCreateAccount(code);
                const eosTestAcc = getEosWrapper({
                  keyProvider: keys.active.privateKey,
                  httpEndpoint: 'http://localhost:8888'
                });
                deployedContract = await eosTestAcc.contract(code);
                done();
            }
            catch (e) {
                done(e);
            }
        })();
    });

    it('test assert', done => {
        (async () => {
            try {
                await deployedContract.testassert({
                    message: "hello"
                }, {
                  authorization: `${code}@active`,
                  broadcast: true,
                  sign: true
                });
                
                let failed = false;
                try {
                    await deployedContract.testassert({
                        message: "nothello"
                    }, {
                      authorization: `${code}@active`,
                      broadcast: true,
                      sign: true
                    });
                } catch(e) {
                    failed = true;
                }
                assert(failed,"should have failed");
                
                const newAccountKeys = await getCreateAccount("newaccount");
                
                done();
            }
            catch (e) {
                done(e);
            }
        })();
    });

    it('test console print', done => {
        (async () => {
            try {
                const message = "testing";
                const res = await deployedContract.testprint({
                    message
                }, {
                  authorization: `${code}@active`,
                  broadcast: true,
                  sign: true
                });
                const console_print = res.processed.action_traces[0].console;
                assert(console_print,message);
                done();
            }
            catch (e) {
                done(e);
            }
        })();
    });

    it('test get table', done => {
        (async () => {
            try {
                const res = await tableHelper.eos.getTableRows({
                    code: "eosio.token",
                    scope: code,
                    table: "accounts",
                    json: true
                });
                // console.log(res.rows[0]);
                const balance = res.rows[0].balance.replace(' SYS', '');
                assert.equal(balance, '1000.0000');
                done();
            }
            catch (e) {
                done(e);
            }
        })();
    });
});
⚡
https://medium.com/@NatPDeveloper/intro-to-antelope-smart-contract-unit-testing-with-zeus-50a6c1d7efce
Create