Skip to content

ChengHua926/Seismic-Vote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anonymous Voting Contract

Seismic Vote Logo - A rock golem chef with a voting box

A secure and anonymous voting system built on the Seismic devnet. The contract allows for proposal creation, anonymous voting, and early vote termination by proposal creators.

Contract Address: 0xF050f37a7F8823e5BAe62962B0345D6Be736E35A

This guide assumes you have already completed the Seismic installation process.

📝 Contract Overview

The AnonymousVoting contract implements a secure voting system with the following key features:

  • Proposal creation with customizable duration
  • Anonymous voting mechanism
  • Vote counting for and against proposals
  • Early termination capability for proposal creators
  • Encrypted vote storage
  • Time-based voting windows

🧪 Testing

The contract includes comprehensive tests covering all major functionality. Here are some key test examples:

// Test for proposal creation
function testCreateProposal() public {
    vm.startPrank(alice);
    uint256 proposalId = voting.createProposal("Test Proposal", 1 days);
    
    (string memory description, uint256 startTime, uint256 endTime, bool hasVoted) = 
        voting.getProposalInfo(proposalId);
    
    assertEq(description, "Test Proposal");
    assertEq(endTime - startTime, 1 days);
    assertFalse(hasVoted);
    assertEq(voting.proposalCreator(proposalId), alice);
}

// Test for early vote termination
function testCreatorCanEndVoteEarly() public {
    vm.startPrank(alice);
    uint256 proposalId = voting.createProposal("Test Proposal", 1 days);
    vm.stopPrank();

    vm.warp(block.timestamp + 12 hours);
    vm.startPrank(alice);
    voting.endVoting(proposalId);
    assertTrue(voting.isVotingComplete(proposalId));
}

Run the tests with detailed output:

sforge test -vvv

You should see output similar to this:

[⠊] Compiling...
No files changed, compilation skipped

Ran 7 tests for test/vote.t.sol:VoteTest
[PASS] testCannotVoteAfterEnd() (gas: 139556)
[PASS] testCannotVoteTwice() (gas: 206833)
[PASS] testCreateProposal() (gas: 142676)
[PASS] testCreatorCanEndVoteEarly() (gas: 140388)
[PASS] testGetResults() (gas: 261616)
[PASS] testNonCreatorCannotEndVoteEarly() (gas: 139609)
[PASS] testVote() (gas: 206718)
Suite result: ok. 7 passed; 0 failed; 0 skipped

🔧 Deployment

Prerequisites

  1. Get test ETH from Seismic Faucet
  2. Set up your private key in the terminal:
export PRIVATE_KEY=your_private_key_here

Deployment Steps

  1. Make the deployment script executable:
chmod +x script/deploy.sh
  1. Run the deployment script:
./script/deploy.sh

💻 Interacting with the Contract

After deployment, you can interact with the contract using cast:

# Create a proposal
cast send <CONTRACT_ADDRESS> "createProposal(string,uint256)" "Test Proposal" 86400 \
    --rpc-url https://node-2.seismicdev.net/rpc \
    --private-key $PRIVATE_KEY

# Get proposal info
cast call <CONTRACT_ADDRESS> "getProposalInfo(uint256)" 1 \
    --rpc-url https://node-2.seismicdev.net/rpc

Replace <CONTRACT_ADDRESS> with the deployed contract address.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published