Skip to content

Commit c03952a

Browse files
fvictorioernestognwAmxx
authored
Remove async from describe blocks and add missing await in tests (#4942)
Co-authored-by: ernestognw <ernestognw@gmail.com> Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
1 parent 33ea111 commit c03952a

File tree

13 files changed

+64
-59
lines changed

13 files changed

+64
-59
lines changed

hardhat/async-test-sanity.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
process.on('unhandledRejection', reason => {
2+
throw new Error(reason);
3+
});

test/access/AccessControl.behavior.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function shouldBehaveLikeAccessControl() {
4343

4444
it('accounts can be granted a role multiple times', async function () {
4545
await this.mock.connect(this.defaultAdmin).grantRole(ROLE, this.authorized);
46-
expect(this.mock.connect(this.defaultAdmin).grantRole(ROLE, this.authorized)).to.not.emit(
46+
await expect(this.mock.connect(this.defaultAdmin).grantRole(ROLE, this.authorized)).to.not.emit(
4747
this.mock,
4848
'RoleGranted',
4949
);
@@ -82,7 +82,7 @@ function shouldBehaveLikeAccessControl() {
8282
it('a role can be revoked multiple times', async function () {
8383
await this.mock.connect(this.defaultAdmin).revokeRole(ROLE, this.authorized);
8484

85-
expect(this.mock.connect(this.defaultAdmin).revokeRole(ROLE, this.authorized)).to.not.emit(
85+
await expect(this.mock.connect(this.defaultAdmin).revokeRole(ROLE, this.authorized)).to.not.emit(
8686
this.mock,
8787
'RoleRevoked',
8888
);
@@ -112,10 +112,9 @@ function shouldBehaveLikeAccessControl() {
112112
});
113113

114114
it('only the sender can renounce their roles', async function () {
115-
expect(this.mock.connect(this.defaultAdmin).renounceRole(ROLE, this.authorized)).to.be.revertedWithCustomError(
116-
this.mock,
117-
'AccessControlBadConfirmation',
118-
);
115+
await expect(
116+
this.mock.connect(this.defaultAdmin).renounceRole(ROLE, this.authorized),
117+
).to.be.revertedWithCustomError(this.mock, 'AccessControlBadConfirmation');
119118
});
120119

121120
it('a role can be renounced multiple times', async function () {
@@ -571,7 +570,7 @@ function shouldBehaveLikeAccessControlDefaultAdminRules() {
571570
]) {
572571
it(`should revert if block.timestamp is ${tag} to schedule`, async function () {
573572
await time.increaseTo.timestamp(this.acceptSchedule + fromSchedule, false);
574-
expect(this.mock.connect(this.newDefaultAdmin).acceptDefaultAdminTransfer())
573+
await expect(this.mock.connect(this.newDefaultAdmin).acceptDefaultAdminTransfer())
575574
.to.be.revertedWithCustomError(this.mock, 'AccessControlEnforcedDefaultAdminDelay')
576575
.withArgs(this.acceptSchedule);
577576
});
@@ -625,7 +624,7 @@ function shouldBehaveLikeAccessControlDefaultAdminRules() {
625624
});
626625
});
627626

628-
describe('when there is no pending default admin transfer', async function () {
627+
describe('when there is no pending default admin transfer', function () {
629628
it('should succeed without changes', async function () {
630629
await expect(this.mock.connect(this.defaultAdmin).cancelDefaultAdminTransfer()).to.not.emit(
631630
this.mock,

test/access/Ownable2Step.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Ownable2Step', function () {
4848
});
4949
});
5050

51-
describe('renouncing ownership', async function () {
51+
describe('renouncing ownership', function () {
5252
it('changes owner after renouncing ownership', async function () {
5353
await expect(this.ownable2Step.connect(this.owner).renounceOwnership())
5454
.to.emit(this.ownable2Step, 'OwnershipTransferred')

test/access/manager/AccessManager.test.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,8 @@ describe('AccessManager', function () {
887887
shouldBehaveLikeDelayedAdminOperation();
888888
});
889889

890-
it('reverts setting grant delay for the PUBLIC_ROLE', function () {
891-
expect(this.manager.connect(this.admin).setGrantDelay(this.roles.PUBLIC.id, 69n))
890+
it('reverts setting grant delay for the PUBLIC_ROLE', async function () {
891+
await expect(this.manager.connect(this.admin).setGrantDelay(this.roles.PUBLIC.id, 69n))
892892
.to.be.revertedWithCustomError(this.manager, 'AccessManagerLockedRole')
893893
.withArgs(this.roles.PUBLIC.id);
894894
});
@@ -907,7 +907,7 @@ describe('AccessManager', function () {
907907
it('increases the delay after minsetback', async function () {
908908
const txResponse = await this.manager.connect(this.admin).setGrantDelay(this.role.id, newDelay);
909909
const setGrantDelayAt = await time.clockFromReceipt.timestamp(txResponse);
910-
expect(txResponse)
910+
await expect(txResponse)
911911
.to.emit(this.manager, 'RoleGrantDelayChanged')
912912
.withArgs(this.role.id, newDelay, setGrantDelayAt + MINSETBACK);
913913

@@ -933,7 +933,7 @@ describe('AccessManager', function () {
933933
it('increases the delay after minsetback', async function () {
934934
const txResponse = await this.manager.connect(this.admin).setGrantDelay(this.role.id, newDelay);
935935
const setGrantDelayAt = await time.clockFromReceipt.timestamp(txResponse);
936-
expect(txResponse)
936+
await expect(txResponse)
937937
.to.emit(this.manager, 'RoleGrantDelayChanged')
938938
.withArgs(this.role.id, newDelay, setGrantDelayAt + MINSETBACK);
939939

@@ -956,7 +956,7 @@ describe('AccessManager', function () {
956956
const txResponse = await this.manager.connect(this.admin).setGrantDelay(this.role.id, newDelay);
957957
const setGrantDelayAt = await time.clockFromReceipt.timestamp(txResponse);
958958

959-
expect(txResponse)
959+
await expect(txResponse)
960960
.to.emit(this.manager, 'RoleGrantDelayChanged')
961961
.withArgs(this.role.id, newDelay, setGrantDelayAt + setback);
962962

@@ -992,7 +992,7 @@ describe('AccessManager', function () {
992992
it('increases the delay after minsetback', async function () {
993993
const txResponse = await this.manager.connect(this.admin).setTargetAdminDelay(this.other, newDelay);
994994
const setTargetAdminDelayAt = await time.clockFromReceipt.timestamp(txResponse);
995-
expect(txResponse)
995+
await expect(txResponse)
996996
.to.emit(this.manager, 'TargetAdminDelayUpdated')
997997
.withArgs(this.other, newDelay, setTargetAdminDelayAt + MINSETBACK);
998998

@@ -1017,7 +1017,7 @@ describe('AccessManager', function () {
10171017
it('increases the delay after minsetback', async function () {
10181018
const txResponse = await this.manager.connect(this.admin).setTargetAdminDelay(this.other, newDelay);
10191019
const setTargetAdminDelayAt = await time.clockFromReceipt.timestamp(txResponse);
1020-
expect(txResponse)
1020+
await expect(txResponse)
10211021
.to.emit(this.manager, 'TargetAdminDelayUpdated')
10221022
.withArgs(this.other, newDelay, setTargetAdminDelayAt + MINSETBACK);
10231023

@@ -1040,7 +1040,7 @@ describe('AccessManager', function () {
10401040
const txResponse = await this.manager.connect(this.admin).setTargetAdminDelay(this.other, newDelay);
10411041
const setTargetAdminDelayAt = await time.clockFromReceipt.timestamp(txResponse);
10421042

1043-
expect(txResponse)
1043+
await expect(txResponse)
10441044
.to.emit(this.manager, 'TargetAdminDelayUpdated')
10451045
.withArgs(this.other, newDelay, setTargetAdminDelayAt + setback);
10461046

@@ -1135,7 +1135,7 @@ describe('AccessManager', function () {
11351135
.setTargetFunctionRole(this.target, sigs, this.roles.SOME.id);
11361136

11371137
for (const sig of sigs) {
1138-
expect(allowRole)
1138+
await expect(allowRole)
11391139
.to.emit(this.manager, 'TargetFunctionRoleUpdated')
11401140
.withArgs(this.target, sig, this.roles.SOME.id);
11411141
expect(await this.manager.getTargetFunctionRole(this.target, sig)).to.equal(this.roles.SOME.id);
@@ -1212,9 +1212,9 @@ describe('AccessManager', function () {
12121212

12131213
it('does not grant role to the user yet', async function () {
12141214
const timestamp = await time.clockFromReceipt.timestamp(this.txResponse);
1215-
expect(this.txResponse)
1215+
await expect(this.txResponse)
12161216
.to.emit(this.manager, 'RoleGranted')
1217-
.withArgs(ANOTHER_ROLE, this.user, timestamp + this.grantDelay, this.executionDelay, true);
1217+
.withArgs(ANOTHER_ROLE, this.user, this.executionDelay, timestamp + this.grantDelay, true);
12181218

12191219
// Access is correctly stored
12201220
const access = await this.manager.getAccess(ANOTHER_ROLE, this.user);
@@ -1237,9 +1237,9 @@ describe('AccessManager', function () {
12371237

12381238
it('grants role to the user', async function () {
12391239
const timestamp = await time.clockFromReceipt.timestamp(this.txResponse);
1240-
expect(this.txResponse)
1241-
.to.emit(this.manager, 'RoleAccessRequested')
1242-
.withArgs(ANOTHER_ROLE, this.user, timestamp + this.grantDelay, this.executionDelay, true);
1240+
await expect(this.txResponse)
1241+
.to.emit(this.manager, 'RoleGranted')
1242+
.withArgs(ANOTHER_ROLE, this.user, this.executionDelay, timestamp + this.grantDelay, true);
12431243

12441244
// Access is correctly stored
12451245
const access = await this.manager.getAccess(ANOTHER_ROLE, this.user);
@@ -1278,7 +1278,7 @@ describe('AccessManager', function () {
12781278
.connect(this.admin)
12791279
.grantRole(ANOTHER_ROLE, this.user, executionDelay);
12801280
const grantedAt = await time.clockFromReceipt.timestamp(txResponse);
1281-
expect(txResponse)
1281+
await expect(txResponse)
12821282
.to.emit(this.manager, 'RoleGranted')
12831283
.withArgs(ANOTHER_ROLE, this.user, executionDelay, grantedAt, true);
12841284

@@ -1335,9 +1335,9 @@ describe('AccessManager', function () {
13351335
.grantRole(ANOTHER_ROLE, this.user, this.newExecutionDelay);
13361336
const timestamp = await time.clockFromReceipt.timestamp(txResponse);
13371337

1338-
expect(txResponse)
1338+
await expect(txResponse)
13391339
.to.emit(this.manager, 'RoleGranted')
1340-
.withArgs(ANOTHER_ROLE, this.user, timestamp, this.newExecutionDelay, false);
1340+
.withArgs(ANOTHER_ROLE, this.user, this.newExecutionDelay, timestamp, false);
13411341

13421342
// Access is correctly stored
13431343
const access = await this.manager.getAccess(ANOTHER_ROLE, this.user);
@@ -1370,10 +1370,10 @@ describe('AccessManager', function () {
13701370
this.delay = this.previousExecutionDelay - this.newExecutionDelay; // For testAsDelay
13711371
});
13721372

1373-
it('emits event', function () {
1374-
expect(this.txResponse)
1373+
it('emits event', async function () {
1374+
await expect(this.txResponse)
13751375
.to.emit(this.manager, 'RoleGranted')
1376-
.withArgs(ANOTHER_ROLE, this.user, this.grantTimestamp + this.delay, this.newExecutionDelay, false);
1376+
.withArgs(ANOTHER_ROLE, this.user, this.newExecutionDelay, this.grantTimestamp + this.delay, false);
13771377
});
13781378

13791379
testAsDelay('execution delay effect', {
@@ -1446,9 +1446,9 @@ describe('AccessManager', function () {
14461446
.grantRole(ANOTHER_ROLE, this.user, this.newExecutionDelay);
14471447
const timestamp = await time.clockFromReceipt.timestamp(txResponse);
14481448

1449-
expect(txResponse)
1449+
await expect(txResponse)
14501450
.to.emit(this.manager, 'RoleGranted')
1451-
.withArgs(ANOTHER_ROLE, this.user, timestamp, this.newExecutionDelay, false);
1451+
.withArgs(ANOTHER_ROLE, this.user, this.newExecutionDelay, timestamp, false);
14521452

14531453
// Access is correctly stored
14541454
const access = await this.manager.getAccess(ANOTHER_ROLE, this.user);
@@ -1481,10 +1481,10 @@ describe('AccessManager', function () {
14811481
this.delay = this.previousExecutionDelay - this.newExecutionDelay; // For testAsDelay
14821482
});
14831483

1484-
it('emits event', function () {
1485-
expect(this.txResponse)
1484+
it('emits event', async function () {
1485+
await expect(this.txResponse)
14861486
.to.emit(this.manager, 'RoleGranted')
1487-
.withArgs(ANOTHER_ROLE, this.user, this.grantTimestamp + this.delay, this.newExecutionDelay, false);
1487+
.withArgs(ANOTHER_ROLE, this.user, this.newExecutionDelay, this.grantTimestamp + this.delay, false);
14881488
});
14891489

14901490
testAsDelay('execution delay effect', {
@@ -1871,9 +1871,9 @@ describe('AccessManager', function () {
18711871
const txResponse = await schedule();
18721872

18731873
expect(await this.manager.getSchedule(operationId)).to.equal(scheduledAt + this.delay);
1874-
expect(txResponse)
1874+
await expect(txResponse)
18751875
.to.emit(this.manager, 'OperationScheduled')
1876-
.withArgs(operationId, '1', scheduledAt + this.delay, this.target, this.calldata);
1876+
.withArgs(operationId, '1', scheduledAt + this.delay, this.caller, this.target, this.calldata);
18771877
});
18781878

18791879
it('schedules an operation at the minimum execution date if no specified execution date (when == 0)', async function () {
@@ -1886,9 +1886,9 @@ describe('AccessManager', function () {
18861886
const operationId = await this.manager.hashOperation(this.caller, this.target, this.calldata);
18871887

18881888
expect(await this.manager.getSchedule(operationId)).to.equal(scheduledAt + executionDelay);
1889-
expect(txResponse)
1889+
await expect(txResponse)
18901890
.to.emit(this.manager, 'OperationScheduled')
1891-
.withArgs(operationId, '1', scheduledAt + executionDelay, this.target, this.calldata);
1891+
.withArgs(operationId, '1', scheduledAt + executionDelay, this.caller, this.target, this.calldata);
18921892
});
18931893

18941894
it('increases the nonce of an operation scheduled more than once', async function () {

test/governance/TimelockController.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe('TimelockController', function () {
171171
MINDELAY,
172172
);
173173

174-
expect(tx)
174+
await expect(tx)
175175
.to.emit(this.mock, 'CallScheduled')
176176
.withArgs(
177177
this.operation.id,
@@ -698,7 +698,7 @@ describe('TimelockController', function () {
698698
this.operation.salt,
699699
);
700700
for (const i in this.operation.targets) {
701-
expect(tx)
701+
await expect(tx)
702702
.to.emit(this.mock, 'CallExecuted')
703703
.withArgs(
704704
this.operation.id,
@@ -843,7 +843,7 @@ describe('TimelockController', function () {
843843
nonReentrantBatchOperation.salt,
844844
);
845845
for (const i in nonReentrantBatchOperation.targets) {
846-
expect(tx)
846+
await expect(tx)
847847
.to.emit(this.mock, 'CallExecuted')
848848
.withArgs(
849849
nonReentrantBatchOperation.id,

test/governance/extensions/GovernorTimelockAccess.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,15 @@ describe('GovernorTimelockAccess', function () {
370370
if (await this.mock.proposalNeedsQueuing(this.proposal.id)) {
371371
expect(await this.helper.queue())
372372
.to.emit(this.mock, 'ProposalQueued')
373-
.withArgs(this.proposal.id);
373+
.withArgs(this.proposal.id, anyValue);
374374
}
375375
if (delay > 0) {
376376
await this.helper.waitForEta();
377377
}
378378
expect(await this.helper.execute())
379379
.to.emit(this.mock, 'ProposalExecuted')
380380
.withArgs(this.proposal.id)
381-
.to.not.emit(this.receiver, 'CalledUnrestricted');
381+
.to.emit(this.receiver, 'CalledUnrestricted');
382382
});
383383
}
384384
});

test/proxy/Proxy.behaviour.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ const { getAddressInSlot, ImplementationSlot } = require('../helpers/storage');
66
module.exports = function shouldBehaveLikeProxy() {
77
it('cannot be initialized with a non-contract address', async function () {
88
const initializeData = '0x';
9+
const contractFactory = await ethers.getContractFactory('ERC1967Proxy');
910
await expect(this.createProxy(this.nonContractAddress, initializeData))
10-
.to.be.revertedWithCustomError(await ethers.getContractFactory('ERC1967Proxy'), 'ERC1967InvalidImplementation')
11+
.to.be.revertedWithCustomError(contractFactory, 'ERC1967InvalidImplementation')
1112
.withArgs(this.nonContractAddress);
1213
});
1314

test/proxy/beacon/BeaconProxy.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('BeaconProxy', function () {
2222
Object.assign(this, await loadFixture(fixture));
2323
});
2424

25-
describe('bad beacon is not accepted', async function () {
25+
describe('bad beacon is not accepted', function () {
2626
it('non-contract beacon', async function () {
2727
const notBeacon = this.other;
2828

@@ -34,7 +34,9 @@ describe('BeaconProxy', function () {
3434
it('non-compliant beacon', async function () {
3535
const badBeacon = await ethers.deployContract('BadBeaconNoImpl');
3636

37-
await expect(this.newBeaconProxy(badBeacon, '0x')).to.be.revertedWithoutReason;
37+
// BadBeaconNoImpl does not provide `implementation()` has no fallback.
38+
// This causes ERC1967Utils._setBeacon to revert.
39+
await expect(this.newBeaconProxy(badBeacon, '0x')).to.be.revertedWithoutReason();
3840
});
3941

4042
it('non-contract implementation', async function () {
@@ -92,7 +94,7 @@ describe('BeaconProxy', function () {
9294
});
9395
});
9496

95-
describe('upgrade', async function () {
97+
describe('upgrade', function () {
9698
it('upgrade a proxy by upgrading its beacon', async function () {
9799
const value = 10n;
98100
const data = this.v1.interface.encodeFunctionData('initializeNonPayableWithValue', [value]);

test/proxy/beacon/UpgradeableBeacon.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('UpgradeableBeacon', function () {
2323
.withArgs(this.other);
2424
});
2525

26-
describe('once deployed', async function () {
26+
describe('once deployed', function () {
2727
it('emits Upgraded event to the first implementation', async function () {
2828
await expect(this.beacon.deploymentTransaction()).to.emit(this.beacon, 'Upgraded').withArgs(this.v1);
2929
});

test/token/ERC1155/ERC1155.behavior.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function shouldBehaveLikeERC1155() {
173173
});
174174
}
175175

176-
describe('when called by the holder', async function () {
176+
describe('when called by the holder', function () {
177177
beforeEach(async function () {
178178
this.args = {
179179
operator: this.holder,
@@ -490,7 +490,7 @@ function shouldBehaveLikeERC1155() {
490490
});
491491
}
492492

493-
describe('when called by the holder', async function () {
493+
describe('when called by the holder', function () {
494494
beforeEach(async function () {
495495
this.args = {
496496
operator: this.holder,

0 commit comments

Comments
 (0)