src
- contains sources of Abax Governance's contractstests
- contains e2e tests as well as utilities used for writing/running testsscripts
- contains helpful scripts
The contract src/contracts/governor
implements two core traits (with many extensions): Stake, StakeView, StakeTimes, StakeCounter, StkaeManage, and Govern, GovernView, GovernRewardableSlashable, GovernManage.
The definitions and implementation of these Triats are found in src/contracts_impls
.
The contract src/contract/governance_token
implements PSP22, PSP22Mintable, PSP22Burnable, and AccessControl.
Other contracts are used for testing.
-
To build Abax Governance smart contracts you need to have a prepared rust environment, with cargo-contract compatible with ink! 4.x . Follow official guides on how to set up/migrate to an environment that supports ink! 4.x:
-
https://use.ink/faq/migrating-from-ink-3-to-4/#compatibility
-
To run tests and use convenience scripts you have to run the
yarn
/yarn install
command to install the required npm packages.
We've prepared some convenience scripts that somehow simplify the build process and streamline it to be usable from the root repo's directory.
yarn build
- allows you to build all contracts contained in thesrc/contracts
folder, have the artifacts copied over to theartifacts
folder, generate typechain types, and measure the amount of time the build took. In additionbuild.log
/build.log.html
are created with the details of the build process - useful since the console output ofcargo contract build
for all contracts is lengthy. For preview we recommend to use either browser (build.log.html
) orANSI Colors
(build.log
)yarn cs <contract_name>
- allows you to build a single contract and have its artifacts copied over to theartifacts
folder.
Note Currently there is a bug in the files generated by typechain. Fix it by changing the import:
// import { ContractAbi } from '../contract-info/governor';
import ContractAbi from 'artifacts/governor.json';
Initially, tests were using Redspot however due to compatibility issues, terrible performance, and dependencies mismatch (including polkadot.js
core packages actively developed or foreshadowed ink! 4) we've abandoned the library.
Instead, we've used the raw mocha
library alongside some scripts to abstract logic required for e2e tests to work properly and that turned out to be a fast and reliable solution.
Tests consist of regular test suites (created via describe
/makeSuite
).
TL;DR; To run tests it is sufficient to run yarn build
and yarn test
.
Test execution consists of a set of simple steps:
- Clear db backup/test artifacts from the previous run
- Deploy, set up contracts (using
yarn deployTest
), and store/persist node's db - run
mocha
- For every set of tests that require a "clean setup", instead of rerunning deployment, use the database state saved previously. The caveat of doing that is that we have to restart the node (details in
nodePersistence.ts
). That being said thanks to doing that tests perform a couple of times better than usingredspot
. This operation happens inbefore
hooks, notably most used in themakeSuite
test suite wrapper frommake-suite.ts
.
yarn test
is what that will perform all of the steps mentioned previously and on top of that store logs of the node in thesubstrate-contracts-node.testrun.log
file (note that with the given approach the node is being restarted so keeping track of logs in the console is rather annoying). Thesubstrate-contracts-node.testrun.retouched.log
log file contains the same data except UInt8 arrays being swapped with proper addresses. In the future, we plan to add removal of duplicate logs (happening because of the node itself ).
- Allow to allocate more memory for node:
echo 'export NODE_OPTIONS="--max-old-space-size=8192"' >> ~/.bashrc
- Run test scenario file in debug (targetting persistent local node):
npm run test:debug <test_scenario_file_name>