Skip to content

Commit 5c6cf2a

Browse files
committed
Extract delegation info checks
1 parent 51ccd94 commit 5c6cf2a

File tree

1 file changed

+69
-27
lines changed

1 file changed

+69
-27
lines changed

test/staking/TokenStaking.test.js

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5294,9 +5294,13 @@ describe("TokenStaking", () => {
52945294
})
52955295

52965296
it("should not call seize in Keep contract", async () => {
5297-
expect(
5298-
await keepStakingMock.getDelegationInfo(stakingProvider.address)
5299-
).to.deep.equal([newKeepAmount, createdAt, Zero])
5297+
await assertDelegationInfo(
5298+
stakingProvider.address,
5299+
newKeepAmount,
5300+
createdAt,
5301+
Zero
5302+
)
5303+
53005304
expect(
53015305
await keepStakingMock.tattletales(otherStaker.address)
53025306
).to.equal(0)
@@ -5335,9 +5339,12 @@ describe("TokenStaking", () => {
53355339
})
53365340

53375341
it("should not call seize in Keep contract", async () => {
5338-
expect(
5339-
await keepStakingMock.getDelegationInfo(stakingProvider.address)
5340-
).to.deep.equal([newKeepAmount, createdAt, Zero])
5342+
await assertDelegationInfo(
5343+
stakingProvider.address,
5344+
newKeepAmount,
5345+
createdAt,
5346+
Zero
5347+
)
53415348
expect(
53425349
await keepStakingMock.tattletales(otherStaker.address)
53435350
).to.equal(0)
@@ -5405,9 +5412,12 @@ describe("TokenStaking", () => {
54055412
})
54065413

54075414
it("should not call seize in Keep contract", async () => {
5408-
expect(
5409-
await keepStakingMock.getDelegationInfo(stakingProvider.address)
5410-
).to.deep.equal([Zero, createdAt, Zero])
5415+
await assertDelegationInfo(
5416+
stakingProvider.address,
5417+
Zero,
5418+
createdAt,
5419+
Zero
5420+
)
54115421
expect(
54125422
await keepStakingMock.tattletales(otherStaker.address)
54135423
).to.equal(0)
@@ -5549,9 +5559,12 @@ describe("TokenStaking", () => {
55495559
})
55505560

55515561
it("should call seize in Keep contract", async () => {
5552-
expect(
5553-
await keepStakingMock.getDelegationInfo(stakingProvider.address)
5554-
).to.deep.equal([expectedKeepAmount, createdAt, Zero])
5562+
await assertDelegationInfo(
5563+
stakingProvider.address,
5564+
expectedKeepAmount,
5565+
createdAt,
5566+
Zero
5567+
)
55555568
expect(
55565569
await keepStakingMock.tattletales(otherStaker.address)
55575570
).to.equal(expectedReward)
@@ -5665,9 +5678,12 @@ describe("TokenStaking", () => {
56655678
})
56665679

56675680
it("should call seize in Keep contract", async () => {
5668-
expect(
5669-
await keepStakingMock.getDelegationInfo(stakingProvider.address)
5670-
).to.deep.equal([expectedKeepAmount, createdAt, Zero])
5681+
await assertDelegationInfo(
5682+
stakingProvider.address,
5683+
expectedKeepAmount,
5684+
createdAt,
5685+
Zero
5686+
)
56715687
expect(
56725688
await keepStakingMock.tattletales(otherStaker.address)
56735689
).to.equal(expectedReward)
@@ -5804,9 +5820,12 @@ describe("TokenStaking", () => {
58045820
})
58055821

58065822
it("should call seize in Keep contract", async () => {
5807-
expect(
5808-
await keepStakingMock.getDelegationInfo(stakingProvider.address)
5809-
).to.deep.equal([expectedKeepAmount, createdAt, undelegatedAt])
5823+
await assertDelegationInfo(
5824+
stakingProvider.address,
5825+
expectedKeepAmount,
5826+
createdAt,
5827+
Zero
5828+
)
58105829
expect(
58115830
await keepStakingMock.tattletales(otherStaker.address)
58125831
).to.equal(expectedReward)
@@ -7026,12 +7045,13 @@ describe("TokenStaking", () => {
70267045
})
70277046

70287047
it("should not call seize in Keep contract", async () => {
7029-
expect(
7030-
await keepStakingMock.getDelegationInfo(stakingProvider.address)
7031-
).to.deep.equal([Zero, Zero, Zero])
7032-
expect(
7033-
await keepStakingMock.getDelegationInfo(otherStaker.address)
7034-
).to.deep.equal([keepAmount, createdAt, Zero])
7048+
await assertDelegationInfo(stakingProvider.address, Zero, Zero, Zero)
7049+
await assertDelegationInfo(
7050+
otherStaker.address,
7051+
keepAmount,
7052+
createdAt,
7053+
Zero
7054+
)
70357055
expect(
70367056
await keepStakingMock.tattletales(auxiliaryAccount.address)
70377057
).to.equal(0)
@@ -7172,9 +7192,7 @@ describe("TokenStaking", () => {
71727192

71737193
it("should call seize in Keep contract", async () => {
71747194
const expectedKeepReward = rewardFromPenalty(keepAmount.div(2), 100)
7175-
expect(
7176-
await keepStakingMock.getDelegationInfo(otherStaker.address)
7177-
).to.deep.equal([Zero, createdAt, Zero])
7195+
await assertDelegationInfo(otherStaker.address, Zero, createdAt, Zero)
71787196
expect(
71797197
await keepStakingMock.tattletales(auxiliaryAccount.address)
71807198
).to.equal(expectedKeepReward)
@@ -7604,4 +7622,28 @@ describe("TokenStaking", () => {
76047622
"invalid deauthorizingTo"
76057623
).to.equal(expectedDeauthorizingTo)
76067624
}
7625+
7626+
async function assertDelegationInfo(
7627+
stakingProviderAddress,
7628+
expectedAmount,
7629+
expectedCreatedAt,
7630+
expectedUndelegatedAt
7631+
) {
7632+
expect(
7633+
(await keepStakingMock.getDelegationInfo(stakingProviderAddress)).amount,
7634+
"invalid amount"
7635+
).to.equal(expectedAmount)
7636+
7637+
expect(
7638+
(await keepStakingMock.getDelegationInfo(stakingProviderAddress))
7639+
.createdAt,
7640+
"invalid createdAt"
7641+
).to.equal(expectedCreatedAt)
7642+
7643+
expect(
7644+
(await keepStakingMock.getDelegationInfo(stakingProviderAddress))
7645+
.undelegatedAt,
7646+
"invalid undelegatedAt"
7647+
).to.equal(expectedUndelegatedAt)
7648+
}
76077649
})

0 commit comments

Comments
 (0)