Skip to content

Commit

Permalink
Add hedera app dependency to hedera-mirror-web3 (#9399)
Browse files Browse the repository at this point in the history
Add com.hedera.hashgraph:app as a dependency in web3, so that the work for integrating reusable services is unblocked.

In addition, this PR stabilizes some inconsistent failing integration tests.

---------

Signed-off-by: IvanKavaldzhiev <ivankavaldzhiev@gmail.com>
  • Loading branch information
IvanKavaldzhiev authored Sep 19, 2024
1 parent a15e33b commit 5d00263
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 49 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies {
api("com.graphql-java-generator:graphql-java-client-runtime:2.8")
api("com.graphql-java:graphql-java-extended-scalars:22.0")
api("com.graphql-java:graphql-java-extended-validation:22.0")
api("com.hedera.hashgraph:app:0.53.5")
api("com.hedera.evm:hedera-evm:0.48.0")
api("com.hedera.hashgraph:hedera-protobuf-java-api:0.54.0")
api("com.hedera.hashgraph:sdk:2.39.0")
Expand Down
1 change: 1 addition & 0 deletions hedera-mirror-web3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
implementation(project(":common"))
implementation("com.bucket4j:bucket4j-core")
implementation("com.esaulpaugh:headlong")
implementation("com.hedera.hashgraph:app") { exclude(group = "io.netty") }
implementation("com.hedera.evm:hedera-evm")
implementation("io.github.mweirauch:micrometer-jvm-extras")
implementation("io.micrometer:micrometer-registry-prometheus")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@

package com.hedera.mirror.web3.convert;

import com.swirlds.common.utility.SemanticVersion;
import com.hedera.hapi.node.base.SemanticVersion;
import jakarta.inject.Named;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.core.convert.converter.Converter;

@Named
@ConfigurationPropertiesBinding
public class SemanticVersionConvertor implements Converter<String, SemanticVersion> {

private final com.hedera.node.config.converter.SemanticVersionConverter delegate =
new com.hedera.node.config.converter.SemanticVersionConverter();

@Override
public SemanticVersion convert(String source) {
return SemanticVersion.parse(source);
return delegate.convert(source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.hyperledger.besu.evm.internal.EvmConfiguration.WorldUpdaterMode.JOURNALED;

import com.github.benmanes.caffeine.cache.Caffeine;
import com.hedera.hapi.node.base.SemanticVersion;
import com.hedera.mirror.web3.evm.contracts.execution.MirrorEvmMessageCallProcessor;
import com.hedera.mirror.web3.evm.contracts.execution.MirrorEvmMessageCallProcessorV30;
import com.hedera.mirror.web3.evm.contracts.execution.traceability.MirrorOperationTracer;
Expand Down Expand Up @@ -48,7 +49,6 @@
import com.hedera.services.evm.contracts.operations.HederaSelfDestructOperationV046;
import com.hedera.services.txns.crypto.AbstractAutoCreationLogic;
import com.hedera.services.txns.util.PrngLogic;
import com.swirlds.common.utility.SemanticVersion;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -107,10 +107,10 @@ public class EvmConfiguration {
public static final String CACHE_NAME_TOKEN_ACCOUNT = "tokenAccount";
public static final String CACHE_NAME_TOKEN_ACCOUNT_COUNT = "tokenAccountCount";
public static final String CACHE_NAME_TOKEN_ALLOWANCE = "tokenAllowance";
public static final SemanticVersion EVM_VERSION_0_30 = SemanticVersion.parse("0.30.0");
public static final SemanticVersion EVM_VERSION_0_34 = SemanticVersion.parse("0.34.0");
public static final SemanticVersion EVM_VERSION_0_38 = SemanticVersion.parse("0.38.0");
public static final SemanticVersion EVM_VERSION_0_46 = SemanticVersion.parse("0.46.0");
public static final SemanticVersion EVM_VERSION_0_30 = new SemanticVersion(0, 30, 0, "", "");
public static final SemanticVersion EVM_VERSION_0_34 = new SemanticVersion(0, 34, 0, "", "");
public static final SemanticVersion EVM_VERSION_0_38 = new SemanticVersion(0, 38, 0, "", "");
public static final SemanticVersion EVM_VERSION_0_46 = new SemanticVersion(0, 46, 0, "", "");
public static final SemanticVersion EVM_VERSION = EVM_VERSION_0_46;
private final CacheProperties cacheProperties;
private final MirrorNodeEvmProperties mirrorNodeEvmProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hedera.mirror.web3.evm.contracts.execution;

import com.hedera.hapi.node.base.SemanticVersion;
import com.hedera.mirror.web3.evm.account.MirrorEvmContractAliases;
import com.hedera.mirror.web3.evm.contracts.execution.traceability.TracerType;
import com.hedera.mirror.web3.evm.store.Store;
Expand All @@ -35,7 +36,6 @@
import com.hedera.services.store.models.Account;
import com.hedera.services.utils.EntityIdUtils;
import com.hederahashgraph.api.proto.java.ResponseCodeEnum;
import com.swirlds.common.utility.SemanticVersion;
import jakarta.inject.Named;
import java.time.Instant;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import static com.hedera.mirror.web3.evm.config.EvmConfiguration.EVM_VERSION_0_38;
import static com.hedera.mirror.web3.evm.config.EvmConfiguration.EVM_VERSION_0_46;
import static com.swirlds.common.utility.CommonUtils.unhex;
import static com.swirlds.state.spi.HapiUtils.SEMANTIC_VERSION_COMPARATOR;

import com.hedera.hapi.node.base.SemanticVersion;
import com.hedera.mirror.common.domain.entity.EntityType;
import com.hedera.mirror.web3.common.ContractCallContext;
import com.hedera.node.app.service.evm.contracts.execution.EvmProperties;
import com.swirlds.common.utility.SemanticVersion;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
Expand Down Expand Up @@ -199,7 +200,7 @@ public boolean isCreate2Enabled() {

@Override
public boolean allowCallsToNonContractAccounts() {
return getSemanticEvmVersion().compareTo(EVM_VERSION_0_46) >= 0;
return SEMANTIC_VERSION_COMPARATOR.compare(getSemanticEvmVersion(), EVM_VERSION_0_46) >= 0;
}

@Override
Expand All @@ -209,7 +210,7 @@ public Set<Address> grandfatherContracts() {

@Override
public boolean callsToNonExistingEntitiesEnabled(Address target) {
return !(getSemanticEvmVersion().compareTo(EVM_VERSION_0_46) < 0
return !(SEMANTIC_VERSION_COMPARATOR.compare(getSemanticEvmVersion(), EVM_VERSION_0_46) < 0
|| !allowCallsToNonContractAccounts()
|| grandfatherContracts().contains(target));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.hedera.mirror.web3.common.PrecompileContext.PRECOMPILE_CONTEXT;

import com.hedera.hapi.node.base.SemanticVersion;
import com.hedera.mirror.web3.common.ContractCallContext;
import com.hedera.mirror.web3.common.PrecompileContext;
import com.hedera.mirror.web3.evm.contracts.execution.traceability.TracerType;
Expand All @@ -26,7 +27,6 @@
import com.hedera.node.app.service.evm.store.contracts.HederaEvmMutableWorldState;
import com.hedera.node.app.service.evm.store.models.HederaEvmAccount;
import com.hederahashgraph.api.proto.java.HederaFunctionality;
import com.swirlds.common.utility.SemanticVersion;
import java.time.Instant;
import java.util.Map;
import javax.inject.Provider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.hedera.services.store.contracts.precompile.utils.PrecompilePricingUtils;
import com.hedera.services.txns.crypto.AbstractAutoCreationLogic;
import com.hedera.services.txns.util.PrngLogic;
import com.swirlds.common.crypto.Hash;
import com.swirlds.common.utility.CommonUtils;
import java.time.Instant;
import java.util.Map;
Expand All @@ -61,14 +60,11 @@
@ExtendWith(MockitoExtension.class)
public abstract class MirrorEvmMessageCallProcessorBaseTest {

private static final Hash WELL_KNOWN_HASH = new Hash(CommonUtils.unhex(
"65386630386164632d356537632d343964342d623437372d62636134346538386338373133633038316162372d616300"));
private static final byte[] WELL_KNOWN_HASH_BYTE_ARRAY = CommonUtils.unhex(
"65386630386164632d356537632d343964342d623437372d62636134346538386338373133633038316162372d6163");

private static MockedStatic<ContractCallContext> contextMockedStatic;

@Spy
private ContractCallContext contractCallContext;

@Mock
AbstractAutoCreationLogic autoCreationLogic;

Expand Down Expand Up @@ -105,32 +101,33 @@ public abstract class MirrorEvmMessageCallProcessorBaseTest {
@Mock
EvmInfrastructureFactory evmInfrastructureFactory;

final EvmHTSPrecompiledContract htsPrecompiledContract = new EvmHTSPrecompiledContract(evmInfrastructureFactory);

@Mock
PrecompilePricingUtils precompilePricingUtils;

@Mock
RatesAndFeesLoader ratesAndFeesLoader;

final EvmHTSPrecompiledContract htsPrecompiledContract = new EvmHTSPrecompiledContract(evmInfrastructureFactory);

final ExchangeRatePrecompiledContract exchangeRatePrecompiledContract = new ExchangeRatePrecompiledContract(
gasCalculatorHederaV22,
new BasicHbarCentExchange(ratesAndFeesLoader),
new MirrorNodeEvmProperties(),
Instant.now());

final PrngSystemPrecompiledContract prngSystemPrecompiledContract = new PrngSystemPrecompiledContract(
gasCalculatorHederaV22,
new PrngLogic(WELL_KNOWN_HASH::getValue),
new PrngLogic(() -> WELL_KNOWN_HASH_BYTE_ARRAY),
new LivePricesSource(
new BasicHbarCentExchange(ratesAndFeesLoader), new BasicFcfsUsagePrices(ratesAndFeesLoader)),
precompilePricingUtils);

final Map<String, PrecompiledContract> hederaPrecompileList = Map.of(
EVM_HTS_PRECOMPILED_CONTRACT_ADDRESS, htsPrecompiledContract,
EXCHANGE_RATE_SYSTEM_CONTRACT_ADDRESS, exchangeRatePrecompiledContract,
PRNG_PRECOMPILE_ADDRESS, prngSystemPrecompiledContract);

@Spy
private ContractCallContext contractCallContext;

@BeforeAll
static void initStaticMocks() {
contextMockedStatic = mockStatic(ContractCallContext.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.mockito.Mockito.when;

import com.google.protobuf.ByteString;
import com.hedera.hapi.node.base.SemanticVersion;
import com.hedera.mirror.web3.ContextExtension;
import com.hedera.mirror.web3.common.ContractCallContext;
import com.hedera.mirror.web3.evm.account.MirrorEvmContractAliases;
Expand All @@ -51,7 +52,6 @@
import com.hedera.node.app.service.evm.store.models.HederaEvmAccount;
import com.hedera.node.app.service.evm.store.tokens.TokenAccessor;
import com.hedera.services.store.models.Account;
import com.swirlds.common.utility.SemanticVersion;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mockStatic;

import com.hedera.hapi.node.base.SemanticVersion;
import com.hedera.mirror.common.domain.transaction.RecordFile;
import com.hedera.mirror.web3.common.ContractCallContext;
import com.hedera.mirror.web3.evm.properties.MirrorNodeEvmProperties.HederaNetwork;
import com.swirlds.common.utility.SemanticVersion;
import java.util.Collections;
import java.util.Map;
import java.util.NavigableMap;
Expand Down Expand Up @@ -163,7 +163,7 @@ void getEvmVersionForBlockFromHederaNetwork(Long blockNumber, SemanticVersion ex
properties.setNetwork(HederaNetwork.MAINNET);

var result = properties.getEvmVersionForBlock(blockNumber);
assertThat(result).isEqualByComparingTo(expectedEvmVersion);
assertThat(result).isEqualTo(expectedEvmVersion);
}

@ParameterizedTest
Expand All @@ -173,6 +173,6 @@ void getEvmVersionForBlockFromConfig(Long blockNumber, SemanticVersion expectedE
properties.setEvmVersions(createEvmVersionsMapCustom());

var result = properties.getEvmVersionForBlock(blockNumber);
assertThat(result).isEqualByComparingTo(expectedEvmVersion);
assertThat(result).isEqualTo(expectedEvmVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.hedera.services.txns.util.PrngLogic;
import com.hederahashgraph.api.proto.java.HederaFunctionality;
import com.hederahashgraph.api.proto.java.ResponseCodeEnum;
import com.swirlds.common.crypto.Hash;
import com.swirlds.common.utility.CommonUtils;
import java.time.Instant;
import java.util.Optional;
Expand All @@ -50,8 +49,9 @@

@ExtendWith(MockitoExtension.class)
class PrngSystemPrecompiledContractTest {
private static final Hash WELL_KNOWN_HASH = new Hash(CommonUtils.unhex(
"65386630386164632d356537632d343964342d623437372d62636134346538386338373133633038316162372d616300"));
private static final byte[] WELL_KNOWN_HASH_BYTE_ARRAY = CommonUtils.unhex(
"65386630386164632d356537632d343964342d623437372d62636134346538386338373133633038316162372d6163");
private final Instant consensusNow = Instant.ofEpochSecond(123456789L);

@Mock
private MessageFrame frame;
Expand All @@ -62,16 +62,22 @@ class PrngSystemPrecompiledContractTest {
@Mock
private PrecompilePricingUtils pricingUtils;

private final Instant consensusNow = Instant.ofEpochSecond(123456789L);

@Mock
private LivePricesSource livePricesSource;

private PrngSystemPrecompiledContract subject;

private static Bytes random256BitGeneratorInput() {
return input(PSEUDORANDOM_SEED_GENERATOR_SELECTOR);
}

private static Bytes input(final int selector) {
return Bytes.concatenate(Bytes.ofUnsignedInt(selector & 0xffffffffL), Bytes.EMPTY);
}

@BeforeEach
void setUp() {
Supplier<byte[]> mockSupplier = WELL_KNOWN_HASH::getValue;
Supplier<byte[]> mockSupplier = () -> WELL_KNOWN_HASH_BYTE_ARRAY;
final var logic = new PrngLogic(mockSupplier);

subject = new PrngSystemPrecompiledContract(gasCalculator, logic, livePricesSource, pricingUtils);
Expand Down Expand Up @@ -169,14 +175,6 @@ void zeroedHashReturnsSentinelOutputs() {
assertNull(result);
}

private static Bytes random256BitGeneratorInput() {
return input(PSEUDORANDOM_SEED_GENERATOR_SELECTOR);
}

private static Bytes input(final int selector) {
return Bytes.concatenate(Bytes.ofUnsignedInt(selector & 0xffffffffL), Bytes.EMPTY);
}

private void initialSetUp() {
given(pricingUtils.getCanonicalPriceInTinyCents(PRNG)).willReturn(100000000L);
given(livePricesSource.currentGasPriceInTinycents(consensusNow, HederaFunctionality.ContractCall))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ void transferFromToHollowAccount() {
final var hollowAccount = domainBuilder
.entity()
.customize(e -> e.key(null).maxAutomaticTokenAssociations(10))
.persist()
.toEntityId();
.persist();

final var contract = testWeb3jService.deploy(ERCTestContract::deploy);
final var contractAddress = Address.fromHexString(contract.getContractAddress());
Expand All @@ -220,7 +219,7 @@ void transferFromToHollowAccount() {
final var functionCall = contract.send_transferFrom(
toAddress(token.getId()).toHexString(),
toAddress(owner).toHexString(),
toAddress(hollowAccount.getId()).toHexString(),
getAliasFromEntity(hollowAccount),
BigInteger.valueOf(amount));
// Then
verifyEthCallAndEstimateGas(functionCall, contract);
Expand Down Expand Up @@ -501,8 +500,7 @@ void transferFromToHollowAccountRedirect() {
final var hollowAccount = domainBuilder
.entity()
.customize(e -> e.key(null).maxAutomaticTokenAssociations(10))
.persist()
.toEntityId();
.persist();

final var contract = testWeb3jService.deploy(RedirectTestContract::deploy);
final var contractAddress = Address.fromHexString(contract.getContractAddress());
Expand All @@ -515,7 +513,7 @@ void transferFromToHollowAccountRedirect() {
final var functionCall = contract.send_transferFromRedirect(
toAddress(tokenEntity.getId()).toHexString(),
toAddress(owner).toHexString(),
toAddress(hollowAccount.getId()).toHexString(),
getAliasFromEntity(hollowAccount),
BigInteger.valueOf(amount));
// Then
verifyEthCallAndEstimateGas(functionCall, contract);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ void dissociateToken(final Boolean single) throws Exception {
// When
final var functionCall = single
? contract.call_dissociateTokenExternal(
getAddressFromEntity(associatedAccount), getAddressFromEntity(tokenEntity))
getAliasFromEntity(associatedAccount), getAddressFromEntity(tokenEntity))
: contract.call_dissociateTokensExternal(
getAddressFromEntity(associatedAccount), List.of(getAddressFromEntity(tokenEntity)));
getAliasFromEntity(associatedAccount), List.of(getAddressFromEntity(tokenEntity)));

// Then
verifyEthCallAndEstimateGas(functionCall, contract, ZERO_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ private void contractPersist(String binary, long entityId) {
.customize(e -> e.type(CONTRACT)
.id(entityId)
.num(entityId)
.alias(null)
.evmAddress(null)
.key(domainBuilder.key(KeyCase.ED25519))
.balance(3000L))
.persist();
Expand Down

0 comments on commit 5d00263

Please sign in to comment.