-
Notifications
You must be signed in to change notification settings - Fork 306
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
teku-6320 Capella helper functions #6403
Conversation
.../src/main/java/tech/pegasys/teku/spec/logic/versions/capella/helpers/MiscHelpersCapella.java
Fixed
Show fixed
Hide fixed
.../src/main/java/tech/pegasys/teku/spec/logic/versions/capella/helpers/MiscHelpersCapella.java
Fixed
Show fixed
Hide fixed
.../src/main/java/tech/pegasys/teku/spec/logic/versions/capella/helpers/MiscHelpersCapella.java
Fixed
Show fixed
Hide fixed
.../src/main/java/tech/pegasys/teku/spec/logic/versions/capella/helpers/MiscHelpersCapella.java
Fixed
Show fixed
Hide fixed
.../src/main/java/tech/pegasys/teku/spec/logic/versions/capella/helpers/MiscHelpersCapella.java
Fixed
Show fixed
Hide fixed
.../src/main/java/tech/pegasys/teku/spec/logic/versions/capella/helpers/MiscHelpersCapella.java
Fixed
Show fixed
Hide fixed
f63f99a
to
fa6b8a8
Compare
@Test | ||
public void isFullyWithdrawableValidatorShouldReturnTrueForEligibleValidator() { | ||
final Validator validator = | ||
dataStructureUtil | ||
.randomValidator() | ||
.withWithdrawalCredentials(eth1WithdrawalsCredentials) | ||
.withWithdrawableEpoch(UInt64.ZERO); | ||
|
||
final UInt64 balance = UInt64.ONE; | ||
final UInt64 epoch = UInt64.ONE; | ||
|
||
assertThat(miscHelpersCapella.isFullyWithdrawableValidator(validator, balance, epoch)).isTrue(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does look like an excellent use case for @ParameterizedTest
if we drove it via balance, epoch, withdrawableEpoch, expectation
, then you'd have 1 set of code...
public Bytes32 randomEth1WithdrawalCredentials() { | ||
return Bytes32.wrap( | ||
Bytes.concatenate(Bytes.fromHexString("0x01"), randomBytes32().slice(0, 31))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eth1 withdrawal credentials are slightly different...
private static final Bytes ETH1_WITHDRAWAL_PREFIX = Bytes.fromHexString("0x01");
private static final Bytes WITHDRAWAL_BUFFER = Bytes.repeat((byte) 0x00, 11);
public static Bytes32 withdrawalAddressFromEth1Address(final Bytes20 toExecutionAddress) {
return Bytes32.wrap(
Bytes.concatenate(
ETH1_WITHDRAWAL_PREFIX, WITHDRAWAL_BUFFER, toExecutionAddress.getWrappedBytes()));
}
above is a snippet from my current work, where I'll create an eth1 address, we can probably migrate this into helpers after, but maybe for this one just make the Bytes32.wrap(Bytes.fromHexString("0x010000000000000000000000"), randomEth1Address()))
or something...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nits, overall lgtm, and i disagree with the codeQL... i'm not sure what it was scanning...
import tech.pegasys.teku.spec.datastructures.state.Validator; | ||
import tech.pegasys.teku.spec.util.DataStructureUtil; | ||
|
||
class MiscHelpersCapellaTest { |
Check notice
Code scanning / CodeQL
Unused classes and interfaces
PR Description
Implemented helper predicate functions:
Reference: Cappella beacon chain spec
Fixed Issue(s)
fixes #6320
Documentation
doc-change-required
label to this PR if updates are required.Changelog