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

Soloseng/streamline-L2-validator-test #11263

Merged

Conversation

soloseng
Copy link
Contributor

@soloseng soloseng commented Oct 25, 2024

Description

Updates the Validators tests to remove duplicate code and streamline L2 testing

Other changes (Martin)

  • Used some assembly tricks to propagate errors from ValidatorsMockTunnel (see recoverErrorString). This can be added to the ReleaseGold tunnel as well.
  • test_ShouldNotTryToSendValidatorPayment_WhenL1 was not correctly checking for the absence of an event emitted - vm.recordLogs() was missing. Added assertDoesNotEmit helper to Utils that checks for the absence of a log. Also applies to:
    • deaffiliate
    • updateCommission
    • forceDeaffiliateIfValidator

Tested

unit tested

Related issues

### Description

Using test contract inheritance to minimize duplicated code during L2 testing

### Other changes

removed unused var

### Tested

unit tested

### Related issues

- Fixes #[issue number here]

### Backwards compatibility

_Brief explanation of why these changes are/are not backwards compatible._

### Documentation

_The set of community facing docs that have been added/modified because of this change_
@soloseng soloseng requested a review from a team as a code owner October 25, 2024 22:01
@soloseng soloseng self-assigned this Oct 25, 2024
Base automatically changed from soloseng/general-framework to release/core-contracts/12 October 30, 2024 12:24
function test_ShouldSendValidatorPayment_WhenL2() public {
_whenL2WithEpoch();
function test_ShouldNotTryToSendValidatorPayment() public {
assertDoesNotEmit(_performAffiliation, "SendValidatorPaymentCalled(address)");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Should this reflect the actual event emitted in epochManager? The mock has a different event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this event is used as a mocking mechanism: it signals that EpochManager.sendValidatorPayment was called during the transaction, without implementing any payment logic in the mock. So we test for its presence in the L2 test (to ensure the function was called) and for its absence here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was suggesting changing it to ValidatorEpochPaymentDistributed() to minimize difference between mock and actual contract.

Either way works.

Comment on lines 216 to 231
_whenL2();

address[] memory _elected = new address[](2);
_elected[0] = validator;
_elected[1] = otherValidator;
epochManager.initializeSystem(l1EpochNumber, block.number, _elected);
}

function _getEpochNumberBasedOnLayer() internal returns (uint256) {
if (isL2()) {
return epochManager.getCurrentEpochNumber();
} else {
return IPrecompiles(address(validators)).getEpochNumber();
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be moved to some parent class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this logic is already implemented in PrecompilesOverride. Created a V2 version (with hardcoded registry, to avoid owner variable clash) and use that in this test.

return result.unwrap();
}
}

contract TransitionToL2AfterL1 is ValidatorsTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove the duplicated code from Election and push to some util file?

contract TransitionToL2After is ElectionTest {

@m-chrzan m-chrzan enabled auto-merge (squash) November 13, 2024 21:48
@m-chrzan m-chrzan merged commit 44c70c9 into release/core-contracts/12 Nov 13, 2024
40 of 42 checks passed
@m-chrzan m-chrzan deleted the soloseng/streamline-L2-validator-test branch November 13, 2024 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants