-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
250 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,75 @@ | ||
// import { expect } from "chai"; | ||
// import { awaitAllDecryptionResults } from "../asyncDecrypt"; | ||
// import { createInstances } from "../instance"; | ||
// import { getSigners, initSigners } from "../signers"; | ||
// import { deployRandomNumberGeneratorFixture } from "./HiddenRandomCards.fixture"; | ||
import { expect } from "chai"; | ||
import { awaitAllDecryptionResults } from "../asyncDecrypt"; | ||
import { createInstances } from "../instance"; | ||
import { getSigners, initSigners } from "../signers"; | ||
import { deployRandomNumberGeneratorFixture } from "./HiddenRandomCards.fixture"; | ||
|
||
// describe("Random Number Generator Tests", function () { | ||
// before(async function () { | ||
// // Initialize signers before running tests | ||
// await initSigners(); | ||
// this.signers = await getSigners(); | ||
// }); | ||
describe("Random Number Generator Tests", function () { | ||
before(async function () { | ||
// Initialize signers before running tests | ||
await initSigners(); | ||
this.signers = await getSigners(); | ||
}); | ||
|
||
// beforeEach(async function () { | ||
// // Deploy the Random Number Generator contract before each test | ||
// const rngContract = await deployRandomNumberGeneratorFixture(); | ||
// this.contractAddress = await rngContract.getAddress(); | ||
// this.rngContract = rngContract; | ||
// this.instances = await createInstances(this.signers); | ||
// }); | ||
beforeEach(async function () { | ||
// Deploy the Random Number Generator contract before each test | ||
const rngContract = await deployRandomNumberGeneratorFixture(); | ||
this.contractAddress = await rngContract.getAddress(); | ||
this.rngContract = rngContract; | ||
this.instances = await createInstances(this.signers); | ||
}); | ||
|
||
// it("Should generate random numbers, re-encrypt, and retrieve them", async function () { | ||
// // Generate random numbers | ||
// const transaction = await this.rngContract.generateRandomNumber({ gasLimit: 5000000 }); | ||
// await transaction.wait(); | ||
it("Should generate random numbers, re-encrypt, and retrieve them", async function () { | ||
// Generate random numbers | ||
const transaction = await this.rngContract.generateRandomNumber({ gasLimit: 5000000 }); | ||
await transaction.wait(); | ||
|
||
// // Retrieve encrypted random numbers from the contract | ||
// const [encRandomNum1, encRandomNum2, encRandomNum3] = await this.rngContract.viewEncryptedRandomNumber(); | ||
// Retrieve encrypted random numbers from the contract | ||
const [encRandomNum1, encRandomNum2, encRandomNum3] = await this.rngContract.viewEncryptedRandomNumber(); | ||
|
||
// // Generate public-private keypair for Alice | ||
// const { publicKey: alicePublicKey, privateKey: alicePrivateKey } = this.instances.alice.generateKeypair(); | ||
// Generate public-private keypair for Alice | ||
const { publicKey: alicePublicKey, privateKey: alicePrivateKey } = this.instances.alice.generateKeypair(); | ||
|
||
// // Prepare EIP-712 signature for Alice's re-encryption request | ||
// const eip712Message = this.instances.alice.createEIP712(alicePublicKey, this.contractAddress); | ||
// const aliceSignature = await this.signers.alice.signTypedData( | ||
// eip712Message.domain, | ||
// { Reencrypt: eip712Message.types.Reencrypt }, | ||
// eip712Message.message, | ||
// ); | ||
// Prepare EIP-712 signature for Alice's re-encryption request | ||
const eip712Message = this.instances.alice.createEIP712(alicePublicKey, this.contractAddress); | ||
const aliceSignature = await this.signers.alice.signTypedData( | ||
eip712Message.domain, | ||
{ Reencrypt: eip712Message.types.Reencrypt }, | ||
eip712Message.message, | ||
); | ||
|
||
// // Re-encrypt each random number and retrieve results | ||
// const firstRandomNumber = await this.instances.alice.reencrypt( | ||
// encRandomNum1, | ||
// alicePrivateKey, | ||
// alicePublicKey, | ||
// aliceSignature.replace("0x", ""), | ||
// this.contractAddress, | ||
// this.signers.alice.address, | ||
// ); | ||
// Re-encrypt each random number and retrieve results | ||
const firstRandomNumber = await this.instances.alice.reencrypt( | ||
encRandomNum1, | ||
alicePrivateKey, | ||
alicePublicKey, | ||
aliceSignature.replace("0x", ""), | ||
this.contractAddress, | ||
this.signers.alice.address, | ||
); | ||
|
||
// const secondRandomNumber = await this.instances.alice.reencrypt( | ||
// encRandomNum2, | ||
// alicePrivateKey, | ||
// alicePublicKey, | ||
// aliceSignature.replace("0x", ""), | ||
// this.contractAddress, | ||
// this.signers.alice.address, | ||
// ); | ||
const secondRandomNumber = await this.instances.alice.reencrypt( | ||
encRandomNum2, | ||
alicePrivateKey, | ||
alicePublicKey, | ||
aliceSignature.replace("0x", ""), | ||
this.contractAddress, | ||
this.signers.alice.address, | ||
); | ||
|
||
// const thirdRandomNumber = await this.instances.alice.reencrypt( | ||
// encRandomNum3, | ||
// alicePrivateKey, | ||
// alicePublicKey, | ||
// aliceSignature.replace("0x", ""), | ||
// this.contractAddress, | ||
// this.signers.alice.address, | ||
// ); | ||
const thirdRandomNumber = await this.instances.alice.reencrypt( | ||
encRandomNum3, | ||
alicePrivateKey, | ||
alicePublicKey, | ||
aliceSignature.replace("0x", ""), | ||
this.contractAddress, | ||
this.signers.alice.address, | ||
); | ||
|
||
// // Output the re-encrypted random numbers | ||
// console.log("First Random Number:", Number(firstRandomNumber)%53); | ||
// console.log("Second Random Number:", Number(secondRandomNumber)%53); | ||
// console.log("Third Random Number:", Number(thirdRandomNumber)%53); | ||
// }); | ||
// Output the re-encrypted random numbers | ||
console.log("First Random Number:", Number(firstRandomNumber)%53); | ||
console.log("Second Random Number:", Number(secondRandomNumber)%53); | ||
console.log("Third Random Number:", Number(thirdRandomNumber)%53); | ||
}); | ||
|
||
// }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,103 @@ | ||
// import { expect } from "chai"; | ||
// import { ethers } from "hardhat"; | ||
// import { createInstances } from "../instance"; | ||
// import { getSigners, initSigners } from "../signers"; | ||
// import { deployVotingFixture } from "./PrivateVoting.fixture"; | ||
|
||
// describe("Voting Contract Tests", function () { | ||
// before(async function () { | ||
// await initSigners(); | ||
// this.signers = await getSigners(); | ||
// this.instances = await createInstances(this.signers); | ||
// }); | ||
|
||
// beforeEach(async function () { | ||
// this.votingContract = await deployVotingFixture(); | ||
// this.contractAddress = await this.votingContract.getAddress(); | ||
// }); | ||
|
||
// describe("Should be able to vote and re-encrypt the values", function () { | ||
// it("should be able to vote in favour and re-encrypt the values ", 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(); | ||
|
||
// const eboolVoteChoice = await this.votingContract.getOwnEncryptedVoteChoice(); | ||
// const euint64VotePower = await this.votingContract.getOwnEncryptedVoteCount(); | ||
// // Generate public-private keypair for Alice | ||
// const { publicKey: alicePublicKey, privateKey: alicePrivateKey } = this.instances.alice.generateKeypair(); | ||
|
||
// // Prepare EIP-712 signature for Alice's re-encryption request | ||
// const eip712Message = this.instances.alice.createEIP712(alicePublicKey, this.contractAddress); | ||
// const aliceSignature = await this.signers.alice.signTypedData( | ||
// eip712Message.domain, | ||
// { Reencrypt: eip712Message.types.Reencrypt }, | ||
// eip712Message.message, | ||
// ); | ||
|
||
// // Re-encrypt each random number and retrieve results | ||
// const voteChoice = await this.instances.alice.reencrypt( | ||
// eboolVoteChoice, | ||
// alicePrivateKey, | ||
// alicePublicKey, | ||
// aliceSignature.replace("0x", ""), | ||
// this.contractAddress, | ||
// this.signers.alice.address, | ||
// ); | ||
|
||
// const votePower = await this.instances.alice.reencrypt( | ||
// euint64VotePower, | ||
// alicePrivateKey, | ||
// alicePublicKey, | ||
// aliceSignature.replace("0x", ""), | ||
// this.contractAddress, | ||
// this.signers.alice.address, | ||
// ); | ||
|
||
// console.log("user voted for : ", voteChoice); | ||
// console.log("user vote power is : ", votePower); | ||
// }); | ||
// }); | ||
|
||
// // 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(); | ||
// // }); | ||
// // }); | ||
|
||
// }); | ||
import { expect } from "chai"; | ||
import { ethers } from "hardhat"; | ||
import { createInstances } from "../instance"; | ||
import { getSigners, initSigners } from "../signers"; | ||
import { deployVotingFixture } from "./PrivateVoting.fixture"; | ||
|
||
describe("Voting Contract Tests", function () { | ||
before(async function () { | ||
await initSigners(); | ||
this.signers = await getSigners(); | ||
this.instances = await createInstances(this.signers); | ||
}); | ||
|
||
beforeEach(async function () { | ||
this.votingContract = await deployVotingFixture(); | ||
this.contractAddress = await this.votingContract.getAddress(); | ||
}); | ||
|
||
describe("Should be able to vote and re-encrypt the values", function () { | ||
it("should be able to vote in favour and re-encrypt the values ", 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(); | ||
|
||
const eboolVoteChoice = await this.votingContract.getOwnEncryptedVoteChoice(); | ||
const euint64VotePower = await this.votingContract.getOwnEncryptedVoteCount(); | ||
// Generate public-private keypair for Alice | ||
const { publicKey: alicePublicKey, privateKey: alicePrivateKey } = this.instances.alice.generateKeypair(); | ||
|
||
// Prepare EIP-712 signature for Alice's re-encryption request | ||
const eip712Message = this.instances.alice.createEIP712(alicePublicKey, this.contractAddress); | ||
const aliceSignature = await this.signers.alice.signTypedData( | ||
eip712Message.domain, | ||
{ Reencrypt: eip712Message.types.Reencrypt }, | ||
eip712Message.message, | ||
); | ||
|
||
// Re-encrypt each random number and retrieve results | ||
const voteChoice = await this.instances.alice.reencrypt( | ||
eboolVoteChoice, | ||
alicePrivateKey, | ||
alicePublicKey, | ||
aliceSignature.replace("0x", ""), | ||
this.contractAddress, | ||
this.signers.alice.address, | ||
); | ||
|
||
const votePower = await this.instances.alice.reencrypt( | ||
euint64VotePower, | ||
alicePrivateKey, | ||
alicePublicKey, | ||
aliceSignature.replace("0x", ""), | ||
this.contractAddress, | ||
this.signers.alice.address, | ||
); | ||
|
||
console.log("user voted for : ", voteChoice); | ||
console.log("user vote power is : ", votePower); | ||
}); | ||
}); | ||
|
||
// 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(); | ||
// }); | ||
// }); | ||
|
||
}); |
Oops, something went wrong.