-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdsAuction.ts
More file actions
102 lines (82 loc) · 3.43 KB
/
AdsAuction.ts
File metadata and controls
102 lines (82 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { expect } from "chai";
import { network } from "hardhat";
import { createInstance } from "../instance";
import { reencryptEuint64 } from "../reencrypt";
import { getSigners, initSigners } from "../signers";
import { debug } from "../utils";
import { deployFheAds, deployConfidentialERC20Fixture, mintAndAllow, bidAndDeposit, getAd} from "./AdsAuction.fixture";
describe("AdsAuction", function () {
before(async function () {
await initSigners();
this.signers = await getSigners();
});
beforeEach(async function () {
const erc20 = await deployConfidentialERC20Fixture();
this.erc20 = erc20;
this.erc20Address = await erc20.getAddress();
const contract = await deployFheAds(erc20);
this.contractAddress = await contract.getAddress();
this.adBidContract = contract;
this.fhevm = await createInstance();
});
it("should accept bids", async function () {
// Alice has 10 000, Bob has 20 000
await mintAndAllow(this.fhevm, this.erc20, this.erc20Address, this.contractAddress, this.signers.alice, 10000);
await mintAndAllow(this.fhevm, this.erc20, this.erc20Address, this.contractAddress, this.signers.bob, 20000);
// Both Alice and Bob deposit 10 000 and set up bid rules
await bidAndDeposit(this.fhevm, this.adBidContract, this.contractAddress, this.signers.alice, 1000, 1000, 1000, 10000);
await bidAndDeposit(this.fhevm, this.adBidContract, this.contractAddress, this.signers.bob, 2000, 1000, 5000, 10000);
const aliceDepositHandle = await this.adBidContract.connect(this.signers.alice).getDeposit();
const aliceBalanceAmount = await reencryptEuint64(
this.signers.alice,
this.fhevm,
aliceDepositHandle,
this.contractAddress,
);
expect(aliceBalanceAmount).to.equal(10000);
const idWinner1 = await getAd(this.fhevm, this.adBidContract, this.contractAddress, this.signers.carol, 1, 1, 1);
const aliceBalanceHandle = await this.erc20.balanceOf(this.signers.alice);
const aliceBalance = await reencryptEuint64(
this.signers.alice,
this.fhevm,
aliceBalanceHandle,
this.erc20Address,
);
expect(aliceBalance).to.equal(0);
const bobBalanceHandle = await this.erc20.balanceOf(this.signers.bob);
const bobBalance = await reencryptEuint64(
this.signers.bob,
this.fhevm,
bobBalanceHandle,
this.erc20Address,
);
expect(bobBalance).to.equal(10000);
expect(idWinner1).to.hexEqual(this.signers.bob.address);
const bobDepositHandle = await this.adBidContract.connect(this.signers.bob).getDeposit();
const bobDepositAmount = await reencryptEuint64(
this.signers.bob,
this.fhevm,
bobDepositHandle,
this.contractAddress,
);
expect(bobDepositAmount).to.equal(2000);
await this.adBidContract.connect(this.signers.alice).withdraw();
const aliceBalanceHandle2 = await this.erc20.balanceOf(this.signers.alice);
const aliceBalance2 = await reencryptEuint64(
this.signers.alice,
this.fhevm,
aliceBalanceHandle2,
this.erc20Address,
);
expect(aliceBalance2).to.equal(10000);
await this.adBidContract.connect(this.signers.bob).withdraw();
const bobBalanceHandle2 = await this.erc20.balanceOf(this.signers.bob);
const bobBalance2 = await reencryptEuint64(
this.signers.bob,
this.fhevm,
bobBalanceHandle2,
this.erc20Address,
);
expect(bobBalance2).to.equal(12000);
});
});