![Logo](https://raw.githubusercontent.com/BksRhalid/Pact_Frontend/main/public/img/pactLogo.png)
PACT is a blockchain-based client-relationship platform. The mission is to remove the friction in the client-relationship. The interest of using blockchain for a platform is to bring trust.
Explore the docs Β»
Video Demo
Table of Contents
The objective of the exercise is to provide the unit tests of a smart contract including everts and revert.
In this context, we have created three test files: :
-
Ownable.test.js
: to test if Ownable from openzepplin is correctly implementedUnits tests on Ownable access functions π Test Ownable Revert if the owner is not the caller β should NOT setProtocolFee if caller is not the owner (244ms) β should NOT setJuryFee if caller is not the owner (61ms) β should NOT setJuryLength if caller is not the owner (70ms) β should CHANGE ProtocolFee if caller is the owner (352ms) β should CHANGE JuryFee if caller is the owner (182ms) β should CHANGE juryLength if caller is the owner (204ms) Units tests on freelance access functions π Deployment hardhat deploy testing β should deploy the smart contract (64ms) π Test dispute contract function β should generate a number (169ms) Units tests on freelance access functions π Deployment hardhat deploy testing β should deploy the smart contract π Test freelance contract set-up β should ADD a new worker (99ms) β should REMOVE the worker (228ms) β should ADD a new client (164ms) β should REMOVE the client (287ms) β should ADD a new jury member (156ms) π Test freelance contract function creation unit test β should CREATE a new contract called by Client (200ms) β should NOT CREATE a new contract called by Worker (128ms) π Test freelance contract function cancel contract β should EMIT ContractStateChange (222ms) β should NOT CANCEL a new contract (120ms) π Test freelance contract function sign contract β should update the worker address (177ms) β should EMIT ContractStateChange (131ms) π Test dispute contract function β should create a new dispute (248ms) β should NOT create a second dispute (325ms) β should NOT revert select a jury (454ms) β should get 3 juryMembers (190ms) π Test function of Voting process β should return the correct juryCounter (67ms) β should return false if juryMembers has no voted β should return true if juryMembers has voted (288ms) β should change vote count for client (111ms) β should change vote count for worker (192ms) π Test function count Vote and change the State β should change state ClientLostInDispute (329ms) β should change state WorkerLostInDispute (478ms) π Unit Test of payments related functions and events when works is confirm by Clients β should Revert as it not in correct state β should worker requestClientValidation and change contract state to WaitingClientReview (125ms) β should NOT allow client to request client validation (52ms) β should client able to confirm worker job and change state to WorkFinishedSuccessufully (190ms) β should Not allow worker to confirm the job (58ms) β should NOT allow client to pull payment β should allow worker to pull payments and not fail (262ms) β should allow client to pull payments after worker cancel (52ms) π Unit Test of payments related functions and events after dispute opened β should Revert as Dispute isn't closed β should NOT allow client to pull payment (185ms)
Below the coverage report of the test :
------------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
------------------------|----------|----------|----------|----------|----------------|
contracts/ | 69.57 | 59.52 | 84.85 | 67.58 | |
freelanceContract.sol | 69.57 | 59.52 | 84.85 | 67.58 |... 674,675,676 |
contracts/utils/ | 100 | 100 | 50 | 100 | |
payments.sol | 100 | 100 | 0 | 100 | |
randomNumber.sol | 100 | 100 | 100 | 100 | |
random_ChainLink.sol | 100 | 100 | 100 | 100 | |
------------------------|----------|----------|----------|----------|----------------|
All files | 70 | 59.52 | 82.86 | 67.87 | |
------------------------|----------|----------|----------|----------|----------------|
Below the instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
Here the list things you need to use the software and how to install them.
- For this project we are going to use yarn
- installation
npm install --global yarn
- check installation
yarn --version
- solidity
_Below instruction installing and setting up the project.
-
Clone the repo
git clone https://github.com/BksRhalid/Pact_Frontend.git git clone https://github.com/BksRhalid/Pact_Backend.git
-
Install packages
yarn install
-
Enter your Wallet Private Key and API in
env
const PK = "YOUR WALLET PRIVATE KEY";
const INFURA = "ENTER YOUR API";
const ETHERSCAN = "ENTER YOUR API";
-
Check dependencies used like Openzepplin contracts / hardhat-deploy
yarn add --dev @openzeppelin/contracts yarn add --dev hardhat-deploy
In case of error: _TypeError: ethers.getContract is not a function
see reference : https://ethereum.stackexchange.com/questions/130125/solvedpatrickcollins-solidity-course-2022-lesson-7-112038-typeerror-e
yarn add --dev hardhat @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers
Try running some of the following tasks:
REPORT_GAS=true npx hardhat test
Distributed under the MIT License.