Skip to content

Commit 79e596a

Browse files
refactor: streamline WalletRegistry test cases for clarity and consistency, enhancing readability and maintainability
1 parent 748dba8 commit 79e596a

3 files changed

Lines changed: 250 additions & 235 deletions

File tree

solidity/ecdsa/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ hardhat-dependency-compiler/
88
typechain/
99
docgen-templates/
1010
export.json
11+
gasReporterOutput.json

solidity/ecdsa/test/WalletRegistry.Slashing.test.ts

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -128,63 +128,66 @@ describe("WalletRegistry - Slashing", () => {
128128
context.skip(
129129
"when the passed wallet members identifiers are valid (skipped: TokenStaking slashing queue API differs from legacy tests)",
130130
() => {
131-
let notifierBalanceBefore
132-
let notifierBalanceAfter
131+
let notifierBalanceBefore
132+
let notifierBalanceAfter
133133

134-
before(async () => {
135-
await createSnapshot()
134+
before(async () => {
135+
await createSnapshot()
136136

137-
notifierBalanceBefore = await tToken.balanceOf(thirdParty.address)
138-
await walletRegistry
139-
.connect(walletOwner.wallet)
140-
.seize(
141-
amountToSlash,
142-
rewardMultiplier,
143-
thirdParty.address,
144-
walletID,
145-
membersIDs
146-
)
147-
notifierBalanceAfter = await tToken.balanceOf(thirdParty.address)
148-
})
149-
150-
after(async () => {
151-
await restoreSnapshot()
152-
})
153-
154-
it("should slash all group members", async () => {
155-
expect(await staking.getSlashingQueueLength()).to.equal(
156-
constants.groupSize
157-
)
158-
})
159-
160-
it("should slash with correct amounts", async () => {
161-
for (let i = 0; i < constants.groupSize; i++) {
162-
const slashing = await staking.slashingQueue(i)
163-
expect(slashing.amount).to.equal(amountToSlash)
164-
}
165-
})
166-
167-
it("should slash correct staking providers", async () => {
168-
for (let i = 0; i < constants.groupSize; i++) {
169-
const slashing = await staking.slashingQueue(i)
170-
const expectedStakingProvider =
171-
await walletRegistry.operatorToStakingProvider(
172-
membersAddresses[i]
137+
notifierBalanceBefore = await tToken.balanceOf(thirdParty.address)
138+
await walletRegistry
139+
.connect(walletOwner.wallet)
140+
.seize(
141+
amountToSlash,
142+
rewardMultiplier,
143+
thirdParty.address,
144+
walletID,
145+
membersIDs
173146
)
147+
notifierBalanceAfter = await tToken.balanceOf(thirdParty.address)
148+
})
174149

175-
expect(slashing.stakingProvider).to.equal(expectedStakingProvider)
176-
}
177-
})
150+
after(async () => {
151+
await restoreSnapshot()
152+
})
178153

179-
it("should send correct reward to notifier", async () => {
180-
// Notification rewards are no longer configured in TokenStaking
181-
// (pushNotificationReward/setNotificationReward methods removed).
182-
// The notifier receives 0 reward.
183-
const receivedReward = notifierBalanceAfter.sub(notifierBalanceBefore)
154+
it("should slash all group members", async () => {
155+
expect(await staking.getSlashingQueueLength()).to.equal(
156+
constants.groupSize
157+
)
158+
})
159+
160+
it("should slash with correct amounts", async () => {
161+
for (let i = 0; i < constants.groupSize; i++) {
162+
const slashing = await staking.slashingQueue(i)
163+
expect(slashing.amount).to.equal(amountToSlash)
164+
}
165+
})
166+
167+
it("should slash correct staking providers", async () => {
168+
for (let i = 0; i < constants.groupSize; i++) {
169+
const slashing = await staking.slashingQueue(i)
170+
const expectedStakingProvider =
171+
await walletRegistry.operatorToStakingProvider(
172+
membersAddresses[i]
173+
)
174+
175+
expect(slashing.stakingProvider).to.equal(expectedStakingProvider)
176+
}
177+
})
178+
179+
it("should send correct reward to notifier", async () => {
180+
// Notification rewards are no longer configured in TokenStaking
181+
// (pushNotificationReward/setNotificationReward methods removed).
182+
// The notifier receives 0 reward.
183+
const receivedReward = notifierBalanceAfter.sub(
184+
notifierBalanceBefore
185+
)
184186

185-
expect(receivedReward).to.equal(0)
186-
})
187-
})
187+
expect(receivedReward).to.equal(0)
188+
})
189+
}
190+
)
188191

189192
// TODO: Add a unit test ensuring `seize` call reverts if the staking
190193
// contract `seize` call reverts.

0 commit comments

Comments
 (0)