Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soloseng committed Sep 24, 2024
1 parent 0cc126a commit 1d4149e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 52 deletions.
6 changes: 4 additions & 2 deletions packages/protocol/test-sol/unit/common/Accounts.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,13 @@ contract AccountsTest_setPaymentDelegation is AccountsTest {
assertEq(realFraction, fraction);
}

function test_Revert_SetPaymentDelegation_WhenL2() public {
function test_ShouldSetAnAddressAndAFraction_WhenL2() public {
_whenL2();
accounts.createAccount();
vm.expectRevert("This method is no longer supported in L2.");
accounts.setPaymentDelegation(beneficiary, fraction);
(address realBeneficiary, uint256 realFraction) = accounts.getPaymentDelegation(address(this));
assertEq(realBeneficiary, beneficiary);
assertEq(realFraction, fraction);
}

function test_ShouldNotAllowFractionGreaterThan1() public {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,12 @@ contract ValidatorsTest_Initialize is ValidatorsTest {
assertEq(actual, commissionUpdateDelay, "Wrong commissionUpdateDelay.");
}

function test_Reverts_setCommissionUpdateDelay_WhenL2() public {
function test_ShouldsetCommissionUpdateDelay_WhenL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
validators.setCommissionUpdateDelay(commissionUpdateDelay);
validators.setCommissionUpdateDelay(5);

uint256 actual = validators.getCommissionUpdateDelay();
assertEq(actual, 5, "Wrong commissionUpdateDelay.");
}

function test_shouldHaveSetDowntimeGracePeriod() public {
Expand Down Expand Up @@ -537,13 +539,14 @@ contract ValidatorsTest_SetMembershipHistoryLength is ValidatorsTest {
assertEq(validators.getMembershipHistoryLength(), newLength);
}

function test_Reverts_SetTheMembershipHistoryLength_WhenL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
function test_Emits_MembershipHistoryLengthSet() public {
vm.expectEmit(true, true, true, true);
emit MembershipHistoryLengthSet(newLength);
validators.setMembershipHistoryLength(newLength);
}

function test_Emits_MembershipHistoryLengthSet() public {
function test_Emits_MembershipHistoryLengthSet_WhenL2() public {
_whenL2();
vm.expectEmit(true, true, true, true);
emit MembershipHistoryLengthSet(newLength);
validators.setMembershipHistoryLength(newLength);
Expand All @@ -561,9 +564,10 @@ contract ValidatorsTest_SetMaxGroupSize is ValidatorsTest {

event MaxGroupSizeSet(uint256 size);

function test_Reverts_SetMaxGroupSize_WhenL2() public {
function test_Emits_MaxGroupSizeSet_WhenL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
vm.expectEmit(true, true, true, true);
emit MaxGroupSizeSet(newSize);
validators.setMaxGroupSize(newSize);
}

Expand Down Expand Up @@ -2142,14 +2146,16 @@ contract ValidatorsTest_AddMember is ValidatorsTest {
assertEq(members, expectedMembersList);
}

function test_Reverts_AddFirstMemberToTheList_WhenL2() public {
_whenL2();
function test_ShouldAddMemberToTheList_WhenL2() public {
address[] memory expectedMembersList = new address[](1);
expectedMembersList[0] = validator;

_whenL2();
vm.prank(group);
vm.expectRevert("This method is no longer supported in L2.");
validators.addFirstMember(validator, address(0), address(0));

(address[] memory members, , , , , , ) = validators.getValidatorGroup(group);

assertEq(members, expectedMembersList);
}

function test_ShouldUpdateGroupSizeHistory() public {
Expand Down Expand Up @@ -3635,35 +3641,9 @@ contract ValidatorsTest_ForceDeaffiliateIfValidator is ValidatorsTest {

function test_ShouldSendValidatorPayment_WhenL2() public {
_whenL2();
vm.expectEmit(true, true, true, true);
emit SendValidatorPaymentCalled(validator);
vm.prank(paymentDelegatee);
validators.forceDeaffiliateIfValidator(validator);
}
}
contract ValidatorsTest_ForceDeaffiliateIfValidator_L2 is ValidatorsTest {
function setUp() public {
super.setUp();

_registerValidatorHelper(validator, validatorPk);
_registerValidatorGroupHelper(group, 1);

vm.prank(validator);
validators.affiliate(group);
_whenL2();
lockedGold.addSlasherTest(paymentDelegatee);
}

function test_ShouldSucceed_WhenSenderIsWhitelistedSlashingAddress() public {
vm.expectRevert("This method is no longer supported in L2.");
vm.prank(paymentDelegatee);
validators.forceDeaffiliateIfValidator(validator);
(, , address affiliation, , ) = validators.getValidator(validator);
assertEq(affiliation, address(0));
}

function test_Reverts_WhenSenderNotApprovedAddress() public {
vm.expectRevert("Only registered slasher can call");
validators.forceDeaffiliateIfValidator(validator);
}
}

Expand Down Expand Up @@ -3740,21 +3720,22 @@ contract ValidatorsTest_GroupMembershipInEpoch is ValidatorsTest {
}
}
}

function test_Reverts_GroupMembershipInEpoch_WhenL2() public {
function test_ShouldCorrectlyGetGroupAddressForExactEpochNumbers_WhenL2() public {
_whenL2();
for (uint256 i = 0; i < epochInfoList.length; i++) {
address _group = epochInfoList[i].groupy;

if (epochInfoList.length.sub(i) <= membershipHistoryLength) {
vm.expectRevert("This method is no longer supported in L2.");
validators.groupMembershipInEpoch(
validator,
epochInfoList[i].epochNumber,
uint256(1).add(i)
assertEq(
validators.groupMembershipInEpoch(
validator,
epochInfoList[i].epochNumber,
uint256(1).add(i)
),
_group
);
} else {
vm.expectRevert("This method is no longer supported in L2.");
vm.expectRevert("index out of bounds");
validators.groupMembershipInEpoch(
validator,
epochInfoList[i].epochNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,9 +1115,8 @@ contract ReleaseGoldTest_AuthorizeWithPublicKeys is ReleaseGoldTest {
assertEq(accounts.validatorSignerToAccount(authorized), address(releaseGold));
}

function test_Reverts_WhenAuthorizeValidatorSignerWithPublicKeyCalledOnL2() public {
function test_ShouldSetTheAuthorizedKeys_WhenUsingECDSAPublickKey_WhenL2() public {
_whenL2();
vm.expectRevert("This method is no longer supported in L2.");
vm.prank(beneficiary);
releaseGold.authorizeValidatorSignerWithPublicKey(
address(uint160(authorized)),
Expand All @@ -1126,6 +1125,10 @@ contract ReleaseGoldTest_AuthorizeWithPublicKeys is ReleaseGoldTest {
s,
ecdsaPublicKey
);

assertEq(accounts.authorizedBy(authorized), address(releaseGold));
assertEq(accounts.getValidatorSigner(address(releaseGold)), authorized);
assertEq(accounts.validatorSignerToAccount(authorized), address(releaseGold));
}

function test_Reverts_WhenAuthorizeValidatorSignerWithKeysCalledOnL2() public {
Expand Down

0 comments on commit 1d4149e

Please sign in to comment.