Skip to content

Commit

Permalink
rename methods and variables, clarify comments (#8155)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Lehrner <[email protected]>
  • Loading branch information
daniellehrner authored Jan 23, 2025
1 parent a1e087d commit 7840e8b
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public TransactionProcessingResult processTransaction(
final Address to = transaction.getTo().get();
final Optional<Account> maybeContract = Optional.ofNullable(evmWorldUpdater.get(to));

if (maybeContract.isPresent() && maybeContract.get().hasCodeDelegation()) {
if (maybeContract.isPresent() && maybeContract.get().hasDelegatedCode()) {
warmAddressList.add(maybeContract.get().codeDelegationAddress().get());
}

Expand All @@ -441,7 +441,7 @@ public TransactionProcessingResult processTransaction(
maybeContract
.map(
c -> {
if (c.hasCodeDelegation()) {
if (c.hasDelegatedCode()) {
return messageCallProcessor.getCodeFromEVM(
c.getCodeDelegationTargetHash().get(),
c.getCodeDelegationTargetCode().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CodeDelegationProcessorTest {

@Mock private Transaction transaction;

@Mock private CodeDelegationService authorizedCodeService;
@Mock private CodeDelegationService delegationCodeService;

@Mock private MutableAccount authority;

Expand Down Expand Up @@ -95,7 +95,7 @@ void shouldRejectMaxNonce() {
@Test
void shouldProcessValidDelegationForNewAccount() {
// Arrange
when(worldUpdater.codeDelegationService()).thenReturn(authorizedCodeService);
when(worldUpdater.codeDelegationService()).thenReturn(delegationCodeService);
CodeDelegation codeDelegation = createCodeDelegation(CHAIN_ID, 0L);
when(transaction.getCodeDelegationList()).thenReturn(Optional.of(List.of(codeDelegation)));
when(worldUpdater.getAccount(any())).thenReturn(null);
Expand All @@ -109,18 +109,18 @@ void shouldProcessValidDelegationForNewAccount() {
assertThat(result.alreadyExistingDelegators()).isZero();
verify(worldUpdater).createAccount(any());
verify(authority).incrementNonce();
verify(authorizedCodeService).processCodeDelegation(authority, DELEGATE_ADDRESS);
verify(delegationCodeService).processCodeDelegation(authority, DELEGATE_ADDRESS);
}

@Test
void shouldProcessValidDelegationForExistingAccount() {
// Arrange
when(worldUpdater.codeDelegationService()).thenReturn(authorizedCodeService);
when(worldUpdater.codeDelegationService()).thenReturn(delegationCodeService);
CodeDelegation codeDelegation = createCodeDelegation(CHAIN_ID, 1L);
when(transaction.getCodeDelegationList()).thenReturn(Optional.of(List.of(codeDelegation)));
when(worldUpdater.getAccount(any())).thenReturn(authority);
when(authority.getNonce()).thenReturn(1L);
when(authorizedCodeService.canSetCodeDelegation(any())).thenReturn(true);
when(delegationCodeService.canSetCodeDelegation(any())).thenReturn(true);

// Act
CodeDelegationResult result = processor.process(worldUpdater, transaction);
Expand All @@ -129,25 +129,25 @@ void shouldProcessValidDelegationForExistingAccount() {
assertThat(result.alreadyExistingDelegators()).isEqualTo(1);
verify(worldUpdater, never()).createAccount(any());
verify(authority).incrementNonce();
verify(authorizedCodeService).processCodeDelegation(authority, DELEGATE_ADDRESS);
verify(delegationCodeService).processCodeDelegation(authority, DELEGATE_ADDRESS);
}

@Test
void shouldRejectDelegationWithInvalidNonce() {
// Arrange
when(worldUpdater.codeDelegationService()).thenReturn(authorizedCodeService);
when(worldUpdater.codeDelegationService()).thenReturn(delegationCodeService);
CodeDelegation codeDelegation = createCodeDelegation(CHAIN_ID, 2L);
when(transaction.getCodeDelegationList()).thenReturn(Optional.of(List.of(codeDelegation)));
when(worldUpdater.getAccount(any())).thenReturn(authority);
when(authorizedCodeService.canSetCodeDelegation(any())).thenReturn(true);
when(delegationCodeService.canSetCodeDelegation(any())).thenReturn(true);

// Act
CodeDelegationResult result = processor.process(worldUpdater, transaction);

// Assert
assertThat(result.alreadyExistingDelegators()).isZero();
verify(authority, never()).incrementNonce();
verify(authorizedCodeService, never()).processCodeDelegation(any(), any());
verify(delegationCodeService, never()).processCodeDelegation(any(), any());
}

@Test
Expand All @@ -163,7 +163,7 @@ void shouldRejectDelegationWithSGreaterThanHalfCurveOrder() {
// Assert
assertThat(result.alreadyExistingDelegators()).isZero();
verify(authority, never()).incrementNonce();
verify(authorizedCodeService, never()).processCodeDelegation(any(), any());
verify(delegationCodeService, never()).processCodeDelegation(any(), any());
}

@Test
Expand All @@ -181,7 +181,7 @@ void shouldRejectDelegationWithRecIdNeitherZeroNorOne() {
// Assert
assertThat(result.alreadyExistingDelegators()).isZero();
verify(authority, never()).incrementNonce();
verify(authorizedCodeService, never()).processCodeDelegation(any(), any());
verify(delegationCodeService, never()).processCodeDelegation(any(), any());
}

@Test
Expand All @@ -201,25 +201,25 @@ void shouldRejectDelegationWithInvalidSignature() {
// Assert
assertThat(result.alreadyExistingDelegators()).isZero();
verify(authority, never()).incrementNonce();
verify(authorizedCodeService, never()).processCodeDelegation(any(), any());
verify(delegationCodeService, never()).processCodeDelegation(any(), any());
}

@Test
void shouldRejectDelegationWhenCannotSetCodeDelegation() {
// Arrange
when(worldUpdater.codeDelegationService()).thenReturn(authorizedCodeService);
when(worldUpdater.codeDelegationService()).thenReturn(delegationCodeService);
CodeDelegation codeDelegation = createCodeDelegation(CHAIN_ID, 1L);
when(transaction.getCodeDelegationList()).thenReturn(Optional.of(List.of(codeDelegation)));
when(worldUpdater.getAccount(any())).thenReturn(authority);
when(authorizedCodeService.canSetCodeDelegation(any())).thenReturn(false);
when(delegationCodeService.canSetCodeDelegation(any())).thenReturn(false);

// Act
CodeDelegationResult result = processor.process(worldUpdater, transaction);

// Assert
assertThat(result.alreadyExistingDelegators()).isZero();
verify(authority, never()).incrementNonce();
verify(authorizedCodeService, never()).processCodeDelegation(any(), any());
verify(delegationCodeService, never()).processCodeDelegation(any(), any());
}

private CodeDelegation createCodeDelegation(final BigInteger chainId, final long nonce) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Optional<Address> codeDelegationAddress() {
}

@Override
public boolean hasCodeDelegation() {
public boolean hasDelegatedCode() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ default Optional<Address> codeDelegationAddress() {
*
* @return true if the account has delegated code otherwise false.
*/
default boolean hasCodeDelegation() {
default boolean hasDelegatedCode() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public interface AccountState {
/**
* The optional EVM bytecode if the account has set a 7702 code delegation.
*
* @return the code of the target account (which may be empty).
* @return the code of the target account that this account delegates to (which may be empty).
*/
default Optional<Bytes> getCodeDelegationTargetCode() {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {

final Account contract = frame.getWorldUpdater().get(to);

if (contract != null && contract.hasCodeDelegation()) {
if (contract != null && contract.hasDelegatedCode()) {
if (contract.getCodeDelegationTargetCode().isEmpty()) {
throw new RuntimeException("A delegated code account must have delegated code");
}
Expand Down Expand Up @@ -357,7 +357,7 @@ protected static Code getCode(final EVM evm, final Account account) {
return CodeV0.EMPTY_CODE;
}

if (account.hasCodeDelegation()) {
if (account.hasDelegatedCode()) {
return evm.getCode(
account.getCodeDelegationTargetHash().get(), account.getCodeDelegationTargetCode().get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
Address to = Words.toAddress(toBytes);
final Account contract = frame.getWorldUpdater().get(to);

if (contract != null && contract.hasCodeDelegation()) {
if (contract != null && contract.hasDelegatedCode()) {
if (contract.getCodeDelegationTargetCode().isEmpty()) {
throw new RuntimeException("A delegated code account must have delegated code");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected Bytes getCode(final Account account) {
return Bytes.EMPTY;
}

return account.hasCodeDelegation()
return account.hasDelegatedCode()
? CodeDelegationHelper.getCodeDelegationForRead()
: account.getCode();
}
Expand All @@ -68,7 +68,7 @@ protected Bytes getCode(final Account account) {
* @return the code hash or the hash of the special 7702 designator
*/
protected Hash getCodeHash(final Account account) {
if (account.hasCodeDelegation()) {
if (account.hasDelegatedCode()) {
return Hash.hash(CodeDelegationHelper.getCodeDelegationForRead());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private CodeDelegationGasCostHelper() {
*/
public static long codeDelegationGasCost(
final MessageFrame frame, final GasCalculator gasCalculator, final Account account) {
if (!account.hasCodeDelegation()) {
if (!account.hasDelegatedCode()) {
return 0;
}

Expand Down

0 comments on commit 7840e8b

Please sign in to comment.