Skip to content

AbaxFinance/Governance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ink!

Abax Governance Smart Contracts v0.1.0

This repository contains the source code of Abax Governance smart contracts as well as a set of tests.

Project structure

  • src - contains sources of Abax Governance's contracts
  • tests - contains e2e tests as well as utilities used for writing/running tests
  • scripts - contains helpful scripts

Contracts, Traits, and Implementations

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.

Contracts build and deployment

Prerequisites

Build

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 the src/contracts folder, have the artifacts copied over to the artifacts folder, generate typechain types, and measure the amount of time the build took. In addition build.log/build.log.html are created with the details of the build process - useful since the console output of cargo contract build for all contracts is lengthy. For preview we recommend to use either browser (build.log.html) or ANSI Colors (build.log)
  • yarn cs <contract_name> - allows you to build a single contract and have its artifacts copied over to the artifacts 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';

Tests

Short description and explication of the testing approach/"framework" used

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).

Test execution

TL;DR; To run tests it is sufficient to run yarn build and yarn test.

yarn test explanation:

Test execution consists of a set of simple steps:

  1. Clear db backup/test artifacts from the previous run
  2. Deploy, set up contracts (using yarn deployTest), and store/persist node's db
  3. run mocha
  4. 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 using redspot. This operation happens in before hooks, notably most used in the makeSuite test suite wrapper from make-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 the substrate-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). The substrate-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 ).

Other useful commands

  1. Allow to allocate more memory for node: echo 'export NODE_OPTIONS="--max-old-space-size=8192"' >> ~/.bashrc
  2. Run test scenario file in debug (targetting persistent local node): npm run test:debug <test_scenario_file_name>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published