generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21-Shop.test.ts
31 lines (26 loc) · 1013 Bytes
/
21-Shop.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
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { Contract } from 'ethers';
import { ethers } from 'hardhat';
describe('Shop', () => {
let owner: SignerWithAddress;
let user1: SignerWithAddress;
let user2: SignerWithAddress;
let attacker: SignerWithAddress;
let contract: Contract;
before(async () => {
[owner, user1, user2, attacker] = await ethers.getSigners();
const Factory = await ethers.getContractFactory('Shop');
contract = await Factory.connect(owner).deploy();
await contract.deployed();
});
it('attack', async () => {
const AttackerFactory = await ethers.getContractFactory('ShopAttacker');
const attackerContract = await AttackerFactory.connect(attacker).deploy(contract.address);
await attackerContract.deployed();
const tx = await attackerContract.attack();
await tx.wait();
expect(await contract.isSold()).to.be.true;
expect(await contract.price()).to.equal(0);
});
});