From d0294abf126656cf52deee3d129856a99972b861 Mon Sep 17 00:00:00 2001 From: David S Bakin <117694041+david-bakin-sl@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:21:57 -0800 Subject: [PATCH] Smart contract service metrics, P2 priority. These are the metrics that are interesting now and we can collect in the consensus node, but later we'll collect in other ways. E.g., from block nodes. (All these metrics are for post-consensus transactions and will show up in the record/block stream.) Does _not_ include metrics for ExchangeRate and PNRG system contracts: Those system contracts are coded differently (don't use the same base (abstract) classes as HAS/HSS/HTS) and so will need a bit more work. Related issue(s): Fixes #16088 Reviewer notes: Changes a boatload of files. Each of the ~60 FooTranslator classes (about one for each system contract method) needs a small change, but that's a change to the construtor, and so it had effects on all the unit tests for those classes as well. You'll quickly see the pattern ... Signed-off-by: David S Bakin <117694041+david-bakin-sl@users.noreply.github.com> --- .../com/hedera/node/app/spi/RpcService.java | 10 + .../main/java/com/hedera/node/app/Hedera.java | 13 +- .../impl/ContractServiceComponent.java | 24 +- .../contract/impl/ContractServiceImpl.java | 70 ++++- .../impl/exec/metrics/ContractMetrics.java | 156 ++++++---- .../common/AbstractCallAttempt.java | 42 +++ .../common/AbstractCallTranslator.java | 93 ++++++ .../systemcontracts/has/HasCallAttempt.java | 10 + .../systemcontracts/has/HasCallFactory.java | 7 +- .../EvmAddressAliasTranslator.java | 14 +- .../HbarAllowanceTranslator.java | 21 +- .../hbarapprove/HbarApproveTranslator.java | 16 +- .../HederaAccountNumAliasTranslator.java | 16 +- .../isauthorized/IsAuthorizedTranslator.java | 13 +- .../IsAuthorizedRawTranslator.java | 13 +- .../isvalidalias/IsValidAliasTranslator.java | 15 +- ...etUnlimitedAutoAssociationsTranslator.java | 13 +- .../systemcontracts/hss/HssCallAttempt.java | 10 + .../systemcontracts/hss/HssCallFactory.java | 7 +- .../signschedule/SignScheduleTranslator.java | 18 +- .../systemcontracts/hts/HtsCallAttempt.java | 10 + .../systemcontracts/hts/HtsCallFactory.java | 7 +- .../hts/airdrops/TokenAirdropTranslator.java | 16 +- .../hts/allowance/GetAllowanceTranslator.java | 20 +- .../associations/AssociationsTranslator.java | 31 +- .../hts/balanceof/BalanceOfTranslator.java | 12 +- .../hts/burn/BurnTranslator.java | 21 +- .../TokenCancelAirdropDecoder.java | 2 +- .../TokenCancelAirdropTranslator.java | 33 ++- .../TokenClaimAirdropDecoder.java | 2 +- .../TokenClaimAirdropTranslator.java | 33 ++- .../hts/create/CreateTranslator.java | 29 +- .../customfees/TokenCustomFeesTranslator.java | 16 +- .../hts/decimals/DecimalsTranslator.java | 12 +- .../DefaultFreezeStatusTranslator.java | 16 +- .../DefaultKycStatusTranslator.java | 16 +- .../hts/delete/DeleteTranslator.java | 13 +- .../hts/freeze/FreezeUnfreezeTranslator.java | 16 +- .../FungibleTokenInfoCall.java | 2 +- .../FungibleTokenInfoTranslator.java | 27 +- .../getapproved/GetApprovedTranslator.java | 21 +- .../GrantApprovalTranslator.java | 36 ++- .../GrantRevokeKycTranslator.java | 16 +- .../IsApprovedForAllTranslator.java | 17 +- .../isassociated/IsAssociatedTranslator.java | 12 +- .../hts/isfrozen/IsFrozenTranslator.java | 15 +- .../hts/iskyc/IsKycTranslator.java | 15 +- .../hts/istoken/IsTokenTranslator.java | 15 +- .../hts/mint/MintTranslator.java | 19 +- .../hts/name/NameTranslator.java | 12 +- .../hts/nfttokeninfo/NftTokenInfoCall.java | 2 +- .../nfttokeninfo/NftTokenInfoTranslator.java | 27 +- .../hts/ownerof/OwnerOfTranslator.java | 13 +- .../hts/pauses/PausesTranslator.java | 16 +- .../rejecttokens/RejectTokensTranslator.java | 34 ++- .../SetApprovalForAllTranslator.java | 24 +- .../hts/symbol/SymbolTranslator.java | 14 +- .../tokenexpiry/TokenExpiryTranslator.java | 16 +- .../hts/tokeninfo/TokenInfoCall.java | 2 +- .../hts/tokeninfo/TokenInfoTranslator.java | 30 +- .../hts/tokenkey/TokenKeyTranslator.java | 16 +- .../hts/tokentype/TokenTypeTranslator.java | 15 +- .../hts/tokenuri/TokenUriTranslator.java | 15 +- .../totalsupply/TotalSupplyTranslator.java | 15 +- .../transfer/ClassicTransfersTranslator.java | 10 +- .../transfer/Erc20TransfersTranslator.java | 7 +- .../Erc721TransferFromTranslator.java | 7 +- .../hts/update/UpdateExpiryTranslator.java | 22 +- .../hts/update/UpdateKeysTranslator.java | 16 +- .../update/UpdateNFTsMetadataTranslator.java | 16 +- .../hts/update/UpdateTranslator.java | 47 +++- .../UpdateTokenCustomFeesTranslator.java | 21 +- .../hts/wipe/WipeTranslator.java | 25 +- .../impl/exec/utils/SystemContractMethod.java | 266 ++++++++++++++++++ .../utils/SystemContractMethodRegistry.java | 140 +++++++++ .../AbstractContractTransactionHandler.java | 5 + .../impl/handlers/ContractCallHandler.java | 2 +- .../handlers/ContractCallLocalHandler.java | 7 +- .../impl/handlers/ContractCreateHandler.java | 2 +- .../handlers/EthereumTransactionHandler.java | 4 +- .../exec/metrics/ContractMetricsTest.java | 8 +- .../systemcontracts/CallAttemptHelpers.java | 223 ++++++++++++++- .../has/HasCallAttemptTest.java | 13 +- .../has/HasCallFactoryTest.java | 8 +- .../EvmAddressAliasTranslatorTest.java | 11 +- .../HbarAllowanceTranslatorTest.java | 14 +- .../HbarApproveTranslatorTest.java | 14 +- .../HederaAccountNumAliasTranslatorTest.java | 11 +- .../IsAuthorizedTranslatorTest.java | 9 +- .../IsAuthorizedRawTranslatorTest.java | 11 +- .../IsValidAliasTranslatorTest.java | 11 +- ...limitedAutoAssociationsTranslatorTest.java | 7 +- .../hss/HssCallAttemptTest.java | 7 +- .../hss/HssCallFactoryTest.java | 6 +- .../SignScheduleTranslatorTest.java | 20 +- .../hts/HtsCallAttemptTest.java | 46 ++- .../hts/HtsCallFactoryTest.java | 9 +- .../airdrops/TokenAirdropTranslatorTest.java | 8 +- .../allowance/GetAllowanceTranslatorTest.java | 24 +- .../hts/burn/BurnTranslatorTest.java | 24 +- .../TokenCancelAirdropDecoderTest.java | 10 +- .../TokenCancelAirdropTranslatorTest.java | 21 +- .../TokenClaimAirdropDecoderTest.java | 10 +- .../TokenClaimAirdropTranslatorTest.java | 21 +- .../hts/create/CreateTranslatorTest.java | 53 +++- .../TokenCustomFeesTranslatorTest.java | 21 +- .../DefaultFreezeStatusTranslatorTest.java | 21 +- .../DefaultKycStatusTranslatorTest.java | 21 +- .../hts/delete/DeleteTranslatorTest.java | 21 +- .../freeze/FreezeUnfreezeTranslatorTest.java | 29 +- .../FungibleTokenInfoCallTest.java | 26 +- .../FungibleTokenInfoTranslatorTest.java | 22 +- .../GetApprovedTranslatorTest.java | 29 +- .../GrantApprovalTranslatorTest.java | 40 ++- .../GrantRevokeKycTranslatorTest.java | 29 +- .../IsAssociatedTranslatorTest.java | 21 +- .../hts/isfrozen/IsFrozenTranslatorTest.java | 21 +- .../hts/iskyc/IsKycTranslatorTest.java | 21 +- .../hts/istoken/IsTokenTranslatorTest.java | 21 +- .../hts/mint/MintTranslatorTest.java | 29 +- .../nfttokeninfo/NftTokenInfoCallTest.java | 12 +- .../NftTokenInfoTranslatorTest.java | 17 +- .../hts/pauses/PausesTranslatorTest.java | 31 +- .../RejectTokensTranslatorTest.java | 15 +- .../SetApprovalForAllTranslatorTest.java | 24 +- .../TokenExpiryTranslatorTest.java | 21 +- .../hts/tokeninfo/TokenInfoCallTest.java | 18 +- .../tokeninfo/TokenInfoTranslatorTest.java | 22 +- .../hts/tokenkey/TokenKeyTranslatorTest.java | 21 +- .../tokentype/TokenTypeTranslatorTest.java | 21 +- .../ClassicTransfersTranslatorTest.java | 11 +- .../update/UpdateExpiryTranslatorTest.java | 14 +- .../hts/update/UpdateKeysTranslatorTest.java | 11 +- .../UpdateNFTsMetadataTranslatorTest.java | 3 +- .../hts/update/UpdateTranslatorTest.java | 30 +- .../UpdateTokenCustomFeesTranslatorTest.java | 8 +- .../hts/wipe/WipeTranslatorTest.java | 37 ++- .../SystemContractMethodRegistryTest.java | 143 ++++++++++ .../handlers/ContractCallHandlerTest.java | 8 +- .../ContractCallLocalHandlerTest.java | 12 +- .../handlers/ContractCreateHandlerTest.java | 8 +- .../EthereumTransactionHandlerTest.java | 8 +- 142 files changed, 2844 insertions(+), 551 deletions(-) create mode 100644 hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/utils/SystemContractMethod.java create mode 100644 hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/utils/SystemContractMethodRegistry.java create mode 100644 hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/utils/SystemContractMethodRegistryTest.java diff --git a/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/RpcService.java b/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/RpcService.java index 44a6334a3e0b..28bf0cc413a7 100644 --- a/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/RpcService.java +++ b/hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/RpcService.java @@ -33,4 +33,14 @@ public interface RpcService extends Service { */ @NonNull Set rpcDefinitions(); + + /** + * Services may have initialization to be done which can't be done in the constructor (too soon) + * but should/must be done before the system starts processing transactions. This is the hook + * for that. + * + * Called on each Service when `Hedera.onStateInitialized() is called for `InitTrigger.GENESIS`. + * Services module is still single-threaded when this happens. + */ + default void onStateInitializedForGenesis() {} } diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java index 741bfbd2f1ce..d2466f7aaa81 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/Hedera.java @@ -89,10 +89,12 @@ import com.hedera.node.app.services.AppContextImpl; import com.hedera.node.app.services.ServiceMigrator; import com.hedera.node.app.services.ServicesRegistry; +import com.hedera.node.app.services.ServicesRegistry.Registration; import com.hedera.node.app.signature.AppSignatureVerifier; import com.hedera.node.app.signature.impl.SignatureExpanderImpl; import com.hedera.node.app.signature.impl.SignatureVerifierImpl; import com.hedera.node.app.spi.AppContext; +import com.hedera.node.app.spi.RpcService; import com.hedera.node.app.spi.workflows.PreCheckException; import com.hedera.node.app.state.MerkleStateLifecyclesImpl; import com.hedera.node.app.state.recordcache.RecordCacheService; @@ -606,7 +608,16 @@ public void onStateInitialized( } // With the States API grounded in the working state, we can create the object graph from it initializeDagger(state, trigger); - contractServiceImpl.registerMetrics(); + + // Tell each service it can do its final initialization (if needed) before the system starts + // processing transactions. + if (trigger == GENESIS) { + servicesRegistry.registrations().stream() + .map(Registration::service) + .filter(RpcService.class::isInstance) + .map(RpcService.class::cast) + .forEach(RpcService::onStateInitializedForGenesis); + } } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/ContractServiceComponent.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/ContractServiceComponent.java index 16ebea137121..baa5757bab9d 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/ContractServiceComponent.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/ContractServiceComponent.java @@ -18,6 +18,11 @@ import com.hedera.node.app.service.contract.impl.exec.metrics.ContractMetrics; import com.hedera.node.app.service.contract.impl.exec.scope.VerificationStrategies; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.CallTranslator; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallAttempt; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.HssCallAttempt; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.handlers.ContractHandlers; import com.hedera.node.app.spi.signatures.SignatureVerifier; import dagger.BindsInstance; @@ -26,6 +31,8 @@ import java.time.InstantSource; import java.util.List; import java.util.function.Supplier; +import javax.inject.Named; +import javax.inject.Provider; import javax.inject.Singleton; import org.hyperledger.besu.evm.tracing.OperationTracer; @@ -52,7 +59,8 @@ ContractServiceComponent create( @BindsInstance SignatureVerifier signatureVerifier, @BindsInstance VerificationStrategies verificationStrategies, @BindsInstance @Nullable Supplier> addOnTracers, - @BindsInstance ContractMetrics contractMetrics); + @BindsInstance ContractMetrics contractMetrics, + @BindsInstance SystemContractMethodRegistry systemContractMethodRegistry); } /** @@ -64,4 +72,18 @@ ContractServiceComponent create( * @return contract metrics collection, instance */ ContractMetrics contractMetrics(); + + /** + * @return method registry for system contracts + */ + SystemContractMethodRegistry systemContractMethodRegistry(); + + @Named("HasTranslators") + Provider>> hasCallTranslators(); + + @Named("HssTranslators") + Provider>> hssCallTranslators(); + + @Named("HtsTranslators") + Provider>> htsCallTranslators(); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/ContractServiceImpl.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/ContractServiceImpl.java index 1e0b8e14e094..1780cc6c2a77 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/ContractServiceImpl.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/ContractServiceImpl.java @@ -22,6 +22,10 @@ import com.hedera.node.app.service.contract.impl.exec.metrics.ContractMetrics; import com.hedera.node.app.service.contract.impl.exec.scope.DefaultVerificationStrategies; import com.hedera.node.app.service.contract.impl.exec.scope.VerificationStrategies; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallAttempt; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.CallTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.handlers.ContractHandlers; import com.hedera.node.app.service.contract.impl.schemas.V0490ContractSchema; import com.hedera.node.app.service.contract.impl.schemas.V0500ContractSchema; @@ -30,15 +34,23 @@ import com.swirlds.state.lifecycle.SchemaRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.function.Supplier; +import java.util.stream.Collectors; +import javax.inject.Singleton; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.hyperledger.besu.evm.tracing.OperationTracer; /** * Implementation of the {@link ContractService}. */ public class ContractServiceImpl implements ContractService { + + private static final Logger log = LogManager.getLogger(ContractServiceImpl.class); + /** * Minimum gas required for contract operations. */ @@ -66,7 +78,10 @@ public ContractServiceImpl( final var metricsSupplier = requireNonNull(appContext.metricsSupplier()); final Supplier contractsConfigSupplier = () -> appContext.configSupplier().get().getConfigData(ContractsConfig.class); - final var contractMetrics = new ContractMetrics(metricsSupplier, contractsConfigSupplier); + final var systemContractMethodRegistry = new SystemContractMethodRegistry(); + final var contractMetrics = + new ContractMetrics(metricsSupplier, contractsConfigSupplier, systemContractMethodRegistry); + this.component = DaggerContractServiceComponent.factory() .create( appContext.instantSource(), @@ -75,7 +90,8 @@ public ContractServiceImpl( appContext.signatureVerifier(), Optional.ofNullable(verificationStrategies).orElseGet(DefaultVerificationStrategies::new), addOnTracers, - contractMetrics); + contractMetrics, + systemContractMethodRegistry); } @Override @@ -84,12 +100,19 @@ public void registerSchemas(@NonNull final SchemaRegistry registry) { registry.register(new V0500ContractSchema()); } - /** - * Create the metrics for the smart contracts service. This needs to be delayed until _after_ - * the metrics are available - which happens after `Hedera.initializeStatesApi`. - */ - public void registerMetrics() { - component.contractMetrics().createContractMetrics(); + @Override + public void onStateInitializedForGenesis() { + // Force call translators to be instantiated now, so that all the system contract methods + // will be registered, so the secondary metrics can be created. (Left to its own devices + // Dagger would delay instantiating them until transactions started flowing.) + final var allTranslators = allCallTranslators(); + + // TESTING + final var msg = "Known call translators:\n" + allTranslatorNames(allTranslators); + // END TESTING + + component.contractMetrics().createContractPrimaryMetrics(); + component.contractMetrics().createContractSecondaryMetrics(); } /** @@ -98,4 +121,35 @@ public void registerMetrics() { public ContractHandlers handlers() { return component.handlers(); } + + private @NonNull List>> allCallTranslators() { + final var allCallTranslators = new ArrayList>>(); + allCallTranslators.addAll(component.hasCallTranslators().get()); + allCallTranslators.addAll(component.hssCallTranslators().get()); + allCallTranslators.addAll(component.htsCallTranslators().get()); + return allCallTranslators; + } + + // ----------------- + // For testing only: + + private @NonNull String allTranslatorNames( + @NonNull List>> translators) { + return translators.stream().map(this::translatorName).sorted().collect(Collectors.joining("\n")); + } + + private @NonNull String translatorName(@NonNull final CallTranslator> translator) { + final var simpleName = translator.getClass().getSimpleName(); + final var isSingleton = isSingleton(translator.getClass()); + final var contractName = translator instanceof AbstractCallTranslator act ? act.kind() : ""; + + var name = contractName + "." + simpleName; + if (!isSingleton) name += "(NOT-SINGLETON)"; + + return name; + } + + private boolean isSingleton(Class klass) { + return klass.getDeclaredAnnotation(Singleton.class) != null; + } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/metrics/ContractMetrics.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/metrics/ContractMetrics.java index 421528bdcddc..1a88844920f4 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/metrics/ContractMetrics.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/metrics/ContractMetrics.java @@ -24,7 +24,9 @@ import com.google.common.annotations.VisibleForTesting; import com.hedera.hapi.node.base.HederaFunctionality; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.config.data.ContractsConfig; +import com.swirlds.common.metrics.platform.prometheus.NameConverter; import com.swirlds.metrics.api.Counter; import com.swirlds.metrics.api.Metric; import com.swirlds.metrics.api.Metrics; @@ -52,6 +54,8 @@ public class ContractMetrics { private final Supplier metricsSupplier; private final Supplier contractsConfigSupplier; private boolean p1MetricsEnabled; + private boolean p2MetricsEnabled; + private final SystemContractMethodRegistry systemContractMethodRegistry; private final HashMap rejectedTxsCounters = new HashMap<>(); private final HashMap rejectedTxsLackingIntrinsicGas = new HashMap<>(); @@ -80,71 +84,92 @@ public class ContractMetrics { @Inject public ContractMetrics( @NonNull final Supplier metricsSupplier, - @NonNull final Supplier contractsConfigSupplier) { + @NonNull final Supplier contractsConfigSupplier, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { this.metricsSupplier = requireNonNull( metricsSupplier, "metrics supplier (from platform via ServicesMain/Hedera must not be null"); this.contractsConfigSupplier = requireNonNull(contractsConfigSupplier, "contracts configuration supplier must not be null"); + this.systemContractMethodRegistry = + requireNonNull(systemContractMethodRegistry, "systemContractMethodRegistry must not be null"); } - private final Object metricsCreationLock = new Object(); - private volatile boolean primaryMetricsAreCreated = false; - - public void createContractMetrics() { - - // Primary metrics are a fixed set and can be created when `Hedera` initializes the system. - // But it actually must wait until the platform calls `Hedera.onStateInitialized` and, - // remarkably, that can happen more than once. We must only create the metrics the - // _first_ time. Hence, the simple gate here. - - synchronized (metricsCreationLock) { - if (!primaryMetricsAreCreated) { - - final var contractsConfig = requireNonNull(contractsConfigSupplier.get()); - this.p1MetricsEnabled = contractsConfig.metricsSmartContractPrimaryEnabled(); - - final var metrics = requireNonNull(metricsSupplier.get()); - - if (p1MetricsEnabled) { - // Rejected transactions counters - for (final var txKind : POSSIBLE_FAILING_TX_TYPES.keySet()) { - final var name = toRejectedName(txKind, REJECTED_TXN_SHORT_DESCR); - final var descr = toRejectedDescr(txKind, REJECTED_TXN_SHORT_DESCR); - final var config = new Counter.Config(METRIC_CATEGORY, name) - .withDescription(descr) - .withUnit(METRIC_TXN_UNIT); - final var metric = newCounter(metrics, config); - rejectedTxsCounters.put(txKind, metric); - } - - // Rejected transactions because they don't even have intrinsic gas - for (final var txKind : POSSIBLE_FAILING_TX_TYPES.keySet()) { - final var functionalityName = POSSIBLE_FAILING_TX_TYPES.get(txKind) + "DueToIntrinsicGas"; - final var name = toRejectedName(functionalityName, REJECTED_FOR_GAS_SHORT_DESCR); - final var descr = toRejectedDescr(functionalityName, REJECTED_FOR_GAS_SHORT_DESCR); - final var config = new Counter.Config(METRIC_CATEGORY, name) - .withDescription(descr) - .withUnit(METRIC_TXN_UNIT); - final var metric = newCounter(metrics, config); - rejectedTxsLackingIntrinsicGas.put(txKind, metric); - } - - // Rejected transactions for ethereum calls that are in type 3 blob transaction format - { - final var name = toRejectedName(REJECTED_TYPE3_FUNCTIONALITY, REJECTED_TYPE3_SHORT_DESCR); - final var descr = toRejectedDescr(REJECTED_TYPE3_FUNCTIONALITY, REJECTED_TYPE3_SHORT_DESCR); - final var config = new Counter.Config(METRIC_CATEGORY, name) - .withDescription(descr) - .withUnit(METRIC_TXN_UNIT); - final var metric = newCounter(metrics, config); - rejectedEthType3Counter = metric; - } - } - primaryMetricsAreCreated = true; + // -------------------- + // Creating the metrics + + /** + * Primary metrics are a fixed set and can be created when `Hedera` initializes the system. But + * it actually must wait until the platform calls `Hedera.onStateInitialized`, and then for + * GENESIS only. + */ + public void createContractPrimaryMetrics() { + final var contractsConfig = requireNonNull(contractsConfigSupplier.get()); + this.p1MetricsEnabled = contractsConfig.metricsSmartContractPrimaryEnabled(); + + if (p1MetricsEnabled) { + final var metrics = requireNonNull(metricsSupplier.get()); + + // Rejected transactions counters + for (final var txKind : POSSIBLE_FAILING_TX_TYPES.keySet()) { + final var name = toRejectedName(txKind, REJECTED_TXN_SHORT_DESCR); + final var descr = toRejectedDescr(txKind, REJECTED_TXN_SHORT_DESCR); + final var config = new Counter.Config(METRIC_CATEGORY, name) + .withDescription(descr) + .withUnit(METRIC_TXN_UNIT); + final var metric = newCounter(metrics, config); + rejectedTxsCounters.put(txKind, metric); + } + + // Rejected transactions because they don't even have intrinsic gas + for (final var txKind : POSSIBLE_FAILING_TX_TYPES.keySet()) { + final var functionalityName = POSSIBLE_FAILING_TX_TYPES.get(txKind) + "DueToIntrinsicGas"; + final var name = toRejectedName(functionalityName, REJECTED_FOR_GAS_SHORT_DESCR); + final var descr = toRejectedDescr(functionalityName, REJECTED_FOR_GAS_SHORT_DESCR); + final var config = new Counter.Config(METRIC_CATEGORY, name) + .withDescription(descr) + .withUnit(METRIC_TXN_UNIT); + final var metric = newCounter(metrics, config); + rejectedTxsLackingIntrinsicGas.put(txKind, metric); + } + + // Rejected transactions for ethereum calls that are in type 3 blob transaction format + { + final var name = toRejectedName(REJECTED_TYPE3_FUNCTIONALITY, REJECTED_TYPE3_SHORT_DESCR); + final var descr = toRejectedDescr(REJECTED_TYPE3_FUNCTIONALITY, REJECTED_TYPE3_SHORT_DESCR); + final var config = new Counter.Config(METRIC_CATEGORY, name) + .withDescription(descr) + .withUnit(METRIC_TXN_UNIT); + final var metric = newCounter(metrics, config); + rejectedEthType3Counter = metric; } } } + public void createContractSecondaryMetrics() { + + if (systemContractMethodRegistry.size() == 0) { + // Something went wrong with the order in which components were initialized + log.warn("no system contract methods registered when trying to create secondary metrics"); + } + + // TESTING + final var msg = systemContractMethodRegistry.allQualifiedMethods().stream() + .sorted() + .collect(Collectors.joining("\n")); + // END TESTING + + final var contractsConfig = requireNonNull(contractsConfigSupplier.get()); + this.p2MetricsEnabled = contractsConfig.metricsSmartContractSecondaryEnabled(); + + if (p2MetricsEnabled) { + final var metrics = requireNonNull(metricsSupplier.get()); + // TBD + } + } + + // --------------------------------- + // P1 metrics: `pureCheck` failures + public void incrementRejectedTx(@NonNull final HederaFunctionality txKind) { bumpRejectedTx(txKind, 1); } @@ -174,6 +199,12 @@ public void bumpRejectedType3EthTx(final long bumpBy) { } } + // --------------------------------------------- + // P2 metrics: System contract per-method counts + + // ----------------- + // Unit test helpers + @VisibleForTesting public @NonNull Map getAllCounters() { return Stream.concat( @@ -216,6 +247,9 @@ public void bumpRejectedType3EthTx(final long bumpBy) { .collect(Collectors.joining(", ", "{", "}")); } + // --------------------------------- + // Helpers for making metrics' names + private @NonNull Counter newCounter(@NonNull final Metrics metrics, @NonNull final Counter.Config config) { return metrics.getOrCreate(config); } @@ -244,6 +278,16 @@ public void bumpRejectedType3EthTx(final long bumpBy) { @NonNull final String template, @NonNull final String functionality, @NonNull final String shortDescription) { - return template.formatted(functionality, METRIC_SERVICE, shortDescription); + final var possiblyUnacceptableName = template.formatted(functionality, METRIC_SERVICE, shortDescription); + final var definitelyAcceptableName = NameConverter.fix(possiblyUnacceptableName); + + // TESTING + if (!definitelyAcceptableName.equals(possiblyUnacceptableName)) { + // Just want to signal this during testing: i.e., to be able to place a breakpoint here + ; + } + // END TESTING + + return definitelyAcceptableName; } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/common/AbstractCallAttempt.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/common/AbstractCallAttempt.java index c05adca731c0..1752152ea568 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/common/AbstractCallAttempt.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/common/AbstractCallAttempt.java @@ -26,6 +26,9 @@ import com.hedera.node.app.service.contract.impl.exec.scope.VerificationStrategies; import com.hedera.node.app.service.contract.impl.exec.scope.VerificationStrategy; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.SystemContract; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.swirlds.config.api.Configuration; import edu.umd.cs.findbugs.annotations.NonNull; @@ -54,6 +57,7 @@ public abstract class AbstractCallAttempt> { private final VerificationStrategies verificationStrategies; private final SystemContractGasCalculator gasCalculator; private final List> callTranslators; + private final SystemContractMethodRegistry systemContractMethodRegistry; private final boolean isStaticCall; // If non-null, the address of a non-contract entity (e.g., account or token) whose @@ -89,6 +93,7 @@ public AbstractCallAttempt( @NonNull final SystemContractGasCalculator gasCalculator, @NonNull final List> callTranslators, final boolean isStaticCall, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry, @NonNull final com.esaulpaugh.headlong.abi.Function redirectFunction) { requireNonNull(input); requireNonNull(redirectFunction); @@ -101,6 +106,7 @@ public AbstractCallAttempt( this.enhancement = requireNonNull(enhancement); this.verificationStrategies = requireNonNull(verificationStrategies); this.onlyDelegatableContractKeysActive = onlyDelegatableContractKeysActive; + this.systemContractMethodRegistry = requireNonNull(systemContractMethodRegistry); if (isRedirectSelector(redirectFunction.selector(), input.toArrayUnsafe())) { Tuple abiCall = null; @@ -127,6 +133,8 @@ public AbstractCallAttempt( this.isStaticCall = isStaticCall; } + protected abstract SystemContract systemContractKind(); + protected abstract T self(); /** @@ -263,6 +271,26 @@ public boolean isRedirect() { return redirectAddress != null; } + public Function asSolidityFunction(@NonNull final String signature, @NonNull final String outputs) { + requireNonNull(signature); + requireNonNull(outputs); + + final var function = Function.parse(signature, outputs); + systemContractMethodRegistry.register(function, systemContractKind()); + return function; + } + + public Function asSolidityFunction( + @NonNull final String methodName, @NonNull final String signature, @NonNull final String outputs) { + requireNonNull(methodName); + requireNonNull(signature); + requireNonNull(outputs); + + final var function = Function.parse(signature, outputs); + systemContractMethodRegistry.register(function, systemContractKind(), methodName); + return function; + } + /** * Returns whether this call attempt is a selector for any of the given functions. * @param functions selectors to match against @@ -277,6 +305,15 @@ public boolean isSelector(@NonNull final Function... functions) { return false; } + public boolean isSelector(@NonNull final SystemContractMethod... methods) { + for (final var method : methods) { + if (Arrays.equals(method.selector(), this.selector())) { + return true; + } + } + return false; + } + /** * Returns whether this call attempt is a selector for any of the given functions. * @param configEnabled whether the config is enabled @@ -287,6 +324,11 @@ public boolean isSelectorIfConfigEnabled(final boolean configEnabled, @NonNull f return configEnabled && isSelector(functions); } + public boolean isSelectorIfConfigEnabled( + final boolean configEnabled, @NonNull final SystemContractMethod... systemContractMethods) { + return configEnabled && isSelector(systemContractMethods); + } + /** * Returns whether this call attempt is a selector for any of the given functions. * @param functionSelector bytes of the function selector diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/common/AbstractCallTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/common/AbstractCallTranslator.java index e2bc2c7904ad..b8ef9b22e792 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/common/AbstractCallTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/common/AbstractCallTranslator.java @@ -18,6 +18,11 @@ import static java.util.Objects.requireNonNull; +import com.esaulpaugh.headlong.abi.Function; +import com.google.common.annotations.VisibleForTesting; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.SystemContract; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -27,6 +32,17 @@ * @param the type of the abstract call translator */ public abstract class AbstractCallTranslator> implements CallTranslator { + + private final SystemContract systemContractKind; + private final SystemContractMethodRegistry systemContractMethodRegistry; + + public AbstractCallTranslator( + @NonNull final SystemContract systemContractKind, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + this.systemContractKind = requireNonNull(systemContractKind); + this.systemContractMethodRegistry = requireNonNull(systemContractMethodRegistry); + } + /** * {@inheritDoc} */ @@ -38,4 +54,81 @@ public abstract class AbstractCallTranslator> i } return null; } + + public void registerMethods(@NonNull final Function... functions) { + requireNonNull(functions); + for (@NonNull final Function function : functions) { + requireNonNull(function); + registerMethod(function); + } + } + + public void registerMethods(@NonNull final SystemContractMethod... methods) { + requireNonNull(methods); + for (@NonNull final var method : methods) { + requireNonNull(method); + registerMethod(method.withContract(systemContractKind)); + } + } + + private void registerMethod(@NonNull final SystemContractMethod method) { + requireNonNull(method); + method.verifyComplete(); + + if (systemContractMethodRegistry != null) { + systemContractMethodRegistry.register(method); + } + } + + public void registerMethod(@NonNull final Function function) { + requireNonNull(function); + requireNonNull(systemContractKind); + + if (systemContractMethodRegistry != null) { + systemContractMethodRegistry.register(function, systemContractKind); + } + } + + public void registerProxyMethods(@NonNull final Function... functions) { + requireNonNull(functions); + for (@NonNull final Function function : functions) { + requireNonNull(function); + registerProxyMethod(function); + } + } + + public void registerProxyMethod(@NonNull final Function function) { + requireNonNull(function); + requireNonNull(systemContractKind); + + if (systemContractMethodRegistry != null) { + systemContractMethodRegistry.register(function, systemContractKind, SystemContractMethod.CallVia.PROXY); + } + } + + public void registerMethod(@NonNull final String methodNameOverride, @NonNull final Function function) { + requireNonNull(methodNameOverride); + requireNonNull(function); + requireNonNull(systemContractKind); + + if (systemContractMethodRegistry != null) { + systemContractMethodRegistry.register(function, systemContractKind, methodNameOverride); + } + } + + public void registerProxyMethod(@NonNull final String methodNameOverride, @NonNull final Function function) { + requireNonNull(methodNameOverride); + requireNonNull(function); + requireNonNull(systemContractKind); + + if (systemContractMethodRegistry != null) { + systemContractMethodRegistry.register( + function, systemContractKind, methodNameOverride, SystemContractMethod.CallVia.PROXY); + } + } + + @VisibleForTesting + public @NonNull String kind() { + return systemContractKind != null ? systemContractKind.name() : ""; + } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/HasCallAttempt.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/HasCallAttempt.java index a6cf40fedd88..e2e19e9cc7ff 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/HasCallAttempt.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/HasCallAttempt.java @@ -31,6 +31,9 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.CallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.SystemContract; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.spi.signatures.SignatureVerifier; import com.swirlds.config.api.Configuration; @@ -68,6 +71,7 @@ public HasCallAttempt( @NonNull final SignatureVerifier signatureVerifier, @NonNull final SystemContractGasCalculator gasCalculator, @NonNull final List> callTranslators, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry, final boolean isStaticCall) { super( input, @@ -81,6 +85,7 @@ public HasCallAttempt( gasCalculator, callTranslators, isStaticCall, + systemContractMethodRegistry, REDIRECT_FOR_ACCOUNT); if (isRedirect()) { this.redirectAccount = linkedAccount(requireNonNull(redirectAddress)); @@ -90,6 +95,11 @@ public HasCallAttempt( this.signatureVerifier = requireNonNull(signatureVerifier); } + @Override + protected SystemContract systemContractKind() { + return SystemContractMethod.SystemContract.HAS; + } + @Override protected HasCallAttempt self() { return this; diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/HasCallFactory.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/HasCallFactory.java index 16b7a2360b4f..39c1e74afefd 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/HasCallFactory.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/HasCallFactory.java @@ -27,6 +27,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.CallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.SyntheticIds; import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.spi.signatures.SignatureVerifier; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.List; @@ -46,6 +47,7 @@ public class HasCallFactory implements CallFactory { private final VerificationStrategies verificationStrategies; private final SignatureVerifier signatureVerifier; private final List> callTranslators; + private final SystemContractMethodRegistry systemContractMethodRegistry; @Inject public HasCallFactory( @@ -53,12 +55,14 @@ public HasCallFactory( @NonNull final CallAddressChecks addressChecks, @NonNull final VerificationStrategies verificationStrategies, @NonNull final SignatureVerifier signatureVerifier, - @NonNull @Named("HasTranslators") final List> callTranslators) { + @NonNull @Named("HasTranslators") final List> callTranslators, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { this.syntheticIds = requireNonNull(syntheticIds); this.addressChecks = requireNonNull(addressChecks); this.verificationStrategies = requireNonNull(verificationStrategies); this.signatureVerifier = requireNonNull(signatureVerifier); this.callTranslators = requireNonNull(callTranslators); + this.systemContractMethodRegistry = requireNonNull(systemContractMethodRegistry); } /** @@ -88,6 +92,7 @@ public HasCallFactory( signatureVerifier, systemContractGasCalculatorOf(frame), callTranslators, + systemContractMethodRegistry, frame.isStatic()); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/getevmaddressalias/EvmAddressAliasTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/getevmaddressalias/EvmAddressAliasTranslator.java index 85b056884397..65c1e6898813 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/getevmaddressalias/EvmAddressAliasTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/getevmaddressalias/EvmAddressAliasTranslator.java @@ -19,10 +19,12 @@ import static java.util.Objects.requireNonNull; import com.esaulpaugh.headlong.abi.Address; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -33,12 +35,16 @@ @Singleton public class EvmAddressAliasTranslator extends AbstractCallTranslator { /** Selector for getEvmAddressAlias(address) method. */ - public static final Function EVM_ADDRESS_ALIAS = - new Function("getEvmAddressAlias(address)", ReturnTypes.RESPONSE_CODE_ADDRESS); + public static final SystemContractMethod EVM_ADDRESS_ALIAS = SystemContractMethod.declare( + "getEvmAddressAlias(address)", ReturnTypes.RESPONSE_CODE_ADDRESS) + .withModifier(Modifier.VIEW); @Inject - public EvmAddressAliasTranslator() { + public EvmAddressAliasTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger + super(SystemContractMethod.SystemContract.HAS, systemContractMethodRegistry); + + registerMethods(EVM_ADDRESS_ALIAS); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hbarallowance/HbarAllowanceTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hbarallowance/HbarAllowanceTranslator.java index 3a687a45ae58..1c10403574a0 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hbarallowance/HbarAllowanceTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hbarallowance/HbarAllowanceTranslator.java @@ -18,11 +18,14 @@ import static java.util.Objects.requireNonNull; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -34,16 +37,22 @@ public class HbarAllowanceTranslator extends AbstractCallTranslator { /** Selector for hbarAllowance(address) method. */ - public static final Function HBAR_ALLOWANCE_PROXY = - new Function("hbarAllowance(address)", ReturnTypes.RESPONSE_CODE_INT256); + public static final SystemContractMethod HBAR_ALLOWANCE_PROXY = SystemContractMethod.declare( + "hbarAllowance(address)", ReturnTypes.RESPONSE_CODE_INT256) + .withVia(CallVia.PROXY) + .withModifier(Modifier.VIEW); /** Selector for hbarAllowance(address,address) method. */ - public static final Function HBAR_ALLOWANCE = - new Function("hbarAllowance(address,address)", ReturnTypes.RESPONSE_CODE_INT256); + public static final SystemContractMethod HBAR_ALLOWANCE = SystemContractMethod.declare( + "hbarAllowance(address,address)", ReturnTypes.RESPONSE_CODE_INT256) + .withModifier(Modifier.VIEW); @Inject - public HbarAllowanceTranslator() { + public HbarAllowanceTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HAS, systemContractMethodRegistry); + + registerMethods(HBAR_ALLOWANCE, HBAR_ALLOWANCE_PROXY); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hbarapprove/HbarApproveTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hbarapprove/HbarApproveTranslator.java index d02d21909d61..fdc08c44bc14 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hbarapprove/HbarApproveTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hbarapprove/HbarApproveTranslator.java @@ -18,7 +18,6 @@ import static java.util.Objects.requireNonNull; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.token.CryptoAllowance; import com.hedera.hapi.node.token.CryptoApproveAllowanceTransactionBody; @@ -27,6 +26,9 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import java.math.BigInteger; import javax.inject.Inject; @@ -39,17 +41,23 @@ public class HbarApproveTranslator extends AbstractCallTranslator { /** Selector for hbarApprove(address,int256) method. */ - public static final Function HBAR_APPROVE_PROXY = new Function("hbarApprove(address,int256)", ReturnTypes.INT_64); + public static final SystemContractMethod HBAR_APPROVE_PROXY = SystemContractMethod.declare( + "hbarApprove(address,int256)", ReturnTypes.INT_64) + .withVia(CallVia.PROXY); /** Selector for hbarApprove(address,address,int256) method. */ - public static final Function HBAR_APPROVE = new Function("hbarApprove(address,address,int256)", ReturnTypes.INT_64); + public static final SystemContractMethod HBAR_APPROVE = + SystemContractMethod.declare("hbarApprove(address,address,int256)", ReturnTypes.INT_64); /** * Default constructor for injection. */ @Inject - public HbarApproveTranslator() { + public HbarApproveTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HAS, systemContractMethodRegistry); + + registerMethods(HBAR_APPROVE, HBAR_APPROVE_PROXY); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hederaaccountnumalias/HederaAccountNumAliasTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hederaaccountnumalias/HederaAccountNumAliasTranslator.java index 430a2ef8b7a7..cd284f4adac1 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hederaaccountnumalias/HederaAccountNumAliasTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hederaaccountnumalias/HederaAccountNumAliasTranslator.java @@ -19,25 +19,33 @@ import static java.util.Objects.requireNonNull; import com.esaulpaugh.headlong.abi.Address; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class HederaAccountNumAliasTranslator extends AbstractCallTranslator { /** Selector for getHederaAccountNumAlias(address) method. */ - public static final Function HEDERA_ACCOUNT_NUM_ALIAS = - new Function("getHederaAccountNumAlias(address)", ReturnTypes.RESPONSE_CODE_ADDRESS); + public static final SystemContractMethod HEDERA_ACCOUNT_NUM_ALIAS = SystemContractMethod.declare( + "getHederaAccountNumAlias(address)", ReturnTypes.RESPONSE_CODE_ADDRESS) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public HederaAccountNumAliasTranslator() { + public HederaAccountNumAliasTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger + super(SystemContractMethod.SystemContract.HAS, systemContractMethodRegistry); + + registerMethods(HEDERA_ACCOUNT_NUM_ALIAS); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/isauthorized/IsAuthorizedTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/isauthorized/IsAuthorizedTranslator.java index eb18982fc789..c3a223cf7511 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/isauthorized/IsAuthorizedTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/isauthorized/IsAuthorizedTranslator.java @@ -19,7 +19,6 @@ import static java.util.Objects.requireNonNull; import com.esaulpaugh.headlong.abi.Address; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.annotations.ServicesV051; import com.hedera.node.app.service.contract.impl.exec.FeatureFlags; import com.hedera.node.app.service.contract.impl.exec.gas.CustomGasCalculator; @@ -27,6 +26,8 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; @@ -35,8 +36,8 @@ @Singleton public class IsAuthorizedTranslator extends AbstractCallTranslator { - public static final Function IS_AUTHORIZED = - new Function("isAuthorized(address,bytes,bytes)", ReturnTypes.RESPONSE_CODE64_BOOL); + public static final SystemContractMethod IS_AUTHORIZED = + SystemContractMethod.declare("isAuthorized(address,bytes,bytes)", ReturnTypes.RESPONSE_CODE64_BOOL); private static final int ADDRESS_ARG = 0; private static final int MESSAGE_ARG = 1; private static final int SIGNATURE_BLOB_ARG = 2; @@ -46,9 +47,13 @@ public class IsAuthorizedTranslator extends AbstractCallTranslator { /** Selector for isAuthorizedRaw(address,bytes,bytes) method. */ - public static final Function IS_AUTHORIZED_RAW = - new Function("isAuthorizedRaw(address,bytes,bytes)", ReturnTypes.BOOL); + public static final SystemContractMethod IS_AUTHORIZED_RAW = + SystemContractMethod.declare("isAuthorizedRaw(address,bytes,bytes)", ReturnTypes.BOOL); private static final int ADDRESS_ARG = 0; private static final int HASH_ARG = 1; @@ -51,9 +52,13 @@ public class IsAuthorizedRawTranslator extends AbstractCallTranslator { /** Selector for isValidAlias(address) method. */ - public static final Function IS_VALID_ALIAS = new Function("isValidAlias(address)", ReturnTypes.BOOL); + public static final SystemContractMethod IS_VALID_ALIAS = SystemContractMethod.declare( + "isValidAlias(address)", ReturnTypes.BOOL) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public IsValidAliasTranslator() { + public IsValidAliasTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger + super(SystemContractMethod.SystemContract.HAS, systemContractMethodRegistry); + + registerMethods(IS_VALID_ALIAS); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/setunlimitedautoassociations/SetUnlimitedAutoAssociationsTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/setunlimitedautoassociations/SetUnlimitedAutoAssociationsTranslator.java index 4c289164d8b0..9a89b98d8968 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/setunlimitedautoassociations/SetUnlimitedAutoAssociationsTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/setunlimitedautoassociations/SetUnlimitedAutoAssociationsTranslator.java @@ -18,13 +18,14 @@ import static java.util.Objects.requireNonNull; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.token.CryptoUpdateTransactionBody; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; @@ -33,15 +34,19 @@ @Singleton public class SetUnlimitedAutoAssociationsTranslator extends AbstractCallTranslator { - public static final Function SET_UNLIMITED_AUTO_ASSOC = - new Function("setUnlimitedAutomaticAssociations(bool)", ReturnTypes.INT_64); + public static final SystemContractMethod SET_UNLIMITED_AUTO_ASSOC = + SystemContractMethod.declare("setUnlimitedAutomaticAssociations(bool)", ReturnTypes.INT_64); private static final int UNLIMITED_AUTO_ASSOCIATIONS = -1; private static final int NO_AUTO_ASSOCIATIONS = 0; @Inject - public SetUnlimitedAutoAssociationsTranslator() { + public SetUnlimitedAutoAssociationsTranslator( + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HAS, systemContractMethodRegistry); + + registerMethods(SET_UNLIMITED_AUTO_ASSOC); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/HssCallAttempt.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/HssCallAttempt.java index 7f9f87a3e949..e01c1811c0ad 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/HssCallAttempt.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/HssCallAttempt.java @@ -31,6 +31,9 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.CallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.SystemContract; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.swirlds.config.api.Configuration; import edu.umd.cs.findbugs.annotations.NonNull; @@ -63,6 +66,7 @@ public HssCallAttempt( @NonNull final VerificationStrategies verificationStrategies, @NonNull final SystemContractGasCalculator gasCalculator, @NonNull final List> callTranslators, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry, final boolean isStaticCall) { super( input, @@ -76,6 +80,7 @@ public HssCallAttempt( gasCalculator, callTranslators, isStaticCall, + systemContractMethodRegistry, REDIRECT_FOR_SCHEDULE_TXN); if (isRedirect()) { this.redirectScheduleTxn = linkedSchedule(requireNonNull(redirectAddress)); @@ -84,6 +89,11 @@ public HssCallAttempt( } } + @Override + protected SystemContract systemContractKind() { + return SystemContractMethod.SystemContract.HSS; + } + @Override protected HssCallAttempt self() { return this; diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/HssCallFactory.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/HssCallFactory.java index b503840b2730..9f1ef0c50e5f 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/HssCallFactory.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/HssCallFactory.java @@ -27,6 +27,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.CallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.SyntheticIds; import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.spi.signatures.SignatureVerifier; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.List; @@ -45,6 +46,7 @@ public class HssCallFactory implements CallFactory { private final CallAddressChecks addressChecks; private final VerificationStrategies verificationStrategies; private final List> callTranslators; + private final SystemContractMethodRegistry systemContractMethodRegistry; @Inject public HssCallFactory( @@ -52,11 +54,13 @@ public HssCallFactory( @NonNull final CallAddressChecks addressChecks, @NonNull final VerificationStrategies verificationStrategies, @NonNull final SignatureVerifier signatureVerifier, - @NonNull @Named("HssTranslators") final List> callTranslators) { + @NonNull @Named("HssTranslators") final List> callTranslators, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { this.syntheticIds = requireNonNull(syntheticIds); this.addressChecks = requireNonNull(addressChecks); this.verificationStrategies = requireNonNull(verificationStrategies); this.callTranslators = requireNonNull(callTranslators); + this.systemContractMethodRegistry = requireNonNull(systemContractMethodRegistry); } /** @@ -85,6 +89,7 @@ public HssCallFactory( verificationStrategies, systemContractGasCalculatorOf(frame), callTranslators, + systemContractMethodRegistry, frame.isStatic()); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/signschedule/SignScheduleTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/signschedule/SignScheduleTranslator.java index 9ff82e104920..c994cc5fabc5 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/signschedule/SignScheduleTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hss/signschedule/SignScheduleTranslator.java @@ -26,7 +26,6 @@ import static java.util.Objects.requireNonNull; import com.esaulpaugh.headlong.abi.Address; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.base.ContractID; import com.hedera.hapi.node.base.Key; @@ -40,6 +39,9 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.DispatchForResponseCodeHssCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.HssCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; @@ -52,13 +54,19 @@ */ @Singleton public class SignScheduleTranslator extends AbstractCallTranslator { - public static final Function SIGN_SCHEDULE = new Function("signSchedule(address,bytes)", ReturnTypes.INT_64); - public static final Function SIGN_SCHEDULE_PROXY = new Function("signSchedule()", ReturnTypes.INT_64); - public static final Function AUTHORIZE_SCHEDULE = new Function("authorizeSchedule(address)", ReturnTypes.INT_64); + public static final SystemContractMethod SIGN_SCHEDULE = + SystemContractMethod.declare("signSchedule(address,bytes)", ReturnTypes.INT_64); + public static final SystemContractMethod SIGN_SCHEDULE_PROXY = + SystemContractMethod.declare("signSchedule()", ReturnTypes.INT_64).withVia(CallVia.PROXY); + public static final SystemContractMethod AUTHORIZE_SCHEDULE = + SystemContractMethod.declare("authorizeSchedule(address)", ReturnTypes.INT_64); @Inject - public SignScheduleTranslator() { + public SignScheduleTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HSS, systemContractMethodRegistry); + + registerMethods(SIGN_SCHEDULE, AUTHORIZE_SCHEDULE, SIGN_SCHEDULE_PROXY); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/HtsCallAttempt.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/HtsCallAttempt.java index b7557667ad4d..33817b36d9d1 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/HtsCallAttempt.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/HtsCallAttempt.java @@ -31,6 +31,9 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.CallTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.SystemContract; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.swirlds.config.api.Configuration; import edu.umd.cs.findbugs.annotations.NonNull; @@ -73,6 +76,7 @@ public HtsCallAttempt( @NonNull final VerificationStrategies verificationStrategies, @NonNull final SystemContractGasCalculator gasCalculator, @NonNull final List> callTranslators, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry, final boolean isStaticCall) { super( input, @@ -86,6 +90,7 @@ public HtsCallAttempt( gasCalculator, callTranslators, isStaticCall, + systemContractMethodRegistry, REDIRECT_FOR_TOKEN); if (isRedirect()) { this.redirectToken = linkedToken(redirectAddress); @@ -96,6 +101,11 @@ public HtsCallAttempt( (authorizingAddress != senderAddress) ? addressIdConverter.convertSender(authorizingAddress) : senderId; } + @Override + protected SystemContract systemContractKind() { + return SystemContractMethod.SystemContract.HTS; + } + @Override protected HtsCallAttempt self() { return this; diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/HtsCallFactory.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/HtsCallFactory.java index 6607ae0a5eb4..9fa3e858ce4e 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/HtsCallFactory.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/HtsCallFactory.java @@ -27,6 +27,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.CallFactory; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.CallTranslator; import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.CallType; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.List; import javax.inject.Inject; @@ -44,17 +45,20 @@ public class HtsCallFactory implements CallFactory { private final CallAddressChecks addressChecks; private final VerificationStrategies verificationStrategies; private final List> callTranslators; + private final SystemContractMethodRegistry systemContractMethodRegistry; @Inject public HtsCallFactory( @NonNull final SyntheticIds syntheticIds, @NonNull final CallAddressChecks addressChecks, @NonNull final VerificationStrategies verificationStrategies, - @NonNull @Named("HtsTranslators") final List> callTranslators) { + @NonNull @Named("HtsTranslators") final List> callTranslators, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { this.syntheticIds = requireNonNull(syntheticIds); this.addressChecks = requireNonNull(addressChecks); this.verificationStrategies = requireNonNull(verificationStrategies); this.callTranslators = requireNonNull(callTranslators); + this.systemContractMethodRegistry = requireNonNull(systemContractMethodRegistry); } /** @@ -93,6 +97,7 @@ public HtsCallFactory( verificationStrategies, systemContractGasCalculatorOf(frame), callTranslators, + systemContractMethodRegistry, frame.isStatic()); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/airdrops/TokenAirdropTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/airdrops/TokenAirdropTranslator.java index c0cb03b4afff..75915749193d 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/airdrops/TokenAirdropTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/airdrops/TokenAirdropTranslator.java @@ -18,7 +18,6 @@ import static java.util.Objects.requireNonNull; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -27,22 +26,31 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class TokenAirdropTranslator extends AbstractCallTranslator { - public static final Function TOKEN_AIRDROP = - new Function("airdropTokens((address,(address,int64,bool)[],(address,address,int64,bool)[])[])", "(int32)"); + public static final SystemContractMethod TOKEN_AIRDROP = SystemContractMethod.declare( + "airdropTokens((address,(address,int64,bool)[],(address,address,int64,bool)[])[])", "(int32)"); private final TokenAirdropDecoder decoder; @Inject - public TokenAirdropTranslator(@NonNull final TokenAirdropDecoder decoder) { + public TokenAirdropTranslator( + @NonNull final TokenAirdropDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); requireNonNull(decoder); this.decoder = decoder; + + registerMethods(TOKEN_AIRDROP); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/allowance/GetAllowanceTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/allowance/GetAllowanceTranslator.java index 7f70aef71567..1217b13edfd3 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/allowance/GetAllowanceTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/allowance/GetAllowanceTranslator.java @@ -17,11 +17,14 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.allowance; import com.esaulpaugh.headlong.abi.Address; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.utils.ConversionUtils; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.Arrays; @@ -37,19 +40,26 @@ public class GetAllowanceTranslator extends AbstractCallTranslator /** * Selector for balanceOf(address) method. */ - public static final Function BALANCE_OF = new Function("balanceOf(address)", ReturnTypes.INT); + public static final SystemContractMethod BALANCE_OF = + SystemContractMethod.declare("balanceOf(address)", ReturnTypes.INT).withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public BalanceOfTranslator() { + public BalanceOfTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(BALANCE_OF); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/burn/BurnTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/burn/BurnTranslator.java index 106d80a0c420..bd6f768be2dd 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/burn/BurnTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/burn/BurnTranslator.java @@ -19,7 +19,6 @@ import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes.INT64_INT64; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.burn.BurnDecoder.BURN_OUTPUT_FN; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -28,22 +27,31 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translator class for burn calls */ +@Singleton public class BurnTranslator extends AbstractCallTranslator { /** * Selector for burnToken(address,uint64,int64[]) method. */ - public static final Function BURN_TOKEN_V1 = new Function("burnToken(address,uint64,int64[])", INT64_INT64); + public static final SystemContractMethod BURN_TOKEN_V1 = SystemContractMethod.declare( + "burnToken(address,uint64,int64[])", INT64_INT64) + .withVariant(Variant.V1); /** * Selector for burnToken(address,int64,int64[]) method. */ - public static final Function BURN_TOKEN_V2 = new Function("burnToken(address,int64,int64[])", INT64_INT64); + public static final SystemContractMethod BURN_TOKEN_V2 = SystemContractMethod.declare( + "burnToken(address,int64,int64[])", INT64_INT64) + .withVariant(Variant.V2); BurnDecoder decoder; @@ -52,8 +60,13 @@ public class BurnTranslator extends AbstractCallTranslator { * @param decoder the decoder to use for decoding burn calls */ @Inject - public BurnTranslator(@NonNull final BurnDecoder decoder) { + public BurnTranslator( + @NonNull final BurnDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethods(BURN_TOKEN_V1, BURN_TOKEN_V2); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropDecoder.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropDecoder.java index c684ac60dc82..1f91e80eb861 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropDecoder.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropDecoder.java @@ -52,7 +52,7 @@ public TokenCancelAirdropDecoder() { } public TransactionBody decodeCancelAirdrop(@NonNull final HtsCallAttempt attempt) { - final var call = TokenCancelAirdropTranslator.CANCEL_AIRDROP.decodeCall(attempt.inputBytes()); + final var call = TokenCancelAirdropTranslator.CANCEL_AIRDROPS.decodeCall(attempt.inputBytes()); final var maxPendingAirdropsToCancel = attempt.configuration().getConfigData(TokensConfig.class).maxAllowedPendingAirdropsToCancel(); final var transferList = (Tuple[]) call.get(TRANSFER_LIST); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropTranslator.java index 3515e354776e..a1c574dfb2d6 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropTranslator.java @@ -18,7 +18,6 @@ import static java.util.Objects.requireNonNull; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -28,27 +27,43 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class TokenCancelAirdropTranslator extends AbstractCallTranslator { // Actual signature definition with struct name before flattening // cancelAirdrops(PendingAirdrop[]) - public static final Function CANCEL_AIRDROP = - new Function("cancelAirdrops((address,address,address,int64)[])", ReturnTypes.INT_64); - public static final Function HRC_CANCEL_AIRDROP_FT = new Function("cancelAirdropFT(address)", ReturnTypes.INT_64); - public static final Function HRC_CANCEL_AIRDROP_NFT = - new Function("cancelAirdropNFT(address,int64)", ReturnTypes.INT_64); + public static final SystemContractMethod CANCEL_AIRDROPS = + SystemContractMethod.declare("cancelAirdrops((address,address,address,int64)[])", ReturnTypes.INT_64); + public static final SystemContractMethod HRC_CANCEL_AIRDROP_FT = SystemContractMethod.declare( + "cancelAirdropFT(address)", ReturnTypes.INT_64) + .withVia(CallVia.PROXY) + .withVariant(Variant.FT); + public static final SystemContractMethod HRC_CANCEL_AIRDROP_NFT = SystemContractMethod.declare( + "cancelAirdropNFT(address,int64)", ReturnTypes.INT_64) + .withVia(CallVia.PROXY) + .withVariant(Variant.NFT); private final TokenCancelAirdropDecoder decoder; @Inject - public TokenCancelAirdropTranslator(@NonNull final TokenCancelAirdropDecoder decoder) { + public TokenCancelAirdropTranslator( + @NonNull final TokenCancelAirdropDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); requireNonNull(decoder); this.decoder = decoder; + + registerMethods(CANCEL_AIRDROPS, HRC_CANCEL_AIRDROP_FT, HRC_CANCEL_AIRDROP_NFT); } @Override @@ -57,7 +72,7 @@ public boolean matches(@NonNull final HtsCallAttempt attempt) { attempt.configuration().getConfigData(ContractsConfig.class).systemContractCancelAirdropsEnabled(); return attempt.isTokenRedirect() ? attempt.isSelectorIfConfigEnabled(cancelAirdropEnabled, HRC_CANCEL_AIRDROP_FT, HRC_CANCEL_AIRDROP_NFT) - : attempt.isSelectorIfConfigEnabled(cancelAirdropEnabled, CANCEL_AIRDROP); + : attempt.isSelectorIfConfigEnabled(cancelAirdropEnabled, CANCEL_AIRDROPS); } @Override @@ -67,7 +82,7 @@ public Call callFrom(@NonNull final HtsCallAttempt attempt) { } private TransactionBody bodyFor(@NonNull final HtsCallAttempt attempt) { - if (attempt.isSelector(CANCEL_AIRDROP)) { + if (attempt.isSelector(CANCEL_AIRDROPS)) { return decoder.decodeCancelAirdrop(attempt); } else if (attempt.isSelector(HRC_CANCEL_AIRDROP_FT)) { return decoder.decodeCancelAirdropFT(attempt); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropDecoder.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropDecoder.java index 8071cedf201c..08ca179755d2 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropDecoder.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropDecoder.java @@ -52,7 +52,7 @@ public TokenClaimAirdropDecoder() { } public TransactionBody decodeTokenClaimAirdrop(@NonNull final HtsCallAttempt attempt) { - final var call = TokenClaimAirdropTranslator.CLAIM_AIRDROP.decodeCall(attempt.inputBytes()); + final var call = TokenClaimAirdropTranslator.CLAIM_AIRDROPS.decodeCall(attempt.inputBytes()); final var maxPendingAirdropsToClaim = attempt.configuration().getConfigData(TokensConfig.class).maxAllowedPendingAirdropsToClaim(); final var transferList = (Tuple[]) call.get(TRANSFER_LIST); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropTranslator.java index 92ae61d762f5..876cd9e83eb3 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropTranslator.java @@ -16,7 +16,6 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.claimairdrops; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -26,23 +25,39 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class TokenClaimAirdropTranslator extends AbstractCallTranslator { - public static final Function CLAIM_AIRDROP = - new Function("claimAirdrops((address,address,address,int64)[])", ReturnTypes.INT_64); - public static final Function HRC_CLAIM_AIRDROP_FT = new Function("claimAirdropFT(address)", ReturnTypes.INT_64); - public static final Function HRC_CLAIM_AIRDROP_NFT = - new Function("claimAirdropNFT(address,int64)", ReturnTypes.INT_64); + public static final SystemContractMethod CLAIM_AIRDROPS = + SystemContractMethod.declare("claimAirdrops((address,address,address,int64)[])", ReturnTypes.INT_64); + public static final SystemContractMethod HRC_CLAIM_AIRDROP_FT = SystemContractMethod.declare( + "claimAirdropFT(address)", ReturnTypes.INT_64) + .withVia(CallVia.PROXY) + .withVariant(Variant.FT); + public static final SystemContractMethod HRC_CLAIM_AIRDROP_NFT = SystemContractMethod.declare( + "claimAirdropNFT(address,int64)", ReturnTypes.INT_64) + .withVia(CallVia.PROXY) + .withVariant(Variant.NFT); private final TokenClaimAirdropDecoder decoder; @Inject - public TokenClaimAirdropTranslator(@NonNull final TokenClaimAirdropDecoder decoder) { + public TokenClaimAirdropTranslator( + @NonNull final TokenClaimAirdropDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethods(CLAIM_AIRDROPS, HRC_CLAIM_AIRDROP_FT, HRC_CLAIM_AIRDROP_NFT); } @Override @@ -51,14 +66,14 @@ public boolean matches(@NonNull final HtsCallAttempt attempt) { attempt.configuration().getConfigData(ContractsConfig.class).systemContractClaimAirdropsEnabled(); return attempt.isTokenRedirect() ? attempt.isSelectorIfConfigEnabled(claimAirdropEnabled, HRC_CLAIM_AIRDROP_FT, HRC_CLAIM_AIRDROP_NFT) - : attempt.isSelectorIfConfigEnabled(claimAirdropEnabled, CLAIM_AIRDROP); + : attempt.isSelectorIfConfigEnabled(claimAirdropEnabled, CLAIM_AIRDROPS); } @Override public Call callFrom(@NonNull final HtsCallAttempt attempt) { return new DispatchForResponseCodeHtsCall( attempt, - attempt.isSelector(CLAIM_AIRDROP) ? bodyForClassic(attempt) : bodyForHRC(attempt), + attempt.isSelector(CLAIM_AIRDROPS) ? bodyForClassic(attempt) : bodyForHRC(attempt), TokenClaimAirdropTranslator::gasRequirement); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/create/CreateTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/create/CreateTranslator.java index 058906ddc1dd..854cc8270a14 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/create/CreateTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/create/CreateTranslator.java @@ -32,6 +32,8 @@ import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -39,11 +41,13 @@ import java.util.Map; import java.util.Set; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translates {@code createFungibleToken}, {@code createNonFungibleToken}, * {@code createFungibleTokenWithCustomFees} and {@code createNonFungibleTokenWithCustomFees} calls to the HTS system contract. */ +@Singleton public class CreateTranslator extends AbstractCallTranslator { /** Selector for createFungibleToken(HEDERA_TOKEN_V1,uint,uint) method. */ @@ -182,7 +186,30 @@ public class CreateTranslator extends AbstractCallTranslator { * @param decoder the decoder used to decode create calls */ @Inject - public CreateTranslator(final CreateDecoder decoder) { + public CreateTranslator( + final CreateDecoder decoder, @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethod("createFungibleToken_V1", CREATE_FUNGIBLE_TOKEN_V1); + registerMethod("createFungibleToken_V2", CREATE_FUNGIBLE_TOKEN_V2); + registerMethod("createFungibleToken_V3", CREATE_FUNGIBLE_TOKEN_V3); + registerMethod("createFungibleToken_WithMetadata", CREATE_FUNGIBLE_TOKEN_WITH_METADATA); + registerMethod("createFungibleTokenWithCustomFees_V1", CREATE_FUNGIBLE_WITH_CUSTOM_FEES_V1); + registerMethod("createFungibleTokenWithCustomFees_V2", CREATE_FUNGIBLE_WITH_CUSTOM_FEES_V2); + registerMethod("createFungibleTokenWithCustomFees_V3", CREATE_FUNGIBLE_WITH_CUSTOM_FEES_V3); + registerMethod( + "createFungibleTokenWithCustomFees_WithMetadata", CREATE_FUNGIBLE_TOKEN_WITH_METADATA_AND_CUSTOM_FEES); + registerMethod("createNonFungibleToken_V1", CREATE_NON_FUNGIBLE_TOKEN_V1); + registerMethod("createNonFungibleToken_V2", CREATE_NON_FUNGIBLE_TOKEN_V2); + registerMethod("createNonFungibleToken_V3", CREATE_NON_FUNGIBLE_TOKEN_V3); + registerMethod("createNonFungibleToken_WithMetadata", CREATE_NON_FUNGIBLE_TOKEN_WITH_METADATA); + registerMethod("createNonFungibleTokenWithCustomFees_V1", CREATE_NON_FUNGIBLE_TOKEN_WITH_CUSTOM_FEES_V1); + registerMethod("createNonFungibleTokenWithCustomFees_V2", CREATE_NON_FUNGIBLE_TOKEN_WITH_CUSTOM_FEES_V2); + registerMethod("createNonFungibleTokenWithCustomFees_V3", CREATE_NON_FUNGIBLE_TOKEN_WITH_CUSTOM_FEES_V3); + registerMethod( + "createNonFungibleTokenWithCustomFees_WithMetadata", + CREATE_NON_FUNGIBLE_TOKEN_WITH_METADATA_AND_CUSTOM_FEES); + createSelectorsMap.put(CREATE_FUNGIBLE_TOKEN_V1, decoder::decodeCreateFungibleTokenV1); createSelectorsMap.put(CREATE_FUNGIBLE_TOKEN_V2, decoder::decodeCreateFungibleTokenV2); createSelectorsMap.put(CREATE_FUNGIBLE_TOKEN_V3, decoder::decodeCreateFungibleTokenV3); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/customfees/TokenCustomFeesTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/customfees/TokenCustomFeesTranslator.java index 0b81af6212e9..52b70eebb6b4 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/customfees/TokenCustomFeesTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/customfees/TokenCustomFeesTranslator.java @@ -18,22 +18,30 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class TokenCustomFeesTranslator extends AbstractCallTranslator { - public static final Function TOKEN_CUSTOM_FEES = - new Function("getTokenCustomFees(address)", ReturnTypes.RESPONSE_CODE_CUSTOM_FEES); + public static final SystemContractMethod TOKEN_CUSTOM_FEES = SystemContractMethod.declare( + "getTokenCustomFees(address)", ReturnTypes.RESPONSE_CODE_CUSTOM_FEES) + .withModifier(Modifier.VIEW); @Inject - public TokenCustomFeesTranslator() { + public TokenCustomFeesTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(TOKEN_CUSTOM_FEES); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/decimals/DecimalsTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/decimals/DecimalsTranslator.java index cf8f65fe0a3d..5696f19d9026 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/decimals/DecimalsTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/decimals/DecimalsTranslator.java @@ -16,11 +16,13 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.decimals; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -31,14 +33,18 @@ @Singleton public class DecimalsTranslator extends AbstractCallTranslator { /** Selector for updateTokenKeys(address, TOKEN_KEY[]) method. */ - public static final Function DECIMALS = new Function("decimals()", ReturnTypes.BYTE); + public static final SystemContractMethod DECIMALS = + SystemContractMethod.declare("decimals()", ReturnTypes.BYTE).withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public DecimalsTranslator() { + public DecimalsTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(DECIMALS); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/defaultfreezestatus/DefaultFreezeStatusTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/defaultfreezestatus/DefaultFreezeStatusTranslator.java index cc1d75cca579..06ddc8e579c8 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/defaultfreezestatus/DefaultFreezeStatusTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/defaultfreezestatus/DefaultFreezeStatusTranslator.java @@ -18,28 +18,36 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translates {@code getTokenDefaultFreezeStatus()} calls to the HTS system contract. */ +@Singleton public class DefaultFreezeStatusTranslator extends AbstractCallTranslator { /** Selector for getTokenDefaultFreezeStatus(address) method. */ - public static final Function DEFAULT_FREEZE_STATUS = - new Function("getTokenDefaultFreezeStatus(address)", ReturnTypes.RESPONSE_CODE_BOOL); + public static final SystemContractMethod DEFAULT_FREEZE_STATUS = SystemContractMethod.declare( + "getTokenDefaultFreezeStatus(address)", ReturnTypes.RESPONSE_CODE_BOOL) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public DefaultFreezeStatusTranslator() { + public DefaultFreezeStatusTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(DEFAULT_FREEZE_STATUS); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/defaultkycstatus/DefaultKycStatusTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/defaultkycstatus/DefaultKycStatusTranslator.java index 58a51c41a9af..4774f4c1aede 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/defaultkycstatus/DefaultKycStatusTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/defaultkycstatus/DefaultKycStatusTranslator.java @@ -18,28 +18,36 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translates {@code getTokenDefaultKycStatus()} calls to the HTS system contract. */ +@Singleton public class DefaultKycStatusTranslator extends AbstractCallTranslator { /** Selector for getTokenDefaultKycStatus(address) method. */ - public static final Function DEFAULT_KYC_STATUS = - new Function("getTokenDefaultKycStatus(address)", ReturnTypes.RESPONSE_CODE_BOOL); + public static final SystemContractMethod DEFAULT_KYC_STATUS = SystemContractMethod.declare( + "getTokenDefaultKycStatus(address)", ReturnTypes.RESPONSE_CODE_BOOL) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public DefaultKycStatusTranslator() { + public DefaultKycStatusTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(DEFAULT_KYC_STATUS); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/delete/DeleteTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/delete/DeleteTranslator.java index cd764819e3a3..13b6c0399b88 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/delete/DeleteTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/delete/DeleteTranslator.java @@ -16,7 +16,6 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.delete; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.token.TokenDeleteTransactionBody; import com.hedera.hapi.node.transaction.TransactionBody; @@ -27,24 +26,32 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.service.contract.impl.utils.ConversionUtils; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translates {@code delete} calls to the HTS system contract. */ +@Singleton public class DeleteTranslator extends AbstractCallTranslator { /** Selector for deleteToken(address) method. */ - public static final Function DELETE_TOKEN = new Function("deleteToken(address)", ReturnTypes.INT); + public static final SystemContractMethod DELETE_TOKEN = + SystemContractMethod.declare("deleteToken(address)", ReturnTypes.INT); /** * Default constructor to delete. */ @Inject - public DeleteTranslator() { + public DeleteTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(DELETE_TOKEN); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/freeze/FreezeUnfreezeTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/freeze/FreezeUnfreezeTranslator.java index de0989201d0e..46b8f51fb55c 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/freeze/FreezeUnfreezeTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/freeze/FreezeUnfreezeTranslator.java @@ -18,7 +18,6 @@ import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall.FailureCustomizer.NOOP_CUSTOMIZER; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -28,6 +27,8 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.Arrays; @@ -40,9 +41,11 @@ @Singleton public class FreezeUnfreezeTranslator extends AbstractCallTranslator { /** Selector for freezeToken(address,address) method. */ - public static final Function FREEZE = new Function("freezeToken(address,address)", ReturnTypes.INT_64); + public static final SystemContractMethod FREEZE = + SystemContractMethod.declare("freezeToken(address,address)", ReturnTypes.INT_64); /** Selector for unfreezeToken(address,address) method. */ - public static final Function UNFREEZE = new Function("unfreezeToken(address,address)", ReturnTypes.INT_64); + public static final SystemContractMethod UNFREEZE = + SystemContractMethod.declare("unfreezeToken(address,address)", ReturnTypes.INT_64); private final FreezeUnfreezeDecoder decoder; @@ -50,8 +53,13 @@ public class FreezeUnfreezeTranslator extends AbstractCallTranslator { /** Selector for getFungibleTokenInfo(address) method. */ - public static final Function FUNGIBLE_TOKEN_INFO = - new Function("getFungibleTokenInfo(address)", ReturnTypes.RESPONSE_CODE_FUNGIBLE_TOKEN_INFO); + public static final SystemContractMethod FUNGIBLE_TOKEN_INFO = SystemContractMethod.declare( + "getFungibleTokenInfo(address)", ReturnTypes.RESPONSE_CODE_FUNGIBLE_TOKEN_INFO) + .withVariant(Variant.V1); /** Selector for getFungibleTokenInfoV2(address) method. */ - public static final Function FUNGIBLE_TOKEN_INFO_V2 = - new Function("getFungibleTokenInfoV2(address)", ReturnTypes.RESPONSE_CODE_FUNGIBLE_TOKEN_INFO_V2); + public static final SystemContractMethod FUNGIBLE_TOKEN_INFO_V2 = SystemContractMethod.declare( + "getFungibleTokenInfoV2(address)", ReturnTypes.RESPONSE_CODE_FUNGIBLE_TOKEN_INFO_V2) + .withVariant(Variant.V2); /** * Default constructor for injection. */ @Inject - public FungibleTokenInfoTranslator() { + public FungibleTokenInfoTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(FUNGIBLE_TOKEN_INFO, FUNGIBLE_TOKEN_INFO_V2); } /** @@ -64,8 +73,8 @@ public boolean matches(@NonNull final HtsCallAttempt attempt) { @Override public Call callFrom(@NonNull final HtsCallAttempt attempt) { requireNonNull(attempt); - final var function = attempt.isSelector(FUNGIBLE_TOKEN_INFO) ? FUNGIBLE_TOKEN_INFO : FUNGIBLE_TOKEN_INFO_V2; - final var args = function.decodeCall(attempt.input().toArrayUnsafe()); + final var method = attempt.isSelector(FUNGIBLE_TOKEN_INFO) ? FUNGIBLE_TOKEN_INFO : FUNGIBLE_TOKEN_INFO_V2; + final var args = method.decodeCall(attempt.input().toArrayUnsafe()); final var token = attempt.linkedToken(fromHeadlongAddress(args.get(0))); return new FungibleTokenInfoCall( attempt.systemContractGasCalculator(), @@ -73,6 +82,6 @@ public Call callFrom(@NonNull final HtsCallAttempt attempt) { attempt.isStaticCall(), token, attempt.configuration(), - function); + method.function()); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/getapproved/GetApprovedTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/getapproved/GetApprovedTranslator.java index 0b6bb0eee6cf..127522129fdd 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/getapproved/GetApprovedTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/getapproved/GetApprovedTranslator.java @@ -19,10 +19,14 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.asExactLongValueOrZero; import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Category; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -34,16 +38,25 @@ public class GetApprovedTranslator extends AbstractCallTranslator { /** Selector for getApproved(address,uint256) method. */ - public static final Function HAPI_GET_APPROVED = new Function("getApproved(address,uint256)", "(int32,address)"); + public static final SystemContractMethod HAPI_GET_APPROVED = SystemContractMethod.declare( + "getApproved(address,uint256)", "(int32,address)") + .withModifier(Modifier.VIEW); /** Selector for getApproved(uint256) method. */ - public static final Function ERC_GET_APPROVED = new Function("getApproved(uint256)", ReturnTypes.ADDRESS); + public static final SystemContractMethod ERC_GET_APPROVED = SystemContractMethod.declare( + "getApproved(uint256)", ReturnTypes.ADDRESS) + .withVia(CallVia.PROXY) + .withModifier(Modifier.VIEW) + .withCategory(Category.ERC721); /** * Default constructor for injection. */ @Inject - public GetApprovedTranslator() { + public GetApprovedTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(HAPI_GET_APPROVED, ERC_GET_APPROVED); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/grantapproval/GrantApprovalTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/grantapproval/GrantApprovalTranslator.java index 8892d642a519..26104a0de609 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/grantapproval/GrantApprovalTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/grantapproval/GrantApprovalTranslator.java @@ -19,7 +19,6 @@ import static java.util.Objects.requireNonNull; import com.esaulpaugh.headlong.abi.Address; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.base.TokenType; import com.hedera.hapi.node.transaction.TransactionBody; @@ -30,6 +29,11 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Category; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.service.contract.impl.utils.ConversionUtils; import edu.umd.cs.findbugs.annotations.NonNull; @@ -44,14 +48,25 @@ public class GrantApprovalTranslator extends AbstractCallTranslator { /** Selector for approve(address,uint256) method. */ - public static final Function ERC_GRANT_APPROVAL = new Function("approve(address,uint256)", ReturnTypes.BOOL); + public static final SystemContractMethod ERC_GRANT_APPROVAL = SystemContractMethod.declare( + "approve(address,uint256)", ReturnTypes.BOOL) + .withVia(CallVia.PROXY) + .withVariant(Variant.FT) + .withCategory(Category.ERC20); /** Selector for approve(address,uint256) method. */ - public static final Function ERC_GRANT_APPROVAL_NFT = new Function("approve(address,uint256)"); + public static final SystemContractMethod ERC_GRANT_APPROVAL_NFT = SystemContractMethod.declare( + "approve(address,uint256)") + .withVia(CallVia.PROXY) + .withVariant(Variant.NFT) + .withCategory(Category.ERC721); /** Selector for approve(address,address,uint256) method. */ - public static final Function GRANT_APPROVAL = new Function("approve(address,address,uint256)", "(int32,bool)"); + public static final SystemContractMethod GRANT_APPROVAL = SystemContractMethod.declare( + "approve(address,address,uint256)", "(int32,bool)") + .withVariant(Variant.FT); /** Selector for approveNFT(address,address,uint256) method. */ - public static final Function GRANT_APPROVAL_NFT = - new Function("approveNFT(address,address,uint256)", ReturnTypes.INT_64); + public static final SystemContractMethod GRANT_APPROVAL_NFT = SystemContractMethod.declare( + "approveNFT(address,address,uint256)", ReturnTypes.INT_64) + .withVariant(Variant.NFT); private final GrantApprovalDecoder decoder; @@ -60,8 +75,13 @@ public class GrantApprovalTranslator extends AbstractCallTranslator { /** Selector for isApprovedForAll(address,address,address) method. */ - public static final Function CLASSIC_IS_APPROVED_FOR_ALL = - new Function("isApprovedForAll(address,address,address)", "(int64,bool)"); + public static final SystemContractMethod CLASSIC_IS_APPROVED_FOR_ALL = + SystemContractMethod.declare("isApprovedForAll(address,address,address)", "(int64,bool)"); /** Selector for isApprovedForAll(address,address) method. */ - public static final Function ERC_IS_APPROVED_FOR_ALL = new Function("isApprovedForAll(address,address)", "(bool)"); + public static final SystemContractMethod ERC_IS_APPROVED_FOR_ALL = SystemContractMethod.declare( + "isApprovedForAll(address,address)", "(bool)") + .withVia(CallVia.PROXY); /** * Default constructor for injection. */ @Inject - public IsApprovedForAllTranslator() { + public IsApprovedForAllTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(CLASSIC_IS_APPROVED_FOR_ALL, ERC_IS_APPROVED_FOR_ALL); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/isassociated/IsAssociatedTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/isassociated/IsAssociatedTranslator.java index 01b61a4449a9..2653cb3c79ce 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/isassociated/IsAssociatedTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/isassociated/IsAssociatedTranslator.java @@ -18,11 +18,13 @@ import static java.util.Objects.requireNonNull; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -30,14 +32,18 @@ @Singleton public class IsAssociatedTranslator extends AbstractCallTranslator { /** Selector for isAssociated() method. */ - public static final Function IS_ASSOCIATED = new Function("isAssociated()", ReturnTypes.BOOL); + public static final SystemContractMethod IS_ASSOCIATED = + SystemContractMethod.declare("isAssociated()", ReturnTypes.BOOL).withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public IsAssociatedTranslator() { + public IsAssociatedTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(IS_ASSOCIATED); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/isfrozen/IsFrozenTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/isfrozen/IsFrozenTranslator.java index e6e887e20435..f3c0f7efa8b7 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/isfrozen/IsFrozenTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/isfrozen/IsFrozenTranslator.java @@ -18,24 +18,33 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class IsFrozenTranslator extends AbstractCallTranslator { /** Selector for isFrozen(address,address) method. */ - public static final Function IS_FROZEN = new Function("isFrozen(address,address)", ReturnTypes.RESPONSE_CODE_BOOL); + public static final SystemContractMethod IS_FROZEN = SystemContractMethod.declare( + "isFrozen(address,address)", ReturnTypes.RESPONSE_CODE_BOOL) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public IsFrozenTranslator() { + public IsFrozenTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(IS_FROZEN); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/iskyc/IsKycTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/iskyc/IsKycTranslator.java index 565dd9ede328..f598cad6b143 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/iskyc/IsKycTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/iskyc/IsKycTranslator.java @@ -18,24 +18,33 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class IsKycTranslator extends AbstractCallTranslator { /** Selector for isKyc(address,address) method. */ - public static final Function IS_KYC = new Function("isKyc(address,address)", ReturnTypes.RESPONSE_CODE_BOOL); + public static final SystemContractMethod IS_KYC = SystemContractMethod.declare( + "isKyc(address,address)", ReturnTypes.RESPONSE_CODE_BOOL) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public IsKycTranslator() { + public IsKycTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(IS_KYC); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenTranslator.java index e91401ee4e48..461ea1ceb5f8 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenTranslator.java @@ -18,24 +18,33 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class IsTokenTranslator extends AbstractCallTranslator { /** Selector for isToken(address) method. */ - public static final Function IS_TOKEN = new Function("isToken(address)", ReturnTypes.RESPONSE_CODE_BOOL); + public static final SystemContractMethod IS_TOKEN = SystemContractMethod.declare( + "isToken(address)", ReturnTypes.RESPONSE_CODE_BOOL) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public IsTokenTranslator() { + public IsTokenTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(IS_TOKEN); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/mint/MintTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/mint/MintTranslator.java index 64a127958b57..b35ffcfe55b8 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/mint/MintTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/mint/MintTranslator.java @@ -18,7 +18,6 @@ import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.mint.MintDecoder.MINT_OUTPUT_FN; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -27,6 +26,9 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; @@ -38,9 +40,13 @@ @Singleton public class MintTranslator extends AbstractCallTranslator { /** Selector for mintToken(address,uint64,bytes[]) method. */ - public static final Function MINT = new Function("mintToken(address,uint64,bytes[])", "(int64,int64,int64[])"); + public static final SystemContractMethod MINT = SystemContractMethod.declare( + "mintToken(address,uint64,bytes[])", "(int64,int64,int64[])") + .withVariant(Variant.V1); /** Selector for mintToken(address,int64,bytes[]) method. */ - public static final Function MINT_V2 = new Function("mintToken(address,int64,bytes[])", "(int64,int64,int64[])"); + public static final SystemContractMethod MINT_V2 = SystemContractMethod.declare( + "mintToken(address,int64,bytes[])", "(int64,int64,int64[])") + .withVariant(Variant.V2); private final MintDecoder decoder; @@ -48,8 +54,13 @@ public class MintTranslator extends AbstractCallTranslator { * @param decoder the decoder to use for mint calls */ @Inject - public MintTranslator(@NonNull final MintDecoder decoder) { + public MintTranslator( + @NonNull final MintDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethods(MINT, MINT_V2); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/name/NameTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/name/NameTranslator.java index fd153112ca0c..0d71bce122b0 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/name/NameTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/name/NameTranslator.java @@ -16,10 +16,12 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.name; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -30,14 +32,18 @@ @Singleton public class NameTranslator extends AbstractCallTranslator { /** Selector for name() method. */ - public static final Function NAME = new Function("name()", ReturnTypes.STRING); + public static final SystemContractMethod NAME = + SystemContractMethod.declare("name()", ReturnTypes.STRING).withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public NameTranslator() { + public NameTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(NAME); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCall.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCall.java index e24bdb55c558..d8b240df538b 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCall.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCall.java @@ -98,7 +98,7 @@ public NftTokenInfoCall( final var ledgerConfig = configuration.getConfigData(LedgerConfig.class); final var ledgerId = Bytes.wrap(ledgerConfig.id().toByteArray()).toString(); - return function.getName().equals(NON_FUNGIBLE_TOKEN_INFO.getName()) + return function.getName().equals(NON_FUNGIBLE_TOKEN_INFO.methodName()) ? successResult( NON_FUNGIBLE_TOKEN_INFO .getOutputs() diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoTranslator.java index b6468797c7f3..ad12b6005748 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoTranslator.java @@ -19,31 +19,40 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; import static java.util.Objects.requireNonNull; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class NftTokenInfoTranslator extends AbstractCallTranslator { /** Selector for getNonFungibleTokenInfo(address,int64) method. */ - public static final Function NON_FUNGIBLE_TOKEN_INFO = - new Function("getNonFungibleTokenInfo(address,int64)", ReturnTypes.RESPONSE_CODE_NON_FUNGIBLE_TOKEN_INFO); + public static final SystemContractMethod NON_FUNGIBLE_TOKEN_INFO = SystemContractMethod.declare( + "getNonFungibleTokenInfo(address,int64)", ReturnTypes.RESPONSE_CODE_NON_FUNGIBLE_TOKEN_INFO) + .withVariant(Variant.V1); /** Selector for getNonFungibleTokenInfoV2(address,int64) method. */ - public static final Function NON_FUNGIBLE_TOKEN_INFO_V2 = new Function( - "getNonFungibleTokenInfoV2(address,int64)", ReturnTypes.RESPONSE_CODE_NON_FUNGIBLE_TOKEN_INFO_V2); + public static final SystemContractMethod NON_FUNGIBLE_TOKEN_INFO_V2 = SystemContractMethod.declare( + "getNonFungibleTokenInfoV2(address,int64)", ReturnTypes.RESPONSE_CODE_NON_FUNGIBLE_TOKEN_INFO_V2) + .withVariant(Variant.V2); /** * Default constructor for injection. */ @Inject - public NftTokenInfoTranslator() { + public NftTokenInfoTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(NON_FUNGIBLE_TOKEN_INFO, NON_FUNGIBLE_TOKEN_INFO_V2); } /** @@ -64,9 +73,9 @@ public boolean matches(@NonNull final HtsCallAttempt attempt) { @Override public Call callFrom(@NonNull final HtsCallAttempt attempt) { requireNonNull(attempt); - final var function = + final var method = attempt.isSelector(NON_FUNGIBLE_TOKEN_INFO) ? NON_FUNGIBLE_TOKEN_INFO : NON_FUNGIBLE_TOKEN_INFO_V2; - final var args = function.decodeCall(attempt.input().toArrayUnsafe()); + final var args = method.decodeCall(attempt.input().toArrayUnsafe()); final var token = attempt.linkedToken(fromHeadlongAddress(args.get(0))); return new NftTokenInfoCall( attempt.systemContractGasCalculator(), @@ -75,6 +84,6 @@ public Call callFrom(@NonNull final HtsCallAttempt attempt) { token, args.get(1), attempt.configuration(), - function); + method.function()); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/ownerof/OwnerOfTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/ownerof/OwnerOfTranslator.java index 77e8cdd12f85..8c17f40a4993 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/ownerof/OwnerOfTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/ownerof/OwnerOfTranslator.java @@ -18,10 +18,12 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.asExactLongValueOrZero; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -32,14 +34,19 @@ @Singleton public class OwnerOfTranslator extends AbstractCallTranslator { /** Selector for ownerOf(uint256) method. */ - public static final Function OWNER_OF = new Function("ownerOf(uint256)", ReturnTypes.ADDRESS); + public static final SystemContractMethod OWNER_OF = SystemContractMethod.declare( + "ownerOf(uint256)", ReturnTypes.ADDRESS) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public OwnerOfTranslator() { + public OwnerOfTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(OWNER_OF); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/pauses/PausesTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/pauses/PausesTranslator.java index 165e4b39a359..70826afa64fc 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/pauses/PausesTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/pauses/PausesTranslator.java @@ -16,7 +16,6 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.pauses; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -26,6 +25,8 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; @@ -38,9 +39,11 @@ @Singleton public class PausesTranslator extends AbstractCallTranslator { /** Selector for pauseToken(address) method. */ - public static final Function PAUSE = new Function("pauseToken(address)", ReturnTypes.INT_64); + public static final SystemContractMethod PAUSE = + SystemContractMethod.declare("pauseToken(address)", ReturnTypes.INT_64); /** Selector for unpauseToken(address) method. */ - public static final Function UNPAUSE = new Function("unpauseToken(address)", ReturnTypes.INT_64); + public static final SystemContractMethod UNPAUSE = + SystemContractMethod.declare("unpauseToken(address)", ReturnTypes.INT_64); private final PausesDecoder decoder; @@ -48,8 +51,13 @@ public class PausesTranslator extends AbstractCallTranslator { * @param decoder the decoder to use for pause calls */ @Inject - public PausesTranslator(@NonNull final PausesDecoder decoder) { + public PausesTranslator( + @NonNull final PausesDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethods(PAUSE, UNPAUSE); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/rejecttokens/RejectTokensTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/rejecttokens/RejectTokensTranslator.java index b21bdb77d5b4..c698795ca736 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/rejecttokens/RejectTokensTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/rejecttokens/RejectTokensTranslator.java @@ -27,6 +27,10 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; @@ -34,22 +38,36 @@ import java.util.Map; import java.util.Map.Entry; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class RejectTokensTranslator extends AbstractCallTranslator { - public static final Function TOKEN_REJECT = - new Function("rejectTokens(address,address[],(address,int64)[])", ReturnTypes.INT_64); - public static final Function HRC_TOKEN_REJECT_FT = new Function("rejectTokenFT()", ReturnTypes.INT_64); - public static final Function HRC_TOKEN_REJECT_NFT = new Function("rejectTokenNFTs(int64[])", ReturnTypes.INT_64); + public static final SystemContractMethod TOKEN_REJECT = + SystemContractMethod.declare("rejectTokens(address,address[],(address,int64)[])", ReturnTypes.INT_64); + public static final SystemContractMethod HRC_TOKEN_REJECT_FT = SystemContractMethod.declare( + "rejectTokenFT()", ReturnTypes.INT_64) + .withVia(CallVia.PROXY) + .withVariant(Variant.FT); + public static final SystemContractMethod HRC_TOKEN_REJECT_NFT = SystemContractMethod.declare( + "rejectTokenNFTs(int64[])", ReturnTypes.INT_64) + .withVia(CallVia.PROXY) + .withVariant(Variant.NFT); private final RejectTokensDecoder decoder; private final Map gasCalculators = new HashMap<>(); @Inject - public RejectTokensTranslator(@NonNull final RejectTokensDecoder decoder) { + public RejectTokensTranslator( + @NonNull final RejectTokensDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; - gasCalculators.put(TOKEN_REJECT, RejectTokensTranslator::gasRequirement); - gasCalculators.put(HRC_TOKEN_REJECT_FT, RejectTokensTranslator::gasRequirementHRCFungible); - gasCalculators.put(HRC_TOKEN_REJECT_NFT, RejectTokensTranslator::gasRequirementHRCNft); + + registerMethods(TOKEN_REJECT, HRC_TOKEN_REJECT_FT, HRC_TOKEN_REJECT_NFT); + + gasCalculators.put(TOKEN_REJECT.function(), RejectTokensTranslator::gasRequirement); + gasCalculators.put(HRC_TOKEN_REJECT_FT.function(), RejectTokensTranslator::gasRequirementHRCFungible); + gasCalculators.put(HRC_TOKEN_REJECT_NFT.function(), RejectTokensTranslator::gasRequirementHRCNft); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/setapproval/SetApprovalForAllTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/setapproval/SetApprovalForAllTranslator.java index 96e3fbb8ff7e..3aebdfd8170a 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/setapproval/SetApprovalForAllTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/setapproval/SetApprovalForAllTranslator.java @@ -16,7 +16,6 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.setapproval; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -26,22 +25,30 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Category; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translates setApprovalForAll (including ERC) call to the HTS system contract. There are no special cases for these * calls, so the returned {@link Call} is simply an instance of {@link DispatchForResponseCodeHtsCall}. */ +@Singleton public class SetApprovalForAllTranslator extends AbstractCallTranslator { /** Selector for setApprovalForAll(address,address,bool) method. */ - public static final Function SET_APPROVAL_FOR_ALL = - new Function("setApprovalForAll(address,address,bool)", ReturnTypes.INT); + public static final SystemContractMethod SET_APPROVAL_FOR_ALL = + SystemContractMethod.declare("setApprovalForAll(address,address,bool)", ReturnTypes.INT); /** Selector for setApprovalForAll(address,bool) method. */ - public static final Function ERC721_SET_APPROVAL_FOR_ALL = - new Function("setApprovalForAll(address,bool)", ReturnTypes.INT); + public static final SystemContractMethod ERC721_SET_APPROVAL_FOR_ALL = SystemContractMethod.declare( + "setApprovalForAll(address,bool)", ReturnTypes.INT) + .withVia(CallVia.PROXY) + .withCategory(Category.ERC721); private final SetApprovalForAllDecoder decoder; @@ -49,8 +56,13 @@ public class SetApprovalForAllTranslator extends AbstractCallTranslator { /** Selector for symbol() method. */ - public static final Function SYMBOL = new Function("symbol()", ReturnTypes.STRING); + public static final SystemContractMethod SYMBOL = SystemContractMethod.declare("symbol()", ReturnTypes.STRING) + .withModifier(Modifier.VIEW) + .withCategories(Category.ERC20, Category.ERC721); /** * Default constructor for injection. */ @Inject - public SymbolTranslator() { + public SymbolTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(SYMBOL); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenexpiry/TokenExpiryTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenexpiry/TokenExpiryTranslator.java index f92d1a31c4fc..0af0805c2ee5 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenexpiry/TokenExpiryTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenexpiry/TokenExpiryTranslator.java @@ -18,28 +18,36 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translates {@code getTokenExpiry()} calls to the HTS system contract. */ +@Singleton public class TokenExpiryTranslator extends AbstractCallTranslator { /** Selector for getTokenExpiryInfo(address) method. */ - public static final Function TOKEN_EXPIRY = - new Function("getTokenExpiryInfo(address)", ReturnTypes.RESPONSE_CODE_EXPIRY); + public static final SystemContractMethod TOKEN_EXPIRY = SystemContractMethod.declare( + "getTokenExpiryInfo(address)", ReturnTypes.RESPONSE_CODE_EXPIRY) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public TokenExpiryTranslator() { + public TokenExpiryTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(TOKEN_EXPIRY); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokeninfo/TokenInfoCall.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokeninfo/TokenInfoCall.java index 7a5f607ec273..4c82839e7cb9 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokeninfo/TokenInfoCall.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokeninfo/TokenInfoCall.java @@ -83,7 +83,7 @@ public TokenInfoCall( return revertResult(status, gasRequirement); } - return function.getName().equals(TOKEN_INFO.getName()) + return function.getName().equals(TOKEN_INFO.methodName()) ? successResult( TOKEN_INFO .getOutputs() diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokeninfo/TokenInfoTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokeninfo/TokenInfoTranslator.java index d65f7a9d0bc5..de47b93fe787 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokeninfo/TokenInfoTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokeninfo/TokenInfoTranslator.java @@ -19,32 +19,44 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; import static java.util.Objects.requireNonNull; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translates {@code getTokenInfo()} calls to the HTS system contract. */ +@Singleton public class TokenInfoTranslator extends AbstractCallTranslator { /** Selector for getTokenInfo(address) method. */ - public static final Function TOKEN_INFO = - new Function("getTokenInfo(address)", ReturnTypes.RESPONSE_CODE_TOKEN_INFO); + public static final SystemContractMethod TOKEN_INFO = SystemContractMethod.declare( + "getTokenInfo(address)", ReturnTypes.RESPONSE_CODE_TOKEN_INFO) + .withModifier(Modifier.VIEW) + .withVariant(Variant.V1); /** Selector for getTokenInfoV2(address) method. */ - public static final Function TOKEN_INFO_V2 = - new Function("getTokenInfoV2(address)", ReturnTypes.RESPONSE_CODE_TOKEN_INFO_V2); + public static final SystemContractMethod TOKEN_INFO_V2 = SystemContractMethod.declare( + "getTokenInfoV2(address)", ReturnTypes.RESPONSE_CODE_TOKEN_INFO_V2) + .withModifier(Modifier.VIEW) + .withVariant(Variant.V2); /** * Default constructor for injection. */ @Inject - public TokenInfoTranslator() { + public TokenInfoTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(TOKEN_INFO, TOKEN_INFO_V2); } /** @@ -64,8 +76,8 @@ public boolean matches(@NonNull final HtsCallAttempt attempt) { @Override public Call callFrom(@NonNull final HtsCallAttempt attempt) { requireNonNull(attempt); - final var function = attempt.isSelector(TOKEN_INFO) ? TOKEN_INFO : TOKEN_INFO_V2; - final var args = function.decodeCall(attempt.input().toArrayUnsafe()); + final var method = attempt.isSelector(TOKEN_INFO) ? TOKEN_INFO : TOKEN_INFO_V2; + final var args = method.decodeCall(attempt.input().toArrayUnsafe()); final var token = attempt.linkedToken(fromHeadlongAddress(args.get(0))); return new TokenInfoCall( attempt.systemContractGasCalculator(), @@ -73,6 +85,6 @@ public Call callFrom(@NonNull final HtsCallAttempt attempt) { attempt.isStaticCall(), token, attempt.configuration(), - function); + method.function()); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenkey/TokenKeyTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenkey/TokenKeyTranslator.java index 0565b69dd5dc..76609e2e8d0a 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenkey/TokenKeyTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenkey/TokenKeyTranslator.java @@ -18,7 +18,6 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.Key; import com.hedera.hapi.node.state.token.Token; import com.hedera.node.app.hapi.utils.InvalidTransactionException; @@ -26,25 +25,34 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import java.math.BigInteger; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translates {@code getTokenKey()} calls to the HTS system contract. */ +@Singleton public class TokenKeyTranslator extends AbstractCallTranslator { /** Selector for getTokenKey(address,uint) method. */ - public static final Function TOKEN_KEY = - new Function("getTokenKey(address,uint)", ReturnTypes.RESPONSE_CODE_TOKEN_KEY); + public static final SystemContractMethod TOKEN_KEY = SystemContractMethod.declare( + "getTokenKey(address,uint)", ReturnTypes.RESPONSE_CODE_TOKEN_KEY) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public TokenKeyTranslator() { + public TokenKeyTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(TOKEN_KEY); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeTranslator.java index fed5aa7aef00..7b5fb10ff74d 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeTranslator.java @@ -18,27 +18,36 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.fromHeadlongAddress; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; /** * Translates {@code getTokenType()} calls to the HTS system contract. */ +@Singleton public class TokenTypeTranslator extends AbstractCallTranslator { /** Selector for getTokenType(address) method. */ - public static final Function TOKEN_TYPE = new Function("getTokenType(address)", ReturnTypes.RESPONSE_CODE_INT32); + public static final SystemContractMethod TOKEN_TYPE = SystemContractMethod.declare( + "getTokenType(address)", ReturnTypes.RESPONSE_CODE_INT32) + .withModifier(Modifier.VIEW); /** * Default constructor for injection. */ @Inject - public TokenTypeTranslator() { + public TokenTypeTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(TOKEN_TYPE); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenuri/TokenUriTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenuri/TokenUriTranslator.java index 425753d7bbb2..6c928b664d4e 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenuri/TokenUriTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokenuri/TokenUriTranslator.java @@ -18,11 +18,14 @@ import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.asExactLongValueOrZero; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Category; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -33,14 +36,20 @@ @Singleton public class TokenUriTranslator extends AbstractCallTranslator { /** Selector for tokenURI(uint256) method. */ - public static final Function TOKEN_URI = new Function("tokenURI(uint256)", ReturnTypes.STRING); + public static final SystemContractMethod TOKEN_URI = SystemContractMethod.declare( + "tokenURI(uint256)", ReturnTypes.STRING) + .withModifier(Modifier.VIEW) + .withCategory(Category.ERC721); /** * Default constructor for injection. */ @Inject - public TokenUriTranslator() { + public TokenUriTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(TOKEN_URI); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/totalsupply/TotalSupplyTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/totalsupply/TotalSupplyTranslator.java index fc30f4754d08..790843aba77e 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/totalsupply/TotalSupplyTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/totalsupply/TotalSupplyTranslator.java @@ -16,10 +16,13 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.totalsupply; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Category; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Modifier; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -30,14 +33,20 @@ @Singleton public class TotalSupplyTranslator extends AbstractCallTranslator { /** Selector for totalSupply() method. */ - public static final Function TOTAL_SUPPLY = new Function("totalSupply()", ReturnTypes.INT); + public static final SystemContractMethod TOTAL_SUPPLY = SystemContractMethod.declare( + "totalSupply()", ReturnTypes.INT) + .withModifier(Modifier.VIEW) + .withCategories(Category.ERC20, Category.ERC721); /** * Default constructor for injection. */ @Inject - public TotalSupplyTranslator() { + public TotalSupplyTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(TOTAL_SUPPLY); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/transfer/ClassicTransfersTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/transfer/ClassicTransfersTranslator.java index bfee6100667c..5f0a2df06ab5 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/transfer/ClassicTransfersTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/transfer/ClassicTransfersTranslator.java @@ -26,6 +26,8 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractCallTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import javax.inject.Inject; @@ -85,8 +87,14 @@ public class ClassicTransfersTranslator extends AbstractCallTranslator { /** * Selector for updateTokenExpiryInfo(address, EXPIRY) method. */ - public static final Function UPDATE_TOKEN_EXPIRY_INFO_V1 = - new Function("updateTokenExpiryInfo(address," + EXPIRY + ")", ReturnTypes.INT); + public static final SystemContractMethod UPDATE_TOKEN_EXPIRY_INFO_V1 = SystemContractMethod.declare( + "updateTokenExpiryInfo(address," + EXPIRY + ")", ReturnTypes.INT) + .withVariant(Variant.V1); /** * Selector for updateTokenExpiryInfo(address, EXPIRY_V2) method. */ - public static final Function UPDATE_TOKEN_EXPIRY_INFO_V2 = - new Function("updateTokenExpiryInfo(address," + EXPIRY_V2 + ")", ReturnTypes.INT); + public static final SystemContractMethod UPDATE_TOKEN_EXPIRY_INFO_V2 = SystemContractMethod.declare( + "updateTokenExpiryInfo(address," + EXPIRY_V2 + ")", ReturnTypes.INT) + .withVariant(Variant.V2); private final UpdateDecoder decoder; @@ -56,8 +62,12 @@ public class UpdateExpiryTranslator extends AbstractCallTranslator { /** Selector for updateTokenKeys(address, TOKEN_KEY[]) method. */ - public static final Function TOKEN_UPDATE_KEYS_FUNCTION = - new Function("updateTokenKeys(address," + TOKEN_KEY + ARRAY_BRACKETS + ")", ReturnTypes.INT); + public static final SystemContractMethod TOKEN_UPDATE_KEYS_FUNCTION = SystemContractMethod.declare( + "updateTokenKeys(address," + TOKEN_KEY + ARRAY_BRACKETS + ")", ReturnTypes.INT); private final UpdateDecoder decoder; @@ -45,8 +48,13 @@ public class UpdateKeysTranslator extends AbstractCallTranslator * @param decoder the decoder to use for token update keys calls */ @Inject - public UpdateKeysTranslator(UpdateDecoder decoder) { + public UpdateKeysTranslator( + @NonNull final UpdateDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethods(TOKEN_UPDATE_KEYS_FUNCTION); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/update/UpdateNFTsMetadataTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/update/UpdateNFTsMetadataTranslator.java index ada69222db8d..95cf4e15bf25 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/update/UpdateNFTsMetadataTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/update/UpdateNFTsMetadataTranslator.java @@ -16,7 +16,6 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.update; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -26,15 +25,19 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class UpdateNFTsMetadataTranslator extends AbstractCallTranslator { /** Selector for updateNFTsMetadata(address,int64[],bytes) method. */ - public static final Function UPDATE_NFTs_METADATA = - new Function("updateNFTsMetadata(address,int64[],bytes)", ReturnTypes.INT); + public static final SystemContractMethod UPDATE_NFTs_METADATA = + SystemContractMethod.declare("updateNFTsMetadata(address,int64[],bytes)", ReturnTypes.INT); private final UpdateDecoder decoder; @@ -42,8 +45,13 @@ public class UpdateNFTsMetadataTranslator extends AbstractCallTranslator { private static final String UPDATE_TOKEN_INFO_STRING = "updateTokenInfo(address,"; private static final String HEDERA_TOKEN_STRUCT = @@ -48,17 +53,21 @@ public class UpdateTranslator extends AbstractCallTranslator { private static final String HEDERA_TOKEN_STRUCT_V3 = "(string,string,address,string,bool,int64,bool," + TOKEN_KEY + ARRAY_BRACKETS + "," + EXPIRY_V2 + ")"; /** Selector for updateTokenInfo(address, HEDERA_TOKEN_STRUCT) method. */ - public static final Function TOKEN_UPDATE_INFO_FUNCTION_V1 = - new Function(UPDATE_TOKEN_INFO_STRING + HEDERA_TOKEN_STRUCT + ")", ReturnTypes.INT); + public static final SystemContractMethod TOKEN_UPDATE_INFO_FUNCTION_V1 = SystemContractMethod.declare( + UPDATE_TOKEN_INFO_STRING + HEDERA_TOKEN_STRUCT + ")", ReturnTypes.INT) + .withVariant(Variant.V1); /** Selector for updateTokenInfo(address, HEDERA_TOKEN_STRUCT_V2) method. */ - public static final Function TOKEN_UPDATE_INFO_FUNCTION_V2 = - new Function(UPDATE_TOKEN_INFO_STRING + HEDERA_TOKEN_STRUCT_V2 + ")", ReturnTypes.INT); + public static final SystemContractMethod TOKEN_UPDATE_INFO_FUNCTION_V2 = SystemContractMethod.declare( + UPDATE_TOKEN_INFO_STRING + HEDERA_TOKEN_STRUCT_V2 + ")", ReturnTypes.INT) + .withVariant(Variant.V2); /** Selector for updateTokenInfo(address, HEDERA_TOKEN_STRUCT_V3) method. */ - public static final Function TOKEN_UPDATE_INFO_FUNCTION_V3 = - new Function(UPDATE_TOKEN_INFO_STRING + HEDERA_TOKEN_STRUCT_V3 + ")", ReturnTypes.INT); + public static final SystemContractMethod TOKEN_UPDATE_INFO_FUNCTION_V3 = SystemContractMethod.declare( + UPDATE_TOKEN_INFO_STRING + HEDERA_TOKEN_STRUCT_V3 + ")", ReturnTypes.INT) + .withVariant(Variant.V3); /** Selector for updateTokenInfo(address, HEDERA_TOKEN_WITH_METADATA) method. */ - public static final Function TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA = - new Function(UPDATE_TOKEN_INFO_STRING + HEDERA_TOKEN_WITH_METADATA + ")", ReturnTypes.INT); + public static final SystemContractMethod TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA = SystemContractMethod.declare( + UPDATE_TOKEN_INFO_STRING + HEDERA_TOKEN_WITH_METADATA + ")", ReturnTypes.INT) + .withVariant(Variant.WITH_METADATA); private static final Map updateSelectorsMap = new HashMap<>(); @@ -66,11 +75,21 @@ public class UpdateTranslator extends AbstractCallTranslator { * @param decoder the decoder to use for token update info calls */ @Inject - public UpdateTranslator(final UpdateDecoder decoder) { - updateSelectorsMap.put(TOKEN_UPDATE_INFO_FUNCTION_V1, decoder::decodeTokenUpdateV1); - updateSelectorsMap.put(TOKEN_UPDATE_INFO_FUNCTION_V2, decoder::decodeTokenUpdateV2); - updateSelectorsMap.put(TOKEN_UPDATE_INFO_FUNCTION_V3, decoder::decodeTokenUpdateV3); - updateSelectorsMap.put(TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA, decoder::decodeTokenUpdateWithMetadata); + public UpdateTranslator( + final UpdateDecoder decoder, @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + + registerMethods( + TOKEN_UPDATE_INFO_FUNCTION_V1, + TOKEN_UPDATE_INFO_FUNCTION_V2, + TOKEN_UPDATE_INFO_FUNCTION_V3, + TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA); + + updateSelectorsMap.put(TOKEN_UPDATE_INFO_FUNCTION_V1.function(), decoder::decodeTokenUpdateV1); + updateSelectorsMap.put(TOKEN_UPDATE_INFO_FUNCTION_V2.function(), decoder::decodeTokenUpdateV2); + updateSelectorsMap.put(TOKEN_UPDATE_INFO_FUNCTION_V3.function(), decoder::decodeTokenUpdateV3); + updateSelectorsMap.put( + TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA.function(), decoder::decodeTokenUpdateWithMetadata); } @Override @@ -79,7 +98,7 @@ public boolean matches(@NonNull HtsCallAttempt attempt) { attempt.configuration().getConfigData(ContractsConfig.class).metadataKeyAndFieldEnabled(); return updateSelectorsMap.keySet().stream() - .anyMatch(selector -> selector.equals(TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA) + .anyMatch(selector -> selector.equals(TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA.function()) ? attempt.isSelectorIfConfigEnabled(metadataSupport, selector) : attempt.isSelector(selector)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/updatetokencustomfees/UpdateTokenCustomFeesTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/updatetokencustomfees/UpdateTokenCustomFeesTranslator.java index 75788816cfd1..41a95eca7549 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/updatetokencustomfees/UpdateTokenCustomFeesTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/updatetokencustomfees/UpdateTokenCustomFeesTranslator.java @@ -20,7 +20,6 @@ import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.updatetokencustomfees.UpdateTokenCustomFeesDecoder.UPDATE_NON_FUNGIBLE_TOKEN_CUSTOM_FEES_STRING; import static java.util.Objects.requireNonNull; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -30,27 +29,37 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.Arrays; import javax.inject.Inject; +import javax.inject.Singleton; +@Singleton public class UpdateTokenCustomFeesTranslator extends AbstractCallTranslator { /** Selector for updateFungibleTokenCustomFees(address,(int64,address,bool,bool,address)[],(int64,int64,int64,int64,bool,address)[]) method. */ - public static final Function UPDATE_FUNGIBLE_TOKEN_CUSTOM_FEES_FUNCTION = - new Function(UPDATE_FUNGIBLE_TOKEN_CUSTOM_FEES_STRING, ReturnTypes.INT); + public static final SystemContractMethod UPDATE_FUNGIBLE_TOKEN_CUSTOM_FEES_FUNCTION = + SystemContractMethod.declare(UPDATE_FUNGIBLE_TOKEN_CUSTOM_FEES_STRING, ReturnTypes.INT); /** Selector for updateNonFungibleTokenCustomFees(address,(int64,address,bool,bool,address)[],(int64,int64,int64,address,bool,address)[]) method. */ - public static final Function UPDATE_NON_FUNGIBLE_TOKEN_CUSTOM_FEES_FUNCTION = - new Function(UPDATE_NON_FUNGIBLE_TOKEN_CUSTOM_FEES_STRING, ReturnTypes.INT); + public static final SystemContractMethod UPDATE_NON_FUNGIBLE_TOKEN_CUSTOM_FEES_FUNCTION = + SystemContractMethod.declare(UPDATE_NON_FUNGIBLE_TOKEN_CUSTOM_FEES_STRING, ReturnTypes.INT); private final UpdateTokenCustomFeesDecoder decoder; @Inject - public UpdateTokenCustomFeesTranslator(@NonNull final UpdateTokenCustomFeesDecoder decoder) { + public UpdateTokenCustomFeesTranslator( + @NonNull final UpdateTokenCustomFeesDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); + requireNonNull(decoder); this.decoder = decoder; + + registerMethods(UPDATE_FUNGIBLE_TOKEN_CUSTOM_FEES_FUNCTION, UPDATE_NON_FUNGIBLE_TOKEN_CUSTOM_FEES_FUNCTION); } @Override diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/wipe/WipeTranslator.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/wipe/WipeTranslator.java index 9d7e43bfecc3..75deaacc5a0e 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/wipe/WipeTranslator.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/wipe/WipeTranslator.java @@ -18,7 +18,6 @@ import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall.FailureCustomizer.NOOP_CUSTOMIZER; -import com.esaulpaugh.headlong.abi.Function; import com.hedera.hapi.node.base.AccountID; import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.node.app.service.contract.impl.exec.gas.DispatchType; @@ -28,6 +27,9 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; @@ -37,20 +39,27 @@ public class WipeTranslator extends AbstractCallTranslator { /** Selector for wipeTokenAccount(address,address,uint32) method. */ - public static final Function WIPE_FUNGIBLE_V1 = - new Function("wipeTokenAccount(address,address,uint32)", ReturnTypes.INT); + public static final SystemContractMethod WIPE_FUNGIBLE_V1 = SystemContractMethod.declare( + "wipeTokenAccount(address,address,uint32)", ReturnTypes.INT) + .withVariant(Variant.V1); /** Selector for wipeTokenAccount(address,address,int64) method. */ - public static final Function WIPE_FUNGIBLE_V2 = - new Function("wipeTokenAccount(address,address,int64)", ReturnTypes.INT); + public static final SystemContractMethod WIPE_FUNGIBLE_V2 = SystemContractMethod.declare( + "wipeTokenAccount(address,address,int64)", ReturnTypes.INT) + .withVariant(Variant.V2); /** Selector for wipeTokenAccountNFT(address,address,int64[]) method. */ - public static final Function WIPE_NFT = - new Function("wipeTokenAccountNFT(address,address,int64[])", ReturnTypes.INT); + public static final SystemContractMethod WIPE_NFT = + SystemContractMethod.declare("wipeTokenAccountNFT(address,address,int64[])", ReturnTypes.INT); private final WipeDecoder decoder; @Inject - public WipeTranslator(@NonNull final WipeDecoder decoder) { + public WipeTranslator( + @NonNull final WipeDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContractMethod.SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethods(WIPE_FUNGIBLE_V1, WIPE_FUNGIBLE_V2, WIPE_NFT); } /** diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/utils/SystemContractMethod.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/utils/SystemContractMethod.java new file mode 100644 index 000000000000..754626d2708e --- /dev/null +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/utils/SystemContractMethod.java @@ -0,0 +1,266 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hedera.node.app.service.contract.impl.exec.utils; + +import static java.util.Objects.requireNonNull; + +import com.esaulpaugh.headlong.abi.Function; +import com.esaulpaugh.headlong.abi.Tuple; +import com.esaulpaugh.headlong.abi.TupleType; +import edu.umd.cs.findbugs.annotations.NonNull; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.Optional; +import java.util.stream.Collectors; +import org.apache.tuweni.bytes.Bytes; + +/** + * Represents a system contract method: It's signature + outputs, and other information about how it is declared + * @param function A headlong description of this method: signature + outputs, selector + * @param systemContract Which system contract this method is part of (HAS, HSS, HTS, PRNG, EXCHANGE) + * @param via Whether called directly or via redirect (aka proxy) + * @param categories Set of category flags possibly empty + * @param modifier An optional Solidity function modifier (e.g., pure or view) + * @param variants Set of method variants (e.g., version number, or FT vs NFT), possibly empty + */ +public record SystemContractMethod( + @NonNull Function function, + @NonNull Optional systemContract, + @NonNull CallVia via, + @NonNull EnumSet categories, + @NonNull Optional modifier, + @NonNull EnumSet variants) { + + public SystemContractMethod { + requireNonNull(function); + requireNonNull(systemContract); + requireNonNull(via); + requireNonNull(categories); + requireNonNull(modifier); + requireNonNull(variants); + } + + public SystemContractMethod(@NonNull final Function function) { + this( + function, + Optional.empty(), + CallVia.DIRECT, + EnumSet.noneOf(Category.class), + Optional.empty(), + EnumSet.noneOf(Variant.class)); + } + + public static SystemContractMethod declare(@NonNull final String signature, @NonNull final String outputs) { + final var function = new com.esaulpaugh.headlong.abi.Function(signature, outputs); + return new SystemContractMethod( + function, + Optional.empty(), + CallVia.DIRECT, + EnumSet.noneOf(Category.class), + Optional.empty(), + EnumSet.noneOf(Variant.class)); + } + + public static SystemContractMethod declare(@NonNull final String signature) { + final var function = new com.esaulpaugh.headlong.abi.Function(signature); + return new SystemContractMethod( + function, + Optional.empty(), + CallVia.DIRECT, + EnumSet.noneOf(Category.class), + Optional.empty(), + EnumSet.noneOf(Variant.class)); + } + + public void verifyComplete() { + if (systemContract.isEmpty()) { + throw new IllegalStateException("System contract %s is empty".formatted(function.getName())); + } + } + + public enum SystemContract { + HTS, + HAS, + HSS, + PNRG, + EXCHANGE; + + public @NonNull String asPrefix() { + return this.name(); + } + } + + public interface AsSuffix { + @NonNull + String asSuffix(); + } + + public enum CallVia implements AsSuffix { + DIRECT(""), + PROXY("[PROXY]"); + + private final String asSuffix; + + CallVia(@NonNull final String viaSuffix) { + asSuffix = viaSuffix; + } + + public @NonNull String asSuffix() { + return asSuffix; + } + } + + public enum Modifier implements AsSuffix { + VIEW("[VIEW]"), + PURE("[PURE]"); + + private final String asSuffix; + + Modifier(String modifierSuffix) { + this.asSuffix = modifierSuffix; + } + + public @NonNull String asSuffix() { + return asSuffix; + } + } + + public enum Category implements AsSuffix { + ERC20("[ERC20]"), + ERC721("[ERC721]"); + + private final String asSuffix; + + Category(@NonNull final String categorySuffix) { + this.asSuffix = requireNonNull(categorySuffix); + } + + public @NonNull String asSuffix() { + return asSuffix; + } + } + + public enum Variant implements AsSuffix { + FT, + NFT, + V1, + V2, + V3, + WITH_METADATA; + + public @NonNull String asSuffix() { + return name(); + } + } + + // Fluent builders + + public @NonNull SystemContractMethod withContract(@NonNull final SystemContract systemContract) { + return new SystemContractMethod(function, Optional.of(systemContract), via, categories, modifier, variants); + } + + public @NonNull SystemContractMethod withVia(@NonNull final CallVia via) { + return new SystemContractMethod(function, systemContract, via, categories, modifier, variants); + } + + public @NonNull SystemContractMethod withCategories(@NonNull final Category... categories) { + final var c = EnumSet.copyOf(this.categories); + c.addAll(Arrays.asList(categories)); + return new SystemContractMethod(function, systemContract, via, c, modifier, variants); + } + + public @NonNull SystemContractMethod withCategory(@NonNull final Category category) { + final var c = EnumSet.copyOf(categories); + c.add(category); + return new SystemContractMethod(function, systemContract, via, c, modifier, variants); + } + + public @NonNull SystemContractMethod withModifier(@NonNull final Modifier modifier) { + return new SystemContractMethod(function, systemContract, via, categories, Optional.of(modifier), variants); + } + + public @NonNull SystemContractMethod withVariant(@NonNull final Variant variant) { + final var v = EnumSet.copyOf(variants); + v.add(variant); + return new SystemContractMethod(function, systemContract, via, categories, modifier, v); + } + + // Forwarding to com.esaulpaugh.headlong.abi.Function + + public Tuple decodeCall(byte[] call) { + return function.decodeCall(call); + } + + public ByteBuffer encodeCall(Tuple tuple) { + return function.encodeCall(tuple); + } + + public ByteBuffer encodeCallWithArgs(Object... args) { + return function.encodeCallWithArgs(args); + } + + public TupleType getOutputs() { + return function.getOutputs(); + } + + // + + public @NonNull String methodName() { + return function.getName(); + } + + /** + * "Qualified" method name has the contract name in front of it, and the variants appended to it. + */ + public @NonNull String qualifiedMethodName() { + final var systemContractName = systemContract.map(Enum::name).orElse("???"); + String methodName = + switch (via) { + case DIRECT -> systemContractName + "." + methodName(); + case PROXY -> systemContractName + "(PROXY)." + methodName(); + }; + methodName += variantsSuffix(); + return methodName; + } + + public @NonNull String variantsSuffix() { + if (variants.isEmpty()) return ""; + return variants.stream().map(Variant::asSuffix).sorted().collect(Collectors.joining("_", "_", "")); + } + + public @NonNull String signature() { + return function.getCanonicalSignature(); + } + + public @NonNull String signatureWithReturn() { + return signature() + ':' + function.getOutputs(); + } + + public @NonNull byte[] selector() { + return function.selector(); + } + + public long selectorLong() { + return Bytes.wrap(function.selector()).toLong(ByteOrder.BIG_ENDIAN); + } + + public @NonNull String selectorHex() { + return function.selectorHex(); + } +} diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/utils/SystemContractMethodRegistry.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/utils/SystemContractMethodRegistry.java new file mode 100644 index 000000000000..b3ad824e4c3d --- /dev/null +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/utils/SystemContractMethodRegistry.java @@ -0,0 +1,140 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hedera.node.app.service.contract.impl.exec.utils; + +import static java.util.Comparator.comparing; +import static java.util.Objects.requireNonNull; + +import com.esaulpaugh.headlong.abi.Function; +import com.google.common.annotations.VisibleForTesting; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.SystemContract; +import edu.umd.cs.findbugs.annotations.NonNull; +import java.util.Collection; +import java.util.SequencedCollection; +import java.util.concurrent.ConcurrentHashMap; +import javax.inject.Inject; +import javax.inject.Singleton; + +/** + * A registry for all the system contract methods - their names, selectors, and signatures. + * + * Methods are added to this registry when they're defined in the various `FooTranslator` classes, + * which, since they're all (or should be) Dagger singletons, is done as the smart contract service + * is coming up. Thus, the completed registry is available once processing starts, and so is ready + * for use to enumerate all system contract methods. + * + * The principal use case for this registry is to be able to generate various per-system-contract-method + * metrics. + */ +@Singleton +public class SystemContractMethodRegistry { + + private static final int EXPECTED_SYSTEM_CONTRACT_METHODS_UPPER_BOUND = 250; + private final ConcurrentHashMap byName = + new ConcurrentHashMap<>(EXPECTED_SYSTEM_CONTRACT_METHODS_UPPER_BOUND); + + @Inject + public SystemContractMethodRegistry() { + requireNonNull(SystemContractMethod.SystemContract.HTS); // DEBUGGING + } + + public void register(@NonNull final SystemContractMethod systemContractMethod) { + requireNonNull(systemContractMethod); + + var keyName = systemContractMethod.methodName(); + if (systemContractMethod.via() == CallVia.PROXY) + keyName += systemContractMethod.via().asSuffix(); + + byName.putIfAbsent(keyName, systemContractMethod); + } + + public void register( + @NonNull final Function function, + @NonNull final SystemContract systemContract, + @NonNull final String methodName, + @NonNull final CallVia via) { + requireNonNull(function); + requireNonNull(systemContract); + requireNonNull(methodName); + + var keyName = methodName; + if (via == SystemContractMethod.CallVia.PROXY) keyName += "(PROXY)"; + + byName.computeIfAbsent(keyName, k -> new SystemContractMethod(function) + .withContract(systemContract) + .withVia(via)); + } + + public void register( + @NonNull final Function function, + @NonNull final SystemContract systemContract, + @NonNull final String methodName) { + register(function, systemContract, methodName, SystemContractMethod.CallVia.DIRECT); + } + + public void register( + @NonNull final Function function, + @NonNull final SystemContract systemContract, + @NonNull final CallVia via) { + register(function, systemContract, function.getName(), via); + } + + public void register(@NonNull final Function function, @NonNull final SystemContract systemContract) { + register(function, systemContract, function.getName(), SystemContractMethod.CallVia.DIRECT); + } + + // Queries: + + public long size() { + return byName.size(); + } + + public @NonNull SequencedCollection allQualifiedMethods() { + return allMethodsGivenMapper(SystemContractMethod::qualifiedMethodName); + } + + public @NonNull SequencedCollection allSignatures() { + return allMethodsGivenMapper(SystemContractMethod::signature); + } + + public @NonNull SequencedCollection allSignaturesWithReturns() { + return allMethodsGivenMapper(SystemContractMethod::signatureWithReturn); + } + + private @NonNull SequencedCollection allMethodsGivenMapper( + @NonNull final java.util.function.Function methodMapper) { + return byName.values().stream().map(methodMapper).sorted().toList(); + } + + public @NonNull Collection allMethods() { + return byName.values(); + } + + @VisibleForTesting + public @NonNull String allMethodsAsTable() { + final var allMethods = allMethods().stream() + .sorted(comparing(SystemContractMethod::qualifiedMethodName)) + .toList(); + final var sb = new StringBuilder(); + for (final var method : allMethods) { + sb.append("%s: 0x%s - %s\n" + .formatted(method.qualifiedMethodName(), method.selectorHex(), method.signatureWithReturn())); + } + return sb.toString(); + } +} diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/AbstractContractTransactionHandler.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/AbstractContractTransactionHandler.java index f2ab8b4aeb79..1e6b2f5afeb9 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/AbstractContractTransactionHandler.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/AbstractContractTransactionHandler.java @@ -104,4 +104,9 @@ protected void bumpExceptionMetrics(@NonNull final HederaFunctionality functiona @NonNull final SigValueObj sigValObj) { throw new IllegalStateException("must be overridden if `calculateFees` _not_ overridden"); } + + protected @NonNull TransactionComponent getTransactionComponent( + @NonNull final HandleContext context, @NonNull final HederaFunctionality functionality) { + return provider.get().create(context, functionality); + } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCallHandler.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCallHandler.java index 33eaf3c5a5c8..fbd0ecd4d541 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCallHandler.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCallHandler.java @@ -65,7 +65,7 @@ public ContractCallHandler( @Override public void handle(@NonNull final HandleContext context) throws HandleException { // Create the transaction-scoped component - final var component = provider.get().create(context, CONTRACT_CALL); + final var component = getTransactionComponent(context, CONTRACT_CALL); // Run its in-scope transaction and get the outcome final var outcome = component.contextTransactionProcessor().call(); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCallLocalHandler.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCallLocalHandler.java index 4c08ffcfedfd..53fcdc969619 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCallLocalHandler.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCallLocalHandler.java @@ -39,6 +39,7 @@ import com.hedera.hapi.node.transaction.Response; import com.hedera.node.app.hapi.utils.CommonPbjConverters; import com.hedera.node.app.hapi.utils.fee.SmartContractFeeBuilder; +import com.hedera.node.app.service.contract.impl.ContractServiceComponent; import com.hedera.node.app.service.contract.impl.exec.QueryComponent; import com.hedera.node.app.service.contract.impl.exec.QueryComponent.Factory; import com.hedera.node.app.service.token.ReadableAccountStore; @@ -65,6 +66,7 @@ public class ContractCallLocalHandler extends PaidQueryHandler { private final Provider provider; private final GasCalculator gasCalculator; private final InstantSource instantSource; + private final ContractServiceComponent contractServiceComponent; /** * Constructs a {@link ContractCreateHandler} with the given {@link Provider}, {@link GasCalculator} and {@link InstantSource}. @@ -77,10 +79,12 @@ public class ContractCallLocalHandler extends PaidQueryHandler { public ContractCallLocalHandler( @NonNull final Provider provider, @NonNull final GasCalculator gasCalculator, - @NonNull final InstantSource instantSource) { + @NonNull final InstantSource instantSource, + @NonNull final ContractServiceComponent contractServiceComponent) { this.provider = requireNonNull(provider); this.gasCalculator = requireNonNull(gasCalculator); this.instantSource = requireNonNull(instantSource); + this.contractServiceComponent = requireNonNull(contractServiceComponent); } @Override @@ -142,6 +146,7 @@ public Response findResponse(@NonNull final QueryContext context, @NonNull final requireNonNull(header); final var component = provider.get().create(context, instantSource.instant(), CONTRACT_CALL_LOCAL); + final var outcome = component.contextQueryProcessor().call(); final var responseHeader = outcome.isSuccess() diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCreateHandler.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCreateHandler.java index c5b05858dd09..f6acb5e41001 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCreateHandler.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/ContractCreateHandler.java @@ -68,7 +68,7 @@ public ContractCreateHandler( @Override public void handle(@NonNull final HandleContext context) throws HandleException { // Create the transaction-scoped component - final var component = provider.get().create(context, CONTRACT_CREATE); + final var component = getTransactionComponent(context, CONTRACT_CREATE); // Run its in-scope transaction and get the outcome final var outcome = component.contextTransactionProcessor().call(); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/EthereumTransactionHandler.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/EthereumTransactionHandler.java index f93e8e890cac..1aab358de0bc 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/EthereumTransactionHandler.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/handlers/EthereumTransactionHandler.java @@ -155,7 +155,7 @@ public void pureChecks(@NonNull final TransactionBody txn) throws PreCheckExcept @Override public void handle(@NonNull final HandleContext context) throws HandleException { // Create the transaction-scoped component - final var component = provider.get().create(context, ETHEREUM_TRANSACTION); + final var component = getTransactionComponent(context, ETHEREUM_TRANSACTION); // Run its in-scope transaction and get the outcome final var outcome = component.contextTransactionProcessor().call(); @@ -180,7 +180,7 @@ public void handle(@NonNull final HandleContext context) throws HandleException * @param context the handle context */ public void handleThrottled(@NonNull final HandleContext context) { - final var component = provider.get().create(context, ETHEREUM_TRANSACTION); + final var component = getTransactionComponent(context, ETHEREUM_TRANSACTION); final var ethTxData = requireNonNull(requireNonNull(component.hydratedEthTxData()).ethTxData()); context.savepointStack() diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/metrics/ContractMetricsTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/metrics/ContractMetricsTest.java index b47b70bfac03..623ee2b5f759 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/metrics/ContractMetricsTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/metrics/ContractMetricsTest.java @@ -22,6 +22,7 @@ import com.hedera.hapi.node.base.HederaFunctionality; import com.hedera.node.app.service.contract.impl.exec.metrics.ContractMetrics; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.config.data.ContractsConfig; import com.hedera.node.config.testfixtures.HederaTestConfigBuilder; import com.swirlds.common.metrics.config.MetricsConfig; @@ -47,9 +48,12 @@ public class ContractMetricsTest { @Mock private ContractsConfig contractsConfig; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + public @NonNull ContractMetrics getSubject() { - final var contractMetrics = new ContractMetrics(metricsSupplier, () -> contractsConfig); - contractMetrics.createContractMetrics(); + final var contractMetrics = + new ContractMetrics(metricsSupplier, () -> contractsConfig, systemContractMethodRegistry); + contractMetrics.createContractPrimaryMetrics(); return contractMetrics; } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/CallAttemptHelpers.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/CallAttemptHelpers.java index feb1f391b644..5848385ce9eb 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/CallAttemptHelpers.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/CallAttemptHelpers.java @@ -28,6 +28,8 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.HssCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.service.contract.impl.test.TestHelpers; import com.hedera.node.app.spi.signatures.SignatureVerifier; @@ -55,7 +57,8 @@ public static HtsCallAttempt prepareHtsAttemptWithSelector( final HederaWorldUpdater.Enhancement enhancement, final AddressIdConverter addressIdConverter, final VerificationStrategies verificationStrategies, - final SystemContractGasCalculator gasCalculator) { + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry) { final var input = Bytes.wrap(function.selector()); return new HtsCallAttempt( @@ -69,6 +72,32 @@ public static HtsCallAttempt prepareHtsAttemptWithSelector( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, + false); + } + + public static HtsCallAttempt prepareHtsAttemptWithSelector( + final SystemContractMethod systemContractMethod, + final CallTranslator translator, + final HederaWorldUpdater.Enhancement enhancement, + final AddressIdConverter addressIdConverter, + final VerificationStrategies verificationStrategies, + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry) { + final var input = Bytes.wrap(systemContractMethod.selector()); + + return new HtsCallAttempt( + input, + OWNER_BESU_ADDRESS, + OWNER_BESU_ADDRESS, + false, + enhancement, + DEFAULT_CONFIG, + addressIdConverter, + verificationStrategies, + gasCalculator, + List.of(translator), + systemContractMethodRegistry, false); } @@ -87,7 +116,8 @@ public static HtsCallAttempt prepareHtsAttemptWithSelectorForRedirect( final HederaWorldUpdater.Enhancement enhancement, final AddressIdConverter addressIdConverter, final VerificationStrategies verificationStrategies, - final SystemContractGasCalculator gasCalculator) { + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry) { final var input = TestHelpers.bytesForRedirect(function.selector(), NON_SYSTEM_LONG_ZERO_ADDRESS); return new HtsCallAttempt( @@ -101,6 +131,32 @@ public static HtsCallAttempt prepareHtsAttemptWithSelectorForRedirect( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, + false); + } + + public static HtsCallAttempt prepareHtsAttemptWithSelectorForRedirect( + final SystemContractMethod systemContractMethod, + final CallTranslator translator, + final HederaWorldUpdater.Enhancement enhancement, + final AddressIdConverter addressIdConverter, + final VerificationStrategies verificationStrategies, + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry) { + final var input = TestHelpers.bytesForRedirect(systemContractMethod.selector(), NON_SYSTEM_LONG_ZERO_ADDRESS); + + return new HtsCallAttempt( + input, + OWNER_BESU_ADDRESS, + OWNER_BESU_ADDRESS, + false, + enhancement, + DEFAULT_CONFIG, + addressIdConverter, + verificationStrategies, + gasCalculator, + List.of(translator), + systemContractMethodRegistry, false); } @@ -121,6 +177,7 @@ public static HtsCallAttempt prepareHtsAttemptWithSelectorForRedirectWithConfig( final AddressIdConverter addressIdConverter, final VerificationStrategies verificationStrategies, final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, final Configuration config) { final var input = TestHelpers.bytesForRedirect(function.selector(), NON_SYSTEM_LONG_ZERO_ADDRESS); @@ -135,6 +192,33 @@ public static HtsCallAttempt prepareHtsAttemptWithSelectorForRedirectWithConfig( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, + false); + } + + public static HtsCallAttempt prepareHtsAttemptWithSelectorForRedirectWithConfig( + final SystemContractMethod systemContractMethod, + final CallTranslator translator, + final HederaWorldUpdater.Enhancement enhancement, + final AddressIdConverter addressIdConverter, + final VerificationStrategies verificationStrategies, + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, + final Configuration config) { + final var input = TestHelpers.bytesForRedirect(systemContractMethod.selector(), NON_SYSTEM_LONG_ZERO_ADDRESS); + + return new HtsCallAttempt( + input, + OWNER_BESU_ADDRESS, + OWNER_BESU_ADDRESS, + false, + enhancement, + config, + addressIdConverter, + verificationStrategies, + gasCalculator, + List.of(translator), + systemContractMethodRegistry, false); } @@ -155,6 +239,7 @@ public static HtsCallAttempt prepareHtsAttemptWithSelectorAndCustomConfig( final AddressIdConverter addressIdConverter, final VerificationStrategies verificationStrategies, final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, final Configuration config) { final var input = Bytes.wrap(function.selector()); @@ -169,6 +254,33 @@ public static HtsCallAttempt prepareHtsAttemptWithSelectorAndCustomConfig( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, + false); + } + + public static HtsCallAttempt prepareHtsAttemptWithSelectorAndCustomConfig( + final SystemContractMethod systemContractMethod, + final CallTranslator translator, + final HederaWorldUpdater.Enhancement enhancement, + final AddressIdConverter addressIdConverter, + final VerificationStrategies verificationStrategies, + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, + final Configuration config) { + final var input = Bytes.wrap(systemContractMethod.selector()); + + return new HtsCallAttempt( + input, + OWNER_BESU_ADDRESS, + OWNER_BESU_ADDRESS, + false, + enhancement, + config, + addressIdConverter, + verificationStrategies, + gasCalculator, + List.of(translator), + systemContractMethodRegistry, false); } @@ -189,7 +301,8 @@ public static HasCallAttempt prepareHasAttemptWithSelector( final AddressIdConverter addressIdConverter, final VerificationStrategies verificationStrategies, final SignatureVerifier signatureVerifier, - final SystemContractGasCalculator gasCalculator) { + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry) { return prepareHasAttemptWithSelectorAndCustomConfig( function, translator, @@ -198,6 +311,28 @@ public static HasCallAttempt prepareHasAttemptWithSelector( verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, + DEFAULT_CONFIG); + } + + public static HasCallAttempt prepareHasAttemptWithSelector( + final SystemContractMethod systemContractMethod, + final CallTranslator translator, + final HederaWorldUpdater.Enhancement enhancement, + final AddressIdConverter addressIdConverter, + final VerificationStrategies verificationStrategies, + final SignatureVerifier signatureVerifier, + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry) { + return prepareHasAttemptWithSelectorAndCustomConfig( + systemContractMethod, + translator, + enhancement, + addressIdConverter, + verificationStrategies, + signatureVerifier, + gasCalculator, + systemContractMethodRegistry, DEFAULT_CONFIG); } @@ -220,6 +355,7 @@ public static HasCallAttempt prepareHasAttemptWithSelectorAndCustomConfig( final VerificationStrategies verificationStrategies, final SignatureVerifier signatureVerifier, final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, final Configuration config) { return prepareHasAttemptWithSelectorAndInputAndCustomConfig( function, @@ -230,6 +366,30 @@ public static HasCallAttempt prepareHasAttemptWithSelectorAndCustomConfig( verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, + config); + } + + public static HasCallAttempt prepareHasAttemptWithSelectorAndCustomConfig( + final SystemContractMethod systemContractMethod, + final CallTranslator translator, + final HederaWorldUpdater.Enhancement enhancement, + final AddressIdConverter addressIdConverter, + final VerificationStrategies verificationStrategies, + final SignatureVerifier signatureVerifier, + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, + final Configuration config) { + return prepareHasAttemptWithSelectorAndInputAndCustomConfig( + systemContractMethod, + TestHelpers.bytesForRedirectAccount(systemContractMethod.selector(), NON_SYSTEM_LONG_ZERO_ADDRESS), + translator, + enhancement, + addressIdConverter, + verificationStrategies, + signatureVerifier, + gasCalculator, + systemContractMethodRegistry, config); } @@ -254,6 +414,33 @@ public static HasCallAttempt prepareHasAttemptWithSelectorAndInputAndCustomConfi final VerificationStrategies verificationStrategies, final SignatureVerifier signatureVerifier, final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, + final Configuration config) { + return new HasCallAttempt( + input, + OWNER_BESU_ADDRESS, + false, + enhancement, + config, + addressIdConverter, + verificationStrategies, + signatureVerifier, + gasCalculator, + List.of(translator), + systemContractMethodRegistry, + false); + } + + public static HasCallAttempt prepareHasAttemptWithSelectorAndInputAndCustomConfig( + final SystemContractMethod systemContractMethod, + final Bytes input, + final CallTranslator translator, + final HederaWorldUpdater.Enhancement enhancement, + final AddressIdConverter addressIdConverter, + final VerificationStrategies verificationStrategies, + final SignatureVerifier signatureVerifier, + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, final Configuration config) { return new HasCallAttempt( input, @@ -266,6 +453,7 @@ public static HasCallAttempt prepareHasAttemptWithSelectorAndInputAndCustomConfi signatureVerifier, gasCalculator, List.of(translator), + systemContractMethodRegistry, false); } @@ -286,6 +474,7 @@ public static HssCallAttempt prepareHssAttemptWithSelectorAndCustomConfig( final AddressIdConverter addressIdConverter, final VerificationStrategies verificationStrategies, final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, final Configuration config) { final var input = Bytes.wrap(function.selector()); @@ -299,6 +488,32 @@ public static HssCallAttempt prepareHssAttemptWithSelectorAndCustomConfig( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, + false); + } + + public static HssCallAttempt prepareHssAttemptWithSelectorAndCustomConfig( + final SystemContractMethod systemContractMethod, + final CallTranslator translator, + final HederaWorldUpdater.Enhancement enhancement, + final AddressIdConverter addressIdConverter, + final VerificationStrategies verificationStrategies, + final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, + final Configuration config) { + final var input = Bytes.wrap(systemContractMethod.selector()); + + return new HssCallAttempt( + input, + OWNER_BESU_ADDRESS, + false, + enhancement, + config, + addressIdConverter, + verificationStrategies, + gasCalculator, + List.of(translator), + systemContractMethodRegistry, false); } @@ -309,6 +524,7 @@ public static HssCallAttempt prepareHssAttemptWithBytesAndCustomConfig( final AddressIdConverter addressIdConverter, final VerificationStrategies verificationStrategies, final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, final Configuration config) { return new HssCallAttempt( @@ -321,6 +537,7 @@ public static HssCallAttempt prepareHssAttemptWithBytesAndCustomConfig( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, false); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/HasCallAttemptTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/HasCallAttemptTest.java index d27d040adf6e..0d34a42e8c6d 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/HasCallAttemptTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/HasCallAttemptTest.java @@ -36,6 +36,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.hbarapprove.HbarApproveCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.hbarapprove.HbarApproveTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.test.TestHelpers; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import com.hedera.node.app.spi.signatures.SignatureVerifier; @@ -58,9 +59,13 @@ class HasCallAttemptTest extends CallTestBase { private List> callTranslators; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + @BeforeEach void setUp() { - callTranslators = List.of(new HbarAllowanceTranslator(), new HbarApproveTranslator()); + callTranslators = List.of( + new HbarAllowanceTranslator(systemContractMethodRegistry), + new HbarApproveTranslator(systemContractMethodRegistry)); } @Test @@ -80,6 +85,7 @@ void returnNullAccountIfAccountNotFound() { signatureVerifier, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertNull(subject.redirectAccount()); } @@ -98,6 +104,7 @@ void invalidSelectorLeadsToMissingCall() { signatureVerifier, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertNull(subject.asExecutableCall()); } @@ -122,6 +129,7 @@ void constructsHbarAllowanceProxy() { signatureVerifier, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(HbarAllowanceCall.class, subject.asExecutableCall()); } @@ -148,6 +156,7 @@ void constructsHbarAllowanceDirect() { signatureVerifier, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(HbarAllowanceCall.class, subject.asExecutableCall()); } @@ -174,6 +183,7 @@ void constructsHbarApproveProxy() { signatureVerifier, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(HbarApproveCall.class, subject.asExecutableCall()); } @@ -201,6 +211,7 @@ void constructsHbarApproveDirect() { signatureVerifier, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(HbarApproveCall.class, subject.asExecutableCall()); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/HasCallFactoryTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/HasCallFactoryTest.java index 762cab3c5c75..732db5813ebf 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/HasCallFactoryTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/HasCallFactoryTest.java @@ -38,6 +38,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.SyntheticIds; import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.state.ProxyWorldUpdater; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import com.hedera.node.app.spi.signatures.SignatureVerifier; @@ -77,11 +78,13 @@ class HasCallFactoryTest extends CallTestBase { @Mock private MessageFrame initialFrame; - private Deque stack = new ArrayDeque<>(); + private final Deque stack = new ArrayDeque<>(); @Mock private ProxyWorldUpdater updater; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private HasCallFactory subject; @BeforeEach @@ -91,7 +94,8 @@ void setUp() { addressChecks, verificationStrategies, signatureVerifier, - List.of(new HbarAllowanceTranslator())); + List.of(new HbarAllowanceTranslator(systemContractMethodRegistry)), + systemContractMethodRegistry); } @Test diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/evmaddressalias/EvmAddressAliasTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/evmaddressalias/EvmAddressAliasTranslatorTest.java index 6e32d80b0db6..980699cde390 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/evmaddressalias/EvmAddressAliasTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/evmaddressalias/EvmAddressAliasTranslatorTest.java @@ -34,6 +34,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.getevmaddressalias.EvmAddressAliasCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.getevmaddressalias.EvmAddressAliasTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.spi.signatures.SignatureVerifier; import org.apache.tuweni.bytes.Bytes; @@ -66,11 +67,13 @@ class EvmAddressAliasTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private EvmAddressAliasTranslator subject; @BeforeEach void setUp() { - subject = new EvmAddressAliasTranslator(); + subject = new EvmAddressAliasTranslator(systemContractMethodRegistry); } @Test @@ -83,7 +86,8 @@ void matchesEvmAddressAlias() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); assertEquals("0xdea3d081" /*copied from HIP-632*/, "0x" + EVM_ADDRESS_ALIAS.selectorHex()); } @@ -98,7 +102,8 @@ void failsOnInvalidSelector() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hbarAllowance/HbarAllowanceTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hbarAllowance/HbarAllowanceTranslatorTest.java index 90dd7017d092..b8337a1dd577 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hbarAllowance/HbarAllowanceTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hbarAllowance/HbarAllowanceTranslatorTest.java @@ -37,6 +37,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.hbarallowance.HbarAllowanceCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.hbarallowance.HbarAllowanceTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.spi.signatures.SignatureVerifier; import org.apache.tuweni.bytes.Bytes; @@ -69,11 +70,13 @@ public class HbarAllowanceTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private HbarAllowanceTranslator subject; @BeforeEach void setUp() { - subject = new HbarAllowanceTranslator(); + subject = new HbarAllowanceTranslator(systemContractMethodRegistry); } @Test @@ -86,7 +89,8 @@ void matchesHbarAllowance() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); attempt = prepareHasAttemptWithSelector( @@ -96,7 +100,8 @@ void matchesHbarAllowance() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -110,7 +115,8 @@ void failsOnInvalidSelector() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hbarApprove/HbarApproveTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hbarApprove/HbarApproveTranslatorTest.java index 706aa22cba96..943f7f2d795e 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hbarApprove/HbarApproveTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hbarApprove/HbarApproveTranslatorTest.java @@ -37,6 +37,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.hbarapprove.HbarApproveCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.hbarapprove.HbarApproveTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.spi.signatures.SignatureVerifier; import java.math.BigInteger; @@ -70,11 +71,13 @@ public class HbarApproveTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private HbarApproveTranslator subject; @BeforeEach void setUp() { - subject = new HbarApproveTranslator(); + subject = new HbarApproveTranslator(systemContractMethodRegistry); } @Test @@ -87,7 +90,8 @@ void matchesHbarApprove() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); attempt = prepareHasAttemptWithSelector( @@ -97,7 +101,8 @@ void matchesHbarApprove() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -111,7 +116,8 @@ void failsOnInvalidSelector() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hederaaccountnumalias/HederaAccountNumAliasTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hederaaccountnumalias/HederaAccountNumAliasTranslatorTest.java index b70092cde1e9..b6860a7552b3 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hederaaccountnumalias/HederaAccountNumAliasTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/hederaaccountnumalias/HederaAccountNumAliasTranslatorTest.java @@ -34,6 +34,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.hederaaccountnumalias.HederaAccountNumAliasCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.hederaaccountnumalias.HederaAccountNumAliasTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.spi.signatures.SignatureVerifier; import org.apache.tuweni.bytes.Bytes; @@ -67,11 +68,13 @@ public class HederaAccountNumAliasTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private HederaAccountNumAliasTranslator subject; @BeforeEach void setUp() { - subject = new HederaAccountNumAliasTranslator(); + subject = new HederaAccountNumAliasTranslator(systemContractMethodRegistry); } @Test @@ -84,7 +87,8 @@ void matchesHederaAccountNumAlias() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); assertEquals("0xbbf12d2e" /*copied from HIP-632*/, "0x" + HEDERA_ACCOUNT_NUM_ALIAS.selectorHex()); } @@ -99,7 +103,8 @@ void failsOnInvalidSelector() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isauthorized/IsAuthorizedTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isauthorized/IsAuthorizedTranslatorTest.java index fd2ab6294a5c..a4bbe54276c8 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isauthorized/IsAuthorizedTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isauthorized/IsAuthorizedTranslatorTest.java @@ -37,6 +37,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.isauthorized.IsAuthorizedCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.isauthorized.IsAuthorizedTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.exec.v051.Version051FeatureFlags; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.spi.signatures.SignatureVerifier; @@ -78,12 +79,14 @@ public class IsAuthorizedTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private IsAuthorizedTranslator subject; @BeforeEach void setUp() { final var featureFlags = new Version051FeatureFlags(); - subject = new IsAuthorizedTranslator(featureFlags, customGasCalculator); + subject = new IsAuthorizedTranslator(featureFlags, customGasCalculator, systemContractMethodRegistry); given(enhancement.nativeOperations()).willReturn(nativeOperations); } @@ -98,6 +101,7 @@ void matchesIsAuthorizedWhenEnabled() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(true)); assertTrue(subject.matches(attempt)); } @@ -112,6 +116,7 @@ void doesNotMatchIsAuthorizedWhenDisabled() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(false)); assertFalse(subject.matches(attempt)); } @@ -126,6 +131,7 @@ void failsOnInvalidSelector() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(true)); assertFalse(subject.matches(attempt)); } @@ -144,6 +150,7 @@ void callFromIsAuthorizedTest() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(true)); final var call = subject.callFrom(attempt); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isauthorizedraw/IsAuthorizedRawTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isauthorizedraw/IsAuthorizedRawTranslatorTest.java index 658702406105..37636bb4c60f 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isauthorizedraw/IsAuthorizedRawTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isauthorizedraw/IsAuthorizedRawTranslatorTest.java @@ -37,6 +37,8 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.isauthorizedraw.IsAuthorizedRawCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.isauthorizedraw.IsAuthorizedRawTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.exec.v051.Version051FeatureFlags; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.spi.signatures.SignatureVerifier; @@ -78,12 +80,14 @@ public class IsAuthorizedRawTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private IsAuthorizedRawTranslator subject; @BeforeEach void setUp() { final var featureFlags = new Version051FeatureFlags(); - subject = new IsAuthorizedRawTranslator(featureFlags, customGasCalculator); + subject = new IsAuthorizedRawTranslator(featureFlags, customGasCalculator, systemContractMethodRegistry); } @Test @@ -97,6 +101,7 @@ void matchesIsAuthorizedRawWhenEnabled() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(true)); assertTrue(subject.matches(attempt)); } @@ -112,6 +117,7 @@ void doesNotMatchIsAuthorizedRawWhenDisabled() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(false)); assertFalse(subject.matches(attempt)); } @@ -127,6 +133,7 @@ void failsOnInvalidSelector() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(true)); assertFalse(subject.matches(attempt)); } @@ -144,8 +151,8 @@ void callFromIsAuthorizedRawTest() { private void givenCommonForCall(Bytes inputBytes) { given(attempt.inputBytes()).willReturn(inputBytes.toArray()); - given(attempt.isSelector(any())).willReturn(true); given(attempt.enhancement()).willReturn(enhancement); + given(attempt.isSelector((SystemContractMethod) any())).willReturn(true); given(attempt.systemContractGasCalculator()).willReturn(gasCalculator); given(attempt.signatureVerifier()).willReturn(signatureVerifier); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isvalidalias/IsValidAliasTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isvalidalias/IsValidAliasTranslatorTest.java index bdd6c1442289..006e5b2349e3 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isvalidalias/IsValidAliasTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/isvalidalias/IsValidAliasTranslatorTest.java @@ -34,6 +34,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.isvalidalias.IsValidAliasCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.isvalidalias.IsValidAliasTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.spi.signatures.SignatureVerifier; import org.apache.tuweni.bytes.Bytes; @@ -67,11 +68,13 @@ public class IsValidAliasTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private IsValidAliasTranslator subject; @BeforeEach void setUp() { - subject = new IsValidAliasTranslator(); + subject = new IsValidAliasTranslator(systemContractMethodRegistry); } @Test @@ -84,7 +87,8 @@ void matchesIsValidAliasSelector() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); assertEquals("0x308ef301" /*copied from HIP-632*/, "0x" + IS_VALID_ALIAS.selectorHex()); } @@ -99,7 +103,8 @@ void failsOnInvalidSelector() { addressIdConverter, verificationStrategies, signatureVerifier, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/setunlimitedautoassociations/SetUnlimitedAutoAssociationsTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/setunlimitedautoassociations/SetUnlimitedAutoAssociationsTranslatorTest.java index 8a05d30fd662..226a2c318f38 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/setunlimitedautoassociations/SetUnlimitedAutoAssociationsTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/has/setunlimitedautoassociations/SetUnlimitedAutoAssociationsTranslatorTest.java @@ -30,6 +30,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.setunlimitedautoassociations.SetUnlimitedAutoAssociationsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.setunlimitedautoassociations.SetUnlimitedAutoAssociationsTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.spi.signatures.SignatureVerifier; import com.hedera.node.config.data.ContractsConfig; @@ -70,11 +71,13 @@ class SetUnlimitedAutoAssociationsTranslatorTest { @Mock private ContractsConfig contractsConfig; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private SetUnlimitedAutoAssociationsTranslator subject; @BeforeEach void setUp() { - subject = new SetUnlimitedAutoAssociationsTranslator(); + subject = new SetUnlimitedAutoAssociationsTranslator(systemContractMethodRegistry); } @Test @@ -91,6 +94,7 @@ void matchesWhenEnabled() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -109,6 +113,7 @@ void matchesWhenDisabled() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, configuration); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/HssCallAttemptTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/HssCallAttemptTest.java index 01227c9d8038..496ea69c9921 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/HssCallAttemptTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/HssCallAttemptTest.java @@ -28,6 +28,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.HssCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.signschedule.SignScheduleTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.test.TestHelpers; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import java.util.List; @@ -44,9 +45,11 @@ class HssCallAttemptTest extends CallTestBase { private List> callTranslators; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + @BeforeEach void setUp() { - callTranslators = List.of(new SignScheduleTranslator()); + callTranslators = List.of(new SignScheduleTranslator(systemContractMethodRegistry)); } @Test @@ -64,6 +67,7 @@ void returnNullScheduleIfScheduleNotFound() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertNull(subject.redirectScheduleTxn()); } @@ -81,6 +85,7 @@ void invalidSelectorLeadsToMissingCall() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertNull(subject.asExecutableCall()); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/HssCallFactoryTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/HssCallFactoryTest.java index daaa6e98e116..41cec2586617 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/HssCallFactoryTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/HssCallFactoryTest.java @@ -40,6 +40,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.SyntheticIds; import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.state.ProxyWorldUpdater; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import com.hedera.node.app.spi.signatures.SignatureVerifier; @@ -91,6 +92,8 @@ class HssCallFactoryTest extends CallTestBase { @Mock private Key maybeEthSenderKey; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private HssCallFactory subject; @BeforeEach @@ -100,7 +103,8 @@ void setUp() { addressChecks, verificationStrategies, signatureVerifier, - List.of(new SignScheduleTranslator())); + List.of(new SignScheduleTranslator(systemContractMethodRegistry)), + systemContractMethodRegistry); } @Test diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/signschedule/SignScheduleTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/signschedule/SignScheduleTranslatorTest.java index 421f8dffb082..8c2c1d6b2b82 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/signschedule/SignScheduleTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hss/signschedule/SignScheduleTranslatorTest.java @@ -47,6 +47,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.signschedule.SignScheduleTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AddressIdConverter; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.mint.MintTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import com.swirlds.config.api.Configuration; @@ -102,11 +103,13 @@ class SignScheduleTranslatorTest { @Mock private ScheduleID scheduleID; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private SignScheduleTranslator subject; @BeforeEach void setUp() { - subject = new SignScheduleTranslator(); + subject = new SignScheduleTranslator(systemContractMethodRegistry); } @Test @@ -121,6 +124,7 @@ void testMatchesWhenSignScheduleEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -142,6 +146,7 @@ void testFailsMatchesWhenSignScheduleEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -163,6 +168,7 @@ void testMatchesWhenAuthorizeScheduleEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -184,6 +190,7 @@ void testFailsMatchesWhenAuthorizeScheduleEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -205,6 +212,7 @@ void testMatchesFailsOnRandomSelector() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -234,6 +242,7 @@ void testScheduleIdForSignScheduleProxy() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // then: @@ -257,7 +266,14 @@ void testScheduleIdForAuthorizeScheduleProxy() { final var input = Bytes.wrapByteBuffer( SignScheduleTranslator.AUTHORIZE_SCHEDULE.encodeCall(Tuple.of(APPROVED_HEADLONG_ADDRESS))); attempt = prepareHssAttemptWithBytesAndCustomConfig( - input, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator, configuration); + input, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry, + configuration); // then: final var call = subject.callFrom(attempt); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/HtsCallAttemptTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/HtsCallAttemptTest.java index cbaefda4b7d7..f400dafd68ce 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/HtsCallAttemptTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/HtsCallAttemptTest.java @@ -71,6 +71,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.transfer.Erc20TransfersTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.transfer.Erc721TransferFromCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.transfer.Erc721TransferFromTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.test.TestHelpers; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import com.swirlds.common.utility.CommonUtils; @@ -105,22 +106,24 @@ class HtsCallAttemptTest extends CallTestBase { private List> callTranslators; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + @BeforeEach void setUp() { callTranslators = List.of( - new AssociationsTranslator(associationsDecoder), - new Erc20TransfersTranslator(), - new Erc721TransferFromTranslator(), - new MintTranslator(mintDecoder), - new ClassicTransfersTranslator(classicTransfersDecoder), - new BalanceOfTranslator(), - new IsApprovedForAllTranslator(), - new NameTranslator(), - new TotalSupplyTranslator(), - new SymbolTranslator(), - new TokenUriTranslator(), - new OwnerOfTranslator(), - new DecimalsTranslator()); + new AssociationsTranslator(associationsDecoder, systemContractMethodRegistry), + new Erc20TransfersTranslator(systemContractMethodRegistry), + new Erc721TransferFromTranslator(systemContractMethodRegistry), + new MintTranslator(mintDecoder, systemContractMethodRegistry), + new ClassicTransfersTranslator(classicTransfersDecoder, systemContractMethodRegistry), + new BalanceOfTranslator(systemContractMethodRegistry), + new IsApprovedForAllTranslator(systemContractMethodRegistry), + new NameTranslator(systemContractMethodRegistry), + new TotalSupplyTranslator(systemContractMethodRegistry), + new SymbolTranslator(systemContractMethodRegistry), + new TokenUriTranslator(systemContractMethodRegistry), + new OwnerOfTranslator(systemContractMethodRegistry), + new DecimalsTranslator(systemContractMethodRegistry)); } @Test @@ -138,6 +141,7 @@ void nonLongZeroAddressesArentTokens() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertNull(subject.redirectToken()); verifyNoInteractions(nativeOperations); @@ -159,6 +163,7 @@ void invalidSelectorLeadsToMissingCall() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertNull(subject.asExecutableCall()); } @@ -178,6 +183,7 @@ void constructsDecimals() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(DecimalsCall.class, subject.asExecutableCall()); } @@ -197,6 +203,7 @@ void constructsTokenUri() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(TokenUriCall.class, subject.asExecutableCall()); } @@ -216,6 +223,7 @@ void constructsOwnerOf() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(OwnerOfCall.class, subject.asExecutableCall()); } @@ -238,6 +246,7 @@ void constructsBalanceOf() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(BalanceOfCall.class, subject.asExecutableCall()); } @@ -261,6 +270,7 @@ void constructsIsApprovedForAllErc() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(IsApprovedForAllCall.class, subject.asExecutableCall()); } @@ -282,6 +292,7 @@ void constructsIsApprovedForAllClassic() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(IsApprovedForAllCall.class, subject.asExecutableCall()); } @@ -301,6 +312,7 @@ void constructsTotalSupply() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(TotalSupplyCall.class, subject.asExecutableCall()); } @@ -320,6 +332,7 @@ void constructsName() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(NameCall.class, subject.asExecutableCall()); } @@ -339,6 +352,7 @@ void constructsSymbol() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(SymbolCall.class, subject.asExecutableCall()); } @@ -369,6 +383,7 @@ void constructsErc721TransferFromRedirectToNonfungible() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(Erc721TransferFromCall.class, subject.asExecutableCall()); } @@ -399,6 +414,7 @@ void constructsErc20TransferFromRedirectToFungible() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(Erc20TransfersCall.class, subject.asExecutableCall()); } @@ -426,6 +442,7 @@ void constructsErc20TransferRedirectToFungible() { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(Erc20TransfersCall.class, subject.asExecutableCall()); } @@ -479,6 +496,7 @@ void constructsAssociations(boolean useExplicitCall, boolean isRedirect, String verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(DispatchForResponseCodeHtsCall.class, subject.asExecutableCall()); @@ -542,6 +560,7 @@ void constructsClassicTransfers(String hexedSelector) { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(ClassicTransfersCall.class, subject.asExecutableCall()); @@ -613,6 +632,7 @@ void constructsMints(String hexedSelector, LinkedTokenType linkedTokenType) { verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); assertInstanceOf(DispatchForResponseCodeHtsCall.class, subject.asExecutableCall()); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/HtsCallFactoryTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/HtsCallFactoryTest.java index 3766b82242f3..7b7c88a72779 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/HtsCallFactoryTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/HtsCallFactoryTest.java @@ -37,6 +37,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.balanceof.BalanceOfCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.balanceof.BalanceOfTranslator; import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.state.ProxyWorldUpdater; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import java.util.ArrayDeque; @@ -78,10 +79,16 @@ class HtsCallFactoryTest extends CallTestBase { private HtsCallFactory subject; + private SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + @BeforeEach void setUp() { subject = new HtsCallFactory( - syntheticIds, addressChecks, verificationStrategies, List.of(new BalanceOfTranslator())); + syntheticIds, + addressChecks, + verificationStrategies, + List.of(new BalanceOfTranslator(systemContractMethodRegistry)), + systemContractMethodRegistry); } @Test diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/airdrops/TokenAirdropTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/airdrops/TokenAirdropTranslatorTest.java index cd1d0d159f05..3d9405c16574 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/airdrops/TokenAirdropTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/airdrops/TokenAirdropTranslatorTest.java @@ -39,6 +39,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.airdrops.TokenAirdropDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.airdrops.TokenAirdropTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.mint.MintTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import com.hedera.node.config.data.ContractsConfig; @@ -87,11 +88,13 @@ class TokenAirdropTranslatorTest extends CallTestBase { @Mock private AccountID payerId; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private TokenAirdropTranslator translator; @BeforeEach void setUp() { - translator = new TokenAirdropTranslator(decoder); + translator = new TokenAirdropTranslator(decoder, systemContractMethodRegistry); } @Test @@ -103,6 +106,7 @@ void matchesWhenAirdropEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(true)); assertTrue(translator.matches(attempt)); } @@ -116,6 +120,7 @@ void doesNotMatchWhenAirdropDisabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(false)); assertFalse(translator.matches(attempt)); } @@ -131,6 +136,7 @@ void matchesFailsForRandomSelector() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); boolean result = translator.matches(attempt); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/allowance/GetAllowanceTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/allowance/GetAllowanceTranslatorTest.java index e5eb55a61a3f..d7130c385687 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/allowance/GetAllowanceTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/allowance/GetAllowanceTranslatorTest.java @@ -35,6 +35,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.allowance.GetAllowanceCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.allowance.GetAllowanceTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -65,22 +66,36 @@ public class GetAllowanceTranslatorTest { private GetAllowanceTranslator subject; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + @BeforeEach void setUp() { - subject = new GetAllowanceTranslator(); + subject = new GetAllowanceTranslator(systemContractMethodRegistry); } @Test void matchesGetAllowance() { attempt = prepareHtsAttemptWithSelector( - GET_ALLOWANCE, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + GET_ALLOWANCE, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesERCGetAllowance() { attempt = prepareHtsAttemptWithSelector( - ERC_GET_ALLOWANCE, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + ERC_GET_ALLOWANCE, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -92,7 +107,8 @@ void failsOnInvalidSelector() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/burn/BurnTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/burn/BurnTranslatorTest.java index dbc41b5506d4..de488bc98bbd 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/burn/BurnTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/burn/BurnTranslatorTest.java @@ -29,6 +29,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.burn.BurnDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.burn.BurnTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -54,26 +55,40 @@ class BurnTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private BurnTranslator subject; private final BurnDecoder decoder = new BurnDecoder(); @BeforeEach void setUp() { - subject = new BurnTranslator(decoder); + subject = new BurnTranslator(decoder, systemContractMethodRegistry); } @Test void matchesBurnTokenV1() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V1, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V1, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesBurnTokenV2() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -85,7 +100,8 @@ void matchFailsOnInvalidSelector() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropDecoderTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropDecoderTest.java index a0a699bc70f6..6f7acfdc20e4 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropDecoderTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropDecoderTest.java @@ -18,7 +18,7 @@ import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TOKEN_ID; import static com.hedera.hapi.node.base.ResponseCodeEnum.PENDING_AIRDROP_ID_LIST_TOO_LONG; -import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.cancelairdrops.TokenCancelAirdropTranslator.CANCEL_AIRDROP; +import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.cancelairdrops.TokenCancelAirdropTranslator.CANCEL_AIRDROPS; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.cancelairdrops.TokenCancelAirdropTranslator.HRC_CANCEL_AIRDROP_FT; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.cancelairdrops.TokenCancelAirdropTranslator.HRC_CANCEL_AIRDROP_NFT; import static com.hedera.node.app.service.contract.impl.test.TestHelpers.FUNGIBLE_TOKEN; @@ -99,7 +99,7 @@ void cancelAirdropDecoder1FTTest() { .willReturn(SENDER_ID); given(addressIdConverter.convert(OWNER_ACCOUNT_AS_ADDRESS)).willReturn(OWNER_ID); - final var encoded = Bytes.wrapByteBuffer(CANCEL_AIRDROP.encodeCall(Tuple.singleton(new Tuple[] { + final var encoded = Bytes.wrapByteBuffer(CANCEL_AIRDROPS.encodeCall(Tuple.singleton(new Tuple[] { Tuple.of( asHeadlongAddress(SENDER_ID.accountNum()), OWNER_ACCOUNT_AS_ADDRESS, @@ -133,7 +133,7 @@ void failsIfPendingAirdropsAboveLimit() { FUNGIBLE_TOKEN_HEADLONG_ADDRESS, 0L); final var encoded = - Bytes.wrapByteBuffer(CANCEL_AIRDROP.encodeCall(Tuple.singleton(new Tuple[] {tuple, tuple, tuple}))); + Bytes.wrapByteBuffer(CANCEL_AIRDROPS.encodeCall(Tuple.singleton(new Tuple[] {tuple, tuple, tuple}))); given(attempt.inputBytes()).willReturn(encoded.toArrayUnsafe()); assertThatExceptionOfType(HandleException.class) @@ -150,7 +150,7 @@ void failsIfTokenIsNull() { .willReturn(SENDER_ID); given(addressIdConverter.convert(OWNER_ACCOUNT_AS_ADDRESS)).willReturn(OWNER_ID); - final var encoded = Bytes.wrapByteBuffer(CANCEL_AIRDROP.encodeCall(Tuple.singleton(new Tuple[] { + final var encoded = Bytes.wrapByteBuffer(CANCEL_AIRDROPS.encodeCall(Tuple.singleton(new Tuple[] { Tuple.of( asHeadlongAddress(SENDER_ID.accountNum()), OWNER_ACCOUNT_AS_ADDRESS, @@ -173,7 +173,7 @@ void cancelAirdropDecoder1NFTTest() { .willReturn(SENDER_ID); given(addressIdConverter.convert(OWNER_ACCOUNT_AS_ADDRESS)).willReturn(OWNER_ID); - final var encoded = Bytes.wrapByteBuffer(CANCEL_AIRDROP.encodeCall(Tuple.singleton(new Tuple[] { + final var encoded = Bytes.wrapByteBuffer(CANCEL_AIRDROPS.encodeCall(Tuple.singleton(new Tuple[] { Tuple.of( asHeadlongAddress(SENDER_ID.accountNum()), OWNER_ACCOUNT_AS_ADDRESS, diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropTranslatorTest.java index 26568e3d7d0a..f63813e8261c 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/cancelairdrops/TokenCancelAirdropTranslatorTest.java @@ -40,6 +40,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.cancelairdrops.TokenCancelAirdropDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.cancelairdrops.TokenCancelAirdropTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.mint.MintTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import com.hedera.node.config.data.ContractsConfig; import com.swirlds.config.api.Configuration; @@ -88,11 +89,13 @@ class TokenCancelAirdropTranslatorTest { @Mock private AccountID payerId; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private TokenCancelAirdropTranslator subject; @BeforeEach void setUp() { - subject = new TokenCancelAirdropTranslator(decoder); + subject = new TokenCancelAirdropTranslator(decoder, systemContractMethodRegistry); } @Test @@ -101,12 +104,13 @@ void matchesHTSCancelAirdropEnabled() { given(configuration.getConfigData(ContractsConfig.class)).willReturn(contractsConfig); given(contractsConfig.systemContractCancelAirdropsEnabled()).willReturn(true); attempt = prepareHtsAttemptWithSelectorAndCustomConfig( - TokenCancelAirdropTranslator.CANCEL_AIRDROP, + TokenCancelAirdropTranslator.CANCEL_AIRDROPS, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -128,6 +132,7 @@ void matchesFailsOnWrongSelector() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -143,12 +148,13 @@ void matchesHTSCancelAirdropDisabled() { given(configuration.getConfigData(ContractsConfig.class)).willReturn(contractsConfig); given(contractsConfig.systemContractCancelAirdropsEnabled()).willReturn(false); attempt = prepareHtsAttemptWithSelectorAndCustomConfig( - TokenCancelAirdropTranslator.CANCEL_AIRDROP, + TokenCancelAirdropTranslator.CANCEL_AIRDROPS, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -171,6 +177,7 @@ void matchesHRCCancelFTAirdropEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -193,6 +200,7 @@ void matchesHRCCancelAirdropDisabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -215,6 +223,7 @@ void matchesHRCCancelNFTAirdropEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -237,6 +246,7 @@ void matchesHRCCancelNFTAirdropDisabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: boolean matches = subject.matches(attempt); @@ -263,12 +273,13 @@ void callFromHtsCancelAirdrop() { given(verificationStrategies.activatingOnlyContractKeysFor(any(), anyBoolean(), any())) .willReturn(verificationStrategy); attempt = prepareHtsAttemptWithSelectorAndCustomConfig( - TokenCancelAirdropTranslator.CANCEL_AIRDROP, + TokenCancelAirdropTranslator.CANCEL_AIRDROPS, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -292,6 +303,7 @@ void callFromHRCCancelFTAirdrop() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -315,6 +327,7 @@ void callFromHRCCancelNFTAirdrop() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropDecoderTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropDecoderTest.java index bcb244eb2303..3724cfb0bbc8 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropDecoderTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropDecoderTest.java @@ -17,7 +17,7 @@ package com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.hts.claimairdrops; import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TOKEN_ID; -import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.claimairdrops.TokenClaimAirdropTranslator.CLAIM_AIRDROP; +import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.claimairdrops.TokenClaimAirdropTranslator.CLAIM_AIRDROPS; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.claimairdrops.TokenClaimAirdropTranslator.HRC_CLAIM_AIRDROP_FT; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.claimairdrops.TokenClaimAirdropTranslator.HRC_CLAIM_AIRDROP_NFT; import static com.hedera.node.app.service.contract.impl.test.TestHelpers.FUNGIBLE_TOKEN; @@ -99,7 +99,7 @@ void claimAirdropDecoder1FTTest() { given(addressIdConverter.convert(asHeadlongAddress(SENDER_ID.accountNum()))) .willReturn(SENDER_ID); - final var encoded = Bytes.wrapByteBuffer(CLAIM_AIRDROP.encodeCall(Tuple.singleton(new Tuple[] { + final var encoded = Bytes.wrapByteBuffer(CLAIM_AIRDROPS.encodeCall(Tuple.singleton(new Tuple[] { Tuple.of( asHeadlongAddress(SENDER_ID.accountNum()), OWNER_ACCOUNT_AS_ADDRESS, @@ -129,7 +129,7 @@ void failsIfPendingAirdropsAboveLimit() { given(configuration.getConfigData(TokensConfig.class)).willReturn(tokensConfig); given(tokensConfig.maxAllowedPendingAirdropsToClaim()).willReturn(10); - final var encoded = Bytes.wrapByteBuffer(CLAIM_AIRDROP.encodeCall(Tuple.singleton(new Tuple[] { + final var encoded = Bytes.wrapByteBuffer(CLAIM_AIRDROPS.encodeCall(Tuple.singleton(new Tuple[] { Tuple.of( asHeadlongAddress(SENDER_ID.accountNum()), OWNER_ACCOUNT_AS_ADDRESS, @@ -204,7 +204,7 @@ void failsIfTokenIsNull() { .willReturn(SENDER_ID); given(addressIdConverter.convert(OWNER_ACCOUNT_AS_ADDRESS)).willReturn(OWNER_ID); - final var encoded = Bytes.wrapByteBuffer(CLAIM_AIRDROP.encodeCall(Tuple.singleton(new Tuple[] { + final var encoded = Bytes.wrapByteBuffer(CLAIM_AIRDROPS.encodeCall(Tuple.singleton(new Tuple[] { Tuple.of( asHeadlongAddress(SENDER_ID.accountNum()), OWNER_ACCOUNT_AS_ADDRESS, @@ -252,7 +252,7 @@ void claimAirdropDecoder1NFTTest() { .willReturn(SENDER_ID); given(addressIdConverter.convert(OWNER_ACCOUNT_AS_ADDRESS)).willReturn(OWNER_ID); - final var encoded = Bytes.wrapByteBuffer(CLAIM_AIRDROP.encodeCall(Tuple.singleton(new Tuple[] { + final var encoded = Bytes.wrapByteBuffer(CLAIM_AIRDROPS.encodeCall(Tuple.singleton(new Tuple[] { Tuple.of( asHeadlongAddress(SENDER_ID.accountNum()), OWNER_ACCOUNT_AS_ADDRESS, diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropTranslatorTest.java index ee5655def64e..37edfb581a14 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/claimairdrops/TokenClaimAirdropTranslatorTest.java @@ -41,6 +41,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.claimairdrops.TokenClaimAirdropDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.claimairdrops.TokenClaimAirdropTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.mint.MintTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import com.swirlds.config.api.Configuration; @@ -89,11 +90,13 @@ class TokenClaimAirdropTranslatorTest { @Mock private AccountID payerId; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private TokenClaimAirdropTranslator subject; @BeforeEach void setUp() { - subject = new TokenClaimAirdropTranslator(decoder); + subject = new TokenClaimAirdropTranslator(decoder, systemContractMethodRegistry); } @Test @@ -102,12 +105,13 @@ void testMatchesWhenClaimAirdropEnabled() { given(configuration.getConfigData(ContractsConfig.class)).willReturn(contractsConfig); given(contractsConfig.systemContractClaimAirdropsEnabled()).willReturn(true); attempt = prepareHtsAttemptWithSelectorAndCustomConfig( - TokenClaimAirdropTranslator.CLAIM_AIRDROP, + TokenClaimAirdropTranslator.CLAIM_AIRDROPS, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -129,6 +133,7 @@ void testMatchesFailsOnRandomSelector() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -145,12 +150,13 @@ void testMatchesWhenClaimAirdropDisabled() { given(configuration.getConfigData(ContractsConfig.class)).willReturn(contractsConfig); given(contractsConfig.systemContractClaimAirdropsEnabled()).willReturn(false); attempt = prepareHtsAttemptWithSelectorAndCustomConfig( - TokenClaimAirdropTranslator.CLAIM_AIRDROP, + TokenClaimAirdropTranslator.CLAIM_AIRDROPS, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -173,6 +179,7 @@ void testMatchesHRCClaimFT() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -195,6 +202,7 @@ void testMatchesHRCClaimNFT() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -217,6 +225,7 @@ void testMatchesHRCClaimFTDisabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -239,6 +248,7 @@ void testMatchesHRCClaimNFTDisabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -255,12 +265,13 @@ void testCallFromForClassic() { given(verificationStrategies.activatingOnlyContractKeysFor(any(), anyBoolean(), any())) .willReturn(verificationStrategy); attempt = prepareHtsAttemptWithSelectorAndCustomConfig( - TokenClaimAirdropTranslator.CLAIM_AIRDROP, + TokenClaimAirdropTranslator.CLAIM_AIRDROPS, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -284,6 +295,7 @@ void callFromHRCClaimFTAirdrop() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -307,6 +319,7 @@ void callFromHRCCancelNFTAirdrop() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/create/CreateTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/create/CreateTranslatorTest.java index 2218e31402b0..398a457b7702 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/create/CreateTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/create/CreateTranslatorTest.java @@ -65,6 +65,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.create.ClassicCreatesCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.create.CreateDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.create.CreateTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import com.hedera.node.config.data.ContractsConfig; @@ -106,13 +107,15 @@ public class CreateTranslatorTest extends CallTestBase { @Mock Configuration configuration; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private CreateDecoder decoder = new CreateDecoder(); private CreateTranslator subject; @BeforeEach void setUp() { - subject = new CreateTranslator(decoder); + subject = new CreateTranslator(decoder, systemContractMethodRegistry); } @Test @@ -123,7 +126,8 @@ void matchesCreateFungibleTokenV1() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -135,7 +139,8 @@ void matchesCreateFungibleTokenV2() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -147,7 +152,8 @@ void matchesCreateFungibleTokenV3() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -161,6 +167,7 @@ void matchesCreateFungibleTokenWithMetadata() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -173,7 +180,8 @@ void matchesCreateFungibleTokenWithCustomFeesV1() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -185,7 +193,8 @@ void matchesCreateFungibleTokenWithCustomFeesV2() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -197,7 +206,8 @@ void matchesCreateFungibleTokenWithCustomFeesV3() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -211,6 +221,7 @@ void matchesCreateFungibleTokenWithMetadataAndCustomFees() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -223,7 +234,8 @@ void matchesCreateNonFungibleTokenV1() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -235,7 +247,8 @@ void matchesCreateNonFungibleTokenV2() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -247,7 +260,8 @@ void matchesCreateNonFungibleTokenV3() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -261,6 +275,7 @@ void matchesCreateNonFungibleTokenWithMetadata() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -273,7 +288,8 @@ void matchesCreateNonFungibleTokenWithCustomFeesV1() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -285,7 +301,8 @@ void matchesCreateNonFungibleTokenWithCustomFeesV2() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -297,7 +314,8 @@ void matchesCreateNonFungibleTokenWithCustomFeesV3() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -311,6 +329,7 @@ void matchesCreateNonFungibleTokenWithMetadataAndCustomFees() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -318,7 +337,13 @@ void matchesCreateNonFungibleTokenWithMetadataAndCustomFees() { @Test void falseOnInvalidSelector() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/customfees/TokenCustomFeesTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/customfees/TokenCustomFeesTranslatorTest.java index 9fc99c88e126..fbc806181225 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/customfees/TokenCustomFeesTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/customfees/TokenCustomFeesTranslatorTest.java @@ -32,6 +32,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.customfees.TokenCustomFeesCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.customfees.TokenCustomFeesTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -57,24 +58,38 @@ class TokenCustomFeesTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private TokenCustomFeesTranslator subject; @BeforeEach void setUp() { - subject = new TokenCustomFeesTranslator(); + subject = new TokenCustomFeesTranslator(systemContractMethodRegistry); } @Test void matchesTokenCustomFeesTranslatorTest() { attempt = prepareHtsAttemptWithSelector( - TOKEN_CUSTOM_FEES, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + TOKEN_CUSTOM_FEES, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/defaultfreezestatus/DefaultFreezeStatusTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/defaultfreezestatus/DefaultFreezeStatusTranslatorTest.java index 298efd01b86e..d3089d7b1206 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/defaultfreezestatus/DefaultFreezeStatusTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/defaultfreezestatus/DefaultFreezeStatusTranslatorTest.java @@ -32,6 +32,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.defaultfreezestatus.DefaultFreezeStatusCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.defaultfreezestatus.DefaultFreezeStatusTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -57,24 +58,38 @@ class DefaultFreezeStatusTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private DefaultFreezeStatusTranslator subject; @BeforeEach void setUp() { - subject = new DefaultFreezeStatusTranslator(); + subject = new DefaultFreezeStatusTranslator(systemContractMethodRegistry); } @Test void matchesDefaultFreezeTranslatorTest() { attempt = prepareHtsAttemptWithSelector( - DEFAULT_FREEZE_STATUS, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + DEFAULT_FREEZE_STATUS, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/defaultkycstatus/DefaultKycStatusTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/defaultkycstatus/DefaultKycStatusTranslatorTest.java index 659ec1afd115..b95460c4955a 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/defaultkycstatus/DefaultKycStatusTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/defaultkycstatus/DefaultKycStatusTranslatorTest.java @@ -32,6 +32,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.defaultkycstatus.DefaultKycStatusCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.defaultkycstatus.DefaultKycStatusTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -57,24 +58,38 @@ class DefaultKycStatusTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private DefaultKycStatusTranslator subject; @BeforeEach void setUp() { - subject = new DefaultKycStatusTranslator(); + subject = new DefaultKycStatusTranslator(systemContractMethodRegistry); } @Test void matchesDefaultKycTranslatorTest() { attempt = prepareHtsAttemptWithSelector( - DEFAULT_KYC_STATUS, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + DEFAULT_KYC_STATUS, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/delete/DeleteTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/delete/DeleteTranslatorTest.java index f7197a42a9b4..9a0cd70aa142 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/delete/DeleteTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/delete/DeleteTranslatorTest.java @@ -35,6 +35,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.DispatchForResponseCodeHtsCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.delete.DeleteTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -63,24 +64,38 @@ class DeleteTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private DeleteTranslator subject; @BeforeEach void setUp() { - subject = new DeleteTranslator(); + subject = new DeleteTranslator(systemContractMethodRegistry); } @Test void matchesDelete() { attempt = prepareHtsAttemptWithSelector( - DELETE_TOKEN, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + DELETE_TOKEN, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/freeze/FreezeUnfreezeTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/freeze/FreezeUnfreezeTranslatorTest.java index f7b385fedb4d..558816a715ad 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/freeze/FreezeUnfreezeTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/freeze/FreezeUnfreezeTranslatorTest.java @@ -29,6 +29,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.freeze.FreezeUnfreezeDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.freeze.FreezeUnfreezeTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -54,32 +55,52 @@ class FreezeUnfreezeTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private final FreezeUnfreezeDecoder decoder = new FreezeUnfreezeDecoder(); private FreezeUnfreezeTranslator subject; @BeforeEach void setUp() { - subject = new FreezeUnfreezeTranslator(decoder); + subject = new FreezeUnfreezeTranslator(decoder, systemContractMethodRegistry); } @Test void freezeMatches() { attempt = prepareHtsAttemptWithSelector( - FREEZE, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + FREEZE, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void unfreezeMatches() { attempt = prepareHtsAttemptWithSelector( - UNFREEZE, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + UNFREEZE, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void falseOnInvalidSelector() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/fungibletokeninfo/FungibleTokenInfoCallTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/fungibletokeninfo/FungibleTokenInfoCallTest.java index e05e758382e9..50fde61c593a 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/fungibletokeninfo/FungibleTokenInfoCallTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/fungibletokeninfo/FungibleTokenInfoCallTest.java @@ -63,7 +63,12 @@ void returnsFungibleTokenInfoStatusForPresentToken() { when(ledgerConfig.id()).thenReturn(expectedLedgerId); final var subject = new FungibleTokenInfoCall( - gasCalculator, mockEnhancement(), false, FUNGIBLE_EVERYTHING_TOKEN, config, FUNGIBLE_TOKEN_INFO); + gasCalculator, + mockEnhancement(), + false, + FUNGIBLE_EVERYTHING_TOKEN, + config, + FUNGIBLE_TOKEN_INFO.function()); final var result = subject.execute().fullResult().result(); @@ -106,7 +111,12 @@ void returnsFungibleTokenInfoStatusForPresentTokenV2() { when(ledgerConfig.id()).thenReturn(expectedLedgerId); final var subject = new FungibleTokenInfoCall( - gasCalculator, mockEnhancement(), false, FUNGIBLE_EVERYTHING_TOKEN_V2, config, FUNGIBLE_TOKEN_INFO_V2); + gasCalculator, + mockEnhancement(), + false, + FUNGIBLE_EVERYTHING_TOKEN_V2, + config, + FUNGIBLE_TOKEN_INFO_V2.function()); final var result = subject.execute().fullResult().result(); @@ -150,8 +160,8 @@ void returnsFungibleTokenInfoStatusForMissingToken() { final var expectedLedgerId = com.hedera.pbj.runtime.io.buffer.Bytes.fromHex("01"); when(ledgerConfig.id()).thenReturn(expectedLedgerId); - final var subject = - new FungibleTokenInfoCall(gasCalculator, mockEnhancement(), false, null, config, FUNGIBLE_TOKEN_INFO); + final var subject = new FungibleTokenInfoCall( + gasCalculator, mockEnhancement(), false, null, config, FUNGIBLE_TOKEN_INFO.function()); final var result = subject.execute().fullResult().result(); @@ -192,8 +202,8 @@ void returnsFungibleTokenInfoStatusForMissingTokenStaticCall() { when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig); when(ledgerConfig.id()).thenReturn(com.hedera.pbj.runtime.io.buffer.Bytes.fromHex("01")); - final var subject = - new FungibleTokenInfoCall(gasCalculator, mockEnhancement(), true, null, config, FUNGIBLE_TOKEN_INFO); + final var subject = new FungibleTokenInfoCall( + gasCalculator, mockEnhancement(), true, null, config, FUNGIBLE_TOKEN_INFO.function()); final var result = subject.execute().fullResult().result(); @@ -206,8 +216,8 @@ void returnsFungibleTokenInfoStatusForMissingTokenStaticCallV2() { when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig); when(ledgerConfig.id()).thenReturn(com.hedera.pbj.runtime.io.buffer.Bytes.fromHex("01")); - final var subject = - new FungibleTokenInfoCall(gasCalculator, mockEnhancement(), true, null, config, FUNGIBLE_TOKEN_INFO_V2); + final var subject = new FungibleTokenInfoCall( + gasCalculator, mockEnhancement(), true, null, config, FUNGIBLE_TOKEN_INFO_V2.function()); final var result = subject.execute().fullResult().result(); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/fungibletokeninfo/FungibleTokenInfoTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/fungibletokeninfo/FungibleTokenInfoTranslatorTest.java index 7e2ea0055dcd..e68e4c254a40 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/fungibletokeninfo/FungibleTokenInfoTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/fungibletokeninfo/FungibleTokenInfoTranslatorTest.java @@ -34,6 +34,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.fungibletokeninfo.FungibleTokenInfoCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.fungibletokeninfo.FungibleTokenInfoTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import com.hedera.node.config.data.ContractsConfig; import com.swirlds.config.api.Configuration; @@ -67,17 +68,25 @@ class FungibleTokenInfoTranslatorTest { @Mock private ContractsConfig contractsConfig; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private FungibleTokenInfoTranslator subject; @BeforeEach void setUp() { - subject = new FungibleTokenInfoTranslator(); + subject = new FungibleTokenInfoTranslator(systemContractMethodRegistry); } @Test void matchesFungibleTokenInfoTranslatorTest() { attempt = prepareHtsAttemptWithSelector( - FUNGIBLE_TOKEN_INFO, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + FUNGIBLE_TOKEN_INFO, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -92,6 +101,7 @@ void matchesFungibleTokenInfoTranslatorTestV2() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -99,7 +109,13 @@ void matchesFungibleTokenInfoTranslatorTestV2() { @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/getapproved/GetApprovedTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/getapproved/GetApprovedTranslatorTest.java index 0a28fc47cf6a..4922a164ba68 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/getapproved/GetApprovedTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/getapproved/GetApprovedTranslatorTest.java @@ -38,6 +38,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.getapproved.GetApprovedCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.getapproved.GetApprovedTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import java.math.BigInteger; import org.apache.tuweni.bytes.Bytes; @@ -73,11 +74,13 @@ public class GetApprovedTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private GetApprovedTranslator subject; @BeforeEach void setUp() { - subject = new GetApprovedTranslator(); + subject = new GetApprovedTranslator(systemContractMethodRegistry); } @Test @@ -85,21 +88,39 @@ void matchesErcGetApprovedTest() { given(enhancement.nativeOperations()).willReturn(nativeOperations); given(nativeOperations.getToken(anyLong())).willReturn(FUNGIBLE_TOKEN); attempt = prepareHtsAttemptWithSelectorForRedirect( - ERC_GET_APPROVED, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + ERC_GET_APPROVED, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesHapiGetApprovedTest() { attempt = prepareHtsAttemptWithSelector( - HAPI_GET_APPROVED, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + HAPI_GET_APPROVED, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsOnIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/grantapproval/GrantApprovalTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/grantapproval/GrantApprovalTranslatorTest.java index f04ef6829ca9..b09aa0c0d891 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/grantapproval/GrantApprovalTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/grantapproval/GrantApprovalTranslatorTest.java @@ -49,6 +49,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.grantapproval.ERCGrantApprovalCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.grantapproval.GrantApprovalDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.grantapproval.GrantApprovalTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import java.math.BigInteger; import org.apache.tuweni.bytes.Bytes; @@ -82,18 +83,26 @@ class GrantApprovalTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private final GrantApprovalDecoder decoder = new GrantApprovalDecoder(); private GrantApprovalTranslator subject; @BeforeEach void setUp() { - subject = new GrantApprovalTranslator(decoder); + subject = new GrantApprovalTranslator(decoder, systemContractMethodRegistry); } @Test void grantApprovalMatches() { attempt = prepareHtsAttemptWithSelector( - GRANT_APPROVAL, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + GRANT_APPROVAL, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -102,7 +111,13 @@ void ERCGrantApprovalMatches() { given(enhancement.nativeOperations()).willReturn(nativeOperations); given(nativeOperations.getToken(anyLong())).willReturn(FUNGIBLE_TOKEN); attempt = prepareHtsAttemptWithSelectorForRedirect( - ERC_GRANT_APPROVAL, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + ERC_GRANT_APPROVAL, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -116,21 +131,34 @@ void ERCGrantApprovalNFTMatches() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void grantApprovalNFTMatches() { attempt = prepareHtsAttemptWithSelector( - GRANT_APPROVAL_NFT, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + GRANT_APPROVAL_NFT, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void falseOnInvalidSelector() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/grantrevokekyc/GrantRevokeKycTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/grantrevokekyc/GrantRevokeKycTranslatorTest.java index bf770ec30f67..a0a98f086f38 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/grantrevokekyc/GrantRevokeKycTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/grantrevokekyc/GrantRevokeKycTranslatorTest.java @@ -29,6 +29,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.grantrevokekyc.GrantRevokeKycDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.grantrevokekyc.GrantRevokeKycTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,32 +54,52 @@ class GrantRevokeKycTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private final GrantRevokeKycDecoder decoder = new GrantRevokeKycDecoder(); private GrantRevokeKycTranslator subject; @BeforeEach void setUp() { - subject = new GrantRevokeKycTranslator(decoder); + subject = new GrantRevokeKycTranslator(decoder, systemContractMethodRegistry); } @Test void matchesGrantKycTest() { attempt = prepareHtsAttemptWithSelector( - GRANT_KYC, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + GRANT_KYC, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesRevokeKycTest() { attempt = prepareHtsAttemptWithSelector( - REVOKE_KYC, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + REVOKE_KYC, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsWithIncorrectSelector() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/isassociated/IsAssociatedTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/isassociated/IsAssociatedTranslatorTest.java index 90031120546d..f11b152d4ca7 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/isassociated/IsAssociatedTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/isassociated/IsAssociatedTranslatorTest.java @@ -36,6 +36,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.isassociated.IsAssociatedCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.isassociated.IsAssociatedTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -64,11 +65,13 @@ class IsAssociatedTranslatorTest { @Mock private HederaNativeOperations nativeOperations; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private IsAssociatedTranslator translator; @BeforeEach void setUp() { - translator = new IsAssociatedTranslator(); + translator = new IsAssociatedTranslator(systemContractMethodRegistry); } @Test @@ -76,7 +79,13 @@ void matchesWithCorrectSelectorAndTokenRedirectReturnsTrue() { given(enhancement.nativeOperations()).willReturn(nativeOperations); given(nativeOperations.getToken(anyLong())).willReturn(FUNGIBLE_TOKEN); mockAttempt = prepareHtsAttemptWithSelectorForRedirect( - IS_ASSOCIATED, translator, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + IS_ASSOCIATED, + translator, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(translator.matches(mockAttempt)); } @@ -85,7 +94,13 @@ void matchesWithIncorrectSelectorReturnsFalse() { given(enhancement.nativeOperations()).willReturn(nativeOperations); given(nativeOperations.getToken(anyLong())).willReturn(FUNGIBLE_TOKEN); mockAttempt = prepareHtsAttemptWithSelectorForRedirect( - BURN_TOKEN_V2, translator, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + translator, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(translator.matches(mockAttempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/isfrozen/IsFrozenTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/isfrozen/IsFrozenTranslatorTest.java index bcd26241eaf3..4c5aa4364c60 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/isfrozen/IsFrozenTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/isfrozen/IsFrozenTranslatorTest.java @@ -35,6 +35,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.isfrozen.IsFrozenCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.isfrozen.IsFrozenTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -63,24 +64,38 @@ class IsFrozenTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private IsFrozenTranslator subject; @BeforeEach void setUp() { - subject = new IsFrozenTranslator(); + subject = new IsFrozenTranslator(systemContractMethodRegistry); } @Test void matchesIsFrozenTest() { attempt = prepareHtsAttemptWithSelector( - IS_FROZEN, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + IS_FROZEN, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/iskyc/IsKycTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/iskyc/IsKycTranslatorTest.java index 9d7b901b7b73..a80cebd8bd9f 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/iskyc/IsKycTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/iskyc/IsKycTranslatorTest.java @@ -35,6 +35,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.iskyc.IsKycCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.iskyc.IsKycTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -63,24 +64,38 @@ class IsKycTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private IsKycTranslator subject; @BeforeEach void setUp() { - subject = new IsKycTranslator(); + subject = new IsKycTranslator(systemContractMethodRegistry); } @Test void matchesIsKycTest() { attempt = prepareHtsAttemptWithSelector( - IS_KYC, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + IS_KYC, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenTranslatorTest.java index e1bb35eb85c6..a40da2b5d4e5 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenTranslatorTest.java @@ -32,6 +32,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.istoken.IsTokenCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.istoken.IsTokenTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -57,24 +58,38 @@ class IsTokenTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private IsTokenTranslator subject; @BeforeEach void setUp() { - subject = new IsTokenTranslator(); + subject = new IsTokenTranslator(systemContractMethodRegistry); } @Test void matchesIsTokenTest() { attempt = prepareHtsAttemptWithSelector( - IS_TOKEN, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + IS_TOKEN, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/mint/MintTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/mint/MintTranslatorTest.java index 2e7bd891de75..957702128f37 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/mint/MintTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/mint/MintTranslatorTest.java @@ -29,6 +29,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.mint.MintDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.mint.MintTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,33 +54,53 @@ class MintTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private MintTranslator subject; private final MintDecoder decoder = new MintDecoder(); @BeforeEach void setUp() { - subject = new MintTranslator(decoder); + subject = new MintTranslator(decoder, systemContractMethodRegistry); } @Test void matchesMintV1Test() { attempt = prepareHtsAttemptWithSelector( - MINT, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + MINT, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesMintV2Test() { attempt = prepareHtsAttemptWithSelector( - MINT_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + MINT_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchFailsOnIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCallTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCallTest.java index 23a9afcfee0a..fdf28de0c679 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCallTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoCallTest.java @@ -80,7 +80,7 @@ void returnsNftTokenInfoStatusForPresentToken() { FUNGIBLE_EVERYTHING_TOKEN, 2L, config, - NON_FUNGIBLE_TOKEN_INFO); + NON_FUNGIBLE_TOKEN_INFO.function()); final var result = subject.execute().fullResult().result(); @@ -139,7 +139,7 @@ void returnsNftTokenInfoStatusForPresentTokenV2() { FUNGIBLE_EVERYTHING_TOKEN_V2, 2L, config, - NON_FUNGIBLE_TOKEN_INFO_V2); + NON_FUNGIBLE_TOKEN_INFO_V2.function()); final var result = subject.execute().fullResult().result(); @@ -189,7 +189,7 @@ void returnsNftTokenInfoStatusForMissingToken() { when(ledgerConfig.id()).thenReturn(expectedLedgerId); final var subject = new NftTokenInfoCall( - gasCalculator, mockEnhancement(), false, null, 0L, config, NON_FUNGIBLE_TOKEN_INFO); + gasCalculator, mockEnhancement(), false, null, 0L, config, NON_FUNGIBLE_TOKEN_INFO.function()); final var result = subject.execute().fullResult().result(); @@ -231,8 +231,8 @@ void returnsNftTokenInfoStatusForMissingToken() { @Test void returnsNftTokenInfoStatusForMissingTokenStaticCall() { - final var subject = - new NftTokenInfoCall(gasCalculator, mockEnhancement(), true, null, 0L, config, NON_FUNGIBLE_TOKEN_INFO); + final var subject = new NftTokenInfoCall( + gasCalculator, mockEnhancement(), true, null, 0L, config, NON_FUNGIBLE_TOKEN_INFO.function()); final var result = subject.execute().fullResult().result(); @@ -243,7 +243,7 @@ void returnsNftTokenInfoStatusForMissingTokenStaticCall() { @Test void returnsNftTokenInfoStatusForMissingTokenStaticCallV2() { final var subject = new NftTokenInfoCall( - gasCalculator, mockEnhancement(), true, null, 0L, config, NON_FUNGIBLE_TOKEN_INFO_V2); + gasCalculator, mockEnhancement(), true, null, 0L, config, NON_FUNGIBLE_TOKEN_INFO_V2.function()); final var result = subject.execute().fullResult().result(); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoTranslatorTest.java index 5516a98a808e..00c1d05e39d9 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/nfttokeninfo/NftTokenInfoTranslatorTest.java @@ -34,6 +34,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.nfttokeninfo.NftTokenInfoCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.nfttokeninfo.NftTokenInfoTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import com.hedera.node.config.data.ContractsConfig; import com.swirlds.config.api.Configuration; @@ -67,11 +68,13 @@ class NftTokenInfoTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private NftTokenInfoTranslator subject; @BeforeEach void setUp() { - subject = new NftTokenInfoTranslator(); + subject = new NftTokenInfoTranslator(systemContractMethodRegistry); } @Test @@ -82,7 +85,8 @@ void matchesTokenInfoTranslatorTest() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -97,6 +101,7 @@ void matchesTokenInfoTranslatorTestV2() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -104,7 +109,13 @@ void matchesTokenInfoTranslatorTestV2() { @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/pauses/PausesTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/pauses/PausesTranslatorTest.java index 123e8d40255f..f0ec3c1afaec 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/pauses/PausesTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/pauses/PausesTranslatorTest.java @@ -29,6 +29,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.pauses.PausesDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.pauses.PausesTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,33 +54,53 @@ public class PausesTranslatorTest { @Mock private VerificationStrategies verificationStrategies; - private PausesDecoder decoder = new PausesDecoder(); + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + + private final PausesDecoder decoder = new PausesDecoder(); private PausesTranslator subject; @BeforeEach void setUp() { - subject = new PausesTranslator(decoder); + subject = new PausesTranslator(decoder, systemContractMethodRegistry); } @Test void matchesPauseTest() { attempt = prepareHtsAttemptWithSelector( - PAUSE, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + PAUSE, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesUnpauseTest() { attempt = prepareHtsAttemptWithSelector( - UNPAUSE, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + UNPAUSE, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsOnIncorrectSelector() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/rejecttokens/RejectTokensTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/rejecttokens/RejectTokensTranslatorTest.java index 62036e369899..329bb6bfedbd 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/rejecttokens/RejectTokensTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/rejecttokens/RejectTokensTranslatorTest.java @@ -43,6 +43,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.burn.BurnTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.rejecttokens.RejectTokensDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.rejecttokens.RejectTokensTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import com.hedera.node.config.data.ContractsConfig; import com.swirlds.config.api.Configuration; @@ -91,11 +92,13 @@ public class RejectTokensTranslatorTest { @Mock private AccountID payerId; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private RejectTokensTranslator subject; @BeforeEach void setUp() { - subject = new RejectTokensTranslator(decoder); + subject = new RejectTokensTranslator(decoder, systemContractMethodRegistry); } @Test @@ -110,6 +113,7 @@ void matchesHTSWithInvalidSig() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -131,6 +135,7 @@ void matchesHTSWithConfigEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -152,6 +157,7 @@ void matchesHTSWithConfigDisabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -174,6 +180,7 @@ void matchesFungibleHRCWithConfigEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -196,6 +203,7 @@ void matchesFungibleHRCWithConfigDisabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -218,6 +226,7 @@ void matchesNftHRCWithConfigEnabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -240,6 +249,7 @@ void matchesNftHRCWithConfigDisabled() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -302,6 +312,7 @@ void callFromHtsTokenReject() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -325,6 +336,7 @@ void callFromHRCCancelFTAirdrop() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: @@ -348,6 +360,7 @@ void callFromHRCCancelNFTAirdrop() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); // when: diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/setapproval/SetApprovalForAllTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/setapproval/SetApprovalForAllTranslatorTest.java index 287dd55eb857..57029c9523fb 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/setapproval/SetApprovalForAllTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/setapproval/SetApprovalForAllTranslatorTest.java @@ -34,6 +34,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.setapproval.SetApprovalForAllDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.setapproval.SetApprovalForAllTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -64,17 +65,25 @@ public class SetApprovalForAllTranslatorTest { private final SetApprovalForAllDecoder decoder = new SetApprovalForAllDecoder(); + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private SetApprovalForAllTranslator subject; @BeforeEach void setUp() { - subject = new SetApprovalForAllTranslator(decoder); + subject = new SetApprovalForAllTranslator(decoder, systemContractMethodRegistry); } @Test void matchesClassicalSelectorTest() { attempt = prepareHtsAttemptWithSelector( - SET_APPROVAL_FOR_ALL, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + SET_APPROVAL_FOR_ALL, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -88,14 +97,21 @@ void matchesERCSelectorTest() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void falseOnInvalidSelector() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokenexpiry/TokenExpiryTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokenexpiry/TokenExpiryTranslatorTest.java index f315e1cd12cd..1f04d94480cd 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokenexpiry/TokenExpiryTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokenexpiry/TokenExpiryTranslatorTest.java @@ -32,6 +32,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokenexpiry.TokenExpiryCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokenexpiry.TokenExpiryTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -57,24 +58,38 @@ class TokenExpiryTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private TokenExpiryTranslator subject; @BeforeEach void setUp() { - subject = new TokenExpiryTranslator(); + subject = new TokenExpiryTranslator(systemContractMethodRegistry); } @Test void matchesTokenExpiryTranslatorTest() { attempt = prepareHtsAttemptWithSelector( - TOKEN_EXPIRY, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + TOKEN_EXPIRY, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokeninfo/TokenInfoCallTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokeninfo/TokenInfoCallTest.java index 0799ec5d4d1c..9c6ce08c9949 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokeninfo/TokenInfoCallTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokeninfo/TokenInfoCallTest.java @@ -64,7 +64,7 @@ void returnsTokenInfoStatusForPresentToken() { when(ledgerConfig.id()).thenReturn(expectedLedgerId); final var subject = new TokenInfoCall( - gasCalculator, mockEnhancement(), false, FUNGIBLE_EVERYTHING_TOKEN, config, TOKEN_INFO); + gasCalculator, mockEnhancement(), false, FUNGIBLE_EVERYTHING_TOKEN, config, TOKEN_INFO.function()); final var result = subject.execute().fullResult().result(); @@ -105,7 +105,12 @@ void returnsTokenInfoStatusForPresentTokenV2() { when(ledgerConfig.id()).thenReturn(expectedLedgerId); final var subject = new TokenInfoCall( - gasCalculator, mockEnhancement(), false, FUNGIBLE_EVERYTHING_TOKEN_V2, config, TOKEN_INFO_V2); + gasCalculator, + mockEnhancement(), + false, + FUNGIBLE_EVERYTHING_TOKEN_V2, + config, + TOKEN_INFO_V2.function()); final var result = subject.execute().fullResult().result(); @@ -147,7 +152,8 @@ void returnsTokenInfoStatusForMissingToken() { final var expectedLedgerId = com.hedera.pbj.runtime.io.buffer.Bytes.fromHex("01"); when(ledgerConfig.id()).thenReturn(expectedLedgerId); - final var subject = new TokenInfoCall(gasCalculator, mockEnhancement(), false, null, config, TOKEN_INFO); + final var subject = + new TokenInfoCall(gasCalculator, mockEnhancement(), false, null, config, TOKEN_INFO.function()); final var result = subject.execute().fullResult().result(); @@ -186,7 +192,8 @@ void returnsTokenInfoStatusForMissingTokenStaticCall() { when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig); when(ledgerConfig.id()).thenReturn(com.hedera.pbj.runtime.io.buffer.Bytes.fromHex("01")); - final var subject = new TokenInfoCall(gasCalculator, mockEnhancement(), true, null, config, TOKEN_INFO); + final var subject = + new TokenInfoCall(gasCalculator, mockEnhancement(), true, null, config, TOKEN_INFO.function()); final var result = subject.execute().fullResult().result(); @@ -199,7 +206,8 @@ void returnsTokenInfoStatusForMissingTokenStaticCallV2() { when(config.getConfigData(LedgerConfig.class)).thenReturn(ledgerConfig); when(ledgerConfig.id()).thenReturn(com.hedera.pbj.runtime.io.buffer.Bytes.fromHex("01")); - final var subject = new TokenInfoCall(gasCalculator, mockEnhancement(), true, null, config, TOKEN_INFO_V2); + final var subject = + new TokenInfoCall(gasCalculator, mockEnhancement(), true, null, config, TOKEN_INFO_V2.function()); final var result = subject.execute().fullResult().result(); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokeninfo/TokenInfoTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokeninfo/TokenInfoTranslatorTest.java index 8f493844c995..b3ecce51371d 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokeninfo/TokenInfoTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokeninfo/TokenInfoTranslatorTest.java @@ -34,6 +34,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokeninfo.TokenInfoCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokeninfo.TokenInfoTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import com.hedera.node.config.data.ContractsConfig; import com.swirlds.config.api.Configuration; @@ -67,17 +68,25 @@ class TokenInfoTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private TokenInfoTranslator subject; @BeforeEach void setUp() { - subject = new TokenInfoTranslator(); + subject = new TokenInfoTranslator(systemContractMethodRegistry); } @Test void matchesTokenInfoTranslatorTest() { attempt = prepareHtsAttemptWithSelector( - TOKEN_INFO, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + TOKEN_INFO, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -92,6 +101,7 @@ void matchesTokenInfoTranslatorTestV2() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -99,7 +109,13 @@ void matchesTokenInfoTranslatorTestV2() { @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokenkey/TokenKeyTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokenkey/TokenKeyTranslatorTest.java index daab372ef262..e73285222e04 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokenkey/TokenKeyTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokenkey/TokenKeyTranslatorTest.java @@ -34,6 +34,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokenkey.TokenKeyCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokenkey.TokenKeyTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import com.hedera.node.config.testfixtures.HederaTestConfigBuilder; import com.hedera.pbj.runtime.io.buffer.Bytes; @@ -63,24 +64,38 @@ class TokenKeyTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private TokenKeyTranslator subject; @BeforeEach void setUp() { - subject = new TokenKeyTranslator(); + subject = new TokenKeyTranslator(systemContractMethodRegistry); } @Test void matchesTokenKeyTranslatorTest() { attempt = prepareHtsAttemptWithSelector( - TOKEN_KEY, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + TOKEN_KEY, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokentype/TokenTypeTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokentype/TokenTypeTranslatorTest.java index f32ca405fa27..cf502207fa2e 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokentype/TokenTypeTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/tokentype/TokenTypeTranslatorTest.java @@ -32,6 +32,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokentype.TokenTypeCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokentype.TokenTypeTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeEach; @@ -57,24 +58,38 @@ class TokenTypeTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private TokenTypeTranslator subject; @BeforeEach void setUp() { - subject = new TokenTypeTranslator(); + subject = new TokenTypeTranslator(systemContractMethodRegistry); } @Test void matchesTokenTypeTest() { attempt = prepareHtsAttemptWithSelector( - TOKEN_TYPE, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + TOKEN_TYPE, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesFailsIfIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/transfer/ClassicTransfersTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/transfer/ClassicTransfersTranslatorTest.java index 5686a0a12588..89c3e4ec22f0 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/transfer/ClassicTransfersTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/transfer/ClassicTransfersTranslatorTest.java @@ -34,6 +34,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.transfer.ClassicTransfersCall; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.transfer.ClassicTransfersDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.transfer.ClassicTransfersTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import com.swirlds.common.utility.CommonUtils; import java.lang.reflect.Field; @@ -63,13 +64,16 @@ class ClassicTransfersTranslatorTest extends CallTestBase { @Mock private VerificationStrategy strategy; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private ClassicTransfersTranslator subject; private List> callTranslators; @BeforeEach void setUp() { - callTranslators = List.of(new ClassicTransfersTranslator(classicTransfersDecoder)); + callTranslators = + List.of(new ClassicTransfersTranslator(classicTransfersDecoder, systemContractMethodRegistry)); } @Test @@ -81,7 +85,7 @@ void returnsAttemptWithAuthorizingId() throws NoSuchFieldException, IllegalAcces NON_SYSTEM_LONG_ZERO_ADDRESS, true, nativeOperations)) .willReturn(strategy); - subject = new ClassicTransfersTranslator(classicTransfersDecoder); + subject = new ClassicTransfersTranslator(classicTransfersDecoder, systemContractMethodRegistry); final var call = subject.callFrom(givenV2SubjectWithV2Enabled(ABI_ID_TRANSFER_TOKEN)); Field senderIdField = ClassicTransfersCall.class.getDeclaredField("senderId"); senderIdField.setAccessible(true); @@ -97,7 +101,7 @@ void returnsAttemptWithSenderId() throws NoSuchFieldException, IllegalAccessExce NON_SYSTEM_LONG_ZERO_ADDRESS, true, nativeOperations)) .willReturn(strategy); - subject = new ClassicTransfersTranslator(classicTransfersDecoder); + subject = new ClassicTransfersTranslator(classicTransfersDecoder, systemContractMethodRegistry); final var call = subject.callFrom(givenV2SubjectWithV2Enabled(ABI_ID_CRYPTO_TRANSFER_V2)); Field senderIdField = ClassicTransfersCall.class.getDeclaredField("senderId"); senderIdField.setAccessible(true); @@ -119,6 +123,7 @@ private HtsCallAttempt givenV2SubjectWithV2Enabled(final String functionSelector verificationStrategies, gasCalculator, callTranslators, + systemContractMethodRegistry, false); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateExpiryTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateExpiryTranslatorTest.java index 0221387dd9c0..df265c0bc742 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateExpiryTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateExpiryTranslatorTest.java @@ -38,6 +38,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.update.UpdateDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.update.UpdateExpiryTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import java.time.Instant; import org.apache.tuweni.bytes.Bytes; @@ -67,6 +68,8 @@ class UpdateExpiryTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private UpdateExpiryTranslator subject; private final UpdateDecoder decoder = new UpdateDecoder(); @@ -77,7 +80,7 @@ class UpdateExpiryTranslatorTest { @BeforeEach void setUp() { - subject = new UpdateExpiryTranslator(decoder); + subject = new UpdateExpiryTranslator(decoder, systemContractMethodRegistry); } @Test @@ -88,7 +91,8 @@ void matchesUpdateExpiryV1Test() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -100,7 +104,8 @@ void matchesUpdateExpiryV2Test() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -112,7 +117,8 @@ void matchesFailsIfIncorrectSelectorTest() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateKeysTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateKeysTranslatorTest.java index ec187f0ae306..b2a2423e727b 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateKeysTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateKeysTranslatorTest.java @@ -27,6 +27,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.freeze.FreezeUnfreezeTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.update.UpdateDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.update.UpdateKeysTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -51,13 +52,15 @@ class UpdateKeysTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private UpdateKeysTranslator subject; private final UpdateDecoder decoder = new UpdateDecoder(); @BeforeEach void setUp() { - subject = new UpdateKeysTranslator(decoder); + subject = new UpdateKeysTranslator(decoder, systemContractMethodRegistry); } @Test @@ -68,7 +71,8 @@ void matchesUpdateKeysTest() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -80,7 +84,8 @@ void matchesIncorrectSelectorFailsTest() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateNFTsMetadataTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateNFTsMetadataTranslatorTest.java index f14f58436c71..9981f9e0c1e8 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateNFTsMetadataTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateNFTsMetadataTranslatorTest.java @@ -31,6 +31,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.update.UpdateDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.update.UpdateNFTsMetadataTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.testfixtures.HederaTestConfigBuilder; import com.swirlds.config.api.Configuration; @@ -66,7 +67,7 @@ class UpdateNFTsMetadataTranslatorTest { @BeforeEach void setUp() { - subject = new UpdateNFTsMetadataTranslator(decoder); + subject = new UpdateNFTsMetadataTranslator(decoder, new SystemContractMethodRegistry()); } @Test diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateTranslatorTest.java index 13d92969da66..a7bc8280835a 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/update/UpdateTranslatorTest.java @@ -54,6 +54,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.freeze.FreezeUnfreezeTranslator; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.update.UpdateDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.update.UpdateTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import com.hedera.node.app.service.token.ReadableAccountStore; @@ -96,6 +97,8 @@ class UpdateTranslatorTest extends CallTestBase { @Mock Configuration configuration; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private UpdateTranslator subject; private final UpdateDecoder decoder = new UpdateDecoder(); @@ -115,7 +118,7 @@ class UpdateTranslatorTest extends CallTestBase { @BeforeEach void setUp() { - subject = new UpdateTranslator(decoder); + subject = new UpdateTranslator(decoder, systemContractMethodRegistry); } @Test @@ -187,7 +190,8 @@ void matchesUpdateV1Test() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -199,7 +203,8 @@ void matchesUpdateV2Test() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -211,7 +216,8 @@ void matchesUpdateV3Test() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @@ -226,6 +232,7 @@ void matchesUpdateMetadataTest() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -238,7 +245,8 @@ void matchesFailsOnIncorrectSelector() { enhancement, addressIdConverter, verificationStrategies, - gasCalculator); + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } @@ -247,12 +255,16 @@ void callFromUpdateTest() { Tuple tuple = new Tuple(NON_FUNGIBLE_TOKEN_HEADLONG_ADDRESS, hederaToken); Bytes inputBytes = Bytes.wrapByteBuffer(TOKEN_UPDATE_INFO_FUNCTION_V1.encodeCall(tuple)); given(attempt.input()).willReturn(inputBytes); - given(attempt.isSelector(TOKEN_UPDATE_INFO_FUNCTION_V1)).willReturn(true); + given(attempt.isSelector(TOKEN_UPDATE_INFO_FUNCTION_V1.function())).willReturn(true); + lenient() + .when(attempt.isSelector(TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA.function())) + .thenReturn(false); + lenient() + .when(attempt.isSelector(TOKEN_UPDATE_INFO_FUNCTION_V2.function())) + .thenReturn(false); lenient() - .when(attempt.isSelector(TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA)) + .when(attempt.isSelector(TOKEN_UPDATE_INFO_FUNCTION_V3.function())) .thenReturn(false); - lenient().when(attempt.isSelector(TOKEN_UPDATE_INFO_FUNCTION_V2)).thenReturn(false); - lenient().when(attempt.isSelector(TOKEN_UPDATE_INFO_FUNCTION_V3)).thenReturn(false); given(attempt.enhancement()).willReturn(mockEnhancement()); given(attempt.addressIdConverter()).willReturn(addressIdConverter); given(addressIdConverter.convertSender(any())).willReturn(NON_SYSTEM_ACCOUNT_ID); diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/updatetokencustomfees/UpdateTokenCustomFeesTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/updatetokencustomfees/UpdateTokenCustomFeesTranslatorTest.java index d658d3081494..3b1bc5c29612 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/updatetokencustomfees/UpdateTokenCustomFeesTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/updatetokencustomfees/UpdateTokenCustomFeesTranslatorTest.java @@ -41,6 +41,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.updatetokencustomfees.UpdateTokenCustomFeesDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.updatetokencustomfees.UpdateTokenCustomFeesTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.common.CallTestBase; import com.hedera.node.config.data.ContractsConfig; @@ -80,13 +81,15 @@ class UpdateTokenCustomFeesTranslatorTest extends CallTestBase { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private final UpdateTokenCustomFeesDecoder decoder = new UpdateTokenCustomFeesDecoder(); private UpdateTokenCustomFeesTranslator subject; @BeforeEach void setUp() { - subject = new UpdateTokenCustomFeesTranslator(decoder); + subject = new UpdateTokenCustomFeesTranslator(decoder, systemContractMethodRegistry); } @Test @@ -100,6 +103,7 @@ void matchesIsTrueWhenSelectorForFungibleIsCorrect() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -115,6 +119,7 @@ void matchesIsTrueWhenSelectorForNFTIsCorrect() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertTrue(subject.matches(attempt)); } @@ -138,6 +143,7 @@ void matchesIsFalseWhenSelectorsAreIncorrect() { addressIdConverter, verificationStrategies, gasCalculator, + systemContractMethodRegistry, configuration); assertFalse(subject.matches(attempt)); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/wipe/WipeTranslatorTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/wipe/WipeTranslatorTest.java index fa616351155a..014fe8cae153 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/wipe/WipeTranslatorTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/wipe/WipeTranslatorTest.java @@ -28,6 +28,7 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallAttempt; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.wipe.WipeDecoder; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.wipe.WipeTranslator; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater.Enhancement; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,40 +54,66 @@ public class WipeTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private final WipeDecoder decoder = new WipeDecoder(); private WipeTranslator subject; @BeforeEach void setup() { - subject = new WipeTranslator(decoder); + subject = new WipeTranslator(decoder, systemContractMethodRegistry); } @Test void matchesWipeFungibleV1Test() { attempt = prepareHtsAttemptWithSelector( - WIPE_FUNGIBLE_V1, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + WIPE_FUNGIBLE_V1, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesWipeFungibleV2Test() { attempt = prepareHtsAttemptWithSelector( - WIPE_FUNGIBLE_V1, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + WIPE_FUNGIBLE_V1, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchesWipeNftTest() { attempt = prepareHtsAttemptWithSelector( - WIPE_FUNGIBLE_V1, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + WIPE_FUNGIBLE_V1, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertTrue(subject.matches(attempt)); } @Test void matchFailsOnIncorrectSelectorTest() { attempt = prepareHtsAttemptWithSelector( - BURN_TOKEN_V2, subject, enhancement, addressIdConverter, verificationStrategies, gasCalculator); + BURN_TOKEN_V2, + subject, + enhancement, + addressIdConverter, + verificationStrategies, + gasCalculator, + systemContractMethodRegistry); assertFalse(subject.matches(attempt)); } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/utils/SystemContractMethodRegistryTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/utils/SystemContractMethodRegistryTest.java new file mode 100644 index 000000000000..96e922e3e792 --- /dev/null +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/utils/SystemContractMethodRegistryTest.java @@ -0,0 +1,143 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hedera.node.app.service.contract.impl.test.exec.utils; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.esaulpaugh.headlong.abi.Function; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.getevmaddressalias.EvmAddressAliasTranslator; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.hbarapprove.HbarApproveTranslator; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.isvalidalias.IsValidAliasTranslator; +import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.ReturnTypes; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.SystemContract; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethod.Variant; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class SystemContractMethodRegistryTest { + + @Test + void testMethodCreationHappyPath() { + + final var signature = new Function("collectReward(string)", ReturnTypes.ADDRESS); + final var subject = SystemContractMethod.declare( + signature.getCanonicalSignature(), + signature.getOutputs().toString()) + .withContract(SystemContract.EXCHANGE) + .withVia(CallVia.DIRECT); + + assertThat(subject.methodName()).isEqualTo("collectReward"); + assertThat(subject.qualifiedMethodName()).isEqualTo("EXCHANGE.collectReward"); + assertThat(subject.signature()).isEqualTo("collectReward(string)"); + assertThat(subject.signatureWithReturn()).isEqualTo("collectReward(string):(address)"); + assertThat(subject.selectorLong()).isEqualTo(0x3cbf0049L); + assertThat(subject.selectorHex()).isEqualTo("3cbf0049"); + } + + @Test + void testMethodCreationVariations() { + + final var signature = new Function("collectReward(string)", ReturnTypes.ADDRESS); + + // Proxy + final var subjectProxy = SystemContractMethod.declare( + signature.getCanonicalSignature(), + signature.getOutputs().toString()) + .withContract(SystemContract.EXCHANGE) + .withVia(CallVia.PROXY); + assertThat(subjectProxy.qualifiedMethodName()).isEqualTo("EXCHANGE(PROXY).collectReward"); + + // Variant method name + final var subjectOverrideName = SystemContractMethod.declare( + signature.getCanonicalSignature(), + signature.getOutputs().toString()) + .withContract(SystemContract.EXCHANGE) + .withVariant(Variant.NFT); + assertThat(subjectOverrideName.qualifiedMethodName()).isEqualTo("EXCHANGE.collectReward_NFT"); + assertThat(subjectOverrideName.signature()).isEqualTo("collectReward(string)"); + assertThat(subjectOverrideName.selectorLong()).isEqualTo(0x3cbf0049L); + } + + @Test + void testHappyMethodRegistrations() { + + final var subject = new SystemContractMethodRegistry(); + + // Add some registrations by simply creating instances of classes known to register methods + + final var t1 = new IsValidAliasTranslator(subject); + final var t2 = new HbarApproveTranslator(subject); + final var t3 = new EvmAddressAliasTranslator(subject); + + // Test expected methods are registered (test data is known from looking at the classes involved) + + // HAS(PROXY).hbarApprove: 0x86aff07c - hbarApprove(address,int256):(int64) + // HAS.getEvmAddressAlias: 0xdea3d081 - getEvmAddressAlias(address):(int64,address) + // HAS.hbarApprove: 0xa0918464 - hbarApprove(address,address,int256):(int64) + // HAS.isValidAlias: 0x308ef301 - isValidAlias(address):(bool) + + final var actualAllQualifiedMethods = subject.allQualifiedMethods(); + assertThat(actualAllQualifiedMethods) + .hasSize(4) + .containsExactlyInAnyOrder( + "HAS.isValidAlias", "HAS.getEvmAddressAlias", "HAS.hbarApprove", "HAS(PROXY).hbarApprove"); + + final var actualAllSignatures = subject.allSignatures(); + assertThat(actualAllSignatures) + .hasSize(4) + .containsExactlyInAnyOrder( + "getEvmAddressAlias(address)", + "hbarApprove(address,address,int256)", + "hbarApprove(address,int256)", + "isValidAlias(address)"); + + final var actualAllSignaturesWithReturns = subject.allSignaturesWithReturns(); + assertThat(actualAllSignaturesWithReturns) + .hasSize(4) + .containsExactlyInAnyOrder( + "getEvmAddressAlias(address):(int64,address)", + "hbarApprove(address,address,int256):(int64)", + "hbarApprove(address,int256):(int64)", + "isValidAlias(address):(bool)"); + } + + @Test + void testDuplicateMethodRegistrationRegistersOnlyOneCopy() { + + final var subject = new SystemContractMethodRegistry(); + + // Add some registrations twice - this might happen if a `FooTranslator` isn't marked `@Singleton` + final var t1 = new IsValidAliasTranslator(subject); + final var t2 = new IsValidAliasTranslator(subject); + + // Test only one method is registered + + final var actualAllQualifiedMethods = subject.allQualifiedMethods(); + assertThat(actualAllQualifiedMethods).hasSize(1).containsExactly("HAS.isValidAlias"); + + final var actualAllSignatures = subject.allSignatures(); + assertThat(actualAllSignatures).hasSize(1).containsExactly("isValidAlias(address)"); + + final var actualAllSignaturesWithReturns = subject.allSignaturesWithReturns(); + assertThat(actualAllSignaturesWithReturns).hasSize(1).containsExactly("isValidAlias(address):(bool)"); + } +} diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCallHandlerTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCallHandlerTest.java index 5d22d1890543..9070a3fb8587 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCallHandlerTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCallHandlerTest.java @@ -37,6 +37,7 @@ import com.hedera.node.app.service.contract.impl.exec.ContextTransactionProcessor; import com.hedera.node.app.service.contract.impl.exec.TransactionComponent; import com.hedera.node.app.service.contract.impl.exec.metrics.ContractMetrics; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.handlers.ContractCallHandler; import com.hedera.node.app.service.contract.impl.records.ContractCallStreamBuilder; import com.hedera.node.app.service.contract.impl.state.RootProxyWorldUpdater; @@ -92,14 +93,17 @@ class ContractCallHandlerTest extends ContractHandlerTestBase { @Mock private ContractsConfig contractsConfig; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private final Metrics metrics = new NoOpMetrics(); - private final ContractMetrics contractMetrics = new ContractMetrics(() -> metrics, () -> contractsConfig); + private final ContractMetrics contractMetrics = + new ContractMetrics(() -> metrics, () -> contractsConfig, systemContractMethodRegistry); private ContractCallHandler subject; @BeforeEach void setUp() { - contractMetrics.createContractMetrics(); + contractMetrics.createContractPrimaryMetrics(); given(contractServiceComponent.contractMetrics()).willReturn(contractMetrics); subject = new ContractCallHandler(() -> factory, gasCalculator, contractServiceComponent); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCallLocalHandlerTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCallLocalHandlerTest.java index 84d6d535d7ae..d2e5fd8afdbf 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCallLocalHandlerTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCallLocalHandlerTest.java @@ -40,9 +40,11 @@ import com.hedera.hapi.node.transaction.Query; import com.hedera.node.app.hapi.utils.fee.FeeBuilder; import com.hedera.node.app.hapi.utils.fee.SigValueObj; +import com.hedera.node.app.service.contract.impl.ContractServiceComponent; import com.hedera.node.app.service.contract.impl.exec.CallOutcome; import com.hedera.node.app.service.contract.impl.exec.ContextQueryProcessor; import com.hedera.node.app.service.contract.impl.exec.QueryComponent; +import com.hedera.node.app.service.contract.impl.exec.metrics.ContractMetrics; import com.hedera.node.app.service.contract.impl.handlers.ContractCallLocalHandler; import com.hedera.node.app.service.token.ReadableAccountStore; import com.hedera.node.app.service.token.ReadableTokenStore; @@ -61,6 +63,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.Mock.Strictness; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -120,9 +123,16 @@ class ContractCallLocalHandlerTest { private ContractCallLocalHandler subject; + @Mock(strictness = Strictness.LENIENT) + private ContractServiceComponent contractServiceComponent; + + @Mock + private ContractMetrics contractMetrics; + @BeforeEach void setUp() { - subject = new ContractCallLocalHandler(() -> factory, gasCalculator, instantSource); + given(contractServiceComponent.contractMetrics()).willReturn(contractMetrics); + subject = new ContractCallLocalHandler(() -> factory, gasCalculator, instantSource, contractServiceComponent); } @Test diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCreateHandlerTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCreateHandlerTest.java index 75b78bdc1136..2441a5619770 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCreateHandlerTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/ContractCreateHandlerTest.java @@ -41,6 +41,7 @@ import com.hedera.node.app.service.contract.impl.exec.ContextTransactionProcessor; import com.hedera.node.app.service.contract.impl.exec.TransactionComponent; import com.hedera.node.app.service.contract.impl.exec.metrics.ContractMetrics; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.handlers.ContractCreateHandler; import com.hedera.node.app.service.contract.impl.records.ContractCreateStreamBuilder; import com.hedera.node.app.service.contract.impl.state.RootProxyWorldUpdater; @@ -98,14 +99,17 @@ class ContractCreateHandlerTest extends ContractHandlerTestBase { @Mock private ContractsConfig contractsConfig; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private final Metrics metrics = new NoOpMetrics(); - private final ContractMetrics contractMetrics = new ContractMetrics(() -> metrics, () -> contractsConfig); + private final ContractMetrics contractMetrics = + new ContractMetrics(() -> metrics, () -> contractsConfig, systemContractMethodRegistry); private ContractCreateHandler subject; @BeforeEach void setUp() { - contractMetrics.createContractMetrics(); + contractMetrics.createContractPrimaryMetrics(); given(contractServiceComponent.contractMetrics()).willReturn(contractMetrics); subject = new ContractCreateHandler(() -> factory, gasCalculator, contractServiceComponent); } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/EthereumTransactionHandlerTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/EthereumTransactionHandlerTest.java index c87e79f5ed42..bd77278249c0 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/EthereumTransactionHandlerTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/handlers/EthereumTransactionHandlerTest.java @@ -50,6 +50,7 @@ import com.hedera.node.app.service.contract.impl.exec.gas.CustomGasCharging; import com.hedera.node.app.service.contract.impl.exec.metrics.ContractMetrics; import com.hedera.node.app.service.contract.impl.exec.tracers.EvmActionTracer; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry; import com.hedera.node.app.service.contract.impl.handlers.EthereumTransactionHandler; import com.hedera.node.app.service.contract.impl.hevm.HederaEvmContext; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; @@ -165,12 +166,15 @@ class EthereumTransactionHandlerTest { @Mock private ContractsConfig contractsConfig; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private final Metrics metrics = new NoOpMetrics(); - private final ContractMetrics contractMetrics = new ContractMetrics(() -> metrics, () -> contractsConfig); + private final ContractMetrics contractMetrics = + new ContractMetrics(() -> metrics, () -> contractsConfig, systemContractMethodRegistry); @BeforeEach void setUp() { - contractMetrics.createContractMetrics(); + contractMetrics.createContractPrimaryMetrics(); given(contractServiceComponent.contractMetrics()).willReturn(contractMetrics); subject = new EthereumTransactionHandler( ethereumSignatures, callDataHydration, () -> factory, gasCalculator, contractServiceComponent);