Skip to content

Commit 89ca5ba

Browse files
author
Mike-CZ
committed
Fix tests
1 parent 0bae479 commit 89ca5ba

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

contracts/sfc/SFCBase.sol

-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ contract SFCBase is SFCState {
1818
// addresses
1919
error ZeroAddress();
2020
error SameAddress();
21-
error RecipientNotSFC();
2221

2322
// values
2423
error ZeroAmount();
@@ -57,10 +56,6 @@ contract SFCBase is SFCState {
5756
error SFCGovAlreadyUpdated();
5857
error SFCWrongGovVersion();
5958

60-
// node driver
61-
error SelfCodeHashMismatch();
62-
error DriverCodeHashMismatch();
63-
6459
// governance
6560
error GovVotesRecountFailed();
6661

test/SFC.ts

+42-33
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('SFC', () => {
5252
to: this.sfc,
5353
value: 1,
5454
}),
55-
).to.revertedWithCustomError(this.sfc, 'TransfersNotAllowed');
55+
).to.revertedWithCustomError(this.sfcLib, 'TransfersNotAllowed');
5656
});
5757

5858
describe('Genesis validator', () => {
@@ -77,11 +77,14 @@ describe('SFC', () => {
7777
});
7878

7979
it('Should revert when sealEpoch not called by node', async function () {
80-
await expect(this.sfc.sealEpoch([1], [1], [1], [1], 0)).to.be.revertedWithCustomError(this.sfc, 'NotDriverAuth');
80+
await expect(this.sfc.sealEpoch([1], [1], [1], [1], 0)).to.be.revertedWithCustomError(
81+
this.sfcLib,
82+
'NotDriverAuth',
83+
);
8184
});
8285

8386
it('Should revert when SealEpochValidators not called by node', async function () {
84-
await expect(this.sfc.sealEpochValidators([1])).to.be.revertedWithCustomError(this.sfc, 'NotDriverAuth');
87+
await expect(this.sfc.sealEpochValidators([1])).to.be.revertedWithCustomError(this.sfcLib, 'NotDriverAuth');
8588
});
8689
});
8790

@@ -176,13 +179,13 @@ describe('SFC', () => {
176179
this.sfc
177180
.connect(this.validator)
178181
.createValidator(ethers.Wallet.createRandom().publicKey, { value: ethers.parseEther('0.1') }),
179-
).to.be.revertedWithCustomError(this.sfc, 'InsufficientSelfStake');
182+
).to.be.revertedWithCustomError(this.sfcLib, 'InsufficientSelfStake');
180183
});
181184

182185
it('Should revert when public key is empty while creating a validator', async function () {
183186
await expect(
184187
this.sfc.connect(this.validator).createValidator('0x', { value: ethers.parseEther('0.4') }),
185-
).to.be.revertedWithCustomError(this.sfc, 'EmptyPubkey');
188+
).to.be.revertedWithCustomError(this.sfcLib, 'EmptyPubkey');
186189
});
187190

188191
it('Should succeed and create two validators and return id of last validator', async function () {
@@ -213,7 +216,7 @@ describe('SFC', () => {
213216
it('Should revert when staking to non-existing validator', async function () {
214217
await expect(
215218
this.sfc.connect(this.secondValidator).delegate(1, { value: ethers.parseEther('0.1') }),
216-
).to.be.revertedWithCustomError(this.sfc, 'ValidatorNotExists');
219+
).to.be.revertedWithCustomError(this.sfcLib, 'ValidatorNotExists');
217220
});
218221

219222
it('Should succeed and stake with different delegators', async function () {
@@ -328,13 +331,13 @@ describe('SFC', () => {
328331
0,
329332
0,
330333
),
331-
).to.be.revertedWithCustomError(this.sfc, 'NotDriverAuth');
334+
).to.be.revertedWithCustomError(this.sfcLib, 'NotDriverAuth');
332335
});
333336

334337
it('Should revert when setGenesisDelegation is not called not node', async function () {
335338
const delegator = ethers.Wallet.createRandom();
336339
await expect(this.sfc.setGenesisDelegation(delegator, 1, 100, 0, 0, 0, 0, 0, 1000)).to.be.revertedWithCustomError(
337-
this.sfc,
340+
this.sfcLib,
338341
'NotDriverAuth',
339342
);
340343
});
@@ -440,7 +443,7 @@ describe('SFC', () => {
440443
this.sfc
441444
.connect(validator)
442445
.createValidator(ethers.Wallet.createRandom().publicKey, { value: ethers.parseEther('0.1') }),
443-
).to.be.revertedWithCustomError(this.sfc, 'InsufficientSelfStake');
446+
).to.be.revertedWithCustomError(this.sfcLib, 'InsufficientSelfStake');
444447

445448
await node.handleTx(
446449
await this.sfc.connect(validator).createValidator(pubkey, { value: ethers.parseEther('0.3175') }),
@@ -450,7 +453,7 @@ describe('SFC', () => {
450453
this.sfc
451454
.connect(validator)
452455
.createValidator(ethers.Wallet.createRandom().publicKey, { value: ethers.parseEther('0.5') }),
453-
).to.be.revertedWithCustomError(this.sfc, 'ValidatorExists');
456+
).to.be.revertedWithCustomError(this.sfcLib, 'ValidatorExists');
454457

455458
await node.handleTx(
456459
await this.sfc.connect(secondValidator).createValidator(secondPubkey, { value: ethers.parseEther('0.5') }),
@@ -768,7 +771,7 @@ describe('SFC', () => {
768771
it('Should revert when deactivating validator if not Node', async function () {
769772
await this.sfc.disableNonNodeCalls();
770773
await expect(this.sfc.deactivateValidator(this.validatorId, 0)).to.be.revertedWithCustomError(
771-
this.sfc,
774+
this.sfcLib,
772775
'NotDriverAuth',
773776
);
774777
});
@@ -1008,7 +1011,7 @@ describe('SFC', () => {
10081011

10091012
it('Should revert when calling deactivateValidator with wrong status', async function () {
10101013
await expect(this.sfc.deactivateValidator(1, 0)).to.be.revertedWithCustomError(
1011-
this.sfc,
1014+
this.sfcLib,
10121015
'WrongValidatorStatus',
10131016
);
10141017
});
@@ -1096,24 +1099,24 @@ describe('SFC', () => {
10961099

10971100
describe('Epoch getters', () => {
10981101
it('Should revert when trying to unlock stake if not lockedup', async function () {
1099-
await expect(this.sfc.unlockStake(1, 10)).to.be.revertedWithCustomError(this.sfc, 'NotLockedUp');
1102+
await expect(this.sfc.unlockStake(1, 10)).to.be.revertedWithCustomError(this.sfcLib, 'NotLockedUp');
11001103
});
11011104

11021105
it('Should revert when trying to unlock stake if amount is 0', async function () {
1103-
await expect(this.sfc.unlockStake(1, 0)).to.be.revertedWithCustomError(this.sfc, 'ZeroAmount');
1106+
await expect(this.sfc.unlockStake(1, 0)).to.be.revertedWithCustomError(this.sfcLib, 'ZeroAmount');
11041107
});
11051108

11061109
it('Should succeed and return slashed status', async function () {
11071110
expect(await this.sfc.isSlashed(1)).to.equal(false);
11081111
});
11091112

11101113
it('Should revert when delegating to an unexisting validator', async function () {
1111-
await expect(this.sfc.delegate(4)).to.be.revertedWithCustomError(this.sfc, 'ValidatorNotExists');
1114+
await expect(this.sfc.delegate(4)).to.be.revertedWithCustomError(this.sfcLib, 'ValidatorNotExists');
11121115
});
11131116

11141117
it('Should revert when delegating to an unexisting validator (2)', async function () {
11151118
await expect(this.sfc.delegate(4, { value: ethers.parseEther('1') })).to.be.revertedWithCustomError(
1116-
this.sfc,
1119+
this.sfcLib,
11171120
'ValidatorNotExists',
11181121
);
11191122
});
@@ -1214,20 +1217,23 @@ describe('SFC', () => {
12141217

12151218
it('Should revert when withdrawing nonexistent request', async function () {
12161219
await expect(this.sfc.withdraw(this.validatorId, 0)).to.be.revertedWithCustomError(
1217-
this.sfc,
1220+
this.sfcLib,
12181221
'RequestNotExists',
12191222
);
12201223
});
12211224

12221225
it('Should revert when undelegating 0 amount', async function () {
12231226
await this.blockchainNode.sealEpoch(1_000);
1224-
await expect(this.sfc.undelegate(this.validatorId, 0, 0)).to.be.revertedWithCustomError(this.sfc, 'ZeroAmount');
1227+
await expect(this.sfc.undelegate(this.validatorId, 0, 0)).to.be.revertedWithCustomError(
1228+
this.sfcLib,
1229+
'ZeroAmount',
1230+
);
12251231
});
12261232

12271233
it('Should revert when undelegating if not enough unlocked stake', async function () {
12281234
await this.blockchainNode.sealEpoch(1_000);
12291235
await expect(this.sfc.undelegate(this.validatorId, 0, 10)).to.be.revertedWithCustomError(
1230-
this.sfc,
1236+
this.sfcLib,
12311237
'NotEnoughUnlockedStake',
12321238
);
12331239
});
@@ -1237,7 +1243,7 @@ describe('SFC', () => {
12371243
await this.sfc.connect(this.thirdDelegator).delegate(this.validatorId, { value: ethers.parseEther('1') });
12381244
await expect(
12391245
this.sfc.connect(this.thirdDelegator).unlockStake(this.validatorId, 10),
1240-
).to.be.revertedWithCustomError(this.sfc, 'NotLockedUp');
1246+
).to.be.revertedWithCustomError(this.sfcLib, 'NotLockedUp');
12411247
});
12421248

12431249
it('Should succeed and return the unlocked stake', async function () {
@@ -1253,7 +1259,7 @@ describe('SFC', () => {
12531259
await this.blockchainNode.sealEpoch(1_000);
12541260
await expect(
12551261
this.sfc.connect(this.thirdDelegator).claimRewards(this.validatorId),
1256-
).to.be.revertedWithCustomError(this.sfc, 'ZeroRewards');
1262+
).to.be.revertedWithCustomError(this.sfcLib, 'ZeroRewards');
12571263
});
12581264
});
12591265

@@ -1271,7 +1277,7 @@ describe('SFC', () => {
12711277
this.sfc
12721278
.connect(this.thirdDelegator)
12731279
.lockStake(this.validatorId, 2 * 60 * 60 * 24 * 365, ethers.parseEther('0')),
1274-
).to.be.revertedWithCustomError(this.sfc, 'ZeroAmount');
1280+
).to.be.revertedWithCustomError(this.sfcLib, 'ZeroAmount');
12751281
});
12761282

12771283
it('Should revert when locking for more than a year', async function () {
@@ -1281,7 +1287,7 @@ describe('SFC', () => {
12811287
this.sfc
12821288
.connect(this.thirdDelegator)
12831289
.lockStake(this.thirdValidatorId, 2 * 60 * 60 * 24 * 365, ethers.parseEther('1')),
1284-
).to.be.revertedWithCustomError(this.sfc, 'IncorrectDuration');
1290+
).to.be.revertedWithCustomError(this.sfcLib, 'IncorrectDuration');
12851291
});
12861292

12871293
it('Should revert when locking for more than a validator lockup period', async function () {
@@ -1291,7 +1297,7 @@ describe('SFC', () => {
12911297
this.sfc
12921298
.connect(this.thirdDelegator)
12931299
.lockStake(this.thirdValidatorId, 60 * 60 * 24 * 364, ethers.parseEther('1')),
1294-
).to.be.revertedWithCustomError(this.sfc, 'ValidatorLockupTooShort');
1300+
).to.be.revertedWithCustomError(this.sfcLib, 'ValidatorLockupTooShort');
12951301
await this.sfc
12961302
.connect(this.thirdDelegator)
12971303
.lockStake(this.thirdValidatorId, 60 * 60 * 24 * 363, ethers.parseEther('1'));
@@ -1315,7 +1321,7 @@ describe('SFC', () => {
13151321
await this.blockchainNode.sealEpoch(60 * 60 * 24 * 14);
13161322
await expect(
13171323
this.sfc.unlockStake(this.thirdValidatorId, ethers.parseEther('10')),
1318-
).to.be.revertedWithCustomError(this.sfc, 'NotLockedUp');
1324+
).to.be.revertedWithCustomError(this.sfcLib, 'NotLockedUp');
13191325
});
13201326

13211327
it('Should revert when unlocking more than locked stake', async function () {
@@ -1327,7 +1333,7 @@ describe('SFC', () => {
13271333
await this.blockchainNode.sealEpoch(60 * 60 * 24 * 14);
13281334
await expect(
13291335
this.sfc.connect(this.thirdDelegator).unlockStake(this.thirdValidatorId, ethers.parseEther('10')),
1330-
).to.be.revertedWithCustomError(this.sfc, 'NotEnoughLockedStake');
1336+
).to.be.revertedWithCustomError(this.sfcLib, 'NotEnoughLockedStake');
13311337
});
13321338

13331339
it('Should succeed and scale unlocking penalty', async function () {
@@ -1358,7 +1364,7 @@ describe('SFC', () => {
13581364

13591365
await expect(
13601366
this.sfc.connect(this.thirdDelegator).unlockStake(this.thirdValidatorId, ethers.parseEther('0.51')),
1361-
).to.be.revertedWithCustomError(this.sfc, 'NotEnoughLockedStake');
1367+
).to.be.revertedWithCustomError(this.sfcLib, 'NotEnoughLockedStake');
13621368
expect(
13631369
await this.sfc
13641370
.connect(this.thirdDelegator)
@@ -1399,7 +1405,7 @@ describe('SFC', () => {
13991405

14001406
await expect(
14011407
this.sfc.connect(this.thirdDelegator).unlockStake(this.thirdValidatorId, ethers.parseEther('0.51')),
1402-
).to.be.revertedWithCustomError(this.sfc, 'NotEnoughLockedStake');
1408+
).to.be.revertedWithCustomError(this.sfcLib, 'NotEnoughLockedStake');
14031409
expect(
14041410
await this.sfc
14051411
.connect(this.thirdDelegator)
@@ -1417,7 +1423,7 @@ describe('SFC', () => {
14171423

14181424
await expect(
14191425
this.sfc.connect(this.thirdDelegator).unlockStake(this.thirdValidatorId, ethers.parseEther('1.51')),
1420-
).to.be.revertedWithCustomError(this.sfc, 'NotEnoughLockedStake');
1426+
).to.be.revertedWithCustomError(this.sfcLib, 'NotEnoughLockedStake');
14211427
expect(
14221428
await this.sfc
14231429
.connect(this.thirdDelegator)
@@ -1479,13 +1485,16 @@ describe('SFC', () => {
14791485

14801486
await expect(
14811487
this.sfc.connect(this.validator).updateSlashingRefundRatio(this.thirdValidatorId, 1),
1482-
).to.be.revertedWithCustomError(this.sfc, 'ValidatorNotSlashed');
1488+
).to.be.revertedWithCustomError(this.sfcLib, 'ValidatorNotSlashed');
14831489

14841490
await this.blockchainNode.sealEpoch(60 * 60 * 24 * 14);
14851491
});
14861492

14871493
it('Should revert when syncing if validator does not exist', async function () {
1488-
await expect(this.sfc._syncValidator(33, false)).to.be.revertedWithCustomError(this.sfc, 'ValidatorNotExists');
1494+
await expect(this.sfc._syncValidator(33, false)).to.be.revertedWithCustomError(
1495+
this.sfcLib,
1496+
'ValidatorNotExists',
1497+
);
14891498
});
14901499
});
14911500
});
@@ -1688,7 +1697,7 @@ describe('SFC', () => {
16881697
await this.blockchainNode.sealEpoch(60 * 60 * 24);
16891698
await expect(
16901699
this.sfc.connect(this.firstDelegator).relockStake(this.validatorId, 60 * 60 * 24 * 20, ethers.parseEther('0')),
1691-
).to.be.revertedWithCustomError(this.sfc, 'TooFrequentReLocks');
1700+
).to.be.revertedWithCustomError(this.sfcLib, 'TooFrequentReLocks');
16921701

16931702
// 4
16941703
await this.sfc.advanceTime(60 * 60 * 24 * 14);
@@ -1698,7 +1707,7 @@ describe('SFC', () => {
16981707
await this.blockchainNode.sealEpoch(60 * 60 * 24);
16991708
await expect(
17001709
this.sfc.connect(this.firstDelegator).relockStake(this.validatorId, 60 * 60 * 24 * 20, ethers.parseEther('0')),
1701-
).to.be.revertedWithCustomError(this.sfc, 'TooFrequentReLocks');
1710+
).to.be.revertedWithCustomError(this.sfcLib, 'TooFrequentReLocks');
17021711

17031712
for (let i = 5; i <= 40; i++) {
17041713
// 5-40

0 commit comments

Comments
 (0)