Skip to content

Commit

Permalink
BLIND AUCTION TESTS
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSwayam committed Nov 14, 2024
1 parent 5515e67 commit df22a8e
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 41 deletions.
77 changes: 77 additions & 0 deletions test/BlindAuctionTests/BlindAuction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { expect } from "chai";

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();
});

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;

// 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();

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();

// 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);
});

// 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;
// });

})
82 changes: 41 additions & 41 deletions test/DecryptionExample/DecryptionExample.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { expect } from "chai";

import { awaitAllDecryptionResults } from "../asyncDecrypt";
import { createInstances } from "../instance";
import { getSigners, initSigners } from "../signers";
import { deployDecryptiponExampleFixture } from "./DecryptionExample.fixture";

describe("Decryption Example 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 dceContract = await deployDecryptiponExampleFixture();
this.contractAddress = await dceContract.getAddress();
this.dceContract = dceContract;
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.dceContract.generateRandomNumber({ gasLimit: 5000000 });
await transaction.wait();

await awaitAllDecryptionResults();

// Wait for 5 seconds
await delay(10000);

// Output the re-encrypted random numbers
console.log("First Random Number:", Number(await this.dceContract.randomNumber()) % 53);
console.log("Second Random Number:", Number(await this.dceContract.randomNumber1()) % 53);
});

function delay(ms: any) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
});
// import { expect } from "chai";

// import { awaitAllDecryptionResults } from "../asyncDecrypt";
// import { createInstances } from "../instance";
// import { getSigners, initSigners } from "../signers";
// import { deployDecryptiponExampleFixture } from "./DecryptionExample.fixture";

// describe("Decryption Example 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 dceContract = await deployDecryptiponExampleFixture();
// this.contractAddress = await dceContract.getAddress();
// this.dceContract = dceContract;
// 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.dceContract.generateRandomNumber({ gasLimit: 5000000 });
// await transaction.wait();

// await awaitAllDecryptionResults();

// // Wait for 5 seconds
// await delay(10000);

// // Output the re-encrypted random numbers
// console.log("First Random Number:", Number(await this.dceContract.randomNumber()) % 53);
// console.log("Second Random Number:", Number(await this.dceContract.randomNumber1()) % 53);
// });

// function delay(ms: any) {
// return new Promise((resolve) => setTimeout(resolve, ms));
// }
// });

0 comments on commit df22a8e

Please sign in to comment.