This project is a Solana Voting Program implemented using the Anchor framework. The program allows users to create polls, cast votes, and close polls in a decentralized environment. It is written in Rust and uses the Anchor framework for efficient program development and testing on the Solana blockchain.
- Create a Poll: Initialize a poll with a title and up to 5 options. Each poll is associated with an authority (the creator).
- Cast a Vote: Users can vote on one of the available options in an active poll. Each user can vote only once per poll.
- End a Poll: The poll creator can close the poll to prevent further voting.
- Account Validation: All accounts (polls and voters) are validated with PDAs (Program Derived Addresses).
To run this project, you'll need the following tools:
- Node.js (v16 or higher)
- Anchor Framework
- Solana CLI
-
Clone the Project:
git clone https://github.com/your-username/voting-program.git cd voting-program -
Install Dependencies:
yarn install
-
Build the Project:
anchor build
-
Start the Test Validator:
solana-test-validator
-
Run Anchor Tests:
anchor test
-
Initialize Poll
initialize_poll(): Initializes a new poll.
-
Voting
cast_vote(): Allows a user to vote on a poll.
-
Finishing the Poll
end_poll(): Ends an active poll.
The tests are written using mocha and Anchor's testing tools. To run the tests:
anchor test- Tests the creation of a poll with a title and options.
- Tests voting for a valid option and ensures only one vote per user.
- Tests the closure of a poll by its creator.
- Do Not Share Admin Key: The admin key used in the tests should remain confidential.
- Exclude Private Keys (.json): Ensure you add sensitive files like Solana wallet
.jsonfiles to.gitignoreto prevent accidental exposure.
This project is licensed under the MIT License.