BlockVote JS Edition
To install BlockVote JS Edition, follow these steps please:
- Clone the repository to your local machine using the following command:
git clone https://github.com/doriancrutcher/BlockVote-JS-Edition-Tutorial.git
- Navigate to the project directory:
- Install the required dependencies using the following command:
- Start the application:
If you don't have
yarn installed, you can install it by running
npm install -g yarn.
This application allows users to create a poll with two candidates, and each user can only vote in a poll once. Results are shown after the vote is cast.
To create a poll, follow these steps:
- Enter the names and URL links for the two candidates in the input fields.
- Click on the "Create Poll" button to create the poll.
- Share the poll link with others to allow them to vote.
To vote in a poll, follow these steps:
- Click on the name of the candidate you want to vote for.
- You will only be able to vote once in each poll.
- After you vote, the poll results will be displayed on the screen.
That's it! If you have any questions or issues while using the BlockVote JS Edition, feel free to open an issue on the project's GitHub page.
The contract contains several view and call methods that allow users to interact with the contract, including:
getUrl: retrieves the URL link for a specific candidate based on the candidate's name and prompt.
didParticipate: checks whether a specific user has participated in a given prompt.
participateArray: retrieves the list of users who have participated in a given prompt.
getAllPrompts: retrieves a list of all prompts currently available in the contract.
getVotes: retrieves the vote tallies for a specific prompt.
getCandidatePair: retrieves the names of the two candidates for a specific prompt.
addCandidatePair: adds a candidate pair for a specific prompt to the contract's unordered map of candidate pairs.
initializeVotes: initializes the vote tallies for a specific prompt
addToPromptArray: adds a prompt to the contract's unordered set of prompts
clearPromptArray: clears all prompts and associated data from the contract (candidate pairs, vote tallies, and user participation)
addVote: casts a vote for a specific candidate in a prompt by updating the vote tally for that candidate in the contract's unordered map of vote tallies. The method takes in the prompt and the index of the candidate
recordUser: records the participation of a user in a specific prompt by adding the user's account ID to an array in the contract's unordered map of user participation
When writing smart contracts, it is very important to test all methods exhaustively. In this project, you have two types of tests: unit tests and integration tests. Before digging into them, it's important to run the tests present in the dApp through the command
Unit tests are designed to test individual functions and methods in the smart contract. These tests are run in isolation, meaning that they do not interact with other components of the system. The purpose of unit tests is to ensure that each individual function or method behaves as expected.
In this project, you can run the unit tests by executing the command
These tests are run to ensure that the different components of the system work together as expected. In the context of a smart contract, integration tests are used to test the interactions between the contract and the blockchain.
In this project, you can run the integration tests by executing the command
These tests use a combination of