-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathReentrancyGuard.ts
48 lines (39 loc) · 1.49 KB
/
ReentrancyGuard.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
42
43
44
45
46
47
48
import { describeBehaviorOfReentrancyGuard } from '@solidstate/spec';
import {
ReentrancyGuardMock,
ReentrancyGuardMock__factory,
} from '@solidstate/typechain-types';
import { expect } from 'chai';
import { ethers } from 'hardhat';
describe('ReentrancyGuard', function () {
let instance: ReentrancyGuardMock;
beforeEach(async function () {
const [deployer] = await ethers.getSigners();
instance = await new ReentrancyGuardMock__factory(deployer).deploy();
});
describeBehaviorOfReentrancyGuard(async () => instance, {});
describe('__internal', function () {
describe('nonReentrant modifier', function () {
it('does not revert non-reentrant call', async function () {
await expect(instance['nonReentrancyTest()']()).not.to.be.reverted;
// test subsequent calls
await expect(instance['nonReentrancyTest()']()).not.to.be.reverted;
await expect(instance['reentrancyTest()']()).to.be.revertedWith(
'ReentrancyGuard: reentrant call',
);
});
describe('reverts if', function () {
it('call is reentrant', async function () {
await expect(instance['reentrancyTest()']()).to.be.revertedWith(
'ReentrancyGuard: reentrant call',
);
});
it('call is cross-function reentrant', async function () {
await expect(
instance['crossFunctionReentrancyTest()'](),
).to.be.revertedWith('ReentrancyGuard: reentrant call');
});
});
});
});
});