A simple vote contract / School Projectπ³οΈ
Objectives: Create a smart voting contract in PascalLigo language:
- A user can vote by saying "yes"(vote(True)) π or "no" π (vote(False))
- All users can vote except the owner of the contract
- A user can only vote once π₯
- The "administrator" is the owner of the contract. He is defined when we deploy the contract.
- The smart contract is paused when 10 people has voted
- When the smart contract is paused, the result of the vote must be available in the storage πͺ
- The owner can reset, pause and resume the vote β
- The smart contract should have unit tests π
How to use :
We assume that you already have set your environement, else you can find it by following the links below:
- https://tezos.gitlab.io/introduction/howtoget.html#build-from-sources
- https://ligolang.org/docs/intro/installation/
Step 1 : Compiling your contract π»
As the unit test is waiting for a file called "voteContract.tz", which is the result of the compiled contract we have to do :
β’ ligo compile-contract votingContract.ligo main > votingContract.tz
The general form of this line is :
β’ ligo compile-contract > <name of your .tz file>
Step 2 : Simulation π¬
To simulate the contract you can use this command below:
β’ ligo dry-run --sender=tz1VPFYwwtWZ5ytH5ZcMYyvqi9AmiR3d8sJT vote.ligo main 'SetAdmin(("tz1VPFYwwtWZ5ytH5ZcMYyvqi9AmiR3d8sJT":address))' 'record votes=map ("tz1VPFYwwtWZ5ytH5ZcMYyvqi9AmiR3d8sJT":address) -> True;end; owner=("tz1VPFYwwtWZ5ytH5ZcMYyvqi9AmiR3d8sJT":address); contractPause=False;yes=0;no=0;end'
If it returns :
β’ ( list[] , record[contractPause -> false , no -> 0 , owner -> @"tz1VPFYwwtWZ5ytH5ZcMYyvqi9AmiR3d8sJT" , votes -> map[@"tz1VPFYwwtWZ5ytH5ZcMYyvqi9AmiR3d8sJT" -> true] , yes -> 0] )
Then it worked, else you made an error copying it ! (I've tested it before pushing ) π
Step 3 : Run unit tests πββοΈ πββοΈ
It's the most easy part, you only have to do the command below:
β’ pytest UnitTest.py
You should see that :
β’ ============================================================================================= 4 failed, 4 passed in 2.50s ============================================================
That's the expected result ! π―
Questions / Help
I would be more than happy to help you, if you need it ! Science is the freer asset to share !
πππ Use this project freely πππ