generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGuessTheSecretNumberChallenge.test.ts
41 lines (34 loc) · 1.1 KB
/
GuessTheSecretNumberChallenge.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
31
32
33
34
35
36
37
38
39
40
41
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { Contract } from 'ethers';
import { ethers, network } from 'hardhat';
const { utils } = ethers;
const ANSWER_HASH = '0xdb81b4d58595fbbbb592d3661a34cdca14d7ab379441400cbfa1b78bc447c365';
const MAX_NUMBER = 2 ** 8;
describe('GuessTheSecretNumberChallenge', () => {
let target: Contract;
before(async () => {
const targetFactory = await ethers.getContractFactory('GuessTheSecretNumberChallenge');
target = await targetFactory.deploy({
value: utils.parseEther('1'),
});
await target.deployed();
console.log('Target deployed to:', target.address);
});
it('Exploit', async () => {
let answer: any;
for (answer = 0; answer < MAX_NUMBER; answer++) {
if (utils.keccak256(answer) === ANSWER_HASH) {
console.log('answer', answer);
break;
}
}
const tx = await target.guess(answer, {
value: utils.parseEther('1'),
});
await tx.wait();
});
after(async () => {
expect(await target.isComplete()).to.equal(true);
});
});