-
Notifications
You must be signed in to change notification settings - Fork 0
/
Telephone.test.js
38 lines (27 loc) · 1.06 KB
/
Telephone.test.js
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
const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers");
const { expect } = require("chai");
const CONTRACT_NAME = "Telephone";
const ATTACK_CONTRACT_NAME = "AttackTelephone";
describe(CONTRACT_NAME, function () {
async function deployLoadFixture() {
const [owner, attacker] = await ethers.getSigners();
const Telephone = await ethers.getContractFactory(CONTRACT_NAME);
const telephone = await Telephone.deploy();
const AttackContract = await ethers.getContractFactory(
ATTACK_CONTRACT_NAME
);
const attackContract = await AttackContract.deploy(telephone.address);
return { telephone, attackContract, attacker };
}
it("Challenge Solved", async function () {
let tx;
let {telephone, attackContract, attacker} = await loadFixture(deployLoadFixture)
attackContract = attackContract.connect(attacker)
// take the ownership
tx = await attackContract.attack(attacker.address)
await tx.wait()
// test
tx = await telephone.owner()
expect(tx).to.equal(attacker.address)
});
});