Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify equalities #137

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 77 additions & 77 deletions test/0.4.24/lib/stakeLimitUtils.test.ts

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions test/0.4.24/nor/nor.aux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ describe("NodeOperatorsRegistry:auxiliary", () => {

context("unsafeUpdateValidatorsCount", () => {
beforeEach(async () => {
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.equal(
firstNodeOperatorId,
);
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.equal(
secondNodeOperatorId,
);
});
Expand All @@ -170,8 +170,8 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
const nonce = await nor.getNonce();

const beforeNOSummary = await nor.getNodeOperatorSummary(firstNodeOperatorId);
expect(beforeNOSummary.stuckValidatorsCount).to.be.equal(0n);
expect(beforeNOSummary.totalExitedValidators).to.be.equal(1n);
expect(beforeNOSummary.stuckValidatorsCount).to.equal(0n);
expect(beforeNOSummary.totalExitedValidators).to.equal(1n);

await expect(nor.connect(stakingRouter).unsafeUpdateValidatorsCount(firstNodeOperatorId, 3n, 2n))
.to.emit(nor, "StuckPenaltyStateChanged")
Expand All @@ -184,8 +184,8 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
.withArgs(nonce + 1n);

const middleNOSummary = await nor.getNodeOperatorSummary(firstNodeOperatorId);
expect(middleNOSummary.stuckValidatorsCount).to.be.equal(2n);
expect(middleNOSummary.totalExitedValidators).to.be.equal(3n);
expect(middleNOSummary.stuckValidatorsCount).to.equal(2n);
expect(middleNOSummary.totalExitedValidators).to.equal(3n);

await expect(nor.connect(stakingRouter).unsafeUpdateValidatorsCount(firstNodeOperatorId, 1n, 2n))
.to.emit(nor, "ExitedSigningKeysCountChanged")
Expand All @@ -197,24 +197,24 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
.to.not.emit(nor, "StuckPenaltyStateChanged");

const lastNOSummary = await nor.getNodeOperatorSummary(firstNodeOperatorId);
expect(lastNOSummary.stuckValidatorsCount).to.be.equal(2n);
expect(lastNOSummary.totalExitedValidators).to.be.equal(1n);
expect(lastNOSummary.stuckValidatorsCount).to.equal(2n);
expect(lastNOSummary.totalExitedValidators).to.equal(1n);
});
});

context("updateTargetValidatorsLimits", () => {
let targetLimit = 0n;

beforeEach(async () => {
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.equal(
firstNodeOperatorId,
);
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.equal(
secondNodeOperatorId,
);
});

it('reverts with "APP_AUTH_FAILED" error when called by sender without STAKING_ROUTER_ROLE', async () => {
it("reverts with \"APP_AUTH_FAILED\" error when called by sender without STAKING_ROUTER_ROLE", async () => {
expect(await acl["hasPermission(address,address,bytes32)"](stranger, nor, await nor.STAKING_ROUTER_ROLE())).to.be
.false;

Expand All @@ -223,7 +223,7 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
);
});

it('reverts with "OUT_OF_RANGE" error when called with targetLimit > UINT64_MAX', async () => {
it("reverts with \"OUT_OF_RANGE\" error when called with targetLimit > UINT64_MAX", async () => {
const targetLimitWrong = BigInt("0x10000000000000000");

await expect(
Expand Down Expand Up @@ -313,10 +313,10 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
});

it("Invalidates all deposit data for every operator", async () => {
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.equal(
firstNodeOperatorId,
);
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.equal(
secondNodeOperatorId,
);

Expand All @@ -335,13 +335,13 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
.withArgs(
firstNodeOperatorId,
NODE_OPERATORS[firstNodeOperatorId].totalSigningKeysCount -
NODE_OPERATORS[firstNodeOperatorId].depositedSigningKeysCount,
NODE_OPERATORS[firstNodeOperatorId].depositedSigningKeysCount,
)
.and.to.emit(nor, "NodeOperatorTotalKeysTrimmed")
.withArgs(
secondNodeOperatorId,
NODE_OPERATORS[secondNodeOperatorId].totalSigningKeysCount -
NODE_OPERATORS[secondNodeOperatorId].depositedSigningKeysCount,
NODE_OPERATORS[secondNodeOperatorId].depositedSigningKeysCount,
)
.to.emit(nor, "KeysOpIndexSet")
.withArgs(nonce + 1n)
Expand All @@ -362,7 +362,7 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
});

it("Invalidates the deposit data even if no trimming needed", async () => {
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[fourthNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[fourthNodeOperatorId])).to.equal(
firstNodeOperatorId,
);

Expand All @@ -377,10 +377,10 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
});

it("Invalidates all deposit data for every operator", async () => {
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.equal(
firstNodeOperatorId,
);
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.equal(
secondNodeOperatorId,
);

Expand All @@ -401,13 +401,13 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
.withArgs(
firstNodeOperatorId,
NODE_OPERATORS[firstNodeOperatorId].totalSigningKeysCount -
NODE_OPERATORS[firstNodeOperatorId].depositedSigningKeysCount,
NODE_OPERATORS[firstNodeOperatorId].depositedSigningKeysCount,
)
.and.to.emit(nor, "NodeOperatorTotalKeysTrimmed")
.withArgs(
secondNodeOperatorId,
NODE_OPERATORS[secondNodeOperatorId].totalSigningKeysCount -
NODE_OPERATORS[secondNodeOperatorId].depositedSigningKeysCount,
NODE_OPERATORS[secondNodeOperatorId].depositedSigningKeysCount,
)
.to.emit(nor, "KeysOpIndexSet")
.withArgs(nonce + 1n)
Expand All @@ -426,45 +426,45 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
});

it("Returns zero rewards if zero shares distributed", async () => {
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.equal(
firstNodeOperatorId,
);

const [recipients, shares, penalized] = await nor.getRewardsDistribution(0n);

expect(recipients.length).to.be.equal(1n);
expect(shares.length).to.be.equal(1n);
expect(penalized.length).to.be.equal(1n);
expect(recipients.length).to.equal(1n);
expect(shares.length).to.equal(1n);
expect(penalized.length).to.equal(1n);

expect(recipients[0]).to.be.equal(NODE_OPERATORS[firstNodeOperatorId].rewardAddress);
expect(shares[0]).to.be.equal(0n);
expect(penalized[0]).to.be.equal(false);
expect(recipients[0]).to.equal(NODE_OPERATORS[firstNodeOperatorId].rewardAddress);
expect(shares[0]).to.equal(0n);
expect(penalized[0]).to.equal(false);
});

it("Distributes all rewards to a single active operator if no others", async () => {
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.equal(
firstNodeOperatorId,
);

const [recipients, shares, penalized] = await nor.getRewardsDistribution(10n);

expect(recipients.length).to.be.equal(1n);
expect(shares.length).to.be.equal(1n);
expect(penalized.length).to.be.equal(1n);
expect(recipients.length).to.equal(1n);
expect(shares.length).to.equal(1n);
expect(penalized.length).to.equal(1n);

expect(recipients[0]).to.be.equal(NODE_OPERATORS[firstNodeOperatorId].rewardAddress);
expect(shares[0]).to.be.equal(10n);
expect(penalized[0]).to.be.equal(false);
expect(recipients[0]).to.equal(NODE_OPERATORS[firstNodeOperatorId].rewardAddress);
expect(shares[0]).to.equal(10n);
expect(penalized[0]).to.equal(false);
});

it("Returns correct reward distribution for multiple NOs", async () => {
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.equal(
firstNodeOperatorId,
);
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.equal(
secondNodeOperatorId,
);
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[thirdNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[thirdNodeOperatorId])).to.equal(
thirdNodeOperatorId,
);

Expand All @@ -480,9 +480,9 @@ describe("NodeOperatorsRegistry:auxiliary", () => {

const [recipients, shares, penalized] = await nor.getRewardsDistribution(100n);

expect(recipients.length).to.be.equal(2n);
expect(shares.length).to.be.equal(2n);
expect(penalized.length).to.be.equal(2n);
expect(recipients.length).to.equal(2n);
expect(shares.length).to.equal(2n);
expect(penalized.length).to.equal(2n);

const firstNOActiveKeys =
NODE_OPERATORS[firstNodeOperatorId].depositedSigningKeysCount -
Expand All @@ -492,13 +492,13 @@ describe("NodeOperatorsRegistry:auxiliary", () => {
NODE_OPERATORS[secondNodeOperatorId].exitedSigningKeysCount;
const totalActiveKeys = firstNOActiveKeys + secondNOActiveKeys;

expect(recipients[0]).to.be.equal(NODE_OPERATORS[firstNodeOperatorId].rewardAddress);
expect(shares[0]).to.be.equal((100n * firstNOActiveKeys) / totalActiveKeys);
expect(penalized[0]).to.be.equal(true);
expect(recipients[0]).to.equal(NODE_OPERATORS[firstNodeOperatorId].rewardAddress);
expect(shares[0]).to.equal((100n * firstNOActiveKeys) / totalActiveKeys);
expect(penalized[0]).to.equal(true);

expect(recipients[1]).to.be.equal(NODE_OPERATORS[secondNodeOperatorId].rewardAddress);
expect(shares[1]).to.be.equal((100n * secondNOActiveKeys) / totalActiveKeys);
expect(penalized[1]).to.be.equal(false);
expect(recipients[1]).to.equal(NODE_OPERATORS[secondNodeOperatorId].rewardAddress);
expect(shares[1]).to.equal((100n * secondNOActiveKeys) / totalActiveKeys);
expect(penalized[1]).to.equal(false);
});
});
});
28 changes: 14 additions & 14 deletions test/0.4.24/nor/nor.initialize.upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,24 +271,24 @@ describe("NodeOperatorsRegistry:initialize-and-upgrade", () => {
});

it("Migrates the contract storage from v1 to v2", async () => {
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[firstNodeOperatorId])).to.equal(
firstNodeOperatorId,
);
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[secondNodeOperatorId])).to.equal(
secondNodeOperatorId,
);
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[thirdNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[thirdNodeOperatorId])).to.equal(
thirdNodeOperatorId,
);
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[fourthNodeOperatorId])).to.be.equal(
expect(await addNodeOperator(nor, nodeOperatorsManager, NODE_OPERATORS[fourthNodeOperatorId])).to.equal(
fourthNodeOperatorId,
);

await nor.harness__unsafeResetModuleSummary();
const resetSummary = await nor.getStakingModuleSummary();
expect(resetSummary.totalExitedValidators).to.be.equal(0n);
expect(resetSummary.totalDepositedValidators).to.be.equal(0n);
expect(resetSummary.depositableValidatorsCount).to.be.equal(0n);
expect(resetSummary.totalExitedValidators).to.equal(0n);
expect(resetSummary.totalDepositedValidators).to.equal(0n);
expect(resetSummary.depositableValidatorsCount).to.equal(0n);

await nor.harness__unsafeSetVettedKeys(
firstNodeOperatorId,
Expand All @@ -314,27 +314,27 @@ describe("NodeOperatorsRegistry:initialize-and-upgrade", () => {
.withArgs(moduleType);

const summary = await nor.getStakingModuleSummary();
expect(summary.totalExitedValidators).to.be.equal(1n + 0n + 0n + 1n);
expect(summary.totalDepositedValidators).to.be.equal(5n + 7n + 0n + 2n);
expect(summary.depositableValidatorsCount).to.be.equal(0n + 8n + 0n + 0n);
expect(summary.totalExitedValidators).to.equal(1n + 0n + 0n + 1n);
expect(summary.totalDepositedValidators).to.equal(5n + 7n + 0n + 2n);
expect(summary.depositableValidatorsCount).to.equal(0n + 8n + 0n + 0n);

const firstNoInfo = await nor.getNodeOperator(firstNodeOperatorId, true);
expect(firstNoInfo.totalVettedValidators).to.be.equal(
expect(firstNoInfo.totalVettedValidators).to.equal(
NODE_OPERATORS[firstNodeOperatorId].depositedSigningKeysCount,
);

const secondNoInfo = await nor.getNodeOperator(secondNodeOperatorId, true);
expect(secondNoInfo.totalVettedValidators).to.be.equal(
expect(secondNoInfo.totalVettedValidators).to.equal(
NODE_OPERATORS[secondNodeOperatorId].totalSigningKeysCount,
);

const thirdNoInfo = await nor.getNodeOperator(thirdNodeOperatorId, true);
expect(thirdNoInfo.totalVettedValidators).to.be.equal(
expect(thirdNoInfo.totalVettedValidators).to.equal(
NODE_OPERATORS[thirdNodeOperatorId].depositedSigningKeysCount,
);

const fourthNoInfo = await nor.getNodeOperator(fourthNodeOperatorId, true);
expect(fourthNoInfo.totalVettedValidators).to.be.equal(
expect(fourthNoInfo.totalVettedValidators).to.equal(
NODE_OPERATORS[fourthNodeOperatorId].vettedSigningKeysCount,
);
});
Expand Down
Loading
Loading