From fcac14d9075da0d9254c9b757f47e8d841b0c57d 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 | 14 +- .../impl/ContractServiceComponent.java | 24 ++- .../contract/impl/ContractServiceImpl.java | 70 ++++++- .../impl/exec/metrics/ContractMetrics.java | 53 ++++- .../common/AbstractCallAttempt.java | 26 +++ .../common/AbstractCallTranslator.java | 80 ++++++++ .../systemcontracts/has/HasCallAttempt.java | 9 + .../systemcontracts/has/HasCallFactory.java | 7 +- .../EvmAddressAliasTranslator.java | 7 +- .../HbarAllowanceTranslator.java | 8 +- .../hbarapprove/HbarApproveTranslator.java | 8 +- .../HederaAccountNumAliasTranslator.java | 9 +- .../isauthorized/IsAuthorizedTranslator.java | 8 +- .../IsAuthorizedRawTranslator.java | 8 +- .../isvalidalias/IsValidAliasTranslator.java | 9 +- ...etUnlimitedAutoAssociationsTranslator.java | 8 +- .../systemcontracts/hss/HssCallAttempt.java | 9 + .../systemcontracts/hss/HssCallFactory.java | 7 +- .../signschedule/SignScheduleTranslator.java | 8 +- .../systemcontracts/hts/HtsCallAttempt.java | 9 + .../systemcontracts/hts/HtsCallFactory.java | 7 +- .../hts/airdrops/TokenAirdropTranslator.java | 11 +- .../hts/allowance/GetAllowanceTranslator.java | 8 +- .../TokenCancelAirdropDecoder.java | 2 +- .../TokenCancelAirdropTranslator.java | 18 +- .../TokenClaimAirdropDecoder.java | 2 +- .../TokenClaimAirdropTranslator.java | 18 +- .../customfees/TokenCustomFeesTranslator.java | 9 +- .../hts/freeze/FreezeUnfreezeTranslator.java | 9 +- .../FungibleTokenInfoTranslator.java | 10 +- .../getapproved/GetApprovedTranslator.java | 8 +- .../GrantApprovalTranslator.java | 12 +- .../GrantRevokeKycTranslator.java | 9 +- .../IsApprovedForAllTranslator.java | 8 +- .../isassociated/IsAssociatedTranslator.java | 7 +- .../hts/isfrozen/IsFrozenTranslator.java | 9 +- .../hts/iskyc/IsKycTranslator.java | 9 +- .../hts/istoken/IsTokenTranslator.java | 9 +- .../hts/mint/MintTranslator.java | 10 +- .../hts/name/NameTranslator.java | 7 +- .../nfttokeninfo/NftTokenInfoTranslator.java | 10 +- .../hts/ownerof/OwnerOfTranslator.java | 7 +- .../hts/pauses/PausesTranslator.java | 9 +- .../rejecttokens/RejectTokensTranslator.java | 13 +- .../SetApprovalForAllTranslator.java | 12 +- .../hts/symbol/SymbolTranslator.java | 7 +- .../tokenexpiry/TokenExpiryTranslator.java | 9 +- .../hts/tokeninfo/TokenInfoTranslator.java | 9 +- .../hts/tokenkey/TokenKeyTranslator.java | 9 +- .../hts/tokentype/TokenTypeTranslator.java | 9 +- .../hts/tokenuri/TokenUriTranslator.java | 7 +- .../totalsupply/TotalSupplyTranslator.java | 7 +- .../hts/update/UpdateExpiryTranslator.java | 11 +- .../hts/update/UpdateKeysTranslator.java | 11 +- .../update/UpdateNFTsMetadataTranslator.java | 11 +- .../hts/update/UpdateTranslator.java | 14 +- .../UpdateTokenCustomFeesTranslator.java | 12 +- .../hts/wipe/WipeTranslator.java | 11 +- .../utils/SystemContractMethodRegistry.java | 188 ++++++++++++++++++ .../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 | 25 ++- .../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 | 8 +- .../IsValidAliasTranslatorTest.java | 11 +- ...limitedAutoAssociationsTranslatorTest.java | 7 +- .../hss/HssCallAttemptTest.java | 7 +- .../hss/HssCallFactoryTest.java | 6 +- .../SignScheduleTranslatorTest.java | 20 +- .../hts/HtsCallAttemptTest.java | 34 +++- .../hts/HtsCallFactoryTest.java | 9 +- .../airdrops/TokenAirdropTranslatorTest.java | 8 +- .../allowance/GetAllowanceTranslatorTest.java | 24 ++- .../hts/burn/BurnTranslatorTest.java | 22 +- .../TokenCancelAirdropDecoderTest.java | 10 +- .../TokenCancelAirdropTranslatorTest.java | 21 +- .../TokenClaimAirdropDecoderTest.java | 10 +- .../TokenClaimAirdropTranslatorTest.java | 21 +- .../hts/create/CreateTranslatorTest.java | 51 +++-- .../TokenCustomFeesTranslatorTest.java | 21 +- .../DefaultFreezeStatusTranslatorTest.java | 19 +- .../DefaultKycStatusTranslatorTest.java | 19 +- .../hts/delete/DeleteTranslatorTest.java | 19 +- .../freeze/FreezeUnfreezeTranslatorTest.java | 29 ++- .../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 ++- .../NftTokenInfoTranslatorTest.java | 17 +- .../hts/pauses/PausesTranslatorTest.java | 29 ++- .../RejectTokensTranslatorTest.java | 15 +- .../SetApprovalForAllTranslatorTest.java | 24 ++- .../TokenExpiryTranslatorTest.java | 21 +- .../tokeninfo/TokenInfoTranslatorTest.java | 22 +- .../hts/tokenkey/TokenKeyTranslatorTest.java | 21 +- .../tokentype/TokenTypeTranslatorTest.java | 21 +- .../ClassicTransfersTranslatorTest.java | 4 + .../update/UpdateExpiryTranslatorTest.java | 14 +- .../hts/update/UpdateKeysTranslatorTest.java | 11 +- .../UpdateNFTsMetadataTranslatorTest.java | 3 +- .../hts/update/UpdateTranslatorTest.java | 18 +- .../UpdateTokenCustomFeesTranslatorTest.java | 8 +- .../hts/wipe/WipeTranslatorTest.java | 37 +++- .../SystemContractMethodRegistryTest.java | 132 ++++++++++++ .../handlers/ContractCallHandlerTest.java | 8 +- .../ContractCallLocalHandlerTest.java | 12 +- .../handlers/ContractCreateHandlerTest.java | 8 +- .../EthereumTransactionHandlerTest.java | 8 +- 124 files changed, 1862 insertions(+), 252 deletions(-) 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 8eb512776b59..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; @@ -603,11 +605,19 @@ public void onStateInitialized( trigger, RosterUtils.buildAddressBook(platform.getRoster()), platform.getContext().getConfiguration()); - - contractServiceImpl.registerMetrics(); } // With the States API grounded in the working state, we can create the object graph from it initializeDagger(state, trigger); + + // 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 4dbab82f2999..eea61b8e5c12 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,6 +24,7 @@ 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.metrics.api.Counter; import com.swirlds.metrics.api.Metric; @@ -53,6 +54,7 @@ public class ContractMetrics { 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<>(); @@ -81,22 +83,31 @@ 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"); } - public void createContractMetrics() { + // -------------------- + // 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(); - this.p2MetricsEnabled = contractsConfig.metricsSmartContractSecondaryEnabled(); - - final var metrics = requireNonNull(metricsSupplier.get()); 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); @@ -131,12 +142,33 @@ public void createContractMetrics() { 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) { - // PLACEHOLDER + final var metrics = requireNonNull(metricsSupplier.get()); + // TBD } } + // --------------------------------- + // P1 metrics: `pureCheck` failures + public void incrementRejectedTx(@NonNull final HederaFunctionality txKind) { bumpRejectedTx(txKind, 1); } @@ -162,6 +194,12 @@ public void bumpRejectedType3EthTx(final long bumpBy) { if (p1MetricsEnabled) rejectedEthType3Counter.add(bumpBy); } + // --------------------------------------------- + // P2 metrics: System contract per-method counts + + // ----------------- + // Unit test helpers + @VisibleForTesting public @NonNull Map getAllCounters() { return Stream.concat( @@ -204,6 +242,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); } 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..dd7499025cef 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,7 @@ 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.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 +55,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 +91,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 +104,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 +131,8 @@ public AbstractCallAttempt( this.isStaticCall = isStaticCall; } + protected abstract SystemContractMethodRegistry.SystemContract systemContractKind(); + protected abstract T self(); /** @@ -263,6 +269,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 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..f11c2c155b0a 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,10 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.CallVia; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -27,6 +31,23 @@ * @param the type of the abstract call translator */ public abstract class AbstractCallTranslator> implements CallTranslator { + + private final SystemContractMethodRegistry.SystemContract systemContractKind; + private final SystemContractMethodRegistry systemContractMethodRegistry; + + @Deprecated // All translators should use the other constructor and register their methods + public AbstractCallTranslator() { + this.systemContractKind = null; + this.systemContractMethodRegistry = null; + } + + public AbstractCallTranslator( + @NonNull final SystemContractMethodRegistry.SystemContract systemContractKind, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + this.systemContractKind = requireNonNull(systemContractKind); + this.systemContractMethodRegistry = requireNonNull(systemContractMethodRegistry); + } + /** * {@inheritDoc} */ @@ -38,4 +59,63 @@ 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 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, 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, 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..b3e0e98547c7 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,8 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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 +70,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 +84,7 @@ public HasCallAttempt( gasCalculator, callTranslators, isStaticCall, + systemContractMethodRegistry, REDIRECT_FOR_ACCOUNT); if (isRedirect()) { this.redirectAccount = linkedAccount(requireNonNull(redirectAddress)); @@ -90,6 +94,11 @@ public HasCallAttempt( this.signatureVerifier = requireNonNull(signatureVerifier); } + @Override + protected SystemContract systemContractKind() { + return SystemContractMethodRegistry.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..70d9f6f26c77 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 @@ -23,6 +23,8 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -37,8 +39,11 @@ public class EvmAddressAliasTranslator extends AbstractCallTranslator { /** Selector for getHederaAccountNumAlias(address) method. */ @@ -36,8 +40,11 @@ public class HederaAccountNumAliasTranslator extends AbstractCallTranslator { /** Selector for isValidAlias(address) method. */ @@ -36,8 +40,11 @@ public class IsValidAliasTranslator extends AbstractCallTranslator> callTranslators, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry, final boolean isStaticCall) { super( input, @@ -76,6 +79,7 @@ public HssCallAttempt( gasCalculator, callTranslators, isStaticCall, + systemContractMethodRegistry, REDIRECT_FOR_SCHEDULE_TXN); if (isRedirect()) { this.redirectScheduleTxn = linkedSchedule(requireNonNull(redirectAddress)); @@ -84,6 +88,11 @@ public HssCallAttempt( } } + @Override + protected SystemContract systemContractKind() { + return SystemContractMethodRegistry.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..3d047cf92868 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 @@ -40,6 +40,8 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import com.hedera.node.config.data.ContractsConfig; import edu.umd.cs.findbugs.annotations.NonNull; @@ -57,8 +59,12 @@ public class SignScheduleTranslator extends AbstractCallTranslator> callTranslators, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry, final boolean isStaticCall) { super( input, @@ -86,6 +89,7 @@ public HtsCallAttempt( gasCalculator, callTranslators, isStaticCall, + systemContractMethodRegistry, REDIRECT_FOR_TOKEN); if (isRedirect()) { this.redirectToken = linkedToken(redirectAddress); @@ -96,6 +100,11 @@ public HtsCallAttempt( (authorizingAddress != senderAddress) ? addressIdConverter.convertSender(authorizingAddress) : senderId; } + @Override + protected SystemContract systemContractKind() { + return SystemContractMethodRegistry.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..ba849b6d3160 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 @@ -27,11 +27,15 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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 = @@ -40,9 +44,14 @@ public class TokenAirdropTranslator extends AbstractCallTranslator { // Actual signature definition with struct name before flattening // cancelAirdrops(PendingAirdrop[]) - public static final Function CANCEL_AIRDROP = + public static final Function CANCEL_AIRDROPS = 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 = @@ -46,9 +50,15 @@ public class TokenCancelAirdropTranslator extends AbstractCallTranslator { - public static final Function CLAIM_AIRDROP = + public static final Function CLAIM_AIRDROPS = 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 = @@ -41,8 +45,14 @@ public class TokenClaimAirdropTranslator extends AbstractCallTranslator { public static final Function TOKEN_CUSTOM_FEES = new Function("getTokenCustomFees(address)", ReturnTypes.RESPONSE_CODE_CUSTOM_FEES); @Inject - public TokenCustomFeesTranslator() { + public TokenCustomFeesTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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/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..f649008f33d1 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 @@ -28,6 +28,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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.Arrays; @@ -50,8 +52,13 @@ public class FreezeUnfreezeTranslator extends AbstractCallTranslator { /** Selector for getFungibleTokenInfo(address) method. */ @@ -42,8 +46,12 @@ public class FungibleTokenInfoTranslator extends AbstractCallTranslator { /** Selector for isFrozen(address,address) method. */ public static final Function IS_FROZEN = new Function("isFrozen(address,address)", ReturnTypes.RESPONSE_CODE_BOOL); @@ -34,8 +38,11 @@ public class IsFrozenTranslator extends AbstractCallTranslator { * Default constructor for injection. */ @Inject - public IsFrozenTranslator() { + public IsFrozenTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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..51429268be67 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 @@ -23,9 +23,13 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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); @@ -34,8 +38,11 @@ public class IsKycTranslator extends AbstractCallTranslator { * Default constructor for injection. */ @Inject - public IsKycTranslator() { + public IsKycTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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..0fad7d87954e 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 @@ -23,9 +23,13 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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); @@ -34,8 +38,11 @@ public class IsTokenTranslator extends AbstractCallTranslator { * Default constructor for injection. */ @Inject - public IsTokenTranslator() { + public IsTokenTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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..cac32f3497de 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 @@ -27,6 +27,8 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; @@ -48,8 +50,14 @@ 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(SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethod("mintToken-V1", MINT); + registerMethod("mintToken-V2", 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..a1de64c8cd2c 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 @@ -20,6 +20,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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -36,8 +38,11 @@ public class NameTranslator extends AbstractCallTranslator { * Default constructor for injection. */ @Inject - public NameTranslator() { + public NameTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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/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..314ab2d37b9d 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 @@ -24,10 +24,14 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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. */ @@ -42,8 +46,12 @@ public class NftTokenInfoTranslator extends AbstractCallTranslator { * Default constructor for injection. */ @Inject - public OwnerOfTranslator() { + public OwnerOfTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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..176dbc123f4f 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 @@ -26,6 +26,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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; @@ -48,8 +50,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(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..0c71c8b77765 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,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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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,7 +36,9 @@ 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); @@ -45,8 +49,15 @@ public class RejectTokensTranslator extends AbstractCallTranslator gasCalculators = new HashMap<>(); @Inject - public RejectTokensTranslator(@NonNull final RejectTokensDecoder decoder) { + public RejectTokensTranslator( + @NonNull final RejectTokensDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethods(TOKEN_REJECT); + registerProxyMethods(HRC_TOKEN_REJECT_FT, HRC_TOKEN_REJECT_NFT); + gasCalculators.put(TOKEN_REJECT, RejectTokensTranslator::gasRequirement); gasCalculators.put(HRC_TOKEN_REJECT_FT, RejectTokensTranslator::gasRequirementHRCFungible); gasCalculators.put(HRC_TOKEN_REJECT_NFT, RejectTokensTranslator::gasRequirementHRCNft); 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..8eb23b941369 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 @@ -26,14 +26,18 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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. */ @@ -49,8 +53,14 @@ public class SetApprovalForAllTranslator extends AbstractCallTranslator { * Default constructor for injection. */ @Inject - public SymbolTranslator() { + public SymbolTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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..a3fdf7bd60d8 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 @@ -23,12 +23,16 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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 = @@ -38,8 +42,11 @@ public class TokenExpiryTranslator extends AbstractCallTranslator { /** Selector for getTokenInfo(address) method. */ public static final Function TOKEN_INFO = @@ -43,8 +47,11 @@ public class TokenInfoTranslator extends AbstractCallTranslator * Default constructor for injection. */ @Inject - public TokenInfoTranslator() { + public TokenInfoTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethods(TOKEN_INFO, TOKEN_INFO_V2); } /** 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..483143c72aa2 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 @@ -26,14 +26,18 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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 = @@ -43,8 +47,11 @@ public class TokenKeyTranslator extends AbstractCallTranslator { * Default constructor for injection. */ @Inject - public TokenKeyTranslator() { + public TokenKeyTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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..94de250e55ec 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 @@ -23,12 +23,16 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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); @@ -37,8 +41,11 @@ public class TokenTypeTranslator extends AbstractCallTranslator * Default constructor for injection. */ @Inject - public TokenTypeTranslator() { + public TokenTypeTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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..5e95ee0f9edb 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 @@ -23,6 +23,8 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -39,8 +41,11 @@ public class TokenUriTranslator extends AbstractCallTranslator { * Default constructor for injection. */ @Inject - public TokenUriTranslator() { + public TokenUriTranslator(@NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { // Dagger2 + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod(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..e57c8d4d8061 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 @@ -20,6 +20,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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; import edu.umd.cs.findbugs.annotations.NonNull; import javax.inject.Inject; import javax.inject.Singleton; @@ -36,8 +38,11 @@ public class TotalSupplyTranslator extends AbstractCallTranslator { /** * Selector for updateTokenExpiryInfo(address, EXPIRY) method. @@ -56,8 +60,13 @@ public class UpdateExpiryTranslator extends AbstractCallTranslator { /** Selector for updateTokenKeys(address, TOKEN_KEY[]) method. */ public static final Function TOKEN_UPDATE_KEYS_FUNCTION = @@ -45,8 +49,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(SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethod(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..399e35884522 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 @@ -26,11 +26,15 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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 = @@ -42,8 +46,13 @@ public class UpdateNFTsMetadataTranslator extends AbstractCallTranslator { private static final String UPDATE_TOKEN_INFO_STRING = "updateTokenInfo(address,"; private static final String HEDERA_TOKEN_STRUCT = @@ -66,7 +70,15 @@ public class UpdateTranslator extends AbstractCallTranslator { * @param decoder the decoder to use for token update info calls */ @Inject - public UpdateTranslator(final UpdateDecoder decoder) { + public UpdateTranslator( + final UpdateDecoder decoder, @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContract.HTS, systemContractMethodRegistry); + + registerMethod("updateTokenInfo-V1", TOKEN_UPDATE_INFO_FUNCTION_V1); + registerMethod("updateTokenInfo-V2", TOKEN_UPDATE_INFO_FUNCTION_V2); + registerMethod("updateTokenInfo-V3", TOKEN_UPDATE_INFO_FUNCTION_V3); + registerMethod("updateTokenInfo-WithMetadata", TOKEN_UPDATE_INFO_FUNCTION_WITH_METADATA); + 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); 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..816fa7d5a6d4 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 @@ -30,12 +30,16 @@ 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; 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. */ @@ -48,9 +52,15 @@ public class UpdateTokenCustomFeesTranslator extends AbstractCallTranslator { private final WipeDecoder decoder; @Inject - public WipeTranslator(@NonNull final WipeDecoder decoder) { + public WipeTranslator( + @NonNull final WipeDecoder decoder, + @NonNull final SystemContractMethodRegistry systemContractMethodRegistry) { + super(SystemContract.HTS, systemContractMethodRegistry); this.decoder = decoder; + + registerMethod("wipeTokenAccount-V1", WIPE_FUNGIBLE_V1); + registerMethod("wipeTokenAccount-V2", WIPE_FUNGIBLE_V2); + registerMethod(WIPE_NFT); } /** 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..20c792ca558d --- /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,188 @@ +/* + * 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 edu.umd.cs.findbugs.annotations.NonNull; +import java.nio.ByteOrder; +import java.util.Collection; +import java.util.SequencedCollection; +import java.util.concurrent.ConcurrentHashMap; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.apache.tuweni.bytes.Bytes; + +/** + * 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 { + + public enum SystemContract { + HTS, + HAS, + HSS, + PNRG, + EXCHANGE + } + + public enum CallVia { + DIRECT, + PROXY + } + + public record Method( + @NonNull Function function, + @NonNull SystemContract systemContract, + @NonNull String methodName, + @NonNull CallVia via) { + public Method { + requireNonNull(function); + requireNonNull(systemContract); + requireNonNull(methodName); + requireNonNull(via); + } + + /** + * "Qualified" method name has the contract name in front of it, and uses the + * provided method name, not the method name from the signature. If the provided + * method name is used to disambiguate methods with the same name but different signatures + * (a versioning method we've used) then these qualified names for all methods in the + * system contracts will be distinct (and will be suitable for use as metrics names). + */ + public @NonNull String qualifiedMethodName() { + return switch (via) { + case DIRECT -> systemContract + "." + methodName; + case PROXY -> systemContract + "(PROXY)." + methodName; + }; + } + + 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(); + } + } + + 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(SystemContract.HTS); // DEBUGGING + } + + 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 == CallVia.PROXY) keyName += "(PROXY)"; + + byName.computeIfAbsent(keyName, k -> new Method(function, systemContract, methodName, via)); + } + + public void register( + @NonNull final Function function, + @NonNull final SystemContract systemContract, + @NonNull final String methodName) { + register(function, systemContract, methodName, 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(), CallVia.DIRECT); + } + + // Queries: + + public long size() { + return byName.size(); + } + + public @NonNull SequencedCollection allQualifiedMethods() { + return allMethodsGivenMapper(Method::qualifiedMethodName); + } + + public @NonNull SequencedCollection allSignatures() { + return allMethodsGivenMapper(Method::signature); + } + + public @NonNull SequencedCollection allSignaturesWithReturns() { + return allMethodsGivenMapper(Method::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(Method::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 ebaf8b8465ed..510f2ef50128 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 @@ -64,7 +64,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 41413a18ac40..1f0419e505b9 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 @@ -38,6 +38,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; @@ -64,6 +65,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}. @@ -76,10 +78,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 @@ -137,6 +141,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 07e86d261b39..a09bdbef16a9 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 @@ -149,7 +149,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(); @@ -174,7 +174,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 4b42a682ce97..d13574962498 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..cad3b14d97ae 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,7 @@ 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.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 +56,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 +71,7 @@ public static HtsCallAttempt prepareHtsAttemptWithSelector( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, false); } @@ -87,7 +90,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 +105,7 @@ public static HtsCallAttempt prepareHtsAttemptWithSelectorForRedirect( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, false); } @@ -121,6 +126,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 +141,7 @@ public static HtsCallAttempt prepareHtsAttemptWithSelectorForRedirectWithConfig( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, false); } @@ -155,6 +162,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 +177,7 @@ public static HtsCallAttempt prepareHtsAttemptWithSelectorAndCustomConfig( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, false); } @@ -189,7 +198,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 +208,7 @@ public static HasCallAttempt prepareHasAttemptWithSelector( verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, DEFAULT_CONFIG); } @@ -220,6 +231,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 +242,7 @@ public static HasCallAttempt prepareHasAttemptWithSelectorAndCustomConfig( verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, config); } @@ -254,6 +267,7 @@ public static HasCallAttempt prepareHasAttemptWithSelectorAndInputAndCustomConfi final VerificationStrategies verificationStrategies, final SignatureVerifier signatureVerifier, final SystemContractGasCalculator gasCalculator, + final SystemContractMethodRegistry systemContractMethodRegistry, final Configuration config) { return new HasCallAttempt( input, @@ -266,6 +280,7 @@ public static HasCallAttempt prepareHasAttemptWithSelectorAndInputAndCustomConfi signatureVerifier, gasCalculator, List.of(translator), + systemContractMethodRegistry, false); } @@ -286,6 +301,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 +315,7 @@ public static HssCallAttempt prepareHssAttemptWithSelectorAndCustomConfig( verificationStrategies, gasCalculator, List.of(translator), + systemContractMethodRegistry, false); } @@ -309,6 +326,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 +339,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..2a2245346173 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,7 @@ 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.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 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 +100,7 @@ void matchesIsAuthorizedRawWhenEnabled() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(true)); assertTrue(subject.matches(attempt)); } @@ -112,6 +116,7 @@ void doesNotMatchIsAuthorizedRawWhenDisabled() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(false)); assertFalse(subject.matches(attempt)); } @@ -127,6 +132,7 @@ void failsOnInvalidSelector() { verificationStrategies, signatureVerifier, gasCalculator, + systemContractMethodRegistry, getTestConfiguration(true)); 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/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..ee1cd73d060d 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,21 +106,23 @@ 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 MintTranslator(mintDecoder, systemContractMethodRegistry), new ClassicTransfersTranslator(classicTransfersDecoder), new BalanceOfTranslator(), - new IsApprovedForAllTranslator(), - new NameTranslator(), - new TotalSupplyTranslator(), - new SymbolTranslator(), - new TokenUriTranslator(), - new OwnerOfTranslator(), + new IsApprovedForAllTranslator(systemContractMethodRegistry), + new NameTranslator(systemContractMethodRegistry), + new TotalSupplyTranslator(systemContractMethodRegistry), + new SymbolTranslator(systemContractMethodRegistry), + new TokenUriTranslator(systemContractMethodRegistry), + new OwnerOfTranslator(systemContractMethodRegistry), new DecimalsTranslator()); } @@ -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..e9fb97de716f 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); } @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..76593a6a5d6f 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,6 +55,8 @@ class BurnTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private BurnTranslator subject; private final BurnDecoder decoder = new BurnDecoder(); @@ -66,14 +69,26 @@ void setUp() { @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..b452143f3301 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,6 +107,8 @@ public class CreateTranslatorTest extends CallTestBase { @Mock Configuration configuration; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private CreateDecoder decoder = new CreateDecoder(); private CreateTranslator subject; @@ -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..7723c6772db2 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,6 +58,8 @@ class DefaultFreezeStatusTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private DefaultFreezeStatusTranslator subject; @BeforeEach @@ -67,14 +70,26 @@ void setUp() { @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..4ced036451c0 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,6 +58,8 @@ class DefaultKycStatusTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private DefaultKycStatusTranslator subject; @BeforeEach @@ -67,14 +70,26 @@ void setUp() { @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..f37f758e306b 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,6 +64,8 @@ class DeleteTranslatorTest { @Mock private VerificationStrategies verificationStrategies; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private DeleteTranslator subject; @BeforeEach @@ -73,14 +76,26 @@ void setUp() { @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/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/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..4e13e5a45f26 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 final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private 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/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..b8a922dbe8aa 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,6 +64,8 @@ class ClassicTransfersTranslatorTest extends CallTestBase { @Mock private VerificationStrategy strategy; + private final SystemContractMethodRegistry systemContractMethodRegistry = new SystemContractMethodRegistry(); + private ClassicTransfersTranslator subject; private List> callTranslators; @@ -119,6 +122,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..44e3152e770c 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)); } 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..b8c5ec0cf724 --- /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,132 @@ +/* + * 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.SystemContractMethodRegistry; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.CallVia; +import com.hedera.node.app.service.contract.impl.exec.utils.SystemContractMethodRegistry.SystemContract; +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 = new SystemContractMethodRegistry.Method( + signature, SystemContract.EXCHANGE, signature.getName(), 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 = new SystemContractMethodRegistry.Method( + signature, SystemContract.EXCHANGE, signature.getName(), CallVia.PROXY); + assertThat(subjectProxy.qualifiedMethodName()).isEqualTo("EXCHANGE(PROXY).collectReward"); + + // Overridden method name + final var subjectOverrideName = + new SystemContractMethodRegistry.Method(signature, SystemContract.EXCHANGE, "F00BAR", CallVia.DIRECT); + assertThat(subjectOverrideName.qualifiedMethodName()).isEqualTo("EXCHANGE.F00BAR"); + 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 de1dab4291f9..bb46e953c08d 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 6a897a9fa1fd..ae91f018a3db 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) @@ -117,9 +120,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 1a9e870bd465..5b705daf4bf7 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; @@ -164,12 +165,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);