-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathpunk-delegate.spec.ts
87 lines (73 loc) · 3.24 KB
/
punk-delegate.spec.ts
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
import BigNumber from "bignumber.js";
import { BigNumber as BN } from "ethers";
import { parseEther } from "ethers/lib/utils";
import DRE from "hardhat";
import { getReservesConfigByPool } from "../helpers/configuration";
import { BendPools, iBendPoolAssets, IReserveParams, ProtocolErrors, ProtocolLoanState } from "../helpers/types";
import { configuration as actionsConfiguration } from "./helpers/actions";
import { makeSuite, TestEnv } from "./helpers/make-suite";
import { configuration as calculationsConfiguration } from "./helpers/utils/calculations";
import { NETWORKS_DEFAULT_GAS } from "../helper-hardhat-config";
const chai = require("chai");
const { expect } = chai;
makeSuite("PunkGateway: Delegate", (testEnv: TestEnv) => {
const depositSize = parseEther("5");
before("Initializing configuration", async () => {
// Sets BigNumber for this suite, instead of globally
BigNumber.config({
DECIMAL_PLACES: 0,
ROUNDING_MODE: BigNumber.ROUND_DOWN,
});
actionsConfiguration.skipIntegrityCheck = false; //set this to true to execute solidity-coverage
calculationsConfiguration.reservesParams = <iBendPoolAssets<IReserveParams>>(
getReservesConfigByPool(BendPools.proto)
);
});
after("Reset", () => {
// Reset BigNumber
BigNumber.config({
DECIMAL_PLACES: 20,
ROUNDING_MODE: BigNumber.ROUND_HALF_UP,
});
});
it("Hacker try to borrow and delegate different onBehalf (should revert)", async () => {
const { users, punkGateway, weth } = testEnv;
const depositor = users[0];
const borrower = users[1];
const liquidator = users[2];
const hacker = users[3];
const borrowSize1 = parseEther("1");
const borrowSize2 = parseEther("2");
const borrowSizeAll = borrowSize1.add(borrowSize2);
const tokenIdNum = testEnv.tokenIdTracker++;
const tokenId = tokenIdNum.toString();
console.log("borrow");
await expect(
punkGateway.connect(hacker.signer).borrow(weth.address, borrowSize2, tokenId, borrower.address, "0")
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_ONBEHALFOF_OR_IN_WHITELIST);
console.log("borrowETH");
await expect(
punkGateway.connect(hacker.signer).borrowETH(borrowSize2, tokenId, borrower.address, "0")
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_ONBEHALFOF_OR_IN_WHITELIST);
});
it("Hacker try to auction and delegate different onBehalf (should revert)", async () => {
const { users, punkGateway, weth } = testEnv;
const depositor = users[0];
const borrower = users[1];
const liquidator = users[2];
const hacker = users[3];
const borrowSize1 = parseEther("1");
const borrowSize2 = parseEther("2");
const borrowSizeAll = borrowSize1.add(borrowSize2);
const tokenIdNum = testEnv.tokenIdTracker++;
const tokenId = tokenIdNum.toString();
console.log("auction");
await expect(punkGateway.connect(hacker.signer).auction(tokenId, "1000000", liquidator.address)).to.be.revertedWith(
ProtocolErrors.CALLER_NOT_ONBEHALFOF_OR_IN_WHITELIST
);
console.log("auctionETH");
await expect(
punkGateway.connect(hacker.signer).auctionETH(tokenId, liquidator.address, { value: depositSize })
).to.be.revertedWith(ProtocolErrors.CALLER_NOT_ONBEHALFOF_OR_IN_WHITELIST);
});
});