Skip to content

Commit

Permalink
Final Working tets for Private Voting
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSwayam committed Nov 14, 2024
1 parent 5cdf213 commit 810a040
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
5 changes: 3 additions & 2 deletions contracts/PrivateVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ contract Voting is GatewayCaller {
} else {
encryptedVoteChoices[msg.sender] = voteChoice;
}
TFHE.allow(encryptedVoteChoices[msg.sender], address(this));
TFHE.allow(encryptedVoteChoices[msg.sender], msg.sender);

// Initialize local variables to avoid issues with uninitialized handles
euint64 inFavorCountToCast = TFHE.asEuint64(0);
Expand Down Expand Up @@ -102,6 +100,9 @@ contract Voting is GatewayCaller {
TFHE.allow(inFavorCountEncrypted, owner);

// Allow the user to view their vote choice and vote count in the future
TFHE.allow(encryptedVoteChoices[msg.sender], address(this));
TFHE.allow(encryptedVoteChoices[msg.sender], msg.sender);
TFHE.allow(encryptedVoteCounts[msg.sender], address(this));
TFHE.allow(encryptedVoteCounts[msg.sender], msg.sender);
}

Expand Down
62 changes: 31 additions & 31 deletions test/PrivateVotingTests/PrivateVoting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,36 @@ describe("Voting Contract Tests", function () {
});
});

describe("Should be able to vote ", function () {
it("should be able to vote in favour ", async function () {
const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
input.add64(1000);
input.add8(1);
const encryptedVotingCountAndEncryptedChoice = input.encrypt();

const castVoteTx = await this.votingContract.castEncryptedVote(
encryptedVotingCountAndEncryptedChoice.handles[0],
encryptedVotingCountAndEncryptedChoice.handles[1],
encryptedVotingCountAndEncryptedChoice.inputProof,
);

await castVoteTx.wait();
});

it("should be able to vote against the proposal ", async function () {
const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
input.add64(1000);
input.add8(0);
const encryptedVotingCountAndEncryptedChoice = input.encrypt();

const castVoteTx = await this.votingContract.castEncryptedVote(
encryptedVotingCountAndEncryptedChoice.handles[0],
encryptedVotingCountAndEncryptedChoice.handles[1],
encryptedVotingCountAndEncryptedChoice.inputProof,
);

await castVoteTx.wait();
});
});
// describe("Should be able to vote ", function () {
// it("should be able to vote in favour ", async function () {
// const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
// input.add64(1000);
// input.add8(1);
// const encryptedVotingCountAndEncryptedChoice = input.encrypt();

// const castVoteTx = await this.votingContract.castEncryptedVote(
// encryptedVotingCountAndEncryptedChoice.handles[0],
// encryptedVotingCountAndEncryptedChoice.handles[1],
// encryptedVotingCountAndEncryptedChoice.inputProof,
// );

// await castVoteTx.wait();
// });

// it("should be able to vote against the proposal ", async function () {
// const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
// input.add64(1000);
// input.add8(0);
// const encryptedVotingCountAndEncryptedChoice = input.encrypt();

// const castVoteTx = await this.votingContract.castEncryptedVote(
// encryptedVotingCountAndEncryptedChoice.handles[0],
// encryptedVotingCountAndEncryptedChoice.handles[1],
// encryptedVotingCountAndEncryptedChoice.inputProof,
// );

// await castVoteTx.wait();
// });
// });

});

0 comments on commit 810a040

Please sign in to comment.