Unit Testing
Unit testing with Zeus is quick and easy. Zeus also provides support for easily integrating DAPP Network services into your contracts.
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:
Test
Options
Truffle
zeus test
zeus test [contract]
​
test
​
Options:
--version Show version number [boolean]
--storage-path path for persistent storage
[default: "/home/ubuntu/.zeus"]
--rc-file use rc file to load options from
[default: "/home/ubuntu/.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: ""]
--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 unbox cmake files using cdt version < 3.0.0
[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 --services "ipfs,cron,oracle,sign,vaccounts" --chain eos
--single-chain
npx truffle test

Customize your own unit tests

To generate this file see the Create 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);
}
})();
});
});
Copy link