Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/github_actions/gradle/actions-…
Browse files Browse the repository at this point in the history
…4.2.2
  • Loading branch information
andrewb1269hg authored Dec 19, 2024
2 parents 64f88cf + d0888fc commit 6a436a9
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -83,7 +83,7 @@ public record ContractsConfig(
@ConfigProperty(value = "systemContract.scheduleService.signSchedule.enabled", defaultValue = "true")
@NetworkProperty
boolean systemContractSignScheduleEnabled,
@ConfigProperty(value = "systemContract.scheduleService.authorizeSchedule.enabled", defaultValue = "false")
@ConfigProperty(value = "systemContract.scheduleService.authorizeSchedule.enabled", defaultValue = "true")
@NetworkProperty
boolean systemContractAuthorizeScheduleEnabled,
@ConfigProperty(value = "systemContract.accountService.isAuthorizedRawEnabled", defaultValue = "true")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -499,6 +499,8 @@ public class TestHelpers {
.key(AN_ED25519_KEY)
.alias(tuweniToPbjBytes(EIP_1014_ADDRESS))
.build();
public static final Account B_CONTRACT =
Account.newBuilder().accountId(B_NEW_ACCOUNT_ID).smartContract(true).build();
public static final TokenRelation A_FUNGIBLE_RELATION = TokenRelation.newBuilder()
.tokenId(FUNGIBLE_TOKEN_ID)
.accountId(A_NEW_ACCOUNT_ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,11 +64,13 @@
import com.hedera.node.app.service.token.ReadableTokenStore;
import com.hedera.node.app.service.token.api.TokenServiceApi;
import com.hedera.node.app.service.token.records.CryptoCreateStreamBuilder;
import com.hedera.node.app.spi.key.KeyVerifier;
import com.hedera.node.app.spi.store.StoreFactory;
import com.hedera.node.app.spi.workflows.HandleContext;
import com.hedera.node.app.spi.workflows.record.DeleteCapableTransactionStreamBuilder;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.SortedSet;
import java.util.function.Predicate;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -112,6 +114,12 @@ class HandleHederaNativeOperationsTest {
@Mock
private ReadableNftStore nftStore;

@Mock
private KeyVerifier keyVerifier;

@Mock
private SortedSet<Key> keys;

private final Deque<MessageFrame> stack = new ArrayDeque<>();

private HandleHederaNativeOperations subject;
Expand Down Expand Up @@ -335,4 +343,11 @@ void customFeesCheckUsesApi() {
final var result = subject.checkForCustomFees(CryptoTransferTransactionBody.DEFAULT);
assertTrue(result);
}

@Test
void authorizingSimpleKeysTest() {
given(context.keyVerifier()).willReturn(keyVerifier);
given(keyVerifier.authorizingSimpleKeys()).willReturn(keys);
assertSame(keys, subject.authorizingSimpleKeys());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -229,4 +229,9 @@ void currentExchangeRateTest() {
verify(context).exchangeRateInfo();
verify(exchangeRateInfo).activeRate(any());
}

@Test
void maybeEthSenderKeyTest() {
assertSame(A_SECP256K1_KEY, subject.maybeEthSenderKey());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.NON_FUNGIBLE_TOKEN_ID;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.NON_SYSTEM_ACCOUNT_ID;
import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.tuweniToPbjBytes;
import static com.hedera.node.app.spi.key.KeyVerifier.NO_AUTHORIZING_KEYS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -146,4 +147,9 @@ void getNftUsesStore() {
given(nftStore.get(CIVILIAN_OWNED_NFT.nftIdOrThrow())).willReturn(CIVILIAN_OWNED_NFT);
assertSame(CIVILIAN_OWNED_NFT, subject.getNft(NON_FUNGIBLE_TOKEN_ID.tokenNum(), NFT_SERIAL_NO));
}

@Test
void authorizingSimpleKeysTest() {
assertSame(NO_AUTHORIZING_KEYS, subject.authorizingSimpleKeys());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,26 @@ public static HssCallAttempt prepareHssAttemptWithBytesAndCustomConfig(
List.of(translator),
false);
}

public static HssCallAttempt prepareHssAttemptWithBytesAndCustomConfigAndDelegatableContractKeys(
final Bytes input,
final CallTranslator<HssCallAttempt> translator,
final HederaWorldUpdater.Enhancement enhancement,
final AddressIdConverter addressIdConverter,
final VerificationStrategies verificationStrategies,
final SystemContractGasCalculator gasCalculator,
final Configuration config) {

return new HssCallAttempt(
input,
OWNER_BESU_ADDRESS,
true,
enhancement,
config,
addressIdConverter,
verificationStrategies,
gasCalculator,
List.of(translator),
false);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

package com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.hss;

import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_SCHEDULE_ID;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS;
import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.ERROR_DECODING_PRECOMPILE_INPUT;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.CONFIG_CONTEXT_VARIABLE;
Expand Down Expand Up @@ -116,4 +117,24 @@ void haltsImmediatelyWithNullDispatch() {
fullResult.result().getHaltReason());
assertEquals(DEFAULT_CONTRACTS_CONFIG.precompileHtsDefaultGasCost(), fullResult.gasRequirement());
}

@Test
void failureResultCustomized() {
given(systemContractOperations.dispatch(
TransactionBody.DEFAULT,
verificationStrategy,
AccountID.DEFAULT,
ContractCallStreamBuilder.class,
emptySet(),
DispatchOptions.UsePresetTxnId.NO))
.willReturn(recordBuilder);
given(dispatchGasCalculator.gasRequirement(
TransactionBody.DEFAULT, gasCalculator, mockEnhancement(), AccountID.DEFAULT))
.willReturn(123L);
given(recordBuilder.status()).willReturn(INVALID_SCHEDULE_ID);

final var pricedResult = subject.execute(frame);
final var contractResult = pricedResult.fullResult().result().getOutput();
assertArrayEquals(ReturnTypes.encodedRc(INVALID_SCHEDULE_ID).array(), contractResult.toArray());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.NON_SYSTEM_LONG_ZERO_ADDRESS;
import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.numberOfLongZero;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.BDDMockito.given;

import com.hedera.node.app.service.contract.impl.exec.scope.VerificationStrategies;
Expand Down Expand Up @@ -84,4 +85,21 @@ void invalidSelectorLeadsToMissingCall() {
false);
assertNull(subject.asExecutableCall());
}

@Test
void isOnlyDelegatableContractKeysActiveTest() {
final var input = TestHelpers.bytesForRedirectAccount(new byte[4], NON_SYSTEM_LONG_ZERO_ADDRESS);
final var subject = new HssCallAttempt(
input,
EIP_1014_ADDRESS,
true,
mockEnhancement(),
DEFAULT_CONFIG,
addressIdConverter,
verificationStrategies,
gasCalculator,
callTranslators,
false);
assertTrue(subject.isOnlyDelegatableContractKeysActive());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@
package com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.hss.signschedule;

import static com.hedera.node.app.service.contract.impl.test.TestHelpers.APPROVED_HEADLONG_ADDRESS;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.B_CONTRACT;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.NON_SYSTEM_LONG_ZERO_ADDRESS;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.OWNER_BESU_ADDRESS;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.SOMEBODY;
import static com.hedera.node.app.service.contract.impl.test.TestHelpers.bytesForRedirectScheduleTxn;
import static com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.CallAttemptHelpers.prepareHssAttemptWithBytesAndCustomConfig;
import static com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.CallAttemptHelpers.prepareHssAttemptWithBytesAndCustomConfigAndDelegatableContractKeys;
import static com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.CallAttemptHelpers.prepareHssAttemptWithSelectorAndCustomConfig;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.when;

import com.esaulpaugh.headlong.abi.Tuple;
import com.hedera.hapi.node.base.AccountID;
import com.hedera.hapi.node.base.Key;
import com.hedera.hapi.node.base.ScheduleID;
import com.hedera.hapi.node.state.schedule.Schedule;
import com.hedera.hapi.node.transaction.TransactionBody;
Expand Down Expand Up @@ -102,6 +106,9 @@ class SignScheduleTranslatorTest {
@Mock
private ScheduleID scheduleID;

@Mock
private Key key;

private SignScheduleTranslator subject;

@BeforeEach
Expand Down Expand Up @@ -243,11 +250,59 @@ void testScheduleIdForSignScheduleProxy() {
}

@Test
void testScheduleIdForAuthorizeScheduleProxy() {
void testScheduleIdForSignScheduleProxyEthSender() {
given(enhancement.nativeOperations()).willReturn(nativeOperations);
given(enhancement.systemOperations()).willReturn(systemContractOperations);
given(nativeOperations.getSchedule(anyLong())).willReturn(schedule);
given(schedule.scheduleId()).willReturn(scheduleID);
given(nativeOperations.getAccount(payerId)).willReturn(SOMEBODY);
given(addressIdConverter.convertSender(OWNER_BESU_ADDRESS)).willReturn(payerId);
given(verificationStrategies.activatingOnlyContractKeysFor(OWNER_BESU_ADDRESS, false, nativeOperations))
.willReturn(verificationStrategy);
given(systemContractOperations.maybeEthSenderKey()).willReturn(key);

// when:
attempt = prepareHssAttemptWithBytesAndCustomConfig(
bytesForRedirectScheduleTxn(
SignScheduleTranslator.SIGN_SCHEDULE_PROXY.selector(), NON_SYSTEM_LONG_ZERO_ADDRESS),
subject,
enhancement,
addressIdConverter,
verificationStrategies,
gasCalculator,
configuration);

// then:
final var call = subject.callFrom(attempt);

assertThat(call).isInstanceOf(DispatchForResponseCodeHssCall.class);
}

@Test
void testScheduleIdForWrongSelectorThrows() {
given(enhancement.nativeOperations()).willReturn(nativeOperations);
given(nativeOperations.getSchedule(anyLong())).willReturn(schedule);
given(addressIdConverter.convertSender(OWNER_BESU_ADDRESS)).willReturn(payerId);

// when:
attempt = prepareHssAttemptWithBytesAndCustomConfig(
bytesForRedirectScheduleTxn(MintTranslator.MINT.selector(), NON_SYSTEM_LONG_ZERO_ADDRESS),
subject,
enhancement,
addressIdConverter,
verificationStrategies,
gasCalculator,
configuration);

// then:
assertThrows(IllegalStateException.class, () -> subject.callFrom(attempt));
}

@Test
void testScheduleIdForAuthorizeSchedule() {
given(enhancement.nativeOperations()).willReturn(nativeOperations);
given(nativeOperations.getSchedule(anyLong())).willReturn(schedule);
given(nativeOperations.getAccount(payerId)).willReturn(B_CONTRACT);
given(schedule.scheduleId()).willReturn(scheduleID);
given(addressIdConverter.convertSender(OWNER_BESU_ADDRESS)).willReturn(payerId);
given(verificationStrategies.activatingOnlyContractKeysFor(OWNER_BESU_ADDRESS, false, nativeOperations))
Expand All @@ -265,6 +320,28 @@ void testScheduleIdForAuthorizeScheduleProxy() {
assertThat(call).isInstanceOf(DispatchForResponseCodeHssCall.class);
}

@Test
void testScheduleIdForAuthorizeScheduleDelegatableContractKeys() {
given(enhancement.nativeOperations()).willReturn(nativeOperations);
given(nativeOperations.getSchedule(anyLong())).willReturn(schedule);
given(nativeOperations.getAccount(payerId)).willReturn(B_CONTRACT);
given(schedule.scheduleId()).willReturn(scheduleID);
given(addressIdConverter.convertSender(OWNER_BESU_ADDRESS)).willReturn(payerId);
given(verificationStrategies.activatingOnlyContractKeysFor(OWNER_BESU_ADDRESS, true, nativeOperations))
.willReturn(verificationStrategy);

// when:
final var input = Bytes.wrapByteBuffer(
SignScheduleTranslator.AUTHORIZE_SCHEDULE.encodeCall(Tuple.of(APPROVED_HEADLONG_ADDRESS)));
attempt = prepareHssAttemptWithBytesAndCustomConfigAndDelegatableContractKeys(
input, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator, configuration);

// then:
final var call = subject.callFrom(attempt);

assertThat(call).isInstanceOf(DispatchForResponseCodeHssCall.class);
}

@Test
void testGasRequirement() {
long expectedGas = 1000L;
Expand Down
Loading

0 comments on commit 6a436a9

Please sign in to comment.