Skip to content

Latest commit

 

History

History
117 lines (86 loc) · 7.35 KB

TESTING-GUIDE.md

File metadata and controls

117 lines (86 loc) · 7.35 KB

Testing Guidelines for PoCS

The testing guide is provided for Milestone-2 PoCS W3F Grant Delivery

pallet-staking has been integrated into pallet-contracts to enable Proof of Contract Stake (PoCS) functionality with Parity's Nominated Proof of Stake (NPoS). By following these steps, developers/reviewers can verify the correctness and reliability of the implemented features.

How PoCS Works

  • Developers deploy smart contracts with stake_score i.e., bond value.

  • stake_score derived from contract execution time (refTime) and reputation.

    Flow Chart

  • Developers nominate a validator using update_delegate() extrinsic.

  • Bonded contracts need minimum reputation to nominate.

  • min_reputation is set at 10 for development, adjustable.

  • stake_score purges to 0 when contract's delegated validator changes.

  • Validators need minimum delegates (nominators i.e., bonded contracts) to start validating.

  • min_delegates set at 3 for development, adjustable.

  • Extended details available in PoCS-Research Document.

Test Locally

  • Building a local node is suitable to verify PoCS's unit & benchmarking tests locally, and further compile to run a Substrate-PoCSxNPoS node.
  1. Clone the repository from GitHub

    git clone https://github.com/auguth/pocs
  2. Run the Rust Setup Script (Mandatory)

    chmod +x setup.sh && ./setup.sh
  3. Run Tests

    cargo test
  4. Run Specific Unit Tests (Optional)

    pallets used : pallet-contracts, pallet_staking

    cargo test -p [pallet-name]
  5. Run Specific Benchmarking Tests (Optional)

    cargo test -p [pallet-name] --features=runtime-benchmarks
  6. Build the project in release mode

    cargo build --release
  7. Run the executable with the specified configuration:

    ./target/release/pocs --dev
    

Alternate Testing Method

  • Using Docker, build and run a node shortly without requiring node specific dependencies, but unit & benchmarking tests cannot be verified manually.
  • Regardless of the choice of any method, front-end tests can be conducted

Docker Compose

  1. Build & Run using Docker Compose:

    docker compose up --build -d
  2. To Stop container

    docker compose down
  3. To Restart the container

    docker compose up
    

    Works in all hosts (Linux/Mac/Windows).

Test Using Front-End

This is an optional extended test to check correctness of PoCS via pallet_contracts extrinsics on front-end, without attempting staking feature via pallet_staking

After running the executable, the following tests using front-end can be done to verify the correctness mentioned in How PoCS Work Section.

  1. Deploying Contracts

    1. Upload a contract e.g., flipper contract using Contracts UI
    2. This uses function instantiate_with_code()
    3. instantiate_with_code() calls the bond() function in pallet-staking to bond the contract deployer address with default stake_score.
    4. After deployment, should expect events - AccountStakeinfoevent & ContractStakeinfoevent with its default values
  2. Executing Contracts

    1. When executing contract bond_extra() function is additionally called to increment the new stake_score
    2. This emits ContractStakeinfoevent
    3. In validator list of bonds, the stake_score will be reflected
  3. Nominating a Validator after minimum reputation achieved

    1. Construct an extrinsic via contracts pallet with update_delegate() function
    2. update_delegate() calls nominate() and new_unbond() in pallet-staking to purge the stake_score (existing bond value) and ensures if the contract has required minimum reputation to nominate
    3. In AccountStakeinfo, delegateTo and delegateAt will be updated and in ContractScarcityinfo, the stake_score will be updated to 0 reflected in the validator list of bonds to zero.