Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

07193: Add in equivalence tests for HTS transfers #7884

Draft
wants to merge 10 commits into
base: 7193-add-in-equivalence-tests-for-internal-calls
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ public ContractResult getContractResultByTransactionId(String transactionId) {

public ContractActionsResponse getContractActions(String transactionId) {
log.debug("Verify contract actions '{}' is returned by Mirror Node", transactionId);
return callRestEndpoint("/contracts/results/{contractId}/actions", ContractActionsResponse.class, transactionId);
return callRestEndpoint(
"/contracts/results/{contractId}/actions", ContractActionsResponse.class, transactionId);
}

public NetworkExchangeRateSetResponse getExchangeRates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.hedera.mirror.test.e2e.acceptance.util.ModelBuilder;
import jakarta.inject.Named;
import java.nio.ByteBuffer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.tuweni.bytes.Bytes;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -120,19 +122,30 @@ public GeneralContractExecutionResponse contractsCall(
.estimate(isEstimate)
.value(amount != null ? amount.toTinybars() : 0);

var response = mirrorClient.contractsCall(contractCallRequestBody);
return new GeneralContractExecutionResponse(ContractCallResponseWrapper.of(response));
try {
var response = mirrorClient.contractsCall(contractCallRequestBody);
return new GeneralContractExecutionResponse(ContractCallResponseWrapper.of(response));
} catch (Exception e) {
return new GeneralContractExecutionResponse(e.getMessage());
}
} else {
final var gas = contractClient
.getSdkClient()
.getAcceptanceTestProperties()
.getFeatureProperties()
.getMaxContractFunctionGas();

final var result = contractClient.executeContract(deployedContract.contractId(), gas, method, data, amount);
final var txId = result.networkTransactionResponse().getTransactionIdStringNoCheckSum();
final var errorMessage = extractInternalCallErrorMessage(txId);
return new GeneralContractExecutionResponse(txId, result.networkTransactionResponse(), errorMessage);
try {
final var result =
contractClient.executeContract(deployedContract.contractId(), gas, method, data, amount);
final var txId = result.networkTransactionResponse().getTransactionIdStringNoCheckSum();
final var errorMessage = extractInternalCallErrorMessage(txId);
return new GeneralContractExecutionResponse(txId, result.networkTransactionResponse(), errorMessage);
} catch (Exception e) {
final var txId = extractTransactionId(e.getMessage());
final var errorMessage = extractInternalCallErrorMessage(txId);
return new GeneralContractExecutionResponse(txId, errorMessage);
}
}
}

Expand Down Expand Up @@ -171,4 +184,14 @@ private String extractInternalCallErrorMessage(String transactionId) throws Ille
var resultMessage = transactions.get(1).getResult();
return resultMessage.equalsIgnoreCase("success") ? null : resultMessage;
}

private static String extractTransactionId(String message) {
Pattern pattern = Pattern.compile("(\\d+\\.\\d+\\.\\d+)@(\\d+)\\.(\\d+)");
Matcher matcher = pattern.matcher(message);
if (matcher.find()) {
return matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3);
} else {
return "Not found";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@ public enum TokenNameEnum {
TokenType.NON_FUNGIBLE_UNIQUE,
TokenKycStatus.KycNotApplicable,
TokenFreezeStatus.FreezeNotApplicable),
NFTEQUIVALENCE(
"non_fungible",
TokenType.NON_FUNGIBLE_UNIQUE,
TokenKycStatus.KycNotApplicable,
TokenFreezeStatus.FreezeNotApplicable),
FUNGIBLE_KYC_UNFROZEN(
"fungible_kyc_unfrozen", TokenType.FUNGIBLE_COMMON, TokenKycStatus.Granted, TokenFreezeStatus.Unfrozen),
FUNGIBLE_KYC_UNFROZEN_2(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public GeneralContractExecutionResponse(
this(transactionId, networkResponse, errorMessage, null);
}

public GeneralContractExecutionResponse(String errorMessage) {
this(null, null, errorMessage, null);
}

public GeneralContractExecutionResponse(String transactionId, String errorMessage) {
this(transactionId, null, errorMessage, null);
}

public String getMirrorNodeResponseAsString() {
return contractCallResponse.getResult().substring(2);
}
Expand Down