-
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
2 changed files
with
166 additions
and
166 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,77 @@ | ||
// import { expect } from "chai"; | ||
import { expect } from "chai"; | ||
|
||
// import { awaitAllDecryptionResults } from "../asyncDecrypt"; | ||
// import { createInstances } from "../instance"; | ||
// import { getSigners, initSigners } from "../signers"; | ||
// import { deployBlindAuctionFixture } from "./BlindAuction.fixture"; | ||
import { awaitAllDecryptionResults } from "../asyncDecrypt"; | ||
import { createInstances } from "../instance"; | ||
import { getSigners, initSigners } from "../signers"; | ||
import { deployBlindAuctionFixture } from "./BlindAuction.fixture"; | ||
|
||
// describe("Decryption Example Tests", function () { | ||
// before(async function () { | ||
// // Initialize signers before running tests | ||
// await initSigners(); | ||
// this.signers = await getSigners(); | ||
// }); | ||
describe("Blin Auction 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 [ConfidentialERC20Contract, BlindAuctionContract] = await deployBlindAuctionFixture(); | ||
// this.contractAddress = await BlindAuctionContract.getAddress(); | ||
// this.auction = BlindAuctionContract; | ||
// this.tokenContract = ConfidentialERC20Contract; | ||
// this.instances = await createInstances(this.signers); | ||
// }); | ||
beforeEach(async function () { | ||
// Deploy the Random Number Generator contract before each test | ||
const [ConfidentialERC20Contract, BlindAuctionContract] = await deployBlindAuctionFixture(); | ||
this.contractAddress = await BlindAuctionContract.getAddress(); | ||
this.auction = BlindAuctionContract; | ||
this.tokenContract = ConfidentialERC20Contract; | ||
this.instances = await createInstances(this.signers); | ||
}); | ||
|
||
|
||
// it("should allow a user to place a bid and update the highest bid", async function () { | ||
// const bidAmount = 1000; | ||
it("should allow a user to place a bid and update the highest bid", async function () { | ||
const bidAmount = 1000; | ||
|
||
// // Mint tokens for Alice | ||
// const mintTx = await this.tokenContract.mint(bidAmount); | ||
// await mintTx.wait(); | ||
// Mint tokens for Alice | ||
const mintTx = await this.tokenContract.mint(bidAmount); | ||
await mintTx.wait(); | ||
|
||
// // Encrypt the bid amount | ||
// const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address); | ||
// input.add64(bidAmount); | ||
// const encryptedBid = input.encrypt(); | ||
// Encrypt the bid amount | ||
const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address); | ||
input.add64(bidAmount); | ||
const encryptedBid = input.encrypt(); | ||
|
||
// const approveTx = await this.tokenContract['approve(address,bytes32,bytes)'](await this.auction.getAddress(), encryptedBid.handles[0],encryptedBid.inputProof); | ||
// await approveTx.wait(); | ||
const approveTx = await this.tokenContract['approve(address,bytes32,bytes)'](await this.auction.getAddress(), encryptedBid.handles[0],encryptedBid.inputProof); | ||
await approveTx.wait(); | ||
|
||
// // Alice places a bid | ||
// const bidTx = await this.auction | ||
// .connect(this.signers.alice) | ||
// .bid(encryptedBid.handles[0], encryptedBid.inputProof,{gasLimit:7000000}); | ||
// await bidTx.wait(); | ||
// Alice places a bid | ||
const bidTx = await this.auction | ||
.connect(this.signers.alice) | ||
.bid(encryptedBid.handles[0], encryptedBid.inputProof,{gasLimit:7000000}); | ||
await bidTx.wait(); | ||
|
||
// // Validate that the bid was recorded | ||
// const bidHandle = await this.auction.getBid(this.signers.alice.address); | ||
// const { publicKey, privateKey } = this.instances.alice.generateKeypair(); | ||
// const eip712 = this.instances.alice.createEIP712(publicKey, this.contractAddress); | ||
// const signature = await this.signers.alice.signTypedData( | ||
// eip712.domain, | ||
// { Reencrypt: eip712.types.Reencrypt }, | ||
// eip712.message | ||
// ); | ||
// Validate that the bid was recorded | ||
const bidHandle = await this.auction.getBid(this.signers.alice.address); | ||
const { publicKey, privateKey } = this.instances.alice.generateKeypair(); | ||
const eip712 = this.instances.alice.createEIP712(publicKey, this.contractAddress); | ||
const signature = await this.signers.alice.signTypedData( | ||
eip712.domain, | ||
{ Reencrypt: eip712.types.Reencrypt }, | ||
eip712.message | ||
); | ||
|
||
// const actualBid = await this.instances.alice.reencrypt( | ||
// bidHandle, | ||
// privateKey, | ||
// publicKey, | ||
// signature.replace("0x", ""), | ||
// this.contractAddress, | ||
// this.signers.alice.address | ||
// ); | ||
// expect(actualBid).to.equal(bidAmount); | ||
// }); | ||
const actualBid = await this.instances.alice.reencrypt( | ||
bidHandle, | ||
privateKey, | ||
publicKey, | ||
signature.replace("0x", ""), | ||
this.contractAddress, | ||
this.signers.alice.address | ||
); | ||
expect(actualBid).to.equal(bidAmount); | ||
}); | ||
|
||
// // it("should allow the owner to stop the auction manually", async function () { | ||
// // // Stop the auction | ||
// // const stopTx = await this.auction.stop(); | ||
// // await stopTx.wait(); | ||
// it("should allow the owner to stop the auction manually", async function () { | ||
// // Stop the auction | ||
// const stopTx = await this.auction.stop(); | ||
// await stopTx.wait(); | ||
|
||
// // // Verify that the auction is stopped | ||
// // const isManuallyStopped = await this.auction.manuallyStopped(); | ||
// // expect(isManuallyStopped).to.be.true; | ||
// // }); | ||
// // Verify that the auction is stopped | ||
// const isManuallyStopped = await this.auction.manuallyStopped(); | ||
// expect(isManuallyStopped).to.be.true; | ||
// }); | ||
|
||
// }) | ||
}) |
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(); | ||
// // }); | ||
// // }); | ||
|
||
// }); |